1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 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(
41 "3292120320cacbc27009e7507656d7be17bb25f06876814c67eeffa369281eed")
44 'GL_KHR_texture_compression_astc_ldr',
45 'GL_KHR_blend_equation_advanced',
46 'GL_KHR_blend_equation_advanced_coherent',
48 'GL_EXT_geometry_point_size',
49 'GL_EXT_tessellation_shader',
50 'GL_EXT_geometry_shader',
52 'GL_EXT_texture_buffer',
53 'GL_EXT_texture_snorm',
54 'GL_EXT_primitive_bounding_box',
56 'GL_OES_compressed_ETC1_RGB8_texture',
57 'GL_OES_compressed_paletted_texture',
58 'GL_OES_texture_half_float',
59 'GL_OES_texture_storage_multisample_2d_array',
60 'GL_OES_sample_shading',
61 'GL_EXT_texture_compression_s3tc',
62 'GL_IMG_texture_compression_pvrtc',
64 'GL_EXT_draw_buffers_indexed',
65 'GL_EXT_texture_sRGB_decode',
66 'GL_EXT_texture_border_clamp',
67 'GL_EXT_texture_sRGB_R8',
68 'GL_EXT_texture_sRGB_RG8',
69 'GL_EXT_debug_marker',
75 return khr_util.registry_cache.getRegistry(GL_SOURCE)
77 # return the name of a core command corresponding to an extension command.
78 # Ideally this should be done using the alias attribute of commands, but dEQP
79 # just strips the extension suffix.
80 def getCoreName (name):
81 return re.sub('[A-Z]+$', '', name)
83 def getHybridInterface ():
84 # This is a bit awkward, since we have to create a strange hybrid
85 # interface that includes both GL and ES features and extensions.
86 registry = getGLRegistry()
87 glFeatures = registry.getFeatures('gl')
88 esFeatures = registry.getFeatures('gles2')
89 spec = khr_util.registry.InterfaceSpec()
91 for feature in registry.getFeatures('gl'):
92 spec.addFeature(feature, 'gl', 'core')
94 for feature in registry.getFeatures('gles2'):
95 spec.addFeature(feature, 'gles2')
97 for extName in EXTENSIONS:
98 extension = registry.extensions[extName]
99 # Add all extensions using the ES2 api, but force even non-ES2
100 # extensions to be included.
101 spec.addExtension(extension, 'gles2', 'core', force=True)
103 # Remove redundant extension commands that are already provided by core.
104 for commandName in list(spec.commands):
105 coreName = getCoreName(commandName)
106 if coreName != commandName and coreName in spec.commands:
107 spec.commands.remove(commandName)
109 return khr_util.registry.createInterface(registry, spec, 'gles2')
111 def getInterface (registry, api, version=None, profile=None, **kwargs):
112 spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
113 if api == 'gl' and profile == 'core' and version < "3.2":
114 gl32 = registry.features['GL_VERSION_3_2']
115 for eRemove in gl32.xpath('remove'):
116 spec.addComponent(eRemove)
117 return khr_util.registry.createInterface(registry, spec, api)
119 def getVersionToken (api, version):
120 prefixes = { 'gles2': "ES", 'gl': "GL" }
121 return prefixes[api] + version.replace(".", "")
123 def genCommandList(iface, renderCommand, directory, filename, align=False):
124 lines = map(renderCommand, iface.commands)
125 lines = filter(lambda l: l != None, lines)
127 lines = indentLines(lines)
128 writeInlFile(os.path.join(directory, filename), lines)
130 def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False):
131 for eFeature in registry.features:
132 api = eFeature.get('api')
133 version = eFeature.get('number')
134 profile = check(api, version)
137 elif profile is False:
139 iface = getInterface(registry, api, version=version, profile=profile)
140 filename = filePattern % getVersionToken(api, version)
141 genCommandList(iface, renderCommand, directory, filename, align)
143 def getFunctionTypeName (funcName):
144 return "%sFunc" % funcName
146 def getFunctionMemberName (funcName):
147 assert funcName[:2] == "gl"
148 if funcName[:5] == "glEGL":
149 # Otherwise we end up with gl.eGLImage...
150 return "egl%s" % funcName[5:]
152 return "%c%s" % (funcName[2].lower(), funcName[3:])
154 INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision())
156 def writeInlFile (filename, source):
157 khr_util.format.writeInlFile(filename, INL_HEADER, source)
159 # Aliases from khr_util.common
160 indentLines = khr_util.format.indentLines
161 normalizeConstant = khr_util.format.normalizeConstant
162 commandParams = khr_util.format.commandParams
163 commandArgs = khr_util.format.commandArgs