2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with _this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 #include "SDL_DirectFB_video.h"
26 #if SDL_DIRECTFB_OPENGL
28 struct SDL_GLDriverData
30 int gl_active; /* to stop switching drivers while we have a valid context */
32 DirectFB_GLContext *firstgl; /* linked list */
35 #define OPENGL_REQUIRS_DLOPEN
36 #if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
38 #define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
39 #define GL_LoadFunction dlsym
40 #define GL_UnloadObject dlclose
42 #define GL_LoadObject SDL_LoadObject
43 #define GL_LoadFunction SDL_LoadFunction
44 #define GL_UnloadObject SDL_UnloadObject
47 static void DirectFB_GL_UnloadLibrary(_THIS);
50 DirectFB_GL_Initialize(_THIS)
57 (struct SDL_GLDriverData *) SDL_calloc(1,
60 if (!_this->gl_data) {
64 _this->gl_data->initialized = 0;
66 ++_this->gl_data->initialized;
67 _this->gl_data->firstgl = NULL;
69 if (DirectFB_GL_LoadLibrary(_this, NULL) < 0) {
73 /* Initialize extensions */
75 * X11_GL_InitExtensions(_this);
82 DirectFB_GL_Shutdown(_THIS)
84 if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
88 DirectFB_GL_UnloadLibrary(_this);
90 SDL_free(_this->gl_data);
91 _this->gl_data = NULL;
95 DirectFB_GL_LoadLibrary(_THIS, const char *path)
97 SDL_DFB_DEVICEDATA(_this);
101 SDL_DFB_DEBUG("Loadlibrary : %s\n", path);
103 if (_this->gl_data->gl_active) {
104 SDL_SetError("OpenGL context already created");
110 path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
116 handle = GL_LoadObject(path);
117 if (handle == NULL) {
118 SDL_DFB_ERR("Library not found: %s\n", path);
119 /* SDL_LoadObject() will call SDL_SetError() for us. */
123 SDL_DFB_DEBUG("Loaded library: %s\n", path);
125 /* Unload the old driver and reset the pointers */
126 DirectFB_GL_UnloadLibrary(_this);
128 _this->gl_config.dll_handle = handle;
129 _this->gl_config.driver_loaded = 1;
131 SDL_strlcpy(_this->gl_config.driver_path, path,
132 SDL_arraysize(_this->gl_config.driver_path));
134 *_this->gl_config.driver_path = '\0';
137 devdata->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
138 devdata->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
144 DirectFB_GL_UnloadLibrary(_THIS)
148 if (_this->gl_config.driver_loaded) {
150 ret = GL_UnloadObject(_this->gl_config.dll_handle);
152 SDL_DFB_ERR("Error #%d trying to unload library.\n", ret);
153 _this->gl_config.dll_handle = NULL;
154 _this->gl_config.driver_loaded = 0;
159 DirectFB_GL_GetProcAddress(_THIS, const char *proc)
163 handle = _this->gl_config.dll_handle;
164 return GL_LoadFunction(handle, proc);
168 DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
170 SDL_DFB_WINDOWDATA(window);
171 DirectFB_GLContext *context;
174 SDL_DFB_CALLOC(context, 1, sizeof(*context));
176 SDL_DFB_CHECKERR(windata->surface->
177 GetGL(windata->surface, &context->context));
178 SDL_DFB_CHECKERR(context->context->Unlock(context->context));
180 context->next = _this->gl_data->firstgl;
181 _this->gl_data->firstgl = context;
183 if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
184 DirectFB_GL_DeleteContext(_this, context);
195 DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
197 SDL_DFB_WINDOWDATA(window);
198 DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
199 DirectFB_GLContext *p;
203 for (p = _this->gl_data->firstgl; p; p = p->next)
204 p->context->Unlock(p->context);
209 windata->gl_context = NULL;
210 /* Everything is unlocked, check for a resize */
211 SDL_DFB_CHECKERR(windata->surface->
212 GetSize(windata->surface, &cw, &ch));
213 if (cw != window->w || ch != window->h)
214 SDL_DFB_CHECKERR(windata->window->
215 ResizeSurface(windata->window, window->w,
220 SDL_DFB_CHECKERR(ctx->context->Lock(ctx->context));
224 windata->gl_context = ctx;
232 DirectFB_GL_SetSwapInterval(_THIS, int interval)
239 DirectFB_GL_GetSwapInterval(_THIS)
246 DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
248 SDL_DFB_DEVICEDATA(_this);
249 SDL_DFB_WINDOWDATA(window);
255 region.x2 = window->w;
256 region.y2 = window->h;
258 if (devdata->glFinish)
260 else if (devdata->glFlush)
263 if (1 || windata->gl_context) {
264 /* SDL_DFB_CHECKERR(windata->gl_context->context->Unlock(windata->gl_context->context)); */
265 SDL_DFB_CHECKERR(windata->surface->
266 Flip(windata->surface, ®ion, DSFLIP_ONSYNC));
267 /* SDL_DFB_CHECKERR(windata->gl_context->context->Lock(windata->gl_context->context)); */
277 DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
279 DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
280 DirectFB_GLContext *p;
282 ctx->context->Unlock(ctx->context);
283 ctx->context->Release(ctx->context);
285 p = _this->gl_data->firstgl;
286 while (p && p->next != ctx)
291 _this->gl_data->firstgl = ctx->next;
299 /* vi: set ts=4 sw=4 expandtab: */