Skip to content

Commit

Permalink
Initial EGL core and extension support with Python egl.xml spec parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nigels-com committed Feb 6, 2016
1 parent 5a61710 commit 43a9299
Show file tree
Hide file tree
Showing 19 changed files with 377 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* text eol=lf
*.png binary
*.pdf binary
build/*/* text eol=crlf
CMakeLists.txt text eol=lf
build/cmake/* text eol=lf
47 changes: 41 additions & 6 deletions auto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ BLACKLIST = blacklist

GL_CORE_SPEC := $(CORE)/GL_VERSION*
GLX_CORE_SPEC := $(CORE)/GLX_VERSION*
EGL_CORE_SPEC := $(CORE)/EGL_VERSION*
ifeq (custom,$(MAKECMDGOALS))
#GL_CORE_SPEC := $(shell grep GL_VERSION custom.txt | perl -pi -e "s=^=$(CORE)/=g;")
GL_EXT_SPEC := $(shell grep "^[ \t]*GL_" custom.txt | grep -v GL_VERSION | perl -pi -e "s=^=$(EXT)/=g;")
WGL_EXT_SPEC := $(shell grep "^[ \t]*WGL_" custom.txt | perl -pi -e "s=^=$(EXT)/=g;")
#GLX_CORE_SPEC := $(shell grep GLX_VERSION custom.txt | perl -pi -e "s=^=$(CORE)/=g;")
GLX_EXT_SPEC := $(shell grep "^[ \t]*GLX_" custom.txt | grep -v GLX_VERSION | perl -pi -e "s=^=$(EXT)/=g;")
EGL_EXT_SPEC := $(shell grep "^[ \t]*EGL_" custom.txt | grep -v EGL_VERSION | perl -pi -e "s=^=$(EXT)/=g;")
else
GL_EXT_SPEC := $(EXT)/GL_*
WGL_EXT_SPEC := $(EXT)/WGL_*
GLX_EXT_SPEC := $(EXT)/GLX_*
EGL_EXT_SPEC := $(EXT)/EGL_*
endif

PARSE_SPEC = parse_spec.pl
Expand All @@ -65,7 +68,8 @@ B.DEST = $(TOP)/build
I.TARGETS = \
$(I.DEST)/glew.h \
$(I.DEST)/wglew.h \
$(I.DEST)/glxew.h
$(I.DEST)/glxew.h \
$(I.DEST)/eglew.h

ifeq (yes,$(GLEW_SPLIT_SOURCE))
S.TARGETS = \
Expand Down Expand Up @@ -175,6 +179,21 @@ $(I.DEST)/glxew.h: $(EXT)/.dummy
perl -e "s/GLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_2;/GLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_0;\nGLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_1;\nGLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_2;/" -pi $@
cat $(SRC)/glxew_tail.h >> $@

$(I.DEST)/eglew.h: $(EXT)/.dummy
@echo "--------------------------------------------------------------------"
@echo "Creating eglew.h"
@echo "--------------------------------------------------------------------"
cp -f $(SRC)/glew_license.h $@
cat $(SRC)/mesa_license.h >> $@
cat $(SRC)/khronos_license.h >> $@
cat $(SRC)/eglew_head.h >> $@
$(BIN)/make_header.pl "" EGL $(EGL_CORE_SPEC) >> $@
$(BIN)/make_header.pl "" EGL $(EGL_EXT_SPEC) >> $@
cat $(SRC)/eglew_mid.h >> $@
$(BIN)/make_struct_fun.pl EGLEW_FUN_EXPORT $(EGL_CORE_SPEC) $(EGL_EXT_SPEC) >> $@
$(BIN)/make_struct_var.pl EGLEW_VAR_EXPORT $(EGL_CORE_SPEC) $(EGL_EXT_SPEC) >> $@
cat $(SRC)/eglew_tail.h >> $@

$(S.DEST)/glew.c: $(EXT)/.dummy
@echo "--------------------------------------------------------------------"
@echo "Creating glew.c"
Expand All @@ -200,14 +219,26 @@ $(S.DEST)/glew.c: $(EXT)/.dummy
$(BIN)/make_list.pl $(GL_EXT_SPEC) >> $@
$(BIN)/make_list2.pl $(GL_EXT_SPEC) >> $@
echo -e "\n return GLEW_OK;\n}\n" >> $@
echo -e "\n#if defined(_WIN32) && !defined(GLEW_EGL) && !defined(GLEW_OSMESA)" >> $@
echo -e "\n#if defined(GLEW_OSMESA)" >> $@
echo -e "\n#elif defined(GLEW_EGL)" >> $@
$(BIN)/make_def_fun.pl EGL $(EGL_CORE_SPEC) >> $@
$(BIN)/make_def_fun.pl EGL $(EGL_EXT_SPEC) >> $@
$(BIN)/make_def_var.pl EGL $(EGL_CORE_SPEC) >> $@
$(BIN)/make_def_var.pl EGL $(EGL_EXT_SPEC) >> $@
$(BIN)/make_init.pl EGL $(EGL_CORE_SPEC) >> $@
$(BIN)/make_init.pl EGL $(EGL_EXT_SPEC) >> $@
cat $(SRC)/glew_init_egl.c >> $@
$(BIN)/make_list.pl $(EGL_CORE_SPEC) >> $@
$(BIN)/make_list.pl $(EGL_EXT_SPEC) >> $@
echo -e "\n return GLEW_OK;\n}" >> $@
echo -e "\n#elif defined(_WIN32)" >> $@
$(BIN)/make_def_fun.pl WGL $(WGL_EXT_SPEC) >> $@
$(BIN)/make_def_var.pl WGL $(WGL_EXT_SPEC) >> $@
$(BIN)/make_init.pl WGL $(WGL_EXT_SPEC) >> $@
cat $(SRC)/glew_init_wgl.c >> $@
$(BIN)/make_list.pl $(WGL_EXT_SPEC) >> $@
echo -e "\n return GLEW_OK;\n}" >> $@;
echo -e "\n#elif !defined(GLEW_EGL) && !defined(GLEW_OSMESA) && !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))" >> $@
echo -e "\n#elif !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))" >> $@
$(BIN)/make_def_fun.pl GLX $(GLX_CORE_SPEC) >> $@
$(BIN)/make_def_fun.pl GLX $(GLX_EXT_SPEC) >> $@
echo -e "\nGLboolean __GLXEW_VERSION_1_0 = GL_FALSE;" >> $@
Expand All @@ -228,6 +259,8 @@ $(S.DEST)/glew.c: $(EXT)/.dummy
$(BIN)/make_str.pl $(WGL_EXT_SPEC) >> $@
cat $(SRC)/glew_str_glx.c >> $@
$(BIN)/make_str.pl $(GLX_CORE_SPEC) $(GLX_EXT_SPEC) >> $@
cat $(SRC)/glew_str_egl.c >> $@
$(BIN)/make_str.pl $(EGL_CORE_SPEC) $(EGL_EXT_SPEC) >> $@
cat $(SRC)/glew_str_tail.c >> $@
perl -e "s/GLEW_VERSION_STRING/$(GLEW_VERSION)/g" -pi $@
perl -e "s/GLEW_VERSION_MAJOR_STRING/$(GLEW_MAJOR)/g" -pi $@
Expand All @@ -245,14 +278,13 @@ $(S.DEST)/glewinfo.c: $(EXT)/.dummy
cat $(SRC)/glewinfo_head.c >> $@
$(BIN)/make_info.pl $(GL_CORE_SPEC) >> $@
$(BIN)/make_info.pl $(GL_EXT_SPEC) >> $@
echo -e "#if !defined(GLEW_EGL)\n" >> $@
echo -e "#ifdef _WIN32\n" >> $@
echo -e "#if defined(GLEW_EGL)\n" >> $@
echo -e "#elif _WIN32\n" >> $@
$(BIN)/make_info.pl $(WGL_EXT_SPEC) >> $@
echo -e "#else /* _UNIX */\n" >> $@
$(BIN)/make_info.pl $(GLX_CORE_SPEC) >> $@
$(BIN)/make_info.pl $(GLX_EXT_SPEC) >> $@
echo -e "#endif /* _WIN32 */\n" >> $@
echo -e "#endif /* !defined(GLEW_EGL) */\n" >> $@

cat $(SRC)/glewinfo_gl.c >> $@
$(BIN)/make_info_list.pl $(GL_CORE_SPEC) >> $@
Expand All @@ -262,6 +294,9 @@ $(S.DEST)/glewinfo.c: $(EXT)/.dummy
cat $(SRC)/glewinfo_glx.c >> $@
$(BIN)/make_info_list.pl $(GLX_CORE_SPEC) >> $@
$(BIN)/make_info_list.pl $(GLX_EXT_SPEC) >> $@
cat $(SRC)/glewinfo_egl.c >> $@
$(BIN)/make_info_list.pl $(EGL_CORE_SPEC) >> $@
$(BIN)/make_info_list.pl $(EGL_EXT_SPEC) >> $@
cat $(SRC)/glewinfo_tail.c >> $@
perl -e 's/"glColorSubTable"/"glBlendEquation", glBlendEquation == NULL);\n glewInfoFunc("glColorSubTable"/g' -pi $@
rm -f [email protected]
Expand Down
2 changes: 1 addition & 1 deletion auto/bin/make_list.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ($%)
$extvar =~ s/GL(X*)_/GL$1EW_/;

my $extpre = $extname;
$extpre =~ s/^(W?)GL(X?).*$/\l$1gl\l$2ew/;
$extpre =~ s/^(W?E?)GL(X?).*$/\l$1gl\l$2ew/;

#my $pextvar = prefix_varname($extvar);

Expand Down
128 changes: 128 additions & 0 deletions auto/bin/parse_xml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/python

import re
import sys
from xml.dom.minidom import parse, Node

def findChildren(node, path):
result = []
if len(path)==1:
for i in node.childNodes:
if i.nodeType==Node.ELEMENT_NODE:
if i.tagName==path[0]:
result.append(i)
else:
for i in node.childNodes:
if i.nodeType==Node.ELEMENT_NODE:
if i.tagName==path[0]:
result.extend(findChildren(i, path[1:]))
return result

def findData(node, path):
return [ i.firstChild.data for i in findChildren(node, path) ]

def findParams(node):
n = findData(node, ['name'])[0]
t = ''
for i in node.childNodes:
if i.nodeType==Node.TEXT_NODE:
t += i.data
if i.nodeType==Node.ELEMENT_NODE and i.tagName=='ptype':
t += i.firstChild.data
return ( t, n)

def findEnums(dom):
ret = {}
for i in findChildren(dom, [ 'registry', 'enums', 'enum' ]):
n = i.getAttribute('name')
v = i.getAttribute('value')
ret[n] = v
return ret

def findCommands(dom):
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'])]
ret[n] = (r, p)
return ret

def findFeatures(dom):
ret = {}
for i in findChildren(dom, [ 'registry', 'feature' ]):
n = i.getAttribute('name')
e = []
c = []
for j in findChildren(i, [ 'require', 'enum' ]):
e.append(j.getAttribute("name"))
for j in findChildren(i, [ 'require', 'command' ]):
c.append(j.getAttribute("name"))
ret[n] = (e,c)
return ret

def findExtensions(dom):
ret = {}
for i in findChildren(dom, [ 'registry', 'extensions', 'extension' ]):
n = i.getAttribute('name')
e = []
c = []
for j in findChildren(i, [ 'require', 'enum' ]):
e.append(j.getAttribute("name"))
for j in findChildren(i, [ 'require', 'command' ]):
c.append(j.getAttribute("name"))
ret[n] = (e,c)
return ret

def findApi(dom, name):
enums = findEnums(dom)
commands = findCommands(dom)
features = findFeatures(dom)
extensions = findExtensions(dom)
return (enums, commands, features, extensions)

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')
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):
f.write('\t%s %s (%s)\n'%(c[1][0], c[0], ', '.join( [ '%s %s'%(j[0], j[1]) for j in c[1][1] ] )))

if __name__ == '__main__':

from optparse import OptionParser
import os

parser = OptionParser('usage: %prog [options] [XML specs...]')
parser.add_option("--core", dest="core", help="location for core outputs", default='')
parser.add_option("--extensions", dest="extensions", help="location for extensions outputs", default='')

(options, args) = parser.parse_args()

for i in args:

dom = parse(i)
api = findApi(dom, 'egl')

print 'Found {} enums, {} commands, {} features and {} extensions.'.format(
len(api[0]), len(api[1]), len(api[2]), len(api[3]))

if len(options.core):
for i in api[2].keys():
f = open('%s/%s'%(options.core, i), 'w')
writeExtension(f, i, api[2][i], api[0], api[1])
f.close()

if len(options.extensions):
for i in api[3].keys():
f = open('%s/%s'%(options.extensions, i), 'w')
writeExtension(f, i, api[3][i], api[0], api[1])
f.close()

Binary file added auto/khronos/readme.pdf
Binary file not shown.
74 changes: 74 additions & 0 deletions auto/src/eglew_head.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef __eglew_h__
#define __eglew_h__
#define __EGLEW_H__

#ifdef __eglext_h_
#error eglext.h included before eglew.h
#endif

#if defined(__egl_h_)
#error egl.h included before eglew.h
#endif

#define __eglext_h_

#define __egl_h_

#ifndef EGLAPIENTRY
#define EGLAPIENTRY
#endif
#ifndef EGLAPI
#define EGLAPI extern
#endif

/* EGL Types */
#include <sys/types.h>

#include <KHR/khrplatform.h>
#include <EGL/eglplatform.h>

typedef int32_t EGLint;

typedef unsigned int EGLBoolean;
typedef void *EGLDisplay;
typedef void *EGLConfig;
typedef void *EGLSurface;
typedef void *EGLContext;
typedef void (*__eglMustCastToProperFunctionPointerType)(void);

typedef unsigned int EGLenum;
typedef void *EGLClientBuffer;

typedef void *EGLSync;
typedef intptr_t EGLAttrib;
typedef khronos_utime_nanoseconds_t EGLTime;
typedef void *EGLImage;

typedef void *EGLSyncKHR;
typedef intptr_t EGLAttribKHR;
typedef void *EGLLabelKHR;
typedef void *EGLObjectKHR;
typedef void (EGLAPIENTRY *EGLDEBUGPROCKHR)(EGLenum error,const char *command,EGLint messageType,EGLLabelKHR threadLabel,EGLLabelKHR objectLabel,const char* message);
typedef khronos_utime_nanoseconds_t EGLTimeKHR;
typedef void *EGLImageKHR;
typedef void *EGLStreamKHR;
typedef khronos_uint64_t EGLuint64KHR;
typedef int EGLNativeFileDescriptorKHR;
typedef khronos_ssize_t EGLsizeiANDROID;
typedef void (*EGLSetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize);
typedef EGLsizeiANDROID (*EGLGetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, void *value, EGLsizeiANDROID valueSize);
typedef void *EGLDeviceEXT;
typedef void *EGLOutputLayerEXT;
typedef void *EGLOutputPortEXT;
typedef void *EGLSyncNV;
typedef khronos_utime_nanoseconds_t EGLTimeNV;
typedef khronos_utime_nanoseconds_t EGLuint64NV;

struct EGLClientPixmapHI;

EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress (const char *procname);

#ifdef __cplusplus
extern "C" {
#endif

4 changes: 4 additions & 0 deletions auto/src/eglew_mid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* ------------------------------------------------------------------------- */

#define EGLEW_FUN_EXPORT GLEW_FUN_EXPORT
#define EGLEW_VAR_EXPORT GLEW_VAR_EXPORT
15 changes: 15 additions & 0 deletions auto/src/eglew_tail.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* ------------------------------------------------------------------------ */

GLEWAPI GLenum GLEWAPIENTRY eglewInit ();
GLEWAPI GLboolean GLEWAPIENTRY eglewIsSupported (const char *name);

#define EGLEW_GET_VAR(x) (*(const GLboolean*)&x)
#define EGLEW_GET_FUN(x) x

GLEWAPI GLboolean GLEWAPIENTRY eglewGetExtension (const char *name);

#ifdef __cplusplus
}
#endif

#endif /* __eglew_h__ */
Loading

0 comments on commit 43a9299

Please sign in to comment.