Skip to content

Commit

Permalink
Fixed loading of functions in multiple extensions.
Browse files Browse the repository at this point in the history
If a function was defined in multiple extensions, it would only be loaded
in the first one that's defined. This could cause some functions to be
missing depending on which are available.

To support this, function pointers are now all cleared at the start of
loading rather than in the else blocks when they are loaded. This ensures
that functions aren't cleared out after previously loading them.

Updated registry version. This required some re-working of type
declarations.
  • Loading branch information
akb825 committed Sep 16, 2019
1 parent 7b6abf3 commit 40038ea
Show file tree
Hide file tree
Showing 22 changed files with 7,409 additions and 10,416 deletions.
12 changes: 5 additions & 7 deletions AnyGL/EGLLoadGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, errFile = sys.stderr, warnFile = sys.stderr, diagFile = sys.s
self.coreFeatures = []
self.extensionFeatures = []
self.curFeature = None
self.allowDuplicateEntries = True

def newLine(self):
write('', file = self.outFile)
Expand All @@ -60,6 +61,7 @@ def beginFile(self, genOpts):
self.write('int AnyGL_updateGLVersion(void);')
self.write('int AnyGL_queryExtension(const char* name);')
self.write('void AnyGL_initDebug(void);')
self.write('void AnyGL_clearFunctionPointers(void);')
self.write('static void* gllib;')
self.newLine()

Expand All @@ -83,6 +85,9 @@ def endFile(self):
self.write('\tif (!gllib || !eglGetCurrentContext())')
self.write('\t\treturn 0;')

self.newLine()
self.write('\tAnyGL_clearFunctionPointers();')

# Load these features from the OpenGL library.
for feature in self.firstFeatures:
self.newLine()
Expand Down Expand Up @@ -114,9 +119,6 @@ def endFile(self):
for function in feature.functions:
self.write('\t\tAnyGL_' + function.name, '= (' + function.type + \
')dlsym(gllib, "' + function.name + '");')
self.write('\t}\n\telse\n\t{')
for function in feature.functions:
self.write('\t\tAnyGL_' + function.name, '= NULL;')
self.write('\t}')

# Load the extensions.
Expand All @@ -135,10 +137,6 @@ def endFile(self):
else:
self.write('\t\tAnyGL_' + function.name, '= (' + function.type + \
')eglGetProcAddress("' + function.name + '");')
self.write('\t}\n\telse\n\t{')
for function in feature.functions:
if not function.alias:
self.write('\t\tAnyGL_' + function.name, '= NULL;')
self.write('\t}')

self.newLine()
Expand Down
10 changes: 5 additions & 5 deletions AnyGL/FptrLoadGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, errFile = sys.stderr, warnFile = sys.stderr, diagFile = sys.s
self.coreFeatures = []
self.extensionFeatures = []
self.curFeature = None
self.allowDuplicateEntries = True

def newLine(self):
write('', file = self.outFile)
Expand Down Expand Up @@ -132,6 +133,7 @@ def beginFile(self, genOpts):
self.write('int AnyGL_updateGLVersion(void);')
self.write('int AnyGL_queryExtension(const char* name);')
self.write('void AnyGL_initDebug(void);')
self.write('void AnyGL_clearFunctionPointers(void);')
self.newLine()

def endFile(self):
Expand All @@ -141,6 +143,9 @@ def endFile(self):

self.write('int AnyGL_load(void)\n{')

self.write('\tAnyGL_clearFunctionPointers();')
self.newLine()

# Alwyas load first features.
for feature in self.firstFeatures:
self.write('\t/*', feature.name, '*/');
Expand All @@ -151,7 +156,6 @@ def endFile(self):
# Get the OpenGL version.
self.write('\tif (!AnyGL_updateGLVersion())')
self.write('\t\treturn 0;')
self.newLine()

if self.isGles:
glEsBool = '1'
Expand Down Expand Up @@ -199,10 +203,6 @@ def endFile(self):
else:
self.write('\t\tAnyGL_' + function.name + ' = (' + function.type + ')&' + \
function.name + ';')
self.write('\t}\n\telse\n\t{')
for function in feature.functions:
if not function.alias:
self.write('\t\tAnyGL_' + function.name + ' = 0;')
self.write('\t}')
self.write('#endif', '/*', feature.name, '*/')
self.newLine()
Expand Down
1 change: 1 addition & 0 deletions AnyGL/FunctionInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'GL_EXT_robustness': 'EXT',
'GL_EXT_blend_func_extended': 'EXT',
'GL_EXT_disjoint_timer_query': 'EXT',
'GL_EXT_occlusion_query_boolean': 'EXT',
'GL_EXT_shader_image_load_store': 'EXT'
}

Expand Down
12 changes: 12 additions & 0 deletions AnyGL/FunctionPointerGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class FunctionPointerGenerator(OutputGenerator):
def __init__(self, errFile = sys.stderr, warnFile = sys.stderr, diagFile = sys.stdout):
OutputGenerator.__init__(self, errFile, warnFile, diagFile)
self.curFeature = None
self.functions = []

def newLine(self):
write('', file = self.outFile)
Expand All @@ -36,6 +37,16 @@ def beginFile(self, genOpts):
self.write('ANYGL_EXPORT GLenum AnyGL_HALF_FLOAT = GL_HALF_FLOAT;')
self.newLine()

def endFile(self):
self.newLine()

self.write('void AnyGL_clearFunctionPointers(void)')
self.write('{')
for function in self.functions:
self.write('\tAnyGL_' + function + ' = NULL;')
self.write('}')
OutputGenerator.endFile(self)

def beginFeature(self, interface, emit):
OutputGenerator.beginFeature(self, interface, emit)
if emit:
Expand All @@ -52,3 +63,4 @@ def genCmd(self, cmdinfo, name):
function = FunctionInfo(cmdinfo.elem, self.curFeature)
if not function.alias:
self.write('ANYGL_EXPORT', function.type, 'AnyGL_' + function.name + ';')
self.functions.append(function.name)
35 changes: 24 additions & 11 deletions AnyGL/GLHeaderGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,35 @@ def endFile(self):
self.newLine()

self.write('/* Type declarations */')

# Basic types are now use khrplatform with the latest spec, which is only guaranteed to be
# available on GLES platforms. Need to manually declare them for desktop platforms.
self.write('#if !ANYGL_GLES')
self.write('#include <stddef.h>')
self.write('#include <stdint.h>')
self.write('typedef int8_t GLbyte;')
self.write('typedef uint8_t GLubyte;')
self.write('typedef int16_t GLshort;')
self.write('typedef uint16_t GLushort;')
self.write('typedef uint16_t GLushort;')
self.write('typedef float GLfloat;')
self.write('typedef float GLclampf;')
self.write('typedef uint16_t GLhalf;')
self.write('typedef int32_t GLfixed;')
self.write('typedef ptrdiff_t GLintptr;')
self.write('typedef ptrdiff_t GLsizeiptr;')
self.write('typedef int64_t GLint64;')
self.write('typedef uint64_t GLuint64;')
self.write('#endif')
self.newLine()

for feature in self.features:
if not feature.types:
continue

# These features have overlap between the types.
if feature.name == 'GL_VERSION_1_0' or feature.name == 'GL_VERSION_1_1' or \
feature.name == 'GL_ES_VERSION_2_0':
self.write('#if defined(ANYGL_VERSION_1_0) && defined(ANYGL_VERSION_1_0)',
'&& defined(ANYGL_ES_VERSION_2_0)')
if feature.name == 'GL_VERSION_1_0' or feature.name == 'GL_ES_VERSION_2_0':
self.write('#if defined(ANYGL_VERSION_1_0) || defined(ANYGL_ES_VERSION_2_0)')
else:
self.write('#ifdef ANY' + feature.name)
curRequire = None
Expand All @@ -128,13 +148,6 @@ def endFile(self):
self.write('#endif /*', feature.name, '*/')
self.newLine()

# When including GLES headers directly no double types will be defined.
self.write('#if defined(ANYGL_VERSION_1_0) && !defined(ANYGL_ES_VERSION_2_0)')
self.write('typedef double GLdouble;')
self.write('typedef double GLclampd;')
self.write('#endif')
self.newLine()

self.write('/* Enum definitions */')
self.write('#ifndef ANYGL_NO_DEFINES')
for feature in self.features:
Expand Down
12 changes: 5 additions & 7 deletions AnyGL/GLXLoadGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, errFile = sys.stderr, warnFile = sys.stderr, diagFile = sys.s
self.coreFeatures = []
self.extensionFeatures = []
self.curFeature = None
self.allowDuplicateEntries = True

def newLine(self):
write('', file = self.outFile)
Expand All @@ -55,6 +56,7 @@ def beginFile(self, genOpts):
self.write('int AnyGL_updateGLVersion(void);')
self.write('int AnyGL_queryExtension(const char* name);')
self.write('void AnyGL_initDebug(void);')
self.write('void AnyGL_clearFunctionPointers(void);')
self.newLine()

def endFile(self):
Expand All @@ -63,6 +65,9 @@ def endFile(self):
'!ANYGL_SUPPORTED(glXGetProcAddress) || !glXGetCurrentContext())')
self.write('\t\treturn 0;')

self.newLine()
self.write('\tAnyGL_clearFunctionPointers();')

# Load these feaures first. This includes glGetIntegerv to get the OpenGL version.
for feature in self.firstFeatures:
self.newLine()
Expand All @@ -85,9 +90,6 @@ def endFile(self):
for function in feature.functions:
self.write('\t\tAnyGL_' + function.name, '= (' + function.type + \
')glXGetProcAddress((const GLubyte*)"' + function.name + '");')
self.write('\t}\n\telse\n\t{')
for function in feature.functions:
self.write('\t\tAnyGL_' + function.name, '= NULL;')
self.write('\t}')

# Load the extensions.
Expand All @@ -106,10 +108,6 @@ def endFile(self):
else:
self.write('\t\tAnyGL_' + function.name, '= (' + function.type + \
')glXGetProcAddress((const GLubyte*)"' + function.name + '");')
self.write('\t}\n\telse\n\t{')
for function in feature.functions:
if not function.alias:
self.write('\t\tAnyGL_' + function.name, '= NULL;')
self.write('\t}')

self.newLine()
Expand Down
12 changes: 5 additions & 7 deletions AnyGL/WGLLoadGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, errFile = sys.stderr, warnFile = sys.stderr, diagFile = sys.s
self.coreFeatures = []
self.extensionFeatures = []
self.curFeature = None
self.allowDuplicateEntries = True

def newLine(self):
write('', file = self.outFile)
Expand All @@ -56,6 +57,7 @@ def beginFile(self, genOpts):
self.write('int AnyGL_updateGLVersion(void);')
self.write('int AnyGL_queryExtension(const char* name);')
self.write('void AnyGL_initDebug(void);')
self.write('void AnyGL_clearFunctionPointers(void);')
self.write('extern HMODULE AnyGL_gllib;')
self.newLine()

Expand All @@ -64,6 +66,9 @@ def endFile(self):
self.write('\tif (!AnyGL_gllib || !wglGetCurrentContext())')
self.write('\t\treturn 0;')

self.newLine()
self.write('\tAnyGL_clearFunctionPointers();')

# Load these features from the OpenGL library.
for feature in self.firstFeatures:
self.newLine()
Expand All @@ -86,9 +91,6 @@ def endFile(self):
for function in feature.functions:
self.write('\t\tAnyGL_' + function.name, '= (' + function.type + \
')wglGetProcAddress("' + function.name + '");')
self.write('\t}\n\telse\n\t{')
for function in feature.functions:
self.write('\t\tAnyGL_' + function.name, '= NULL;')
self.write('\t}')

# Load the extensions.
Expand All @@ -107,10 +109,6 @@ def endFile(self):
else:
self.write('\t\tAnyGL_' + function.name, '= (' + function.type + \
')wglGetProcAddress("' + function.name + '");')
self.write('\t}\n\telse\n\t{')
for function in feature.functions:
if not function.alias:
self.write('\t\tAnyGL_' + function.name, '= NULL;')
self.write('\t}')

self.newLine()
Expand Down
7 changes: 6 additions & 1 deletion AnyGL/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ def __init__(self):
self.gen = OutputGenerator()
self.genOpts = None
self.emitFeatures = False
self.allowDuplicateEntries = False
def loadElementTree(self, tree):
"""Load ElementTree into a Registry object and parse it"""
self.tree = tree
Expand All @@ -723,6 +724,10 @@ def loadFile(self, file):
def setGenerator(self, gen):
"""Specify output generator object. None restores the default generator"""
self.gen = gen
if hasattr(gen, 'allowDuplicateEntries'):
self.allowDuplicateEntries = gen.allowDuplicateEntries
else:
self.allowDuplicateEntries = False
# addElementInfo - add information about an element to the
# corresponding dictionary
# elem - <type>/<group>/<enum>/<command>/<feature>/<extension> Element
Expand Down Expand Up @@ -952,7 +957,7 @@ def generateFeature(self, fname, ftype, api, dictionary, genProc):
if (not f.required):
self.gen.logMsg('diag', '*** Skipping', ftype, fname, '(not required)')
return
if (f.declared):
if (f.declared and not self.allowDuplicateEntries):
self.gen.logMsg('diag', '*** Skipping', ftype, fname, '(already declared)')
return
#
Expand Down
2 changes: 1 addition & 1 deletion OpenGLRegistry
Submodule OpenGLRegistry updated 541 files
Loading

0 comments on commit 40038ea

Please sign in to comment.