From 62b9213b44c89c1ae6811be1e5fd13a51c504aeb Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Sat, 2 Feb 2019 18:43:47 +1000 Subject: [PATCH 1/3] Use parse_xml.py for WGL code generation --- auto/Makefile | 12 +++++- auto/bin/parse_xml.py | 57 +++++++++++++++++++++++------ auto/core/gl/WGL_ARB_create_context | 1 - 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/auto/Makefile b/auto/Makefile index 9be637b..be100ae 100644 --- a/auto/Makefile +++ b/auto/Makefile @@ -111,11 +111,19 @@ $(EXT)/.dummy: OpenGL-Registry/.dummy EGL-Registry/.dummy cp -r glfixes/gl/specs/ANGLE OpenGL-Registry/extensions cp -r glfixes/gl/specs/REGAL OpenGL-Registry/extensions $(BIN)/update_ext.sh $(EXT) OpenGL-Registry/extensions $(BLACKLIST) - $(BIN)/filter_gl_ext.sh $(EXT) + @echo "--------------------------------------------------------------------" + @echo "WGL descriptors" + @echo "--------------------------------------------------------------------" + rm -f $(EXT)/WGL_* + $(PYTHON) $(BIN)/parse_xml.py OpenGL-Registry/xml/wgl.xml --api wgl --extensions extensions/gl @echo "--------------------------------------------------------------------" @echo "EGL descriptors" @echo "--------------------------------------------------------------------" - $(PYTHON) $(BIN)/parse_xml.py EGL-Registry/api/egl.xml --extensions extensions/gl + $(PYTHON) $(BIN)/parse_xml.py EGL-Registry/api/egl.xml --api egl --extensions extensions/gl + @echo "--------------------------------------------------------------------" + @echo "filter descriptors" + @echo "--------------------------------------------------------------------" + $(BIN)/filter_gl_ext.sh $(EXT) ifeq ($(patsubst Darwin%,Darwin,$(SYSTEM)), Darwin) find $(CORE) -maxdepth 1 -type f | grep -v VERSION | grep -v "~" | \ xargs -J % cp % $(EXT) diff --git a/auto/bin/parse_xml.py b/auto/bin/parse_xml.py index 1340deb..daa1449 100755 --- a/auto/bin/parse_xml.py +++ b/auto/bin/parse_xml.py @@ -1,9 +1,13 @@ -#!/usr/bin/python +#!/usr/bin/env python import re import sys from xml.dom.minidom import parse, Node +# +# DOM traversal utility functions +# + def findChildren(node, path): result = [] if len(path)==1: @@ -21,7 +25,9 @@ def findChildren(node, path): def findData(node, path): return [ i.firstChild.data for i in findChildren(node, path) ] -def findParams(node): +isPointer = re.compile('(.*)([ ]+)([*]+)') + +def findParams(node, typeMap = {}): n = findData(node, ['name'])[0] t = '' for i in node.childNodes: @@ -29,7 +35,14 @@ def findParams(node): t += i.data if i.nodeType==Node.ELEMENT_NODE and i.tagName=='ptype': t += i.firstChild.data - return ( t, n) + + t.strip() + m = isPointer.match(t) + if m: + t = ('%s%s'%(m.group(1), m.group(3))).strip() + if t in typeMap: + t = typeMap[t] + return ( t, n.strip()) def findEnums(dom): ret = {} @@ -39,11 +52,11 @@ def findEnums(dom): ret[n] = v return ret -def findCommands(dom): +def findCommands(dom, typeMap = {}): ret = {} for i in findChildren(dom, [ 'registry', 'commands', 'command' ]): - r,n = findParams(findChildren(i, ['proto'])[0]) - p = [ findParams(j) for j in findChildren(i, ['param'])] + r,n = findParams(findChildren(i, ['proto'])[0], typeMap) + p = [ findParams(j, typeMap) for j in findChildren(i, ['param'])] ret[n] = (r, p) return ret @@ -74,29 +87,48 @@ def findExtensions(dom): return ret def findApi(dom, name): + typeMap = {} +# if name=='wgl': +# typeMap = { 'int' : 'INT', 'void' : 'VOID' } enums = findEnums(dom) - commands = findCommands(dom) + commands = findCommands(dom, typeMap) features = findFeatures(dom) extensions = findExtensions(dom) return (enums, commands, features, extensions) +# +# +# + +isWGL = re.compile('WGL_([A-Z0-9]+)_.*') + def writeExtension(f, name, extension, enums, commands): f.write('%s\n'%name) - f.write('%s\n'%'https://www.khronos.org/registry/egl/specs/eglspec.1.5.pdf') + + url = 'https://www.khronos.org/registry/egl/specs/eglspec.1.5.pdf' + + m = isWGL.match(name) + if m: + url = 'https://www.khronos.org/registry/OpenGL/extensions/%s/%s.txt'%(m.group(1), name) + + f.write('%s\n'%(url)) + if name.find('_VERSION_')==-1: f.write('%s\n'%name) else: f.write('\n') f.write('\n') + enums = [ (j, enums[j]) for j in extension[0] ] for e in sorted(enums, key=lambda i: i[1]): f.write('\t%s %s\n'%(e[0], e[1])) + commands = [ (j, commands[j]) for j in extension[1] ] for c in sorted(commands): - params = ', '.join( [ '%s %s'%(j[0], j[1]) for j in c[1][1] ] ) + params = ', '.join( [ '%s %s'%(j[0].strip(), j[1].strip()) for j in c[1][1] ] ) if len(params)==0: - params = ' void ' - f.write('\t%s %s (%s)\n'%(c[1][0], c[0], params)) + params = 'void' + f.write('\t%s %s (%s)\n'%(c[1][0].strip(), c[0].strip(), params)) if __name__ == '__main__': @@ -105,6 +137,7 @@ if __name__ == '__main__': parser = OptionParser('usage: %prog [options] [XML specs...]') parser.add_option("--core", dest="core", help="location for core outputs", default='') + parser.add_option("--api", dest="name", help="API name: egl, wgl, glx, etc", default='') parser.add_option("--extensions", dest="extensions", help="location for extensions outputs", default='') (options, args) = parser.parse_args() @@ -112,7 +145,7 @@ if __name__ == '__main__': for i in args: dom = parse(i) - api = findApi(dom, 'egl') + api = findApi(dom, options.name) print('Found {} enums, {} commands, {} features and {} extensions.'.format( len(api[0]), len(api[1]), len(api[2]), len(api[3]))) diff --git a/auto/core/gl/WGL_ARB_create_context b/auto/core/gl/WGL_ARB_create_context index 7e7c163..b617481 100644 --- a/auto/core/gl/WGL_ARB_create_context +++ b/auto/core/gl/WGL_ARB_create_context @@ -9,5 +9,4 @@ WGL_ARB_create_context WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 WGL_CONTEXT_FLAGS_ARB 0x2094 ERROR_INVALID_VERSION_ARB 0x2095 - ERROR_INVALID_PROFILE_ARB 0x2096 HGLRC wglCreateContextAttribsARB (HDC hDC, HGLRC hShareContext, const int* attribList) From dcff76b0d1816aa00980568e6917743be7e507fb Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Sat, 2 Feb 2019 18:46:35 +1000 Subject: [PATCH 2/3] Type-mapping isn't needed for parse_xml.py WGL purposes, after all --- auto/bin/parse_xml.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/auto/bin/parse_xml.py b/auto/bin/parse_xml.py index daa1449..ff5567f 100755 --- a/auto/bin/parse_xml.py +++ b/auto/bin/parse_xml.py @@ -27,7 +27,7 @@ def findData(node, path): isPointer = re.compile('(.*)([ ]+)([*]+)') -def findParams(node, typeMap = {}): +def findParams(node): n = findData(node, ['name'])[0] t = '' for i in node.childNodes: @@ -40,8 +40,6 @@ def findParams(node, typeMap = {}): m = isPointer.match(t) if m: t = ('%s%s'%(m.group(1), m.group(3))).strip() - if t in typeMap: - t = typeMap[t] return ( t, n.strip()) def findEnums(dom): @@ -52,11 +50,11 @@ def findEnums(dom): ret[n] = v return ret -def findCommands(dom, typeMap = {}): +def findCommands(dom): ret = {} for i in findChildren(dom, [ 'registry', 'commands', 'command' ]): - r,n = findParams(findChildren(i, ['proto'])[0], typeMap) - p = [ findParams(j, typeMap) for j in findChildren(i, ['param'])] + r,n = findParams(findChildren(i, ['proto'])[0]) + p = [ findParams(j) for j in findChildren(i, ['param'])] ret[n] = (r, p) return ret @@ -87,11 +85,8 @@ def findExtensions(dom): return ret def findApi(dom, name): - typeMap = {} -# if name=='wgl': -# typeMap = { 'int' : 'INT', 'void' : 'VOID' } enums = findEnums(dom) - commands = findCommands(dom, typeMap) + commands = findCommands(dom) features = findFeatures(dom) extensions = findExtensions(dom) return (enums, commands, features, extensions) From 3e6dfc44143e46be4b6e00ad8e9c303f39f4dd5a Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Sat, 2 Feb 2019 22:33:06 +1000 Subject: [PATCH 3/3] Prune auto/core for WGL code generation from XML --- auto/core/gl/WGL_ARB_context_flush_control | 8 -------- auto/core/gl/WGL_ARB_create_context | 12 ------------ auto/core/gl/WGL_ATI_render_texture_rectangle | 5 ----- auto/core/gl/WGL_EXT_create_context_es2_profile | 5 ----- auto/core/gl/WGL_EXT_create_context_es_profile | 5 ----- auto/core/gl/WGL_EXT_framebuffer_sRGB | 5 ----- auto/core/gl/WGL_EXT_pixel_format_packed_float | 5 ----- auto/core/gl/WGL_NV_vertex_array_range | 6 ------ 8 files changed, 51 deletions(-) delete mode 100644 auto/core/gl/WGL_ARB_context_flush_control delete mode 100644 auto/core/gl/WGL_ARB_create_context delete mode 100644 auto/core/gl/WGL_ATI_render_texture_rectangle delete mode 100644 auto/core/gl/WGL_EXT_create_context_es2_profile delete mode 100644 auto/core/gl/WGL_EXT_create_context_es_profile delete mode 100644 auto/core/gl/WGL_EXT_framebuffer_sRGB delete mode 100644 auto/core/gl/WGL_EXT_pixel_format_packed_float delete mode 100644 auto/core/gl/WGL_NV_vertex_array_range diff --git a/auto/core/gl/WGL_ARB_context_flush_control b/auto/core/gl/WGL_ARB_context_flush_control deleted file mode 100644 index 903000f..0000000 --- a/auto/core/gl/WGL_ARB_context_flush_control +++ /dev/null @@ -1,8 +0,0 @@ -WGL_ARB_context_flush_control -https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_context_flush_control.txt -WGL_ARB_context_flush_control - - WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 - WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0x0000 - WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 - diff --git a/auto/core/gl/WGL_ARB_create_context b/auto/core/gl/WGL_ARB_create_context deleted file mode 100644 index b617481..0000000 --- a/auto/core/gl/WGL_ARB_create_context +++ /dev/null @@ -1,12 +0,0 @@ -WGL_ARB_create_context -http://www.opengl.org/registry/specs/ARB/wgl_create_context.txt -WGL_ARB_create_context - - WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 - WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002 - WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 - WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 - WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 - WGL_CONTEXT_FLAGS_ARB 0x2094 - ERROR_INVALID_VERSION_ARB 0x2095 - HGLRC wglCreateContextAttribsARB (HDC hDC, HGLRC hShareContext, const int* attribList) diff --git a/auto/core/gl/WGL_ATI_render_texture_rectangle b/auto/core/gl/WGL_ATI_render_texture_rectangle deleted file mode 100644 index aba7be1..0000000 --- a/auto/core/gl/WGL_ATI_render_texture_rectangle +++ /dev/null @@ -1,5 +0,0 @@ -WGL_ATI_render_texture_rectangle - -WGL_ATI_render_texture_rectangle - - WGL_TEXTURE_RECTANGLE_ATI 0x21A5 diff --git a/auto/core/gl/WGL_EXT_create_context_es2_profile b/auto/core/gl/WGL_EXT_create_context_es2_profile deleted file mode 100644 index 3105737..0000000 --- a/auto/core/gl/WGL_EXT_create_context_es2_profile +++ /dev/null @@ -1,5 +0,0 @@ -WGL_EXT_create_context_es2_profile -http://www.opengl.org/registry/specs/EXT/wgl_create_context_es2_profile.txt -WGL_EXT_create_context_es2_profile - - WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 diff --git a/auto/core/gl/WGL_EXT_create_context_es_profile b/auto/core/gl/WGL_EXT_create_context_es_profile deleted file mode 100644 index 5c7ce7e..0000000 --- a/auto/core/gl/WGL_EXT_create_context_es_profile +++ /dev/null @@ -1,5 +0,0 @@ -WGL_EXT_create_context_es_profile -http://www.opengl.org/registry/specs/EXT/wgl_create_context_es_profile.txt -WGL_EXT_create_context_es_profile - - WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004 diff --git a/auto/core/gl/WGL_EXT_framebuffer_sRGB b/auto/core/gl/WGL_EXT_framebuffer_sRGB deleted file mode 100644 index 5f2f5b8..0000000 --- a/auto/core/gl/WGL_EXT_framebuffer_sRGB +++ /dev/null @@ -1,5 +0,0 @@ -WGL_EXT_framebuffer_sRGB -http://developer.download.nvidia.com/opengl/specs/GL_EXT_framebuffer_sRGB.txt -WGL_EXT_framebuffer_sRGB - - WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9 diff --git a/auto/core/gl/WGL_EXT_pixel_format_packed_float b/auto/core/gl/WGL_EXT_pixel_format_packed_float deleted file mode 100644 index 662a993..0000000 --- a/auto/core/gl/WGL_EXT_pixel_format_packed_float +++ /dev/null @@ -1,5 +0,0 @@ -WGL_EXT_pixel_format_packed_float -http://developer.download.nvidia.com/opengl/specs/GL_EXT_packed_float.txt -WGL_EXT_pixel_format_packed_float - - WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8 diff --git a/auto/core/gl/WGL_NV_vertex_array_range b/auto/core/gl/WGL_NV_vertex_array_range deleted file mode 100644 index 27b43ce..0000000 --- a/auto/core/gl/WGL_NV_vertex_array_range +++ /dev/null @@ -1,6 +0,0 @@ -WGL_NV_vertex_array_range -http://oss.sgi.com/projects/ogl-sample/registry/NV/vertex_array_range.txt -WGL_NV_vertex_array_range - - void * wglAllocateMemoryNV (GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority) - void wglFreeMemoryNV (void *pointer)