Mercurial > hg > forks > gldragon
comparison 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 |
comparison
equal
deleted
inserted
replaced
41:eaa3e8575c12 | 42:3c7e1d3fa5a2 |
---|---|
37 SDL_GLContext dmGLContext = NULL; | 37 SDL_GLContext dmGLContext = NULL; |
38 | 38 |
39 | 39 |
40 /* Helpers | 40 /* Helpers |
41 */ | 41 */ |
42 #ifdef GL_GLEXT_PROTOTYPES | |
43 #define DM_GLEXT_INIT(extproctype, extprocname) /* stub */ | |
44 #else | |
45 // GL_GLEXT_PROTOTYPES not defined | |
46 | |
47 #define DM_GLEXT_INIT(extproctype, extprocname) extproctype extprocname = NULL; | |
48 #include "dmglexts.h" | |
49 #undef DM_GLEXT_INIT | |
50 | |
51 | |
52 void * dmGLExtTry(const std::string &name) | |
53 { | |
54 bool res = SDL_GL_ExtensionSupported(name.c_str()); | |
55 void *ptr = SDL_GL_GetProcAddress(name.c_str()); | |
56 res = true; | |
57 | |
58 printf(" - Checking '%s' : %s : %p\n", | |
59 name.c_str(), | |
60 res ? "YES" : "no", | |
61 ptr); | |
62 | |
63 if (res && ptr != NULL) | |
64 return ptr; | |
65 else | |
66 return NULL; | |
67 } | |
68 | |
69 void * dmGLExtInit(const std::string &name, bool &status) | |
70 { | |
71 void *ptr; | |
72 | |
73 if ((ptr = dmGLExtTry(name)) != NULL) | |
74 return ptr; | |
75 else | |
76 if ((ptr = dmGLExtTry(name + "EXT")) != NULL) | |
77 return ptr; | |
78 else | |
79 if ((ptr = dmGLExtTry(name + "ARB")) != NULL) | |
80 return ptr; | |
81 | |
82 status = false; | |
83 return NULL; | |
84 } | |
85 | |
86 | |
87 #define DM_GLEXT_INIT(extproctype, extprocname) \ | |
88 extprocname = (extproctype) dmGLExtInit(#extprocname, status); | |
89 | |
90 #endif | |
91 | |
92 | |
93 | |
94 bool dmInitGLExtensions(void) | |
95 { | |
96 #ifdef GL_GLEXT_PROTOTYPES | |
97 return true; | |
98 #else | |
99 bool status = true; | |
100 #include "dmglexts.h" | |
101 return status; | |
102 #endif | |
103 } | |
104 | |
105 | |
42 bool dmInitSDLGL(const int width, const int height, const char *title) | 106 bool dmInitSDLGL(const int width, const int height, const char *title) |
43 { | 107 { |
44 int ret; | 108 int ret; |
45 std::string msg; | 109 std::string msg; |
46 | 110 |
111 { | 175 { |
112 printf("ERROR: Could not set vsync mode to %s.\n", | 176 printf("ERROR: Could not set vsync mode to %s.\n", |
113 msg.c_str()); | 177 msg.c_str()); |
114 return false; | 178 return false; |
115 } | 179 } |
180 | |
181 // Get/initialize OpenGL extension function pointers | |
182 if (optUseShaders && !dmInitGLExtensions()) | |
183 return false; | |
116 | 184 |
117 // Dump some information | 185 // Dump some information |
118 printf( | 186 printf( |
119 "GL_VENDOR : %s\n" | 187 "GL_VENDOR : %s\n" |
120 "GL_RENDERER : %s\n" | 188 "GL_RENDERER : %s\n" |