commit 973e1c38f9199f83f15dd1c1328232ea0e6993a0 parent d9e6a843ef88cc637f25be43e4f1f87e2c701172 Author: Michael Savage <mikejsavage@gmail.com> Date: Mon Jan 23 20:52:08 +0200 Remove D/nim/volt support from glad Diffstat:
libs/glad/glad/lang/__init__.py | | | 6 | ------ |
libs/glad/glad/lang/d/__init__.py | | | 25 | ------------------------- |
libs/glad/glad/lang/d/generator.py | | | 861 | ------------------------------------------------------------------------------- |
libs/glad/glad/lang/d/loader/__init__.py | | | 91 | ------------------------------------------------------------------------------- |
libs/glad/glad/lang/d/loader/egl.py | | | 39 | --------------------------------------- |
libs/glad/glad/lang/d/loader/gl.py | | | 118 | ------------------------------------------------------------------------------- |
libs/glad/glad/lang/d/loader/glx.py | | | 49 | ------------------------------------------------- |
libs/glad/glad/lang/d/loader/wgl.py | | | 36 | ------------------------------------ |
libs/glad/glad/lang/nim/__init__.py | | | 27 | --------------------------- |
libs/glad/glad/lang/nim/generator.py | | | 530 | ------------------------------------------------------------------------------- |
libs/glad/glad/lang/nim/loader/__init__.py | | | 91 | ------------------------------------------------------------------------------- |
libs/glad/glad/lang/nim/loader/egl.py | | | 40 | ---------------------------------------- |
libs/glad/glad/lang/nim/loader/gl.py | | | 147 | ------------------------------------------------------------------------------- |
libs/glad/glad/lang/nim/loader/glx.py | | | 51 | --------------------------------------------------- |
libs/glad/glad/lang/nim/loader/wgl.py | | | 38 | -------------------------------------- |
libs/glad/glad/lang/volt/__init__.py | | | 25 | ------------------------- |
libs/glad/glad/lang/volt/generator.py | | | 86 | ------------------------------------------------------------------------------- |
libs/glad/glad/lang/volt/loader/__init__.py | | | 65 | ----------------------------------------------------------------- |
libs/glad/glad/lang/volt/loader/egl.py | | | 49 | ------------------------------------------------- |
libs/glad/glad/lang/volt/loader/gl.py | | | 61 | ------------------------------------------------------------- |
libs/glad/glad/lang/volt/loader/glx.py | | | 48 | ------------------------------------------------ |
libs/glad/glad/lang/volt/loader/wgl.py | | | 36 | ------------------------------------ |
diff --git a/libs/glad/glad/lang/__init__.py b/libs/glad/glad/lang/__init__.py @@ -1,15 +1,9 @@ import glad.lang.c -import glad.lang.d -import glad.lang.nim -import glad.lang.volt def get_generator(name, spec): _langs = [ glad.lang.c, - glad.lang.d, - glad.lang.nim, - glad.lang.volt ] for lang in _langs: diff --git a/libs/glad/glad/lang/d/__init__.py b/libs/glad/glad/lang/d/__init__.py @@ -1,25 +0,0 @@ -from glad.lang.d.loader.egl import EGLDLoader -from glad.lang.d.loader.gl import OpenGLDLoader -from glad.lang.d.loader.glx import GLXDLoader -from glad.lang.d.loader.wgl import WGLDLoader - -from glad.lang.d.generator import DGenerator - - -_specs = { - 'egl': EGLDLoader, - 'gl': OpenGLDLoader, - 'glx': GLXDLoader, - 'wgl': WGLDLoader -} - -_generators = { - 'd': DGenerator, -} - - -def get_generator(name, spec): - gen = _generators.get(name) - loader = _specs.get(spec) - - return gen, loader diff --git a/libs/glad/glad/lang/d/generator.py b/libs/glad/glad/lang/d/generator.py @@ -1,861 +0,0 @@ -from itertools import chain -import os.path -import sys - -from glad.lang.common.generator import Generator -from glad.lang.common.util import makefiledir - - -if sys.version_info >= (3, 0): - from io import StringIO - basestring = str -else: - from StringIO import StringIO - - -def _gl_types(gen, f): - gen.write_opaque_struct(f, '__GLsync') - gen.write_alias(f, 'GLsync', '__GLsync*') - gen.write_opaque_struct(f, '_cl_context') - gen.write_opaque_struct(f, '_cl_event') - gen.write_extern(f) - gen.write_alias( - f, - 'GLDEBUGPROC', 'void function(GLenum, GLenum, ' - 'GLuint, GLenum, GLsizei, in GLchar*, GLvoid*)' - ) - gen.write_alias(f, 'GLDEBUGPROCARB', 'GLDEBUGPROC') - gen.write_alias(f, 'GLDEBUGPROCKHR', 'GLDEBUGPROC') - gen.write_alias( - f, - 'GLDEBUGPROCAMD', 'void function(GLuint, GLenum, ' - 'GLenum, GLsizei, in GLchar*, GLvoid*)' - ) - gen.write_extern_end(f) - - -def _egl_types(gen, f): - io = StringIO() - gen.write_opaque_struct(io, 'egl_native_pixmap_t') - - f.write(''' -// Thanks to @jpf91 (github) for these declarations -version(Windows) { - import core.sys.windows.windows; - alias EGLNativeDisplayType = HDC; - alias EGLNativePixmapType = HBITMAP; - alias EGLNativeWindowType = HWND; -} else version(Symbian) { - alias EGLNativeDisplayType = int; - alias EGLNativeWindowType = void*; - alias EGLNativePixmapType = void*; -} else version(Android) { - //import android.native_window; - //struct egl_native_pixmap_t; - ''' + io.getvalue() + ''' - //alias ANativeWindow* EGLNativeWindowType; - //alias egl_native_pixmap_t* EGLNativePixmapType; - alias EGLNativeWindowType = void*; - alias EGLNativePixmapType = void*; - alias EGLNativeDisplayType = void*; -} else version(linux) { - version(Xlib) { - import X11.Xlib; - import X11.Xutil; - alias EGLNativeDisplayType = Display*; - alias EGLNativePixmapType = Pixmap; - alias EGLNativeWindowType = Window; - } else { - alias EGLNativeDisplayType = void*; - alias EGLNativePixmapType = uint; - alias EGLNativeWindowType = uint; - } -} -alias EGLObjectKHR = void*; -alias EGLLabelKHR = void*; - -extern(System) { -alias EGLSetBlobFuncANDROID = void function(const(void)*, EGLsizeiANDROID, const(void)*, EGLsizeiANDROID); -alias EGLGetBlobFuncANDROID = EGLsizeiANDROID function(const(void)*, EGLsizeiANDROID, const(void)* EGLsizeiANDROID); -struct EGLClientPixmapHI { - void *pData; - EGLint iWidth; - EGLint iHeight; - EGLint iStride; -} -alias EGLDEBUGPROCKHR = void function(EGLenum error,const char *command,EGLint messageType,EGLLabelKHR threadLabel,EGLLabelKHR objectLabel,const char* message); -} -''') - gen.write_extern(f) - gen.write_opaque_struct(f, '_cl_event') - gen.write_extern_end(f) - - -def _glx_types(gen, f): - f.write(''' -version(Xlib) { - import X11.Xlib; - import X11.Xutil; -} else { - alias Bool = int; - alias Status = int; - alias VisualID = uint; - alias XPointer = byte*; - alias XID = uint; - alias Colormap = XID; - alias Display = void; - alias Font = XID; - alias Window = XID; - alias Drawable = XID; - alias Pixmap = XID; - alias Cursor = XID; - alias GContext = XID; - alias KeySym = XID; - - extern(System) { - // Borrowed from derelict - struct XExtData { - int number; - XExtData* next; - extern(C) int function(XExtData*) free_private; - XPointer private_data; - } - - struct Visual { - XExtData* ext_data; - VisualID visualid; - int _class; - uint red_mask, green_mask, blue_mask; - int bits_per_rgb; - int map_entries; - } - - struct XVisualInfo { - Visual *visual; - VisualID visualid; - int screen; - int depth; - int _class; - uint red_mask; - uint green_mask; - uint blue_mask; - int colormap_size; - int bits_per_rgb; - } - } -} - -alias DMbuffer = void*; -alias DMparams = void*; -alias VLNode = void*; -alias VLPath = void*; -alias VLServer = void*; - -alias int64_t = long; -alias uint64_t = ulong; -alias int32_t = int; - -alias GLXContextID = uint; -alias GLXPixmap = uint; -alias GLXDrawable = uint; -alias GLXPbuffer = uint; -alias GLXWindow = uint; -alias GLXFBConfigID = uint; -alias GLXVideoCaptureDeviceNV = XID; -alias GLXPbufferSGIX = XID; -alias GLXVideoSourceSGIX = XID; -alias GLXVideoDeviceNV = uint; - - -extern(System) { - alias __GLXextFuncPtr = void function(); - - struct GLXPbufferClobberEvent { - int event_type; /* GLX_DAMAGED or GLX_SAVED */ - int draw_type; /* GLX_WINDOW or GLX_PBUFFER */ - ulong serial; /* # of last request processed by server */ - Bool send_event; /* true if this came for SendEvent request */ - Display *display; /* display the event was read from */ - GLXDrawable drawable; /* XID of Drawable */ - uint buffer_mask; /* mask indicating which buffers are affected */ - uint aux_buffer; /* which aux buffer was affected */ - int x, y; - int width, height; - int count; /* if nonzero, at least this many more */ - } - - struct GLXBufferSwapComplete { - int type; - ulong serial; /* # of last request processed by server */ - Bool send_event; /* true if this came from a SendEvent request */ - Display *display; /* Display the event was read from */ - GLXDrawable drawable; /* drawable on which event was requested in event mask */ - int event_type; - long ust; - long msc; - long sbc; - } - - union GLXEvent { - GLXPbufferClobberEvent glxpbufferclobber; - GLXBufferSwapComplete glxbufferswapcomplete; - int[24] pad; - } - - struct GLXBufferClobberEventSGIX { - int type; - ulong serial; /* # of last request processed by server */ - Bool send_event; /* true if this came for SendEvent request */ - Display *display; /* display the event was read from */ - GLXDrawable drawable; /* i.d. of Drawable */ - int event_type; /* GLX_DAMAGED_SGIX or GLX_SAVED_SGIX */ - int draw_type; /* GLX_WINDOW_SGIX or GLX_PBUFFER_SGIX */ - uint mask; /* mask indicating which buffers are affected*/ - int x, y; - int width, height; - int count; /* if nonzero, at least this many more */ - } - - struct GLXHyperpipeNetworkSGIX { - char[80] pipeName; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */ - int networkId; - } - - struct GLXHyperpipeConfigSGIX { - char[80] pipeName; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */ - int channel; - uint participationType; - int timeSlice; - } - - struct GLXPipeRect { - char[80] pipeName; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */ - int srcXOrigin, srcYOrigin, srcWidth, srcHeight; - int destXOrigin, destYOrigin, destWidth, destHeight; - } - - struct GLXPipeRectLimits { - char[80] pipeName; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */ - int XOrigin, YOrigin, maxHeight, maxWidth; - } -} -''') - gen.write_extern(f) - gen.write_opaque_struct(f, '__GLXcontextRec') - gen.write_alias(f, 'GLXContext', '__GLXcontextRec*') - gen.write_opaque_struct(f, '__GLXFBConfigRec') - gen.write_alias(f, 'GLXFBConfig', '__GLXFBConfigRec*') - gen.write_alias(f, 'GLXFBConfigSGIX', '__GLXFBConfigRec*') - gen.write_extern_end(f) - - -def _wgl_types(gen, f): - f.write(''' -version(Windows) { - public import core.sys.windows.windows; -} else { - alias BOOL = int; - alias CHAR = char; - alias WORD = ushort; - alias DWORD = uint; - alias FLOAT = float; - alias HANDLE = void*; - alias HDC = HANDLE; - alias HGLRC = HANDLE; - alias INT = int; - alias LPCSTR = const(CHAR)*; - alias LPVOID = void*; - alias UINT = uint; - alias USHORT = ushort; - alias VOID = void; - alias COLORREF = DWORD; - alias HENHMETAFILE = HANDLE; - alias BYTE = byte; -} - -alias PROC = HANDLE; - -extern(System) { - struct RECT { - int left; - int top; - int right; - int bottom; - } - - struct LAYERPLANEDESCRIPTOR { - WORD nSize; - WORD nVersion; - DWORD dwFlags; - BYTE iPixelType; - BYTE cColorBits; - BYTE cRedBits; - BYTE cRedShift; - BYTE cGreenBits; - BYTE cGreenShift; - BYTE cBlueBits; - BYTE cBlueShift; - BYTE cAlphaBits; - BYTE cAlphaShift; - BYTE cAccumBits; - BYTE cAccumRedBits; - BYTE cAccumGreenBits; - BYTE cAccumBlueBits; - BYTE cAccumAlphaBits; - BYTE cDepthBits; - BYTE cStencilBits; - BYTE cAuxBuffers; - BYTE iLayerType; - BYTE bReserved; - COLORREF crTransparent; - } - - struct PIXELFORMATDESCRIPTOR { - WORD nSize; - WORD nVersion; - DWORD dwFlags; - BYTE iPixelType; - BYTE cColorBits; - BYTE cRedBits; - BYTE cRedShift; - BYTE cGreenBits; - BYTE cGreenShift; - BYTE cBlueBits; - BYTE cBlueShift; - BYTE cAlphaBits; - BYTE cAlphaShift; - BYTE cAccumBits; - BYTE cAccumRedBits; - BYTE cAccumGreenBits; - BYTE cAccumBlueBits; - BYTE cAccumAlphaBits; - BYTE cDepthBits; - BYTE cStencilBits; - BYTE cAuxBuffers; - BYTE iLayerType; - BYTE bReserved; - DWORD dwLayerMask; - DWORD dwVisibleMask; - DWORD dwDamageMask; - } - - struct POINTFLOAT { - FLOAT x; - FLOAT y; - } - - struct GLYPHMETRICSFLOAT { - FLOAT gmfBlackBoxX; - FLOAT gmfBlackBoxY; - POINTFLOAT gmfptGlyphOrigin; - FLOAT gmfCellIncX; - FLOAT gmfCellIncY; - } - alias PGLYPHMETRICSFLOAT = GLYPHMETRICSFLOAT*; - alias LPGLYPHMETRICSFLOAT = GLYPHMETRICSFLOAT; - - struct GPU_DEVICE { - DWORD cb; - CHAR[32] DeviceName; - CHAR[128] DeviceString; - DWORD Flags; - RECT rcVirtualScreen; - } - - alias PGPU_DEVICE = GPU_DEVICE; -} -''') - gen.write_opaque_struct(f, 'HPBUFFERARB') - gen.write_opaque_struct(f, 'HPBUFFEREXT') - gen.write_opaque_struct(f, 'HVIDEOOUTPUTDEVICENV') - gen.write_opaque_struct(f, 'HPVIDEODEV') - gen.write_opaque_struct(f, 'HPGPUNV') - gen.write_opaque_struct(f, 'HGPUNV') - gen.write_opaque_struct(f, 'HVIDEOINPUTDEVICENV') - - -DTYPES = { - '__pre': { - 'egl': 'import core.stdc.stdint : intptr_t;\n\n' - }, - - '__other': { - 'gl': _gl_types, - 'egl': _egl_types, - 'glx': _glx_types, - 'wgl': _wgl_types - }, - - 'gl': { - 'GLenum': 'uint', 'GLvoid': 'void', 'GLboolean': 'ubyte', - 'GLbitfield': 'uint', 'GLchar': 'char', 'GLbyte': 'byte', - 'GLshort': 'short', 'GLint': 'int', 'GLclampx': 'int', - 'GLsizei': 'int', 'GLubyte': 'ubyte', 'GLushort': 'ushort', - 'GLuint': 'uint', 'GLhalf': 'ushort', 'GLfloat': 'float', - 'GLclampf': 'float', 'GLdouble': 'double', 'GLclampd': 'double', - 'GLfixed': 'int', 'GLintptr': 'ptrdiff_t', 'GLsizeiptr': 'ptrdiff_t', - 'GLintptrARB': 'ptrdiff_t', 'GLsizeiptrARB': 'ptrdiff_t', - 'GLcharARB': 'byte', 'GLhandleARB': 'uint', 'GLhalfARB': 'ushort', - 'GLhalfNV': 'ushort', 'GLint64EXT': 'long', 'GLuint64EXT': 'ulong', - 'GLint64': 'long', 'GLuint64': 'ulong', - 'GLvdpauSurfaceNV': 'ptrdiff_t', 'GLeglImageOES': 'void*' - }, - 'egl': { - 'EGLBoolean': 'uint', 'EGLenum': 'uint', 'EGLAttribKHR': 'intptr_t', - 'EGLAttrib': 'intptr_t', 'EGLClientBuffer': 'void*', 'EGLConfig': 'void*', - 'EGLContext': 'void*', 'EGLDeviceEXT': 'void*', 'EGLDisplay': 'void*', - 'EGLImage': 'void*', 'EGLImageKHR': 'void*', 'EGLOutputLayerEXT': 'void*', - 'EGLOutputPortEXT': 'void*', 'EGLStreamKHR': 'void*', 'EGLSurface': 'void*', - 'EGLSync': 'void*', 'EGLSyncKHR': 'void*', 'EGLSyncNV': 'void*', - '__eglMustCastToProperFunctionPointerType': 'void function()', - 'EGLint': 'int', 'EGLTimeKHR': 'ulong', 'EGLTime': 'ulong', - 'EGLTimeNV': 'ulong', 'EGLuint64NV': 'ulong', - 'EGLuint64KHR': 'ulong', 'EGLuint64MESA': 'ulong', - 'EGLsizeiANDROID': 'ptrdiff_t', 'EGLNativeFileDescriptorKHR': 'int' - }, - 'glx': { - 'GLboolean': 'ubyte', 'GLenum': 'uint', 'GLint': 'int', - 'GLsizei': 'int', 'GLubyte': 'ubyte', 'GLuint': 'uint', - 'GLfloat': 'float', 'GLbitfield': 'uint', 'GLintptr': 'ptrdiff_t', - 'GLsizeiptr': 'ptrdiff_t' - - }, - 'wgl': { - 'GLbitfield': 'uint', 'GLenum': 'uint', 'GLfloat': 'float', - 'GLint': 'int', 'GLsizei': 'int', 'GLuint': 'uint', - 'GLushort': 'ushort', 'INT32': 'int', 'INT64': 'long', - 'GLboolean': 'ubyte' - }, - - 'SpecialNumbers': { - 'gl': [ - ('GL_FALSE', '0', 'ubyte'), ('GL_TRUE', '1', 'ubyte'), - ('GL_NO_ERROR', '0', 'uint'), ('GL_NONE', '0', 'uint'), - ('GL_ZERO', '0', 'uint'), ('GL_ONE', '1', 'uint'), - ('GL_NONE_OES', '0', 'uint'), - ('GL_INVALID_INDEX', '0xFFFFFFFF', 'uint'), - ('GL_TIMEOUT_IGNORED', '0xFFFFFFFFFFFFFFFF', 'ulong'), - ('GL_TIMEOUT_IGNORED_APPLE', '0xFFFFFFFFFFFFFFFF', 'ulong'), - ('GL_VERSION_ES_CL_1_0', '1', 'uint'), ('GL_VERSION_ES_CM_1_1', '1', 'uint'), - ('GL_VERSION_ES_CL_1_1', '1', 'uint') - ], - 'egl': [ - ('EGL_DONT_CARE', '-1', 'int'), ('EGL_UNKNOWN', '-1', 'int'), - ('EGL_NO_NATIVE_FENCE_FD_ANDROID', '-1', 'uint'), - ('EGL_DEPTH_ENCODING_NONE_NV', '0', 'uint'), - ('EGL_NO_CONTEXT', 'cast(EGLContext)0', 'EGLContext'), - ('EGL_NO_DEVICE_EXT', 'cast(EGLDeviceEXT)0', 'EGLDeviceEXT'), - ('EGL_NO_DISPLAY', 'cast(EGLDisplay)0', 'EGLDisplay'), - ('EGL_NO_IMAGE', 'cast(EGLImage)0', 'EGLImage'), - ('EGL_NO_IMAGE_KHR', 'cast(EGLImageKHR)0', 'EGLImageKHR'), - ('EGL_DEFAULT_DISPLAY', 'cast(EGLNativeDisplayType)0', 'EGLNativeDisplayType'), - ('EGL_NO_FILE_DESCRIPTOR_KHR', 'cast(EGLNativeFileDescriptorKHR)-1', 'EGLNativeFileDescriptorKHR'), - ('EGL_NO_OUTPUT_LAYER_EXT', 'cast(EGLOutputLayerEXT)0', 'EGLOutputLayerEXT'), - ('EGL_NO_OUTPUT_PORT_EXT', 'cast(EGLOutputPortEXT)0', 'EGLOutputPortEXT'), - ('EGL_NO_STREAM_KHR', 'cast(EGLStreamKHR)0', 'EGLStreamKHR'), - ('EGL_NO_SURFACE', 'cast(EGLSurface)0', 'EGLSurface'), - ('EGL_NO_SYNC', 'cast(EGLSync)0', 'EGLSync'), - ('EGL_NO_SYNC_KHR', 'cast(EGLSyncKHR)0', 'EGLSyncKHR'), - ('EGL_NO_SYNC_NV', 'cast(EGLSyncNV)0', 'EGLSyncNV'), - ('EGL_DISPLAY_SCALING', '10000', 'uint'), - ('EGL_FOREVER', '0xFFFFFFFFFFFFFFFF', 'ulong'), - ('EGL_FOREVER_KHR', '0xFFFFFFFFFFFFFFFF', 'ulong'), - ('EGL_FOREVER_NV', '0xFFFFFFFFFFFFFFFF', 'ulong') - ], - 'glx': [ - ('GLX_DONT_CARE', '0xFFFFFFFF', 'uint'), - ('GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB', '0', 'uint') - ], - 'wgl': [ - ('WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB', '0', 'uint'), - ('WGL_FONT_LINES', '0', 'uint'), - ('WGL_FONT_POLYGONS', 1, 'uint') - ] - } -} - - -class BaseDGenerator(Generator): - NAME = 'd' - NAME_LONG = 'D' - - def open(self): - self._f_loader = open(self.make_path(self.LOADER), 'w') - self._f_gl = open(self.make_path(self.PACKAGE), 'w') - self._f_types = open(self.make_path(self.TYPES), 'w') - self._f_enums = open(self.make_path(self.ENUMS), 'w') - self._f_funcs = open(self.make_path(self.FUNCS), 'w') - self._f_exts = open(self.make_path(self.EXT), 'w') - - def close(self): - self._f_loader.close() - self._f_gl.close() - self._f_types.close() - self._f_enums.close() - self._f_funcs.close() - self._f_exts.close() - - @property - def PACKAGE(self): - return 'all' - - def generate_header(self): - self._f_gl.write('/*\n') - self._f_gl.write(self.header) - self._f_gl.write('*/\n\n') - - def generate_loader(self, features, extensions): - f = self._f_loader - - rfeatures = features - if self.spec.NAME in ('egl', 'wgl'): - features = {'egl': [], 'wgl': []} - - self.write_module(f, self.LOADER) - self.write_imports(f, [self.FUNCS, self.EXT, self.ENUMS, self.TYPES]) - - self.loader.write(f) - self.loader.write_has_ext(f) - - written = set() - for api, version in self.api.items(): - loadername = 'Load' if self.LOAD_GL_PREFIX else 'load' - f.write('bool {}{}{}(Loader load) {{\n' - .format(self.LOAD_GL_PREFIX, loadername, api.upper())) - self.loader.write_begin_load(f) - f.write('\tfind_core{}();\n'.format(api.upper())) - for feature in features[api]: - f.write('\tload_{}(load);\n'.format(feature.name)) - f.write('\n\tfind_extensions{}();\n'.format(api.upper())) - for ext in extensions[api]: - if len(list(ext.functions)) == 0: - continue - f.write('\tload_{}(load);\n'.format(ext.name)) - self.loader.write_end_load(f) - f.write('}\n\n') - - f.write('private {\n\n') - - f.write('void find_core{}() {{\n'.format(api.upper())) - self.loader.write_find_core(f) - if self.spec.NAME == 'gl': - for feature in features[api]: - f.write('\t{} = (major == {num[0]} && minor >= {num[1]}) ||' - ' major > {num[0]};\n'.format(feature.name, num=feature.number)) - f.write('\treturn;\n') - f.write('}\n\n') - - f.write('void find_extensions{}() {{\n'.format(api.upper())) - if self.spec.NAME == 'gl': - for ext in extensions[api]: - f.write('\t{0} = has_ext("{0}");\n'.format(ext.name)) - f.write('\treturn;\n') - f.write('}\n\n') - - for feature in features[api]: - f.write('void load_{}(Loader load) {{\n' - .format(feature.name)) - if self.spec.NAME == 'gl': - f.write('\tif(!{}) return;\n'.format(feature.name)) - for func in feature.functions: - f.write('\t{name} = cast(typeof({name}))load("{name}");\n' - .format(name=func.proto.name)) - f.write('\treturn;\n}\n\n') - - for ext in extensions[api]: - if len(list(ext.functions)) == 0 or ext.name in written: - continue - - f.write('void load_{}(Loader load) {{\n' - .format(ext.name)) - if self.spec.NAME == 'gl': - f.write('\tif(!{}) return;\n'.format(ext.name)) - for func in ext.functions: - # even if they were in written we need to load it - f.write('\t{name} = cast(typeof({name}))load("{name}");\n' - .format(name=func.proto.name)) - f.write('\treturn;\n') - f.write('}\n') - - written.add(ext.name) - - f.write('\n} /* private */\n\n') - - self.write_packages(rfeatures, extensions) - - def write_packages(self, allfeatures, allextensions): - f = self._f_gl - - self.write_module(f, self.PACKAGE) - self.write_imports(f, [self.FUNCS, self.EXT, self.ENUMS, self.TYPES], False) - - for api, features in allfeatures.items(): - extensions = allextensions[api] - with open(self.make_path(api), 'w') as f: - self.write_module(f, api) - - self.write_imports(f, [self.TYPES], False) - - extenums = chain.from_iterable(ext.enums for ext in extensions) - funcenums = chain.from_iterable(ext.enums for ext in extensions) - enums = set(enum.name for enum in extenums) | \ - set(enum.name for enum in funcenums) - - featfuncs = set(func.proto.name for func in - chain.from_iterable(feat.functions for feat in features)) - extfuncs = set(func.proto.name for func in - chain.from_iterable(ext.functions for ext in extensions)) - extfuncs = extfuncs - featfuncs - - enums |= set(enum.name for enum in - chain.from_iterable(feat.enums for feat in features)) - - self.write_selective_import(f, self.FUNCS, featfuncs) - self.write_selective_import(f, self.EXT, extfuncs) - self.write_selective_import(f, self.ENUMS, enums) - - - def generate_types(self, types): - f = self._f_types - - self.write_module(f, self.TYPES) - - f.write(self.TYPE_DICT.get('__pre', {}).get(self.spec.NAME,'')) - for ogl, d in self.TYPE_DICT[self.spec.NAME].items(): - self.write_alias(f, ogl, d) - self.TYPE_DICT['__other'][self.spec.NAME](self, f) - - def generate_features(self, features): - self.write_enums(features) - self.write_funcs(features) - - def write_enums(self, features): - e = self._f_enums - - self.write_module(e, self.ENUMS) - self.write_imports(e, [self.TYPES]) - - for v in self.TYPE_DICT['SpecialNumbers'][self.spec.NAME]: - self.write_enum(e, *v) - - written = set() - for feature in features: - for enum in feature.enums: - if enum.group == 'SpecialNumbers': - written.add(enum) - continue - if not enum in written: - self.write_enum(e, enum.name, enum.value) - written.add(enum) - - def write_funcs(self, features): - f = self._f_funcs - - self.write_module(f, self.FUNCS) - self.write_imports(f, [self.TYPES]) - - if self.spec.NAME == 'gl': - for feature in features: - self.write_boolean(f, feature.name) - - if self.spec.NAME in ('egl', 'wgl'): - self.write_extern(f) - for feature in features: - for func in feature.functions: - self.write_function_def(f, func) - self.write_extern_end(f) - else: - self.write_functions(f, set(), set(), features) - - def generate_extensions(self, extensions, enums, functions): - f = self._f_exts - - self.write_module(f, self.EXT) - self.write_imports(f, [self.TYPES, self.ENUMS, self.FUNCS]) - - write = set() - written = set(enum.name for enum in enums) | \ - set(function.proto.name for function in functions) - for ext in extensions: - if self.spec.NAME == 'gl' and not ext.name in written: - self.write_boolean(f, ext.name) - for enum in ext.enums: - if not enum.name in written and not enum.group == 'SpecialNumbers': - self.write_enum(self._f_enums, enum.name, enum.value) - written.add(enum.name) - written.add(ext.name) - - self.write_functions(f, write, written, extensions) - - def write_functions(self, f, write, written, extensions): - self.write_prototype_pre(f) - for ext in extensions: - for func in ext.functions: - if not func.proto.name in written: - self.write_function_prototype(f, func) - write.add(func) - written.add(func.proto.name) - self.write_prototype_post(f) - - self.write_function_pre(f) - for func in write: - self.write_function(f, func) - self.write_function_post(f) - - - def make_path(self, name): - path = os.path.join(self.path, self.MODULE.split('.')[-1], - self.spec.NAME, name.split('.')[-1] + self.FILE_EXTENSION) - makefiledir(path) - return path - - def write_imports(self, fobj, modules, private=True): - raise NotImplementedError - - def write_selective_import(self, fobj, imports): - raise NotImplementedError - - def write_module(self, fobj, name): - raise NotImplementedError - - def write_prototype_pre(self, fobj): - raise NotImplementedError - - def write_prototype_post(self, fobj): - raise NotImplementedError - - def write_function_pre(self, fobj): - raise NotImplementedError - - def write_function_post(self, fobj): - raise NotImplementedError - - def write_extern(self, fobj): - raise NotImplementedError - - def write_extern_end(self, fobj): - raise NotImplementedError - - def write_shared(self, fobj): - raise NotImplementedError - - def write_shared_end(self, fobj): - raise NotImplementedError - - def write_function_def(self, fobj, func): - raise NotImplementedError - - def write_function(self, fobj, func): - raise NotImplementedError - - def write_function_prototype(self, fobj, func): - raise NotImplementedError - - def write_boolean(self, fobj, name, value=False): - raise NotImplementedError - - def write_enum(self, fobj, name, value, type='uint'): - raise NotImplementedError - - def write_opaque_struct(self, fobj, name): - raise NotImplementedError - - def write_alias(self, fobj, newn, decl): - raise NotImplementedError - - -class DGenerator(BaseDGenerator): - MODULE = 'glad' - LOADER = 'loader' - ENUMS = 'enums' - EXT = 'ext' - FUNCS = 'funcs' - TYPES = 'types' - FILE_EXTENSION = '.d' - TYPE_DICT = DTYPES - - LOAD_GL_PREFIX = 'glad' - - def write_imports(self, fobj, modules, private=True): - for mod in modules: - if private: - fobj.write('private ') - else: - fobj.write('public ') - - fobj.write('import {}.{}.{};\n'.format(self.MODULE, self.spec.NAME, mod)) - - def write_selective_import(self, fobj, mod, imports): - if len(imports) == 0: return - - fobj.write('public import {}.{}.{} :\n'.format(self.MODULE, self.spec.NAME, mod)) - imports = set(imports) - last = len(imports) - for i, im in enumerate(imports, 1): - fobj.write(im) - if not i == last: - fobj.write(', ') - if (i % 5) == 0: - fobj.write('\n') - fobj.write(';\n\n') - - def write_module(self, fobj, name): - fobj.write('module {}.{}.{};\n\n\n'.format(self.MODULE, self.spec.NAME, name)) - - def write_prototype_pre(self, fobj): - fobj.write('nothrow @nogc ') - self.write_extern(fobj) - - def write_prototype_post(self, fobj): - self.write_extern_end(fobj) - - def write_function_pre(self, fobj): - self.write_shared(fobj) - - def write_function_post(self, fobj): - self.write_shared_end(fobj) - - def write_extern(self, fobj): - fobj.write('extern(System) {\n') - - def write_extern_end(self, fobj): - fobj.write('}\n') - - def write_shared(self, fobj): - fobj.write('__gshared {\n') - - def write_shared_end(self, fobj): - fobj.write('}\n') - - def write_function_def(self, fobj, func): - fobj.write('{} {}('.format(func.proto.ret.to_d(), func.proto.name)) - fobj.write(', '.join(param.type.to_d() for param in func.params)) - fobj.write(');\n') - - def write_function(self, fobj, func): - fobj.write('fp_{0} {0};\n'.format(func.proto.name)) - - def write_function_prototype(self, fobj, func): - fobj.write('alias fp_{} = {} function(' - .format(func.proto.name, func.proto.ret.to_d())) - fobj.write(', '.join(param.type.to_d() for param in func.params)) - fobj.write(');\n') - - def write_boolean(self, fobj, name, value=False): - if value: - fobj.write('bool {} = true;\n'.format(name)) - else: - fobj.write('bool {};\n'.format(name)) - - def write_enum(self, fobj, name, value, type='uint'): - if isinstance(value, basestring) and '"' in value: - type = 'const(char)*' - - fobj.write('enum {} {} = {};\n'.format(type, name, value)) - - def write_opaque_struct(self, fobj, name): - fobj.write('struct _{name}; alias {name} = _{name}*;\n'.format(name=name)) - - def write_alias(self, fobj, newn, decl): - fobj.write('alias {} = {};\n'.format(newn, decl)) - diff --git a/libs/glad/glad/lang/d/loader/__init__.py b/libs/glad/glad/lang/d/loader/__init__.py @@ -1,90 +0,0 @@ - -LOAD_OPENGL_DLL = ''' -version(Windows) { - private import core.sys.windows.windows; -} else { - private import core.sys.posix.dlfcn; -} - -version(Windows) { - private __gshared HMODULE libGL; -} else { - private __gshared void* libGL; -} -extern(System) private @nogc alias gladGetProcAddressPtrType = void* function(const(char)*); -private __gshared gladGetProcAddressPtrType gladGetProcAddressPtr; - -%(pre)s -bool %(init)s() @nogc { - version(Windows) { - libGL = LoadLibraryA("opengl32.dll"); - if(libGL !is null) { - gladGetProcAddressPtr = cast(typeof(gladGetProcAddressPtr))GetProcAddress( - libGL, "wglGetProcAddress"); - return gladGetProcAddressPtr !is null; - } - - return false; - } else { - version(OSX) { - enum const(char)*[] NAMES = [ - "../Frameworks/OpenGL.framework/OpenGL", - "/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL" - ]; - } else { - enum const(char)*[] NAMES = ["libGL.so.1", "libGL.so"]; - } - - foreach(name; NAMES) { - libGL = dlopen(name, RTLD_NOW | RTLD_GLOBAL); - if(libGL !is null) { - version(OSX) { - return true; - } else { - gladGetProcAddressPtr = cast(typeof(gladGetProcAddressPtr))dlsym(libGL, - "glXGetProcAddressARB"); - return gladGetProcAddressPtr !is null; - } - } - } - - return false; - } -} - -%(pre)s -void* %(proc)s(const(char)* namez) @nogc { - if(libGL is null) return null; - void* result; - - if(gladGetProcAddressPtr !is null) { - result = gladGetProcAddressPtr(namez); - } - if(result is null) { - version(Windows) { - result = GetProcAddress(libGL, namez); - } else { - result = dlsym(libGL, namez); - } - } - - return result; -} - -%(pre)s -void %(terminate)s() @nogc { - version(Windows) { - if(libGL !is null) { - FreeLibrary(libGL); - libGL = null; - } - } else { - if(libGL !is null) { - dlclose(libGL); - libGL = null; - } - } -} -'''- \ No newline at end of file diff --git a/libs/glad/glad/lang/d/loader/egl.py b/libs/glad/glad/lang/d/loader/egl.py @@ -1,39 +0,0 @@ -from glad.lang.common.loader import BaseLoader - - -_EGL_LOADER = ''' -bool gladLoadEGL() { - return gladLoadEGL(x => eglGetProcAddress(x)); -} -''' - -_EGL_HAS_EXT = ''' -private bool has_ext(const(char)* ext) @nogc { - return true; -} -''' - - -class EGLDLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - fobj.write('alias Loader = void* delegate(const(char)*);\n') - if not self.disabled: - fobj.write(_EGL_LOADER) - - def write_begin_load(self, fobj): - pass - - def write_end_load(self, fobj): - fobj.write('\treturn true;\n') - - def write_find_core(self, fobj): - pass - - def write_has_ext(self, fobj): - fobj.write(_EGL_HAS_EXT) diff --git a/libs/glad/glad/lang/d/loader/gl.py b/libs/glad/glad/lang/d/loader/gl.py @@ -1,118 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.d.loader import LOAD_OPENGL_DLL - - -_OPENGL_LOADER = \ - LOAD_OPENGL_DLL % {'pre':'private', 'init':'open_gl', - 'proc':'get_proc', 'terminate':'close_gl'} + ''' -bool gladLoadGL() { - bool status = false; - - if(open_gl()) { - status = gladLoadGL(x => get_proc(x)); - close_gl(); - } - - return status; -} -''' - -_OPENGL_HAS_EXT = ''' -static struct GLVersion { static int major = 0; static int minor = 0; } -private extern(C) char* strstr(const(char)*, const(char)*) @nogc; -private extern(C) int strcmp(const(char)*, const(char)*) @nogc; -private extern(C) int strncmp(const(char)*, const(char)*, size_t) @nogc; -private extern(C) size_t strlen(const(char)*) @nogc; -private bool has_ext(const(char)* ext) @nogc { - if(GLVersion.major < 3) { - const(char)* extensions = cast(const(char)*)glGetString(GL_EXTENSIONS); - const(char)* loc; - const(char)* terminator; - - if(extensions is null || ext is null) { - return false; - } - - while(1) { - loc = strstr(extensions, ext); - if(loc is null) { - return false; - } - - terminator = loc + strlen(ext); - if((loc is extensions || *(loc - 1) == ' ') && - (*terminator == ' ' || *terminator == '\\0')) { - return true; - } - extensions = terminator; - } - } else { - int num; - glGetIntegerv(GL_NUM_EXTENSIONS, &num); - - for(uint i=0; i < cast(uint)num; i++) { - if(strcmp(cast(const(char)*)glGetStringi(GL_EXTENSIONS, i), ext) == 0) { - return true; - } - } - } - - return false; -} -''' - -_FIND_VERSION = ''' - // Thank you @elmindreda - // https://github.com/elmindreda/greg/blob/master/templates/greg.c.in#L176 - // https://github.com/glfw/glfw/blob/master/src/context.c#L36 - int i; - const(char)* glversion; - const(char)*[] prefixes = [ - "OpenGL ES-CM ".ptr, - "OpenGL ES-CL ".ptr, - "OpenGL ES ".ptr, - ]; - - glversion = cast(const(char)*)glGetString(GL_VERSION); - if (glversion is null) return; - - foreach(prefix; prefixes) { - size_t length = strlen(prefix); - if (strncmp(glversion, prefix, length) == 0) { - glversion += length; - break; - } - } - - int major = glversion[0] - \'0\'; - int minor = glversion[2] - \'0\'; - GLVersion.major = major; GLVersion.minor = minor; -''' - - -class OpenGLDLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - fobj.write('alias Loader = void* delegate(const(char)*);\n') - if not self.disabled and 'gl' in self.apis: - fobj.write(_OPENGL_LOADER) - - def write_begin_load(self, fobj): - fobj.write('\tglGetString = cast(typeof(glGetString))load("glGetString");\n') - fobj.write('\tif(glGetString is null) { return false; }\n') - fobj.write('\tif(glGetString(GL_VERSION) is null) { return false; }\n\n') - - def write_end_load(self, fobj): - fobj.write('\treturn GLVersion.major != 0 || GLVersion.minor != 0;\n') - - def write_find_core(self, fobj): - fobj.write(_FIND_VERSION) - - def write_has_ext(self, fobj): - fobj.write(_OPENGL_HAS_EXT) - diff --git a/libs/glad/glad/lang/d/loader/glx.py b/libs/glad/glad/lang/d/loader/glx.py @@ -1,49 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.d.loader import LOAD_OPENGL_DLL - - -_GLX_LOADER = \ - LOAD_OPENGL_DLL % {'pre':'private', 'init':'open_gl', - 'proc':'get_proc', 'terminate':'close_gl'} + ''' -bool gladLoadGLX() { - bool status = false; - - if(open_gl()) { - status = gladLoadGLX(x => get_proc(x)); - close_gl(); - } - - return status; -} -''' - -_GLX_HAS_EXT = ''' -private bool has_ext(const(char)* name) @nogc { - return true; -} -''' - - -class GLXDLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - fobj.write('alias Loader = void* delegate(const(char)*);\n') - if not self.disabled: - fobj.write(_GLX_LOADER) - - def write_begin_load(self, fobj): - pass - - def write_end_load(self, fobj): - fobj.write('\treturn true;\n') - - def write_find_core(self, fobj): - pass - - def write_has_ext(self, fobj): - fobj.write(_GLX_HAS_EXT) diff --git a/libs/glad/glad/lang/d/loader/wgl.py b/libs/glad/glad/lang/d/loader/wgl.py @@ -1,36 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.d.loader.glx import _GLX_LOADER - - -_WGL_LOADER = _GLX_LOADER.replace('GLX', 'WGL') - -_WGL_HAS_EXT = ''' -private bool has_ext(const(char)* name) @nogc { - return true; -} -''' - - -class WGLDLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - fobj.write('alias Loader = void* delegate(const(char)*);\n') - if not self.disabled: - fobj.write(_WGL_LOADER) - - def write_begin_load(self, fobj): - pass - - def write_end_load(self, fobj): - fobj.write('\treturn true;\n') - - def write_find_core(self, fobj): - pass - - def write_has_ext(self, fobj): - fobj.write(_WGL_HAS_EXT) diff --git a/libs/glad/glad/lang/nim/__init__.py b/libs/glad/glad/lang/nim/__init__.py @@ -1,27 +0,0 @@ -from glad.lang.nim.loader.egl import EGLNimLoader -from glad.lang.nim.loader.gl import OpenGLNimLoader -from glad.lang.nim.loader.glx import GLXNimLoader -from glad.lang.nim.loader.wgl import WGLNimLoader - -from glad.lang.nim.generator import NimGenerator - - -# TODO finish converting the egl, glx & wgl loaders to Nim - -_specs = { -# 'egl': EGLNimLoader, - 'gl': OpenGLNimLoader -# 'glx': GLXNimLoader, -# 'wgl': WGLNimLoader -} - -_generators = { - 'nim': NimGenerator, -} - - -def get_generator(name, spec): - gen = _generators.get(name) - loader = _specs.get(spec) - - return gen, loader diff --git a/libs/glad/glad/lang/nim/generator.py b/libs/glad/glad/lang/nim/generator.py @@ -1,530 +0,0 @@ -from itertools import chain -import os.path -import sys - -from glad.lang.common.generator import Generator -from glad.lang.common.util import makefiledir - - -if sys.version_info >= (3, 0): - from io import StringIO - basestring = str -else: - from StringIO import StringIO - - -def _gl_types(gen, f): - f.write(''' - GLdebugProc* = proc ( - source: GLenum, - typ: GLenum, - id: GLuint, - severity: GLenum, - length: GLsizei, - message: ptr GLchar, - userParam: pointer) {.stdcall.} - - GLdebugProcArb* = proc ( - source: GLenum, - typ: GLenum, - id: GLuint, - severity: GLenum, - len: GLsizei, - message: ptr GLchar, - userParam: pointer) {.stdcall.} - - GLdebugProcAmd* = proc ( - id: GLuint, - category: GLenum, - severity: GLenum, - len: GLsizei, - message: ptr GLchar, - userParam: pointer) {.stdcall.} - - GLdebugProcKhr* = proc ( - source, typ: GLenum, - id: GLuint, - severity: GLenum, - length: GLsizei, - message: ptr GLchar, - userParam: pointer) {.stdcall.} -''') - - -# TODO finish converting the egl, glx & wgl loaders to Nim - -# def _egl_types(gen, f): -# def _glx_types(gen, f): -# def _wgl_types(gen, f): - -NIMTYPES = { - '__other': { - 'gl': _gl_types -# 'egl': _egl_types, -# 'glx': _glx_types, -# 'wgl': _wgl_types - }, - - 'gl': { - 'GLbitfield': 'uint32', - 'GLboolean': 'bool', - 'GLbyte': 'int8', - 'GLchar': 'char', - 'GLcharARB': 'byte', - 'GLclampd': 'float64', - 'GLclampf': 'float32', - 'GLclampx': 'int32', - 'GLdouble': 'float64', - 'GLeglImageOES': 'distinct pointer', - 'GLenum': 'uint32', - 'GLfixed': 'int32', - 'GLfloat': 'float32', - 'GLhalf': 'uint16', - 'GLhalfARB': 'uint16', - 'GLhalfNV': 'uint16', - 'GLhandleARB': 'uint32', - 'GLint': 'int32', - 'GLint64': 'int64', - 'GLint64EXT': 'int64', - 'GLintptr': 'int32', - 'GLintptrARB': 'int32', - 'GLshort': 'int16', - 'GLsizei': 'int32', - 'GLsizeiptr': 'int32', - 'GLsizeiptrARB': 'int32', - 'GLubyte': 'uint8', - 'GLuint': 'uint32', - 'GLuint64': 'uint64', - 'GLuint64EXT': 'uint64', - 'GLushort': 'uint16', - 'GLvdpauSurfaceNV': 'int32', - 'GLvoid': 'pointer', - 'GLsync': 'distinct pointer', - 'ClContext': 'distinct pointer', - 'ClEvent': 'distinct pointer' - }, - 'egl': { - 'EGLAttrib': 'int32', - 'EGLAttribKHR': 'int32', - 'EGLBoolean': 'bool', - 'EGLClientBuffer': 'distinct pointer', - 'EGLConfig': 'distinct pointer', - 'EGLContext': 'distinct pointer', - 'EGLDeviceEXT': 'distinct pointer', - 'EGLDisplay': 'distinct pointer', - 'EGLImage': 'distinct pointer', - 'EGLImageKHR': 'distinct pointer', - 'EGLNativeFileDescriptorKHR': 'int32', - 'EGLOutputLayerEXT': 'distinct pointer', - 'EGLOutputPortEXT': 'distinct pointer', - 'EGLStreamKHR': 'distinct pointer', - 'EGLSurface': 'distinct pointer', - 'EGLSync': 'distinct pointer', - 'EGLSyncKHR': 'distinct pointer', - 'EGLSyncNV': 'distinct pointer', - 'EGLTimeKHR': 'uint64', - 'EGLTime': 'uint64', - 'EGLTimeNV': 'uint64', - 'EGLenum': 'uint32', - 'EGLint': 'int32', - 'EGLsizeiANDROID': 'distinct pointer', - 'EGLuint64KHR': 'uint64', - 'EGLuint64MESA': 'uint64', - 'EGLuint64NV': 'uint64', -# '__eglMustCastToProperFunctionPointerType': 'void function()' - }, - 'glx': { - 'GLbitfield': 'uint32', - 'GLboolean': 'uint8', - 'GLenum': 'uint32', - 'GLfloat': 'float32', - 'GLint': 'int32', - 'GLintptr': 'int32', - 'GLsizei': 'int32', - 'GLsizeiptr': 'int32', - 'GLubyte': 'uint8', - 'GLuint': 'uint32' - }, - 'wgl': { - 'GLbitfield': 'uint32', - 'GLboolean': 'uint8', - 'GLenum': 'uint32', - 'GLfloat': 'float32', - 'GLint': 'int32', - 'GLsizei': 'int32', - 'GLuint': 'uint32', - 'GLushort': 'uint16', - 'INT32': 'int32', - 'INT64': 'int64' - }, - - 'SpecialNumbers': { - 'gl': [ - ('GL_FALSE', '0', None), - ('GL_INVALID_INDEX', '0xFFFFFFFF', 'uint32'), - ('GL_NONE', '0', None), - ('GL_NONE_OES', '0', None), - ('GL_NO_ERROR', '0', None), - ('GL_ONE', '1', None), - ('GL_TIMEOUT_IGNORED', '0xFFFFFFFFFFFFFFFF', 'uint64'), - ('GL_TIMEOUT_IGNORED_APPLE', '0xFFFFFFFFFFFFFFFF', 'uint64'), - ('GL_TRUE', '1', None), - ('GL_VERSION_ES_CL_1_0', '1', None), - ('GL_VERSION_ES_CL_1_1', '1', None), - ('GL_VERSION_ES_CM_1_1', '1', None), - ('GL_ZERO', '0', None), - ], - 'egl': [ -# ('EGL_DONT_CARE', '-1', 'int'), ('EGL_UNKNOWN', '-1', 'int'), -# ('EGL_NO_NATIVE_FENCE_FD_ANDROID', '-1', 'uint'), -# ('EGL_DEPTH_ENCODING_NONE_NV', '0', 'uint'), -# ('EGL_NO_CONTEXT', 'cast(EGLContext)0', 'EGLContext'), -# ('EGL_NO_DEVICE_EXT', 'cast(EGLDeviceEXT)0', 'EGLDeviceEXT'), -# ('EGL_NO_DISPLAY', 'cast(EGLDisplay)0', 'EGLDisplay'), -# ('EGL_NO_IMAGE', 'cast(EGLImage)0', 'EGLImage'), -# ('EGL_NO_IMAGE_KHR', 'cast(EGLImageKHR)0', 'EGLImageKHR'), -# ('EGL_DEFAULT_DISPLAY', 'cast(EGLNativeDisplayType)0', 'EGLNativeDisplayType'), -# ('EGL_NO_FILE_DESCRIPTOR_KHR', 'cast(EGLNativeFileDescriptorKHR)-1', 'EGLNativeFileDescriptorKHR'), -# ('EGL_NO_OUTPUT_LAYER_EXT', 'cast(EGLOutputLayerEXT)0', 'EGLOutputLayerEXT'), -# ('EGL_NO_OUTPUT_PORT_EXT', 'cast(EGLOutputPortEXT)0', 'EGLOutputPortEXT'), -# ('EGL_NO_STREAM_KHR', 'cast(EGLStreamKHR)0', 'EGLStreamKHR'), -# ('EGL_NO_SURFACE', 'cast(EGLSurface)0', 'EGLSurface'), -# ('EGL_NO_SYNC', 'cast(EGLSync)0', 'EGLSync'), -# ('EGL_NO_SYNC_KHR', 'cast(EGLSyncKHR)0', 'EGLSyncKHR'), -# ('EGL_NO_SYNC_NV', 'cast(EGLSyncNV)0', 'EGLSyncNV'), -# ('EGL_DISPLAY_SCALING', '10000', 'uint'), -# ('EGL_FOREVER', '0xFFFFFFFFFFFFFFFF', 'ulong'), -# ('EGL_FOREVER_KHR', '0xFFFFFFFFFFFFFFFF', 'ulong'), -# ('EGL_FOREVER_NV', '0xFFFFFFFFFFFFFFFF', 'ulong') - ], - 'glx': [ -# ('GLX_DONT_CARE', '0xFFFFFFFF', 'uint'), -# ('GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB', '0', 'uint') - ], - 'wgl': [ -# ('WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB', '0', 'uint'), -# ('WGL_FONT_LINES', '0', 'uint'), -# ('WGL_FONT_POLYGONS', 1, 'uint') - ] - }, - - 'SpecialEnumNames': { - 'gl': { - 'GL_BYTE': 'cGL_BYTE', - 'GL_SHORT': 'cGL_SHORT', - 'GL_INT': 'cGL_INT', - 'GL_FLOAT': 'cGL_FLOAT', - 'GL_DOUBLE': 'cGL_DOUBLE', - 'GL_FIXED': 'cGL_FIXED' - }, - 'egl': {}, - 'glx': {}, - 'wgl': {} - }, - - 'SpecialFuncNames': { - 'gl': { - 'glGetTransformFeedbacki_v': 'glGetTransformFeedbacki_v2' - }, - 'egl': {}, - 'glx': {}, - 'wgl': {} - } -} - - -class NimGenerator(Generator): - NAME = 'nim' - NAME_LONG = 'Nim' - - MODULE = 'glad' - FILE_EXTENSION = '.nim' - TYPE_DICT = NIMTYPES - - LOAD_GL_PREFIX = 'glad' - EXT_PREFIX = 'GLAD_' - - def open(self): - self._f_gl = open(self.make_path(self.spec.NAME), 'w') - - def close(self): - self._f_gl.close() - - def generate_header(self): - self._f_gl.write('#[') - self._f_gl.write(self.header) - self._f_gl.write(']#\n\n') - self._f_gl.write('import strutils\n\n') - self._f_gl.write('var glVersionMajor, glVersionMinor: int\n\n') - - def generate_loader(self, features, extensions): - f = self._f_gl - - rfeatures = features - if self.spec.NAME in ('egl', 'wgl'): - features = {'egl': [], 'wgl': []} - - self.loader.write(f) - self.loader.write_has_ext(f, self.get_version()) - - written = set() - for api, version in self.api.items(): - # core load procs - for feature in features[api]: - f.write('proc load_{}(load: proc) =\n' - .format(feature.name)) - if self.spec.NAME == 'gl': - f.write(' if not {}{}: return\n\n'.format(self.EXT_PREFIX, - feature.name)) - for func in feature.functions: - self.write_func_definition(f, func) - f.write('\n\n') - - # extension load procs - for ext in extensions[api]: - if len(list(ext.functions)) == 0 or ext.name in written: - continue - - f.write('proc load_{}(load: proc) =\n' - .format(ext.name)) - if self.spec.NAME == 'gl': - f.write(' if not {}{}: return\n'.format(self.EXT_PREFIX, - ext.name)) - for func in ext.functions: - # even if they were in written we need to load it - self.write_func_definition(f, func) - - f.write('\n\n') - - written.add(ext.name) - - # findExtensions proc - f.write('proc findExtensions{}() =\n'.format(api.upper())) - if self.spec.NAME == 'gl': - for ext in extensions[api]: - f.write(' {0}{1} = hasExt("{1}")\n'.format(self.EXT_PREFIX, - ext.name)) - f.write('\n\n') - - # findCore proc - f.write('proc findCore{}(glVersion: string) =\n'.format(api.upper())) - self.loader.write_find_core(f) - if self.spec.NAME == 'gl': - for feature in features[api]: - f.write(' {}{} = (major == {num[0]} and minor >= {num[1]}) or' - ' major > {num[0]}\n'.format(self.EXT_PREFIX, feature.name, - num=feature.number)) - f.write('\n\n') - - # main loader proc - loadername = 'Load' if self.LOAD_GL_PREFIX else 'load' - f.write('proc {}{}{}*(load: proc): bool =\n' - .format(self.LOAD_GL_PREFIX, loadername, api.upper())) - self.loader.write_begin_load(f) - - f.write(' findCore{}($glVersion)\n\n'.format(api.upper())) - for feature in features[api]: - f.write(' load_{}(load)\n'.format(feature.name)) - f.write('\n findExtensions{}()\n\n'.format(api.upper())) - for ext in extensions[api]: - if len(list(ext.functions)) == 0: - continue - f.write(' load_{}(load);\n'.format(ext.name)) - self.loader.write_end_load(f) - f.write('\n') - - - def write_func_definition(self, fobj, func): - func_name = self.map_func_name(func) - fobj.write(' {} = cast['.format(func_name)) - self.write_function_declaration(fobj, func) - fobj.write('](load("{}"))\n'.format(func_name)) - - - def map_func_name(self, func): - name = func.proto.name - m = self.TYPE_DICT['SpecialFuncNames'][self.spec.NAME] - return m[name] if name in m else name - - - def generate_types(self, types): - f = self._f_gl - - f.write('# Types\ntype\n') - for ogl, d in sorted(self.TYPE_DICT[self.spec.NAME].items()): - f.write(' {}* = {}\n'.format(ogl, d)) - self.TYPE_DICT['__other'][self.spec.NAME](self, f) - f.write('\n') - - - def generate_features(self, features): - self.write_enums(features) - self.write_funcs(features) - - - def write_enums(self, features): - f = self._f_gl - - f.write('\n# Enums\nconst\n') - for v in sorted(self.TYPE_DICT['SpecialNumbers'][self.spec.NAME]): - self.write_enum(f, *v) - f.write('\n') - - written = set() - for feature in features: - for enum in feature.enums: - if enum.group == 'SpecialNumbers': - written.add(enum) - continue - if not enum in written: - self.write_enum(f, enum.name, enum.value) - written.add(enum) - f.write('\n') - - - def write_funcs(self, features): - f = self._f_gl - - f.write('\n# Functions\nvar\n') - if self.spec.NAME == 'gl': - for feature in features: - self.write_boolean(f, feature.name) - f.write('\n') - - # TODO - if self.spec.NAME in ('egl', 'wgl'): - for feature in features: - for func in feature.functions: - self.write_function_def(f, func) # TODO - f.write('\n') - else: - self.write_functions(f, set(), set(), features) - f.write('\n\n') - - - # TODO - def write_function_def(self, fobj, func): - fobj.write('{} {}('.format(func.proto.ret.to_nim(), self.map_func_name(func))) - fobj.write(', '.join(param.type.to_nim() for param in func.params)) - fobj.write(');\n') - - - def generate_extensions(self, extensions, enums, functions): - f = self._f_gl - - write = set() - written = set(enum.name for enum in enums) | \ - set(function.proto.name for function in functions) - - f.write('# Extensions\nvar\n') - for ext in extensions: - if self.spec.NAME == 'gl' and not ext.name in written: - self.write_boolean(f, ext.name) - - for enum in ext.enums: - if not enum.name in written and not enum.group == 'SpecialNumbers': - type = (None if enum.group == 'TransformFeedbackTokenNV' - else 'GLenum') - self.write_enum(f, enum.name, enum.value, type) - written.add(enum.name) - written.add(ext.name) - f.write('\n') - - self.write_functions(f, write, written, extensions) - f.write('\n\n') - - - def write_functions(self, f, write, written, extensions): - for ext in extensions: - for func in ext.functions: - if not func.proto.name in written: - self.write_function_var(f, func) - write.add(func) - written.add(func.proto.name) - - - def write_function_var(self, fobj, func): - fobj.write(' {}*: '.format(self.map_func_name(func))) - self.write_function_declaration(fobj, func) - fobj.write('\n') - - - def write_function_declaration(self, fobj, func): - fobj.write('proc ('.format(self.map_func_name(func))) - fobj.write(', '.join('{}: {}'.format(self.to_nim_param_name(param.name), - param.type.to_nim()) - for param in func.params)) - fobj.write(')') - - ret = func.proto.ret.to_nim() - if (ret != 'void'): - fobj.write(': {}'.format(ret)) - - fobj.write(' {.cdecl.}') - -# TODO -# def write_function_var(self, fobj, func): -# fobj.write(' {} = cast[proc ('.format(func.proto.name)) -# fobj.write(', '.join('{}: {}'.format(self.to_nim_param_name(param.name), -# param.type.to_nim()) -# for param in func.params)) -# fobj.write(')') -# -# ret = func.proto.ret.to_nim() -# if (ret != 'void'): -# fobj.write(': {}'.format(ret)) -# -# fobj.write(' {.cdecl.}]') -# fobj.write(' (getProcAddress("{}"))\n'.format(func.proto.name)) - - - NIM_KEYWORDS = [ # as of Nim 0.13.0 - 'addr', 'and', 'as', 'asm', 'atomic', - 'bind', 'block', 'break', - 'case', 'cast', 'concept', 'const', 'continue', 'converter', - 'defer', 'discard', 'distinct', 'div', 'do', - 'elif', 'else', 'end', 'enum', 'except', 'export', - 'finally', 'for', 'from', 'func', - 'generic', - 'if', 'import', 'in', 'include', 'interface', 'is', 'isnot', 'iterator', - 'let', - 'macro', 'method', 'mixin', 'mod', - 'nil', 'not', 'notin', - 'object', 'of', 'or', 'out', - 'proc', 'ptr', - 'raise', 'ref', 'return', - 'shl', 'shr', 'static', - 'template', 'try', 'tuple', 'type', - 'using', - 'var', - 'when', 'while', 'with', 'without', - 'xor', - 'yield' - ] - - def to_nim_param_name(self, name): - return '`{}`'.format(name) if name in self.NIM_KEYWORDS else name - - def make_path(self, name): - path = os.path.join(self.path, self.MODULE.split('.')[-1], - name.split('.')[-1] + self.FILE_EXTENSION) - makefiledir(path) - return path - - def write_boolean(self, fobj, name): - fobj.write(' {}{}*: bool\n'.format(self.EXT_PREFIX, name)) - - def write_enum(self, fobj, name, value, type='GLenum'): - fobj.write(' {}*'.format(self.map_enum_name(name))) - if type: - fobj.write(': {0} = {0}({1})'.format(type, value)) - else: - fobj.write(' = {}'.format(value)) - fobj.write('\n') - - def map_enum_name(self, name): - m = self.TYPE_DICT['SpecialEnumNames'][self.spec.NAME] - return m[name] if name in m else name - - def get_version(self): - return self.api[self.spec.NAME] diff --git a/libs/glad/glad/lang/nim/loader/__init__.py b/libs/glad/glad/lang/nim/loader/__init__.py @@ -1,90 +0,0 @@ - -LOAD_OPENGL_DLL = ''' -version(Windows) { - private import std.c.windows.windows; -} else { - private import core.sys.posix.dlfcn; -} - -version(Windows) { - private __gshared HMODULE libGL; -} else { - private __gshared void* libGL; -} -extern(System) private @nogc alias gladGetProcAddressPtrType = void* function(const(char)*); -private __gshared gladGetProcAddressPtrType gladGetProcAddressPtr; - -%(pre)s -bool %(init)s() @nogc { - version(Windows) { - libGL = LoadLibraryA("opengl32.dll"); - if(libGL !is null) { - gladGetProcAddressPtr = cast(typeof(gladGetProcAddressPtr))GetProcAddress( - libGL, "wglGetProcAddress"); - return gladGetProcAddressPtr !is null; - } - - return false; - } else { - version(OSX) { - enum const(char)*[] NAMES = [ - "../Frameworks/OpenGL.framework/OpenGL", - "/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL" - ]; - } else { - enum const(char)*[] NAMES = ["libGL.so.1", "libGL.so"]; - } - - foreach(name; NAMES) { - libGL = dlopen(name, RTLD_NOW | RTLD_GLOBAL); - if(libGL !is null) { - version(OSX) { - return true; - } else { - gladGetProcAddressPtr = cast(typeof(gladGetProcAddressPtr))dlsym(libGL, - "glXGetProcAddressARB"); - return gladGetProcAddressPtr !is null; - } - } - } - - return false; - } -} - -%(pre)s -void* %(proc)s(const(char)* namez) @nogc { - if(libGL is null) return null; - void* result; - - if(gladGetProcAddressPtr !is null) { - result = gladGetProcAddressPtr(namez); - } - if(result is null) { - version(Windows) { - result = GetProcAddress(libGL, namez); - } else { - result = dlsym(libGL, namez); - } - } - - return result; -} - -%(pre)s -void %(terminate)s() @nogc { - version(Windows) { - if(libGL !is null) { - FreeLibrary(libGL); - libGL = null; - } - } else { - if(libGL !is null) { - dlclose(libGL); - libGL = null; - } - } -} -'''- \ No newline at end of file diff --git a/libs/glad/glad/lang/nim/loader/egl.py b/libs/glad/glad/lang/nim/loader/egl.py @@ -1,40 +0,0 @@ -from glad.lang.common.loader import BaseLoader - - -# TODO this is just a quick initial conversion of the D loader - -_EGL_LOADER = ''' -bool gladLoadEGL() { - return gladLoadEGL(x => eglGetProcAddress(x)) -} -''' - -_EGL_HAS_EXT = ''' -private bool has_ext(const(char)* ext) @nogc { - return true -} -''' - - -class EGLNimLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - if not self.disabled: - fobj.write(_EGL_LOADER) - - def write_begin_load(self, fobj): - pass - - def write_end_load(self, fobj): - fobj.write(' return true\n') - - def write_find_core(self, fobj): - pass - - def write_has_ext(self, fobj): - fobj.write(_EGL_HAS_EXT) diff --git a/libs/glad/glad/lang/nim/loader/gl.py b/libs/glad/glad/lang/nim/loader/gl.py @@ -1,147 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.nim.loader import LOAD_OPENGL_DLL - - -_OPENGL_LOADER = \ - LOAD_OPENGL_DLL % {'pre':'private', 'init':'open_gl', - 'proc':'get_proc', 'terminate':'close_gl'} + ''' -bool gladLoadGL() - bool status = false - - if(open_gl()) - status = gladLoadGL(x => get_proc(x)) - close_gl() - - return status - -''' - -_OPENGL_HAS_EXT_LT3 = '''proc hasExt(extname: string): bool = - if extname == nil: - return false - - var extensions = $cast[cstring](glGetString(GL_EXTENSIONS)) - if extensions == nil: - return false - - var - loc, terminatorLoc: int - terminator: char - - while true: - loc = extensions.find(extname) - if loc < 0: - return false - - terminatorLoc = loc + extname.len - terminator = extensions[terminatorLoc] - - if (loc == 0 or extensions[loc - 1] == ' ') and - (terminator == ' ' or terminator == '\\0'): - return true - - extensions = extensions[terminatorLoc..^1] - - -''' - -_OPENGL_HAS_EXT_GTE3 = '''proc hasExt(extname: string): bool = - if extname == nil: - return false - - if glVersionMajor < 3: - var extensions = $cast[cstring](glGetString(GL_EXTENSIONS)) - if extensions == nil: - return false - - var - loc, terminatorLoc: int - terminator: char - - while true: - loc = extensions.find(extname) - if loc < 0: - return false - - terminatorLoc = loc + extname.len - terminator = extensions[terminatorLoc] - - if (loc == 0 or extensions[loc - 1] == ' ') and - (terminator == ' ' or terminator == '\\0'): - return true - - extensions = extensions[terminatorLoc..^1] - - else: - var - num: GLint - s: cstring - - glGetIntegerv(GL_NUM_EXTENSIONS, num.addr) - - for i in 0..num-1: - s = cast[cstring](glGetStringi(GL_EXTENSIONS, GLuint(i))) - if s == extname: - return true - - -''' - -_FIND_VERSION = ''' # Thank you @elmindreda - # https://github.com/elmindreda/greg/blob/master/templates/greg.c.in#L176 - # https://github.com/glfw/glfw/blob/master/src/context.c#L36 - var prefixes = ["OpenGL ES-CM ", "OpenGL ES-CL ", "OpenGL ES "] - - var version = glVersion - for p in prefixes: - if version.startsWith(p): - version = version.replace(p) - break - - var major = ord(glVersion[0]) - ord('0') - var minor = ord(glVersion[2]) - ord('0') - - glVersionMajor = major - glVersionMinor = minor - -''' - -_BEGIN_LOAD = ''' glGetString = cast[proc (name: GLenum): ptr GLubyte {.cdecl.}](load("glGetString")) - if glGetString == nil: return false - - var glVersion = cast[cstring](glGetString(GL_VERSION)) - if glVersion == nil: return false - -''' - -class OpenGLNimLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - pass - # TODO -# if not self.disabled and 'gl' in self.apis: -# fobj.write(_OPENGL_LOADER) - - def write_begin_load(self, fobj): - fobj.write(_BEGIN_LOAD) - - def write_end_load(self, fobj): - fobj.write('\n return glVersionMajor != 0 or glVersionMinor != 0\n') - - def write_find_core(self, fobj): - fobj.write(_FIND_VERSION) - - def write_has_ext(self, fobj, apiversion): - if apiversion.major == 1 and apiversion.minor == 0: - return - if apiversion.major < 3: - fobj.write(_OPENGL_HAS_EXT_LT3) - else: - fobj.write(_OPENGL_HAS_EXT_GTE3) - - diff --git a/libs/glad/glad/lang/nim/loader/glx.py b/libs/glad/glad/lang/nim/loader/glx.py @@ -1,51 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.nim.loader import LOAD_OPENGL_DLL - - -# TODO this is just a quick initial conversion of the D loader - -_GLX_LOADER = \ - LOAD_OPENGL_DLL % {'pre':'private', 'init':'open_gl', - 'proc':'get_proc', 'terminate':'close_gl'} + ''' -bool gladLoadGLX() { - bool status = false - - if(open_gl()) { - status = gladLoadGLX(x => get_proc(x)) - close_gl() - } - - return status -} -''' - -_GLX_HAS_EXT = ''' -private bool has_ext(const(char)* name) @nogc { - return true -} -''' - - -class GLXNimLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - fobj.write('alias Loader = void* delegate(const(char)*)\n') - if not self.disabled: - fobj.write(_GLX_LOADER) - - def write_begin_load(self, fobj): - pass - - def write_end_load(self, fobj): - fobj.write(' return true\n') - - def write_find_core(self, fobj): - pass - - def write_has_ext(self, fobj): - fobj.write(_GLX_HAS_EXT) diff --git a/libs/glad/glad/lang/nim/loader/wgl.py b/libs/glad/glad/lang/nim/loader/wgl.py @@ -1,38 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.nim.loader.glx import _GLX_LOADER - - -# TODO this is just a quick initial conversion of the D loader - -_WGL_LOADER = _GLX_LOADER.replace('GLX', 'WGL') - -_WGL_HAS_EXT = ''' -private bool has_ext(const(char)* name) @nogc { - return true; -} -''' - - -class WGLNimLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - fobj.write('alias Loader = void* delegate(const(char)*);\n') - if not self.disabled: - fobj.write(_WGL_LOADER) - - def write_begin_load(self, fobj): - pass - - def write_end_load(self, fobj): - fobj.write(' return true\n') - - def write_find_core(self, fobj): - pass - - def write_has_ext(self, fobj): - fobj.write(_WGL_HAS_EXT) diff --git a/libs/glad/glad/lang/volt/__init__.py b/libs/glad/glad/lang/volt/__init__.py @@ -1,25 +0,0 @@ -from glad.lang.volt.loader.egl import EGLVoltLoader -from glad.lang.volt.loader.gl import OpenGLVoltLoader -from glad.lang.volt.loader.glx import GLXVoltLoader -from glad.lang.volt.loader.wgl import WGLVoltLoader - -from glad.lang.volt.generator import VoltGenerator - - -_specs = { - 'egl': EGLVoltLoader, - 'gl': OpenGLVoltLoader, - 'glx': GLXVoltLoader, - 'wgl': WGLVoltLoader -} - -_generators = { - 'volt': VoltGenerator, -} - - -def get_generator(name, spec): - gen = _generators.get(name) - loader = _specs.get(spec) - - return gen, loader diff --git a/libs/glad/glad/lang/volt/generator.py b/libs/glad/glad/lang/volt/generator.py @@ -1,86 +0,0 @@ -import sys - -from glad.lang.d.generator import DGenerator - - -if sys.version_info >= (3, 0): - basestring = str - - -class VoltGenerator(DGenerator): - NAME = 'volt' - NAME_LONG = 'Volt' - - MODULE = 'amp' - LOADER = 'loader' - ENUMS = 'enums' - EXT = 'ext' - FUNCS = 'funcs' - TYPES = 'types' - FILE_EXTENSION = '.volt' - API = '' - - LOAD_GL_NAME = 'load' - - @property - def PACKAGE(self): - return 'package' - - def write_module(self, fobj, name): - if name == 'package': - fobj.write('module {}.{};\n\n'.format(self.MODULE, self.spec.NAME)) - else: - DGenerator.write_module(self, fobj, name) - - def write_prototype_pre(self, fobj): - fobj.write('extern(System) @loadDynamic {\n') - - def write_prototype_post(self, fobj): - fobj.write('}\n') - - def write_function_pre(self, fobj): - pass - - def write_function_post(self, fobj): - pass - - def write_shared(self, fobj): - fobj.write('global {\n') - - def write_shared_end(self, fobj): - fobj.write('}\n') - - def write_function(self, fobj, func): - pass - - def write_function_prototype(self, fobj, func): - fobj.write('{} {}(' - .format(func.proto.ret.to_volt(), func.proto.name)) - fobj.write(', '.join(param.type.to_volt() for param in func.params)) - fobj.write(');\n') - - def write_boolean(self, fobj, name, **kwargs): - fobj.write('global bool {};\n'.format(name)) - - def write_enum(self, fobj, name, value, type_='uint'): - if isinstance(value, basestring): - if value.startswith('0x') and type_.startswith('u'): - value += 'U' - if len(value) > 12 and type_.startswith('u'): - value += 'L' - - try: - v = int(value) - if v < 0: - type_ = 'int' - except ValueError: - pass - - if isinstance(value, basestring) and '"' in value: - type_ = 'const(char)*' - - fobj.write('enum {} {} = {};\n'.format(type_, name, value)) - - def write_opaque_struct(self, fobj, name): - fobj.write('struct _{name} {{}}\nalias {name} = _{name}*;\n'.format(name=name)) - diff --git a/libs/glad/glad/lang/volt/loader/__init__.py b/libs/glad/glad/lang/volt/loader/__init__.py @@ -1,64 +0,0 @@ - -LOAD_OPENGL_DLL = ''' -private global Library libGL; -extern(System) private alias gladGetProcAddressPtrType = void* function(const(char)*); -private global gladGetProcAddressPtrType gladGetProcAddressPtr; - -%(pre)s -bool %(init)s() { - version(Windows) { - libGL = Library.load("opengl32.dll"); - } else version(OSX) { - libGL = Library.loads([ - "../Frameworks/OpenGL.framework/OpenGL", - "/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL" - ]); - } else { - libGL = Library.loads(["libGL.so.1", "libGL.so"]); - } - - if(libGL !is null) { - version(Windows) { - string sym = "wglGetProcAddress"; - } else { - string sym = "glXGetProcAddressARB"; - } - // returns null on OSX, but that's fine - gladGetProcAddressPtr = cast(typeof(gladGetProcAddressPtr))libGL.symbol(sym); - return true; - } - - return false; -} - -private struct StructToDg { - void* instance; - void* func; -} - -%(pre)s -void* %(proc)s(string name) { - if(libGL is null) return null; - void* result; - - if(gladGetProcAddressPtr !is null) { - // TODO: name.ptr - result = gladGetProcAddressPtr(name.ptr); - } - if(result is null) { - result = libGL.symbol(name); - } - - return result; -} - -%(pre)s -void %(terminate)s() { - if(libGL !is null) { - libGL.free(); - } - return; -} -'''- \ No newline at end of file diff --git a/libs/glad/glad/lang/volt/loader/egl.py b/libs/glad/glad/lang/volt/loader/egl.py @@ -1,48 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.d.loader.egl import _EGL_HAS_EXT as _D_EGL_HAS_EXT - - -_EGL_LOADER = ''' -private struct StructToDg { - void* instance; - void* func; -} - -private void* get_proc(string name) { - return eglGetProcAddress(arg.ptr); -} - -bool gladLoadEGL() { - StructToDg structToDg; - structToDg.func = cast(void*)get_proc; - auto dg = *cast(Loader*)&structToDg; - - return gladLoadEGL(dg); -} -''' -_EGL_HAS_EXT = _D_EGL_HAS_EXT - - -class EGLVoltLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - fobj.write('import watt.library;\n') - if not self.disabled: - fobj.write(_EGL_LOADER) - - def write_begin_load(self, fobj): - pass - - def write_end_load(self, fobj): - fobj.write('\treturn true;') - - def write_find_core(self, fobj): - pass - - def write_has_ext(self, fobj): - fobj.write(_EGL_HAS_EXT)- \ No newline at end of file diff --git a/libs/glad/glad/lang/volt/loader/gl.py b/libs/glad/glad/lang/volt/loader/gl.py @@ -1,60 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.volt.loader import LOAD_OPENGL_DLL -from glad.lang.d.loader.gl import _OPENGL_HAS_EXT as _D_OPENGL_HAS_EXT - - -_OPENGL_LOADER = \ - LOAD_OPENGL_DLL % {'pre':'private', 'init':'open_gl', - 'proc':'get_proc', 'terminate':'close_gl'} + ''' -bool gladLoadGL() { - StructToDg structToDg; - structToDg.func = cast(void*)get_proc; - auto dg = *cast(Loader*)&structToDg; - - bool status = false; - - if(open_gl()) { - status = gladLoadGL(dg); - close_gl(); - } - - return status; -} -''' - -_OPENGL_HAS_EXT = ( - 'global int GL_MAJOR = 0;\nglobal int GL_MINOR = 0;' + - '\n'.join(l for l in _D_OPENGL_HAS_EXT.replace('@nogc', '').splitlines() if 'struct' not in l) - .replace('GLVersion.major', 'GL_MAJOR') + - '\n\n' -) - - -class OpenGLVoltLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - fobj.write('import watt.library;\n') - if not self.disabled and 'gl' in self.apis: - fobj.write(_OPENGL_LOADER) - - def write_begin_load(self, fobj): - fobj.write('\tglGetString = cast(typeof(glGetString))load("glGetString");\n') - fobj.write('\tif(glGetString is null) { return false; }\n') - fobj.write('\tif(glGetString(GL_VERSION) is null) { return false; }\n\n') - - def write_end_load(self, fobj): - fobj.write('\treturn GL_MAJOR != 0 || GL_MINOR != 0;\n') - - def write_find_core(self, fobj): - fobj.write('\tconst(char)* v = cast(const(char)*)glGetString(GL_VERSION);\n') - fobj.write('\tint major = v[0] - \'0\';\n') - fobj.write('\tint minor = v[2] - \'0\';\n') - fobj.write('\tGL_MAJOR = major; GL_MINOR = minor;\n') - - def write_has_ext(self, fobj): - fobj.write(_OPENGL_HAS_EXT)- \ No newline at end of file diff --git a/libs/glad/glad/lang/volt/loader/glx.py b/libs/glad/glad/lang/volt/loader/glx.py @@ -1,47 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.volt.loader import LOAD_OPENGL_DLL - - -_GLX_LOADER = \ - LOAD_OPENGL_DLL % {'pre':'private', 'init':'open_gl', - 'proc':'get_proc', 'terminate':'close_gl'} + ''' -bool gladLoadGLX() { - StructToDg structToDg; - structToDg.func = cast(void*)get_proc; - auto dg = *cast(Loader*)&structToDg; - - bool status = false; - - if(open_gl()) { - status = gladLoadGLX(dg); - close_gl(); - } - - return status; -} -''' - -_GLX_HAS_EXT = ''' -private bool has_ext(const(char)* name) { - return true; -} -''' - - -class GLXVoltLoader(BaseLoader): - def write(self, fobj): - fobj.write('import watt.library;\n') - if not self.disabled: - fobj.write(_GLX_LOADER) - - def write_begin_load(self, fobj): - pass - - def write_end_load(self, fobj): - fobj.write('\treturn true;\n') - - def write_find_core(self, fobj): - pass - - def write_has_ext(self, fobj): - fobj.write(_GLX_HAS_EXT)- \ No newline at end of file diff --git a/libs/glad/glad/lang/volt/loader/wgl.py b/libs/glad/glad/lang/volt/loader/wgl.py @@ -1,35 +0,0 @@ -from glad.lang.common.loader import BaseLoader -from glad.lang.volt.loader.glx import _GLX_LOADER - - -_WGL_LOADER = _GLX_LOADER.replace('GLX', 'WGL') -_WGL_HAS_EXT = ''' -private bool has_ext(const(char)* name) { - return true; -} -''' - - -class WGLVoltLoader(BaseLoader): - def write_header_end(self, fobj): - pass - - def write_header(self, fobj): - pass - - def write(self, fobj): - fobj.write('import watt.library;\n') - if not self.disabled: - fobj.write(_WGL_LOADER) - - def write_begin_load(self, fobj): - pass - - def write_end_load(self, fobj): - fobj.write('\treturn true;\n') - - def write_find_core(self, fobj): - pass - - def write_has_ext(self, fobj): - fobj.write(_WGL_HAS_EXT)- \ No newline at end of file