blob: 376553e1d1ed972aab0cc5a2abf9677130913014 [file] [log] [blame]
# -*- coding: utf-8 -*-
# drawElements Quality Program utilities
# --------------------------------------
# Copyright 2015 The Android Open Source Project
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import re
import sys
import khr_util.format
import khr_util.registry
import khr_util.registry_cache
SCRIPTS_DIR = os.path.dirname(__file__)
OPENGL_DIR = os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "opengl"))
EGL_DIR = os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "egl"))
OPENGL_INC_DIR = os.path.join(OPENGL_DIR, "wrapper")
GL_SOURCE = khr_util.registry_cache.RegistrySource(
def getGLRegistry ():
return khr_util.registry_cache.getRegistry(GL_SOURCE)
# return the name of a core command corresponding to an extension command.
# Ideally this should be done using the alias attribute of commands, but dEQP
# just strips the extension suffix.
def getCoreName (name):
return re.sub('[A-Z]+$', '', name)
def getHybridInterface ():
# This is a bit awkward, since we have to create a strange hybrid
# interface that includes both GL and ES features and extensions.
registry = getGLRegistry()
glFeatures = registry.getFeatures('gl')
esFeatures = registry.getFeatures('gles2')
spec = khr_util.registry.InterfaceSpec()
for feature in registry.getFeatures('gl'):
spec.addFeature(feature, 'gl', 'core')
for feature in registry.getFeatures('gles2'):
spec.addFeature(feature, 'gles2')
for extName in EXTENSIONS:
extension = registry.extensions[extName]
# Add all extensions using the ES2 api, but force even non-ES2
# extensions to be included.
spec.addExtension(extension, 'gles2', 'core', force=True)
# Remove redundant extension commands that are already provided by core.
for commandName in list(spec.commands):
coreName = getCoreName(commandName)
if coreName != commandName and coreName in spec.commands:
return khr_util.registry.createInterface(registry, spec, 'gles2')
def getInterface (registry, api, version=None, profile=None, **kwargs):
spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
if api == 'gl' and profile == 'core' and version < "3.2":
gl32 = registry.features['GL_VERSION_3_2']
for eRemove in gl32.xpath('remove'):
return khr_util.registry.createInterface(registry, spec, api)
def getVersionToken (api, version):
prefixes = { 'gles2': "ES", 'gl': "GL" }
return prefixes[api] + version.replace(".", "")
def genCommandList(iface, renderCommand, directory, filename, align=False):
lines = map(renderCommand, iface.commands)
lines = filter(lambda l: l != None, lines)
if align:
lines = indentLines(lines)
writeInlFile(os.path.join(directory, filename), lines)
def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False):
for eFeature in registry.features:
api = eFeature.get('api')
version = eFeature.get('number')
profile = check(api, version)
if profile is True:
profile = None
elif profile is False:
iface = getInterface(registry, api, version=version, profile=profile)
filename = filePattern % getVersionToken(api, version)
genCommandList(iface, renderCommand, directory, filename, align)
def getFunctionTypeName (funcName):
return "%sFunc" % funcName
def getFunctionMemberName (funcName):
assert funcName[:2] == "gl"
if funcName[:5] == "glEGL":
# Otherwise we end up with gl.eGLImage...
return "egl%s" % funcName[5:]
return "%c%s" % (funcName[2].lower(), funcName[3:])
INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision())
def writeInlFile (filename, source):
khr_util.format.writeInlFile(filename, INL_HEADER, source)
# Aliases from khr_util.common
indentLines = khr_util.format.indentLines
normalizeConstant = khr_util.format.normalizeConstant
commandParams = khr_util.format.commandParams
commandArgs = khr_util.format.commandArgs