OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """code generator for GLES2 command buffers.""" | 6 """code generator for GLES2 command buffers.""" |
7 | 7 |
8 import itertools | 8 import itertools |
9 import os | 9 import os |
10 import os.path | 10 import os.path |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 }, | 537 }, |
538 ], | 538 ], |
539 }, | 539 }, |
540 } | 540 } |
541 | 541 |
542 # Named type info object represents a named type that is used in OpenGL call | 542 # Named type info object represents a named type that is used in OpenGL call |
543 # arguments. Each named type defines a set of valid OpenGL call arguments. The | 543 # arguments. Each named type defines a set of valid OpenGL call arguments. The |
544 # named types are used in 'cmd_buffer_functions.txt'. | 544 # named types are used in 'cmd_buffer_functions.txt'. |
545 # type: The actual GL type of the named type. | 545 # type: The actual GL type of the named type. |
546 # valid: The list of values that are valid for both the client and the service. | 546 # valid: The list of values that are valid for both the client and the service. |
| 547 # valid_es3: The list of values that are valid in OpenGL ES 3, but not ES 2. |
547 # invalid: Examples of invalid values for the type. At least these values | 548 # invalid: Examples of invalid values for the type. At least these values |
548 # should be tested to be invalid. | 549 # should be tested to be invalid. |
549 # is_complete: The list of valid values of type are final and will not be | 550 # is_complete: The list of valid values of type are final and will not be |
550 # modified during runtime. | 551 # modified during runtime. |
551 _NAMED_TYPE_INFO = { | 552 _NAMED_TYPE_INFO = { |
552 'BlitFilter': { | 553 'BlitFilter': { |
553 'type': 'GLenum', | 554 'type': 'GLenum', |
554 'valid': [ | 555 'valid': [ |
555 'GL_NEAREST', | 556 'GL_NEAREST', |
556 'GL_LINEAR', | 557 'GL_LINEAR', |
(...skipping 20 matching lines...) Expand all Loading... |
577 'invalid': [ | 578 'invalid': [ |
578 'GL_FRAMEBUFFER', | 579 'GL_FRAMEBUFFER', |
579 ], | 580 ], |
580 }, | 581 }, |
581 'BufferTarget': { | 582 'BufferTarget': { |
582 'type': 'GLenum', | 583 'type': 'GLenum', |
583 'valid': [ | 584 'valid': [ |
584 'GL_ARRAY_BUFFER', | 585 'GL_ARRAY_BUFFER', |
585 'GL_ELEMENT_ARRAY_BUFFER', | 586 'GL_ELEMENT_ARRAY_BUFFER', |
586 ], | 587 ], |
| 588 'valid_es3': [ |
| 589 'GL_COPY_READ_BUFFER', |
| 590 'GL_COPY_WRITE_BUFFER', |
| 591 'GL_PIXEL_PACK_BUFFER', |
| 592 'GL_PIXEL_UNPACK_BUFFER', |
| 593 'GL_TRANSFORM_FEEDBACK_BUFFER', |
| 594 'GL_UNIFORM_BUFFER', |
| 595 ], |
587 'invalid': [ | 596 'invalid': [ |
588 'GL_RENDERBUFFER', | 597 'GL_RENDERBUFFER', |
589 ], | 598 ], |
590 }, | 599 }, |
591 'IndexedBufferTarget': { | 600 'IndexedBufferTarget': { |
592 'type': 'GLenum', | 601 'type': 'GLenum', |
593 'valid': [ | 602 'valid': [ |
594 'GL_TRANSFORM_FEEDBACK_BUFFER', | 603 'GL_TRANSFORM_FEEDBACK_BUFFER', |
595 'GL_UNIFORM_BUFFER', | 604 'GL_UNIFORM_BUFFER', |
596 ], | 605 ], |
(...skipping 6903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7500 """ | 7509 """ |
7501 | 7510 |
7502 def __init__(self, info): | 7511 def __init__(self, info): |
7503 assert not 'is_complete' in info or info['is_complete'] == True | 7512 assert not 'is_complete' in info or info['is_complete'] == True |
7504 self.info = info | 7513 self.info = info |
7505 self.valid = info['valid'] | 7514 self.valid = info['valid'] |
7506 if 'invalid' in info: | 7515 if 'invalid' in info: |
7507 self.invalid = info['invalid'] | 7516 self.invalid = info['invalid'] |
7508 else: | 7517 else: |
7509 self.invalid = [] | 7518 self.invalid = [] |
| 7519 if 'valid_es3' in info: |
| 7520 self.valid_es3 = info['valid_es3'] |
| 7521 else: |
| 7522 self.valid_es3 = [] |
7510 | 7523 |
7511 def GetType(self): | 7524 def GetType(self): |
7512 return self.info['type'] | 7525 return self.info['type'] |
7513 | 7526 |
7514 def GetInvalidValues(self): | 7527 def GetInvalidValues(self): |
7515 return self.invalid | 7528 return self.invalid |
7516 | 7529 |
7517 def GetValidValues(self): | 7530 def GetValidValues(self): |
7518 return self.valid | 7531 return self.valid |
7519 | 7532 |
| 7533 def GetValidValuesES3(self): |
| 7534 return self.valid_es3 |
| 7535 |
7520 def IsConstant(self): | 7536 def IsConstant(self): |
7521 if not 'is_complete' in self.info: | 7537 if not 'is_complete' in self.info: |
7522 return False | 7538 return False |
7523 | 7539 |
7524 return len(self.GetValidValues()) == 1 | 7540 return len(self.GetValidValues()) == 1 |
7525 | 7541 |
7526 def GetConstantValue(self): | 7542 def GetConstantValue(self): |
7527 return self.GetValidValues()[0] | 7543 return self.GetValidValues()[0] |
7528 | 7544 |
7529 class Argument(object): | 7545 class Argument(object): |
(...skipping 2279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9809 named_type = NamedType(_NAMED_TYPE_INFO[name]) | 9825 named_type = NamedType(_NAMED_TYPE_INFO[name]) |
9810 if named_type.IsConstant(): | 9826 if named_type.IsConstant(): |
9811 continue | 9827 continue |
9812 if named_type.GetValidValues(): | 9828 if named_type.GetValidValues(): |
9813 file.Write("static const %s valid_%s_table[] = {\n" % | 9829 file.Write("static const %s valid_%s_table[] = {\n" % |
9814 (named_type.GetType(), ToUnderscore(name))) | 9830 (named_type.GetType(), ToUnderscore(name))) |
9815 for value in named_type.GetValidValues(): | 9831 for value in named_type.GetValidValues(): |
9816 file.Write(" %s,\n" % value) | 9832 file.Write(" %s,\n" % value) |
9817 file.Write("};\n") | 9833 file.Write("};\n") |
9818 file.Write("\n") | 9834 file.Write("\n") |
| 9835 if named_type.GetValidValuesES3(): |
| 9836 file.Write("static const %s valid_%s_table_es3[] = {\n" % |
| 9837 (named_type.GetType(), ToUnderscore(name))) |
| 9838 for value in named_type.GetValidValuesES3(): |
| 9839 file.Write(" %s,\n" % value) |
| 9840 file.Write("};\n") |
| 9841 file.Write("\n") |
9819 file.Write("Validators::Validators()") | 9842 file.Write("Validators::Validators()") |
9820 pre = ' : ' | 9843 pre = ' : ' |
9821 for count, name in enumerate(names): | 9844 for count, name in enumerate(names): |
9822 named_type = NamedType(_NAMED_TYPE_INFO[name]) | 9845 named_type = NamedType(_NAMED_TYPE_INFO[name]) |
9823 if named_type.IsConstant(): | 9846 if named_type.IsConstant(): |
9824 continue | 9847 continue |
9825 if named_type.GetValidValues(): | 9848 if named_type.GetValidValues(): |
9826 code = """%(pre)s%(name)s( | 9849 code = """%(pre)s%(name)s( |
9827 valid_%(name)s_table, arraysize(valid_%(name)s_table))""" | 9850 valid_%(name)s_table, arraysize(valid_%(name)s_table))""" |
9828 else: | 9851 else: |
9829 code = "%(pre)s%(name)s()" | 9852 code = "%(pre)s%(name)s()" |
9830 file.Write(code % { | 9853 file.Write(code % { |
9831 'name': ToUnderscore(name), | 9854 'name': ToUnderscore(name), |
9832 'pre': pre, | 9855 'pre': pre, |
9833 }) | 9856 }) |
9834 pre = ',\n ' | 9857 pre = ',\n ' |
9835 file.Write(" {\n"); | 9858 file.Write(" {\n"); |
9836 file.Write("}\n\n"); | 9859 file.Write("}\n\n"); |
| 9860 |
| 9861 file.Write("void Validators::AddES3Values() {\n") |
| 9862 for name in names: |
| 9863 named_type = NamedType(_NAMED_TYPE_INFO[name]) |
| 9864 if named_type.GetValidValuesES3(): |
| 9865 code = """ %(name)s.AddValues( |
| 9866 valid_%(name)s_table_es3, arraysize(valid_%(name)s_table_es3)); |
| 9867 """ |
| 9868 file.Write(code % { |
| 9869 'name': ToUnderscore(name), |
| 9870 }) |
| 9871 file.Write("}\n\n"); |
9837 file.Close() | 9872 file.Close() |
9838 self.generated_cpp_filenames.append(file.filename) | 9873 self.generated_cpp_filenames.append(file.filename) |
9839 | 9874 |
9840 def WriteCommonUtilsHeader(self, filename): | 9875 def WriteCommonUtilsHeader(self, filename): |
9841 """Writes the gles2 common utility header.""" | 9876 """Writes the gles2 common utility header.""" |
9842 file = CHeaderWriter(filename) | 9877 file = CHeaderWriter(filename) |
9843 type_infos = sorted(_NAMED_TYPE_INFO.keys()) | 9878 type_infos = sorted(_NAMED_TYPE_INFO.keys()) |
9844 for type_info in type_infos: | 9879 for type_info in type_infos: |
9845 if _NAMED_TYPE_INFO[type_info]['type'] == 'GLenum': | 9880 if _NAMED_TYPE_INFO[type_info]['type'] == 'GLenum': |
9846 file.Write("static std::string GetString%s(uint32_t value);\n" % | 9881 file.Write("static std::string GetString%s(uint32_t value);\n" % |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9885 const size_t GLES2Util::enum_to_string_table_len_ = | 9920 const size_t GLES2Util::enum_to_string_table_len_ = |
9886 sizeof(enum_to_string_table) / sizeof(enum_to_string_table[0]); | 9921 sizeof(enum_to_string_table) / sizeof(enum_to_string_table[0]); |
9887 | 9922 |
9888 """) | 9923 """) |
9889 | 9924 |
9890 enums = sorted(_NAMED_TYPE_INFO.keys()) | 9925 enums = sorted(_NAMED_TYPE_INFO.keys()) |
9891 for enum in enums: | 9926 for enum in enums: |
9892 if _NAMED_TYPE_INFO[enum]['type'] == 'GLenum': | 9927 if _NAMED_TYPE_INFO[enum]['type'] == 'GLenum': |
9893 file.Write("std::string GLES2Util::GetString%s(uint32_t value) {\n" % | 9928 file.Write("std::string GLES2Util::GetString%s(uint32_t value) {\n" % |
9894 enum) | 9929 enum) |
9895 if len(_NAMED_TYPE_INFO[enum]['valid']) > 0: | 9930 valid_list = _NAMED_TYPE_INFO[enum]['valid'] |
| 9931 if 'valid_es3' in _NAMED_TYPE_INFO[enum]: |
| 9932 valid_list = valid_list + _NAMED_TYPE_INFO[enum]['valid_es3'] |
| 9933 assert len(valid_list) == len(set(valid_list)) |
| 9934 if len(valid_list) > 0: |
9896 file.Write(" static const EnumToString string_table[] = {\n") | 9935 file.Write(" static const EnumToString string_table[] = {\n") |
9897 for value in _NAMED_TYPE_INFO[enum]['valid']: | 9936 for value in valid_list: |
9898 file.Write(' { %s, "%s" },\n' % (value, value)) | 9937 file.Write(' { %s, "%s" },\n' % (value, value)) |
9899 file.Write(""" }; | 9938 file.Write(""" }; |
9900 return GLES2Util::GetQualifiedEnumString( | 9939 return GLES2Util::GetQualifiedEnumString( |
9901 string_table, arraysize(string_table), value); | 9940 string_table, arraysize(string_table), value); |
9902 } | 9941 } |
9903 | 9942 |
9904 """) | 9943 """) |
9905 else: | 9944 else: |
9906 file.Write(""" return GLES2Util::GetQualifiedEnumString( | 9945 file.Write(""" return GLES2Util::GetQualifiedEnumString( |
9907 NULL, 0, value); | 9946 NULL, 0, value); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10252 Format(gen.generated_cpp_filenames) | 10291 Format(gen.generated_cpp_filenames) |
10253 | 10292 |
10254 if gen.errors > 0: | 10293 if gen.errors > 0: |
10255 print "%d errors" % gen.errors | 10294 print "%d errors" % gen.errors |
10256 return 1 | 10295 return 1 |
10257 return 0 | 10296 return 0 |
10258 | 10297 |
10259 | 10298 |
10260 if __name__ == '__main__': | 10299 if __name__ == '__main__': |
10261 sys.exit(main(sys.argv[1:])) | 10300 sys.exit(main(sys.argv[1:])) |
OLD | NEW |