Skip to content

Commit

Permalink
Added support for EGL with desktop OpenGL.
Browse files Browse the repository at this point in the history
Also updated OpenGL registry submodule.
  • Loading branch information
akb825 committed May 7, 2018
1 parent 1c84bd9 commit 2247e99
Show file tree
Hide file tree
Showing 15 changed files with 6,997 additions and 82 deletions.
8 changes: 7 additions & 1 deletion AnyGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@
glRegistry.setGenerator(DebugGenerator(glRegistry, diagFile = diagFile))
glRegistry.apiGen(glOptions)

glOptions.apiname = ['gl']
glOptions.filename = os.path.join(args.outDir, 'AnyGLLoadEGL_GL.c')
write('Outputting', glOptions.filename + '...')
glRegistry.setGenerator(EGLLoadGenerator(diagFile = diagFile))
glRegistry.apiGen(glOptions)

glOptions.apiname = ['gles2']
glOptions.filename = os.path.join(args.outDir, 'AnyGLLoadEGL.c')
glOptions.filename = os.path.join(args.outDir, 'AnyGLLoadEGL_GLES.c')
write('Outputting', glOptions.filename + '...')
glRegistry.setGenerator(EGLLoadGenerator(diagFile = diagFile))
glRegistry.apiGen(glOptions)
Expand Down
33 changes: 19 additions & 14 deletions AnyGL/EGLLoadGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
from .FunctionInfo import *

class FeatureInfo:
def __init__(self, interface):
def __init__(self, interface, firstVersion):
self.name = interface.get('name')
self.extension = interface.tag == 'extension'
if self.extension:
self.version = None
else:
self.version = interface.get('number')

self.loadFirst = self.version != None and self.version == "2.0"
self.loadFirst = self.version != None and self.version == firstVersion
self.functions = []

class EGLLoadGenerator(OutputGenerator):
Expand All @@ -43,13 +43,13 @@ def write(self, *args):

def beginFile(self, genOpts):
OutputGenerator.beginFile(self, genOpts)
self.gles = len(genOpts.apiname) == 1 and genOpts.apiname[0] == 'gles2'

self.write('#include "AnyGL.h"')
self.write('#include "gl.h"')
self.newLine()
self.write('#if ANYGL_LOAD == ANYGL_LOAD_EGL')
self.write('#if !ANYGL_GLES')
self.write('#error EGL loading currently requires OpenGL ES')
self.write('#endif')
self.write('#if ANYGL_LOAD == ANYGL_LOAD_EGL && ANYGL_GLES == ' +
('1' if self.gles else '0'))
self.write('#include <EGL/egl.h>')
self.write('#include <dlfcn.h>')
self.newLine()
Expand All @@ -65,7 +65,10 @@ def beginFile(self, genOpts):

self.write('int AnyGL_initialize(void)\n{')
self.write('\tif (gllib)\n\t\treturn 1;')
self.write('\tgllib = dlopen("libGLESv2.so", RTLD_LAZY);')
if self.gles:
self.write('\tgllib = dlopen("libGLESv2.so", RTLD_LAZY);')
else:
self.write('\tgllib = dlopen("libOpenGL.so", RTLD_LAZY);')
self.write('\treturn gllib != NULL;\n}')
self.newLine()

Expand Down Expand Up @@ -94,18 +97,20 @@ def endFile(self):
self.write('\t\treturn 0;')

# GL_HALF_FLOAT workaround
self.newLine()
self.write('\tif (AnyGL_atLeastVersion(3, 0, 1))')
self.write('\t\tAnyGL_HALF_FLOAT = GL_HALF_FLOAT;')
self.write('\telse')
self.write('\t\tAnyGL_HALF_FLOAT = GL_HALF_FLOAT_OES;')
if self.gles:
self.newLine()
self.write('\tif (AnyGL_atLeastVersion(3, 0, 1))')
self.write('\t\tAnyGL_HALF_FLOAT = GL_HALF_FLOAT;')
self.write('\telse')
self.write('\t\tAnyGL_HALF_FLOAT = GL_HALF_FLOAT_OES;')

# Load the core features.
glesBool = '1' if self.gles else '0'
for feature in self.coreFeatures:
self.newLine()
self.write('\t/*', feature.name, '*/')
self.write('\tif (AnyGL_atLeastVersion(' + feature.version[0] + ',', feature.version[2] + \
', 1))\n\t{')
', ' + glesBool + '))\n\t{')
for function in feature.functions:
self.write('\t\tAnyGL_' + function.name, '= (' + function.type + \
')dlsym(gllib, "' + function.name + '");')
Expand Down Expand Up @@ -148,7 +153,7 @@ def endFile(self):
def beginFeature(self, interface, emit):
OutputGenerator.beginFeature(self, interface, emit)
if emit:
self.curFeature = FeatureInfo(interface)
self.curFeature = FeatureInfo(interface, '2.0' if self.gles else '1.0')

def endFeature(self):
if self.curFeature:
Expand Down
2 changes: 1 addition & 1 deletion OpenGLRegistry
Submodule OpenGLRegistry updated 37 files
+35 −4 api/GL/glcorearb.h
+38 −3 api/GL/glext.h
+3 −3 api/GL/glxext.h
+3 −3 api/GL/wglext.h
+3 −3 api/GLES/gl.h
+3 −3 api/GLES/glext.h
+3 −3 api/GLES2/gl2.h
+33 −3 api/GLES2/gl2ext.h
+3 −3 api/GLES3/gl3.h
+2,058 −0 extensions/AMD/AMD_gpu_shader_half_float_fetch.txt
+40 −2 extensions/AMD/AMD_gpu_shader_int16.txt
+113 −4 extensions/AMD/AMD_shader_ballot.txt
+11 −3 extensions/ARB/ARB_clip_control.txt
+86 −22 extensions/ARB/ARB_gl_spirv.txt
+22 −6 extensions/ARB/ARB_internalformat_query2.txt
+6 −2 extensions/ARB/ARB_spirv_extensions.txt
+206 −0 extensions/EXT/EXT_EGL_image_external_wrap_modes.txt
+221 −0 extensions/EXT/EXT_EGL_image_storage.txt
+4 −2 extensions/EXT/EXT_YUV_target.txt
+51 −6 extensions/EXT/EXT_multisampled_render_to_texture.txt
+17 −2 extensions/EXT/EXT_primitive_bounding_box.txt
+507 −56 extensions/EXT/EXT_shader_framebuffer_fetch.txt
+231 −0 extensions/EXT/EXT_texture_format_sRGB_override.txt
+47 −18 extensions/EXT/EXT_texture_sRGB_decode.txt
+124 −0 extensions/INTEL/INTEL_blackhole_render.txt
+32 −5 extensions/KHR/KHR_blend_equation_advanced.txt
+34 −6 extensions/NV/NV_blend_equation_advanced.txt
+10 −8 extensions/OES/OES_EGL_image_external.txt
+16 −2 extensions/OES/OES_primitive_bounding_box.txt
+30 −10 extensions/OVR/OVR_multiview.txt
+3 −3 extensions/QCOM/QCOM_texture_foveated.txt
+10 −0 extensions/esext.php
+11 −1 extensions/glext.php
+32 −1 extensions/registry.py
+78 −36 xml/gl.xml
+2 −2 xml/readme.tex
+1 −1 xml/reg.py
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ When checking if a function is supported, you may use the `ANYGL_SUPPORTED()` ma

> **Note:** OpenGL ES 2.0 uses the `GL_HALF_FLOAT_OES` enum, which is a different value from `GL_HALF_FLOAT`, used for all other OpenGL versions, including OpenGL ES 3.0. To work around this, the `AnyGL_HALF_FLOAT` variable is defined, which will have the value `GL_HALF_FLOAT_OES` after loading OpenGL ES 2.0 and `GL_HALF_FLOAT` otherwise.
## Using in applications

AnyGL manages loading of the OpenGL functions, but the application is responsible for management of the OpenGL contexts themselves. The flow of control within the application should be:

1. Call `AnyGL_initialize()` at application startup.
2. Create a context and bind it.
3. Call `AnyGL_load()` to load the OpenGL functions.
4. Optionally call `AnyGL_setDebugEnabled()` to toggle debugging. See next section for more information.
5. When the application is closed, call `AnyGL_shutdown()`.

## Debugging

When `ANYGL_ENABLE_DEBUG` is defined to 1 (default when `NDEBUG` isn't defined), the debugging feature may be enabled. Once you call `AnyGL_setDebugEnabled(1)` the OpenGL function pointers will be replaced with debug versions. These will check if any OpenGL occurred after the function was called, and if so will call the error function with a string version of the call, including the values of the parameters. (such as resolving enum names) By default, this will print to the console.
Expand Down
7 changes: 6 additions & 1 deletion generated/AnyGLConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#define ANYGL_GLES (ANYGL_ANDROID || ANYGL_IOS)
#endif

/* @define this to force usage of EGL, even when platform-specific libraries are available. */
#ifndef ANYGL_FORCE_EGL
#define ANYGL_FORCE_EGL 0
#endif

/* #define this to the OpenGL version (times 10) to include when loading via function pointer. */
#ifndef ANYGL_GL_VERSION
#define ANYGL_GL_VERSION 33
Expand All @@ -58,7 +63,7 @@
#ifndef ANYGL_LOAD
#if ANYGL_APPLE
# define ANYGL_LOAD ANYGL_LOAD_FPTR
#elif ANYGL_GLES
#elif ANYGL_GLES || ANYGL_FORCE_EGL
# define ANYGL_LOAD ANYGL_LOAD_EGL
#elif ANYGL_WINDOWS
# define ANYGL_LOAD ANYGL_LOAD_WGL
Expand Down
Loading

0 comments on commit 2247e99

Please sign in to comment.