Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11opengl.c @ 3057:089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Make sure OpenGL library is loaded before working with OpenGL windows,
even those created with SDL_CreateWindowFrom()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 09 Feb 2009 05:32:12 +0000 |
parents | 8cc00819c8d6 |
children | 7dc982143c06 |
comparison
equal
deleted
inserted
replaced
3056:a434fe6360df | 3057:089a77aebb7d |
---|---|
63 #define GL_LoadObject SDL_LoadObject | 63 #define GL_LoadObject SDL_LoadObject |
64 #define GL_LoadFunction SDL_LoadFunction | 64 #define GL_LoadFunction SDL_LoadFunction |
65 #define GL_UnloadObject SDL_UnloadObject | 65 #define GL_UnloadObject SDL_UnloadObject |
66 #endif | 66 #endif |
67 | 67 |
68 static int X11_GL_InitializeMemory(_THIS); | 68 static void X11_GL_InitExtensions(_THIS); |
69 | 69 |
70 int | 70 int |
71 X11_GL_LoadLibrary(_THIS, const char *path) | 71 X11_GL_LoadLibrary(_THIS, const char *path) |
72 { | 72 { |
73 void *handle; | 73 void *handle; |
74 | 74 |
75 if (_this->gl_config.driver_loaded) { | 75 /* Load the OpenGL library */ |
76 /* do not return without reinitializing the function hooks */ | 76 if (path == NULL) { |
77 if (path) { | 77 path = SDL_getenv("SDL_OPENGL_LIBRARY"); |
78 SDL_SetError("OpenGL library already loaded"); | 78 } |
79 } | 79 if (path == NULL) { |
80 handle = _this->gl_config.dll_handle; | 80 path = DEFAULT_OPENGL; |
81 } else { | 81 } |
82 if (path == NULL) { | 82 _this->gl_config.dll_handle = SDL_LoadObject(path); |
83 path = SDL_getenv("SDL_OPENGL_LIBRARY"); | 83 if (!_this->gl_config.dll_handle) { |
84 } | 84 return -1; |
85 if (path == NULL) { | 85 } |
86 path = DEFAULT_OPENGL; | 86 SDL_strlcpy(_this->gl_config.driver_path, path, |
87 } | 87 SDL_arraysize(_this->gl_config.driver_path)); |
88 handle = GL_LoadObject(path); | 88 |
89 if (!handle) { | 89 /* Allocate OpenGL memory */ |
90 return -1; | 90 _this->gl_data = |
91 } | 91 (struct SDL_GLDriverData *) SDL_calloc(1, |
92 _this->gl_config.dll_handle = handle; | 92 sizeof(struct |
93 SDL_strlcpy(_this->gl_config.driver_path, path, | 93 SDL_GLDriverData)); |
94 SDL_arraysize(_this->gl_config.driver_path)); | 94 if (!_this->gl_data) { |
95 } | 95 SDL_OutOfMemory(); |
96 X11_GL_InitializeMemory(_this); | 96 return -1; |
97 | 97 } |
98 /* Load new function pointers */ | 98 |
99 /* Load function pointers */ | |
100 handle = _this->gl_config.dll_handle; | |
99 _this->gl_data->glXGetProcAddress = | 101 _this->gl_data->glXGetProcAddress = |
100 (void *(*)(const GLubyte *)) GL_LoadFunction(handle, | 102 (void *(*)(const GLubyte *)) GL_LoadFunction(handle, |
101 "glXGetProcAddressARB"); | 103 "glXGetProcAddressARB"); |
102 _this->gl_data->glXChooseVisual = | 104 _this->gl_data->glXChooseVisual = |
103 (XVisualInfo * (*)(Display *, int, int *)) GL_LoadFunction(handle, | 105 (XVisualInfo * (*)(Display *, int, int *)) GL_LoadFunction(handle, |
121 !_this->gl_data->glXMakeCurrent || !_this->gl_data->glXSwapBuffers) { | 123 !_this->gl_data->glXMakeCurrent || !_this->gl_data->glXSwapBuffers) { |
122 SDL_SetError("Could not retrieve OpenGL functions"); | 124 SDL_SetError("Could not retrieve OpenGL functions"); |
123 return -1; | 125 return -1; |
124 } | 126 } |
125 | 127 |
126 ++_this->gl_config.driver_loaded; | 128 /* Initialize extensions */ |
129 X11_GL_InitExtensions(_this); | |
130 | |
127 return 0; | 131 return 0; |
128 } | 132 } |
129 | 133 |
130 void * | 134 void * |
131 X11_GL_GetProcAddress(_THIS, const char *proc) | 135 X11_GL_GetProcAddress(_THIS, const char *proc) |
137 return _this->gl_data->glXGetProcAddress((const GLubyte *) proc); | 141 return _this->gl_data->glXGetProcAddress((const GLubyte *) proc); |
138 } | 142 } |
139 return GL_LoadFunction(handle, proc); | 143 return GL_LoadFunction(handle, proc); |
140 } | 144 } |
141 | 145 |
142 static void | 146 void |
143 X11_GL_UnloadLibrary(_THIS) | 147 X11_GL_UnloadLibrary(_THIS) |
144 { | 148 { |
145 if (_this->gl_config.driver_loaded > 0) { | 149 /* Don't actually unload the library, since it may have registered |
146 if (--_this->gl_config.driver_loaded > 0) { | 150 * X11 shutdown hooks, per the notes at: |
147 return; | 151 * http://dri.sourceforge.net/doc/DRIuserguide.html |
148 } | 152 */ |
149 GL_UnloadObject(_this->gl_config.dll_handle); | 153 #if 0 |
150 _this->gl_config.dll_handle = NULL; | 154 GL_UnloadObject(_this->gl_config.dll_handle); |
151 } | 155 _this->gl_config.dll_handle = NULL; |
156 #endif | |
157 | |
158 /* Free OpenGL memory */ | |
159 SDL_free(_this->gl_data); | |
160 _this->gl_data = NULL; | |
152 } | 161 } |
153 | 162 |
154 static SDL_bool | 163 static SDL_bool |
155 HasExtension(const char *extension, const char *extensions) | 164 HasExtension(const char *extension, const char *extensions) |
156 { | 165 { |
250 _this->gl_data->glXMakeCurrent(display, None, NULL); | 259 _this->gl_data->glXMakeCurrent(display, None, NULL); |
251 _this->gl_data->glXDestroyContext(display, context); | 260 _this->gl_data->glXDestroyContext(display, context); |
252 } | 261 } |
253 XDestroyWindow(display, w); | 262 XDestroyWindow(display, w); |
254 X11_PumpEvents(_this); | 263 X11_PumpEvents(_this); |
255 } | |
256 | |
257 static int | |
258 X11_GL_InitializeMemory(_THIS) | |
259 { | |
260 if (_this->gl_data) { | |
261 return 0; | |
262 } | |
263 | |
264 _this->gl_data = | |
265 (struct SDL_GLDriverData *) SDL_calloc(1, | |
266 sizeof(struct | |
267 SDL_GLDriverData)); | |
268 if (!_this->gl_data) { | |
269 SDL_OutOfMemory(); | |
270 return -1; | |
271 } | |
272 _this->gl_data->initialized = 0; | |
273 | |
274 return 0; | |
275 } | |
276 | |
277 int | |
278 X11_GL_Initialize(_THIS) | |
279 { | |
280 | |
281 if (X11_GL_InitializeMemory(_this) < 0) { | |
282 return -1; | |
283 } | |
284 ++_this->gl_data->initialized; | |
285 | |
286 if (X11_GL_LoadLibrary(_this, NULL) < 0) { | |
287 return -1; | |
288 } | |
289 | |
290 /* Initialize extensions */ | |
291 X11_GL_InitExtensions(_this); | |
292 | |
293 return 0; | |
294 } | |
295 | |
296 void | |
297 X11_GL_Shutdown(_THIS) | |
298 { | |
299 if (!_this->gl_data || (--_this->gl_data->initialized > 0)) { | |
300 return; | |
301 } | |
302 | |
303 /* Don't actually unload the library, since it may have registered | |
304 * X11 shutdown hooks, per the notes at: | |
305 * http://dri.sourceforge.net/doc/DRIuserguide.html | |
306 * //X11_GL_UnloadLibrary(_this); | |
307 */ | |
308 | |
309 SDL_free(_this->gl_data); | |
310 _this->gl_data = NULL; | |
311 } | 264 } |
312 | 265 |
313 XVisualInfo * | 266 XVisualInfo * |
314 X11_GL_GetVisual(_THIS, Display * display, int screen) | 267 X11_GL_GetVisual(_THIS, Display * display, int screen) |
315 { | 268 { |