• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright 2015-2017 The Android Open Source Project
8#
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
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
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.
20#
21#-------------------------------------------------------------------------
22
23import os
24import re
25import sys
26
27sys.path.append(os.path.dirname(os.path.dirname(__file__)))
28
29import khr_util.format
30import khr_util.registry
31import khr_util.registry_cache
32
33SCRIPTS_DIR			= os.path.dirname(__file__)
34OPENGL_DIR			= os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "opengl"))
35EGL_DIR				= os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "egl"))
36OPENGL_INC_DIR		= os.path.join(OPENGL_DIR, "wrapper")
37
38GL_SOURCE			= khr_util.registry_cache.RegistrySource(
39						"https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry",
40						"xml/gl.xml",
41						"7ac9c857db1e3a6065485e4e2144151f48a4f1c4",
42						"2475e1ff6d69048e67a49188d8be09195b261ed96b2b4108a0f7d7a459834674")
43
44EXTENSIONS			= [
45	'GL_KHR_texture_compression_astc_ldr',
46	'GL_KHR_blend_equation_advanced',
47	'GL_KHR_blend_equation_advanced_coherent',
48	'GL_KHR_debug',
49	'GL_EXT_geometry_point_size',
50	'GL_EXT_tessellation_shader',
51	'GL_EXT_geometry_shader',
52	'GL_EXT_robustness',
53	'GL_EXT_texture_buffer',
54	'GL_EXT_texture_snorm',
55	'GL_EXT_primitive_bounding_box',
56	'GL_OES_EGL_image',
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',
64	'GL_EXT_copy_image',
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',
71	'GL_EXT_robustness',
72	'GL_KHR_robustness',
73	'GL_EXT_draw_elements_base_vertex',
74	'GL_OES_draw_elements_base_vertex',
75]
76
77def getGLRegistry ():
78	return khr_util.registry_cache.getRegistry(GL_SOURCE)
79
80# return the name of a core command corresponding to an extension command.
81# Ideally this should be done using the alias attribute of commands, but dEQP
82# just strips the extension suffix.
83def getCoreName (name):
84	return re.sub('[A-Z]+$', '', name)
85
86def getHybridInterface ():
87	# This is a bit awkward, since we have to create a strange hybrid
88	# interface that includes both GL and ES features and extensions.
89	registry = getGLRegistry()
90	glFeatures = registry.getFeatures('gl')
91	esFeatures = registry.getFeatures('gles2')
92	spec = khr_util.registry.InterfaceSpec()
93
94	for feature in registry.getFeatures('gl'):
95		spec.addFeature(feature, 'gl', 'core')
96
97	for feature in registry.getFeatures('gles2'):
98		spec.addFeature(feature, 'gles2')
99
100	for extName in EXTENSIONS:
101		extension = registry.extensions[extName]
102		# Add all extensions using the ES2 api, but force even non-ES2
103		# extensions to be included.
104		spec.addExtension(extension, 'gles2', 'core', force=True)
105
106	# Remove redundant extension commands that are already provided by core.
107	for commandName in list(spec.commands):
108		coreName = getCoreName(commandName)
109		if coreName != commandName and coreName in spec.commands:
110			spec.commands.remove(commandName)
111
112	return khr_util.registry.createInterface(registry, spec, 'gles2')
113
114def getInterface (registry, api, version=None, profile=None, **kwargs):
115	spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
116	if api == 'gl' and profile == 'core' and version < "3.2":
117		gl32 = registry.features['GL_VERSION_3_2']
118		for eRemove in gl32.xpath('remove'):
119			spec.addComponent(eRemove)
120	return khr_util.registry.createInterface(registry, spec, api)
121
122def getVersionToken (api, version):
123	prefixes = { 'gles2': "ES", 'gl': "GL" }
124	return prefixes[api] + version.replace(".", "")
125
126def genCommandList(iface, renderCommand, directory, filename, align=False):
127	lines = map(renderCommand, iface.commands)
128	lines = filter(lambda l: l != None, lines)
129	if align:
130		lines = indentLines(lines)
131	writeInlFile(os.path.join(directory, filename), lines)
132
133def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False):
134	for eFeature in registry.features:
135		api			= eFeature.get('api')
136		version		= eFeature.get('number')
137		profile		= check(api, version)
138		if profile is True:
139			profile = None
140		elif profile is False:
141			continue
142		iface		= getInterface(registry, api, version=version, profile=profile)
143		filename	= filePattern % getVersionToken(api, version)
144		genCommandList(iface, renderCommand, directory, filename, align)
145
146def getFunctionTypeName (funcName):
147	return "%sFunc" % funcName
148
149def getFunctionMemberName (funcName):
150	assert funcName[:2] == "gl"
151	if funcName[:5] == "glEGL":
152		# Otherwise we end up with gl.eGLImage...
153		return "egl%s" % funcName[5:]
154	else:
155		return "%c%s" % (funcName[2].lower(), funcName[3:])
156
157INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision())
158
159def writeInlFile (filename, source):
160	khr_util.format.writeInlFile(filename, INL_HEADER, source)
161
162# Aliases from khr_util.common
163indentLines			= khr_util.format.indentLines
164normalizeConstant	= khr_util.format.normalizeConstant
165commandParams		= khr_util.format.commandParams
166commandArgs			= khr_util.format.commandArgs
167