Mercurial > hg > forks > gldragon
diff gldragon.cpp @ 42:3c7e1d3fa5a2
Implement OpengL extension handling through new header file dmglexts.h to
"define" the entrypoints we require and some wonderful preprocessor macro
magic to add checks for them via SDL_GL_ExtensionSupported() and initialize
function pointers with SDL_GL_GetProcAddress().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 05 Dec 2019 21:05:43 +0200 |
parents | 4de11a54215a |
children | d93b1c2690f8 |
line wrap: on
line diff
--- a/gldragon.cpp Thu Dec 05 18:32:13 2019 +0200 +++ b/gldragon.cpp Thu Dec 05 21:05:43 2019 +0200 @@ -39,6 +39,70 @@ /* Helpers */ +#ifdef GL_GLEXT_PROTOTYPES +#define DM_GLEXT_INIT(extproctype, extprocname) /* stub */ +#else +// GL_GLEXT_PROTOTYPES not defined + +#define DM_GLEXT_INIT(extproctype, extprocname) extproctype extprocname = NULL; +#include "dmglexts.h" +#undef DM_GLEXT_INIT + + +void * dmGLExtTry(const std::string &name) +{ + bool res = SDL_GL_ExtensionSupported(name.c_str()); + void *ptr = SDL_GL_GetProcAddress(name.c_str()); + res = true; + + printf(" - Checking '%s' : %s : %p\n", + name.c_str(), + res ? "YES" : "no", + ptr); + + if (res && ptr != NULL) + return ptr; + else + return NULL; +} + +void * dmGLExtInit(const std::string &name, bool &status) +{ + void *ptr; + + if ((ptr = dmGLExtTry(name)) != NULL) + return ptr; + else + if ((ptr = dmGLExtTry(name + "EXT")) != NULL) + return ptr; + else + if ((ptr = dmGLExtTry(name + "ARB")) != NULL) + return ptr; + + status = false; + return NULL; +} + + +#define DM_GLEXT_INIT(extproctype, extprocname) \ + extprocname = (extproctype) dmGLExtInit(#extprocname, status); + +#endif + + + +bool dmInitGLExtensions(void) +{ +#ifdef GL_GLEXT_PROTOTYPES + return true; +#else + bool status = true; +#include "dmglexts.h" + return status; +#endif +} + + bool dmInitSDLGL(const int width, const int height, const char *title) { int ret; @@ -114,6 +178,10 @@ return false; } + // Get/initialize OpenGL extension function pointers + if (optUseShaders && !dmInitGLExtensions()) + return false; + // Dump some information printf( "GL_VENDOR : %s\n"