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 "db2965fc26513b254e2f964171f79e416a05fe29",
42 "c4a4e241dc63ed3d1c4cd50451e5baef330dbb51dd3ecb278be80a5779f5b348")
45 'GL_KHR_texture_compression_astc_ldr',
46 'GL_KHR_blend_equation_advanced',
47 'GL_KHR_blend_equation_advanced_coherent',
49 'GL_EXT_geometry_point_size',
50 'GL_EXT_tessellation_shader',
51 'GL_EXT_geometry_shader',
53 'GL_EXT_texture_buffer',
54 'GL_EXT_texture_snorm',
55 'GL_EXT_primitive_bounding_box',
57 'GL_OES_compressed_ETC1_RGB8_texture',
58 'GL_OES_compressed_paletted_texture',
59 'GL_OES_texture_half_float',
60 'GL_OES_texture_storage_multisample_2d_array',
61 'GL_OES_sample_shading',
62 'GL_EXT_texture_compression_s3tc',
63 'GL_IMG_texture_compression_pvrtc',
65 'GL_EXT_draw_buffers_indexed',
66 'GL_EXT_texture_sRGB_decode',
67 'GL_EXT_texture_border_clamp',
68 'GL_EXT_texture_sRGB_R8',
69 'GL_EXT_texture_sRGB_RG8',
70 'GL_EXT_debug_marker',
76 return khr_util.registry_cache.getRegistry(GL_SOURCE)
78 # return the name of a core command corresponding to an extension command.
79 # Ideally this should be done using the alias attribute of commands, but dEQP
80 # just strips the extension suffix.
81 def getCoreName (name):
82 return re.sub('[A-Z]+$', '', name)
84 def getHybridInterface ():
85 # This is a bit awkward, since we have to create a strange hybrid
86 # interface that includes both GL and ES features and extensions.
87 registry = getGLRegistry()
88 glFeatures = registry.getFeatures('gl')
89 esFeatures = registry.getFeatures('gles2')
90 spec = khr_util.registry.InterfaceSpec()
92 for feature in registry.getFeatures('gl'):
93 spec.addFeature(feature, 'gl', 'core')
95 for feature in registry.getFeatures('gles2'):
96 spec.addFeature(feature, 'gles2')
98 for extName in EXTENSIONS:
99 extension = registry.extensions[extName]
100 # Add all extensions using the ES2 api, but force even non-ES2
101 # extensions to be included.
102 spec.addExtension(extension, 'gles2', 'core', force=True)
104 # Remove redundant extension commands that are already provided by core.
105 for commandName in list(spec.commands):
106 coreName = getCoreName(commandName)
107 if coreName != commandName and coreName in spec.commands:
108 spec.commands.remove(commandName)
110 return khr_util.registry.createInterface(registry, spec, 'gles2')
112 def getInterface (registry, api, version=None, profile=None, **kwargs):
113 spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
114 if api == 'gl' and profile == 'core' and version < "3.2":
115 gl32 = registry.features['GL_VERSION_3_2']
116 for eRemove in gl32.xpath('remove'):
117 spec.addComponent(eRemove)
118 return khr_util.registry.createInterface(registry, spec, api)
120 def getVersionToken (api, version):
121 prefixes = { 'gles2': "ES", 'gl': "GL" }
122 return prefixes[api] + version.replace(".", "")
124 def genCommandList(iface, renderCommand, directory, filename, align=False):
125 lines = map(renderCommand, iface.commands)
126 lines = filter(lambda l: l != None, lines)
128 lines = indentLines(lines)
129 writeInlFile(os.path.join(directory, filename), lines)
131 def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False):
132 for eFeature in registry.features:
133 api = eFeature.get('api')
134 version = eFeature.get('number')
135 profile = check(api, version)
138 elif profile is False:
140 iface = getInterface(registry, api, version=version, profile=profile)
141 filename = filePattern % getVersionToken(api, version)
142 genCommandList(iface, renderCommand, directory, filename, align)
144 def getFunctionTypeName (funcName):
145 return "%sFunc" % funcName
147 def getFunctionMemberName (funcName):
148 assert funcName[:2] == "gl"
149 if funcName[:5] == "glEGL":
150 # Otherwise we end up with gl.eGLImage...
151 return "egl%s" % funcName[5:]
153 return "%c%s" % (funcName[2].lower(), funcName[3:])
155 INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision())
157 def writeInlFile (filename, source):
158 khr_util.format.writeInlFile(filename, INL_HEADER, source)
160 # Aliases from khr_util.common
161 indentLines = khr_util.format.indentLines
162 normalizeConstant = khr_util.format.normalizeConstant
163 commandParams = khr_util.format.commandParams
164 commandArgs = khr_util.format.commandArgs