1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015-2017 The Android Open Source Project
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
27 sys.path.append(os.path.dirname(os.path.dirname(__file__)))
29 import khr_util.format
30 import khr_util.registry
31 import khr_util.registry_cache
33 SCRIPTS_DIR = os.path.dirname(__file__)
34 OPENGL_DIR = os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "opengl"))
35 EGL_DIR = os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "egl"))
36 OPENGL_INC_DIR = os.path.join(OPENGL_DIR, "wrapper")
38 GL_SOURCE = khr_util.registry_cache.RegistrySource(
39 "https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry",
41 "a3ee0ed08111d44ac3cb863d9e3e81a7c28f9d90",
42 "bfe070bafe6a0758f23964a078262b45ad163adf7f2dc320f44757908033d107")
45 'GL_KHR_texture_compression_astc_ldr',
46 'GL_KHR_blend_equation_advanced',
47 'GL_KHR_blend_equation_advanced_coherent',
51 'GL_KHR_parallel_shader_compile',
53 'GL_EXT_geometry_point_size',
54 'GL_EXT_tessellation_shader',
55 'GL_EXT_geometry_shader',
57 'GL_EXT_texture_buffer',
58 'GL_EXT_texture_filter_anisotropic',
59 'GL_EXT_texture_cube_map_array',
60 'GL_EXT_texture_snorm',
61 'GL_EXT_primitive_bounding_box',
62 'GL_EXT_texture_compression_s3tc',
63 'GL_EXT_texture_type_2_10_10_10_REV',
65 'GL_EXT_depth_bounds_test',
66 'GL_EXT_direct_state_access',
67 'GL_EXT_draw_buffers_indexed',
68 'GL_EXT_draw_elements_base_vertex',
69 'GL_EXT_direct_state_access',
70 'GL_EXT_read_format_bgra',
71 'GL_EXT_texture_storage',
72 'GL_EXT_texture_sRGB_decode',
73 'GL_EXT_texture_border_clamp',
74 'GL_EXT_texture_sRGB_R8',
75 'GL_EXT_texture_sRGB_RG8',
76 'GL_EXT_debug_marker',
77 'GL_EXT_polygon_offset_clamp',
78 'GL_IMG_texture_compression_pvrtc',
80 'GL_OES_EGL_image_external',
81 'GL_OES_compressed_ETC1_RGB8_texture',
82 'GL_OES_compressed_paletted_texture',
83 'GL_OES_required_internalformat',
84 'GL_OES_packed_depth_stencil',
86 'GL_OES_texture_half_float',
87 'GL_OES_texture_storage_multisample_2d_array',
88 'GL_OES_sample_shading',
89 'GL_OES_standard_derivatives',
92 'GL_OES_surfaceless_context',
94 'GL_OES_vertex_array_object',
95 'GL_OES_viewport_array',
96 'GL_ARB_clip_control',
97 'GL_ARB_buffer_storage',
98 'GL_ARB_compute_shader',
99 'GL_ARB_draw_instanced',
100 'GL_ARB_draw_elements_base_vertex',
101 'GL_ARB_direct_state_access',
102 'GL_ARB_get_program_binary',
103 'GL_ARB_indirect_parameters',
104 'GL_ARB_internalformat_query',
105 'GL_ARB_instanced_arrays',
106 'GL_ARB_multi_draw_indirect',
107 'GL_ARB_parallel_shader_compile',
108 'GL_ARB_program_interface_query',
109 'GL_ARB_separate_shader_objects',
110 'GL_ARB_shader_ballot',
111 'GL_ARB_shader_image_load_store',
112 'GL_ARB_shader_viewport_layer_array',
113 'GL_ARB_sparse_buffer',
114 'GL_ARB_sparse_texture',
115 'GL_ARB_spirv_extensions',
116 'GL_ARB_tessellation_shader',
117 'GL_ARB_texture_barrier',
118 'GL_ARB_texture_filter_minmax',
119 'GL_ARB_texture_gather',
120 'GL_ARB_texture_storage',
121 'GL_ARB_texture_storage_multisample',
122 'GL_ARB_texture_multisample',
123 'GL_ARB_texture_view',
124 'GL_ARB_transform_feedback2',
125 'GL_ARB_transform_feedback3',
126 'GL_ARB_transform_feedback_instanced',
127 'GL_ARB_transform_feedback_overflow_query',
128 'GL_ARB_vertex_array_bgra',
129 'GL_ARB_vertex_attrib_64bit',
130 'GL_ARB_vertex_attrib_binding',
131 'GL_NV_deep_texture3D',
132 'GL_NV_internalformat_sample_query',
133 'GL_OES_draw_elements_base_vertex',
136 def getGLRegistry ():
137 return khr_util.registry_cache.getRegistry(GL_SOURCE)
139 def getHybridInterface (stripAliasedExtCommands = True):
140 # This is a bit awkward, since we have to create a strange hybrid
141 # interface that includes both GL and ES features and extensions.
142 registry = getGLRegistry()
143 glFeatures = registry.getFeatures('gl')
144 esFeatures = registry.getFeatures('gles2')
145 spec = khr_util.registry.InterfaceSpec()
147 for feature in registry.getFeatures('gl'):
148 spec.addFeature(feature, 'gl', 'core')
150 for feature in registry.getFeatures('gles2'):
151 spec.addFeature(feature, 'gles2')
153 for extName in EXTENSIONS:
154 extension = registry.extensions[extName]
155 # Add all extensions using the ES2 api, but force even non-ES2
156 # extensions to be included.
157 spec.addExtension(extension, 'gles2', 'core', force=True)
159 iface = khr_util.registry.createInterface(registry, spec, 'gles2')
161 if stripAliasedExtCommands:
162 # Remove redundant extension commands that are already provided by core.
165 for command in iface.commands:
166 if command.alias == None:
167 strippedCmds.append(command)
169 iface.commands = strippedCmds
173 def getInterface (registry, api, version=None, profile=None, **kwargs):
174 spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
175 if api == 'gl' and profile == 'core' and version < "3.2":
176 gl32 = registry.features['GL_VERSION_3_2']
177 for eRemove in gl32.xpath('remove'):
178 spec.addComponent(eRemove)
179 return khr_util.registry.createInterface(registry, spec, api)
181 def getVersionToken (api, version):
182 prefixes = { 'gles2': "ES", 'gl': "GL" }
183 return prefixes[api] + version.replace(".", "")
185 def genCommandList(iface, renderCommand, directory, filename, align=False):
186 lines = map(renderCommand, iface.commands)
187 lines = filter(lambda l: l != None, lines)
189 lines = indentLines(lines)
190 writeInlFile(os.path.join(directory, filename), lines)
192 def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False):
193 for eFeature in registry.features:
194 api = eFeature.get('api')
195 version = eFeature.get('number')
196 profile = check(api, version)
199 elif profile is False:
201 iface = getInterface(registry, api, version=version, profile=profile)
202 filename = filePattern % getVersionToken(api, version)
203 genCommandList(iface, renderCommand, directory, filename, align)
205 def getFunctionTypeName (funcName):
206 return "%sFunc" % funcName
208 def getFunctionMemberName (funcName):
209 assert funcName[:2] == "gl"
210 if funcName[:5] == "glEGL":
211 # Otherwise we end up with gl.eGLImage...
212 return "egl%s" % funcName[5:]
214 return "%c%s" % (funcName[2].lower(), funcName[3:])
216 INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision())
218 def writeInlFile (filename, source):
219 khr_util.format.writeInlFile(filename, INL_HEADER, source)
221 # Aliases from khr_util.common
222 indentLines = khr_util.format.indentLines
223 normalizeConstant = khr_util.format.normalizeConstant
224 commandParams = khr_util.format.commandParams
225 commandArgs = khr_util.format.commandArgs