Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
355 lines (282 loc) · 8.42 KB

SDL_DirectFB_opengl.c

File metadata and controls

355 lines (282 loc) · 8.42 KB
 
1
/*
Apr 8, 2011
Apr 8, 2011
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
20
21
22
23
*/
#include "SDL_DirectFB_video.h"
Feb 6, 2011
Feb 6, 2011
24
#if SDL_DIRECTFB_OPENGL
Mar 15, 2011
Mar 15, 2011
25
Feb 6, 2011
Feb 6, 2011
26
27
28
29
30
31
32
#include "SDL_DirectFB_opengl.h"
#include "SDL_DirectFB_window.h"
#include <directfbgl.h>
#include "SDL_loadso.h"
#endif
33
34
35
36
37
38
39
#if SDL_DIRECTFB_OPENGL
struct SDL_GLDriverData
{
int gl_active; /* to stop switching drivers while we have a valid context */
int initialized;
DirectFB_GLContext *firstgl; /* linked list */
Aug 16, 2010
Aug 16, 2010
40
41
42
43
/* OpenGL */
void (*glFinish) (void);
void (*glFlush) (void);
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
};
#define OPENGL_REQUIRS_DLOPEN
#if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
#include <dlfcn.h>
#define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
#define GL_LoadFunction dlsym
#define GL_UnloadObject dlclose
#else
#define GL_LoadObject SDL_LoadObject
#define GL_LoadFunction SDL_LoadFunction
#define GL_UnloadObject SDL_UnloadObject
#endif
static void DirectFB_GL_UnloadLibrary(_THIS);
int
DirectFB_GL_Initialize(_THIS)
{
if (_this->gl_data) {
return 0;
}
_this->gl_data =
(struct SDL_GLDriverData *) SDL_calloc(1,
sizeof(struct
SDL_GLDriverData));
if (!_this->gl_data) {
SDL_OutOfMemory();
return -1;
}
_this->gl_data->initialized = 0;
++_this->gl_data->initialized;
_this->gl_data->firstgl = NULL;
if (DirectFB_GL_LoadLibrary(_this, NULL) < 0) {
return -1;
}
/* Initialize extensions */
/* FIXME needed?
* X11_GL_InitExtensions(_this);
*/
return 0;
}
void
DirectFB_GL_Shutdown(_THIS)
{
if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
return;
}
DirectFB_GL_UnloadLibrary(_this);
SDL_free(_this->gl_data);
_this->gl_data = NULL;
}
int
DirectFB_GL_LoadLibrary(_THIS, const char *path)
{
Aug 16, 2010
Aug 16, 2010
108
//SDL_DFB_DEVICEDATA(_this);
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
void *handle = NULL;
SDL_DFB_DEBUG("Loadlibrary : %s\n", path);
if (_this->gl_data->gl_active) {
SDL_SetError("OpenGL context already created");
return -1;
}
if (path == NULL) {
path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
if (path == NULL) {
path = "libGL.so";
}
}
handle = GL_LoadObject(path);
if (handle == NULL) {
SDL_DFB_ERR("Library not found: %s\n", path);
/* SDL_LoadObject() will call SDL_SetError() for us. */
return -1;
}
SDL_DFB_DEBUG("Loaded library: %s\n", path);
_this->gl_config.dll_handle = handle;
_this->gl_config.driver_loaded = 1;
if (path) {
SDL_strlcpy(_this->gl_config.driver_path, path,
SDL_arraysize(_this->gl_config.driver_path));
} else {
*_this->gl_config.driver_path = '\0';
}
Aug 16, 2010
Aug 16, 2010
145
146
_this->gl_data->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
_this->gl_data->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
147
148
149
150
151
152
153
return 0;
}
static void
DirectFB_GL_UnloadLibrary(_THIS)
{
Aug 16, 2010
Aug 16, 2010
154
#if 0
155
156
157
158
159
160
161
162
163
164
int ret;
if (_this->gl_config.driver_loaded) {
ret = GL_UnloadObject(_this->gl_config.dll_handle);
if (ret)
SDL_DFB_ERR("Error #%d trying to unload library.\n", ret);
_this->gl_config.dll_handle = NULL;
_this->gl_config.driver_loaded = 0;
}
Aug 16, 2010
Aug 16, 2010
165
166
167
168
#endif
/* Free OpenGL memory */
SDL_free(_this->gl_data);
_this->gl_data = NULL;
169
170
171
172
173
174
175
176
177
178
179
180
181
182
}
void *
DirectFB_GL_GetProcAddress(_THIS, const char *proc)
{
void *handle;
handle = _this->gl_config.dll_handle;
return GL_LoadFunction(handle, proc);
}
SDL_GLContext
DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
{
Aug 16, 2010
Aug 16, 2010
183
//SDL_DFB_DEVICEDATA(_this);
184
185
186
SDL_DFB_WINDOWDATA(window);
DirectFB_GLContext *context;
Feb 6, 2011
Feb 6, 2011
187
SDL_DFB_ALLOC_CLEAR(context, sizeof(DirectFB_GLContext));
188
Jan 11, 2009
Jan 11, 2009
189
190
SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface,
&context->context));
Jan 4, 2009
Jan 4, 2009
191
192
193
194
if (!context->context)
return NULL;
Aug 16, 2010
Aug 16, 2010
195
196
197
context->is_locked = 0;
context->sdl_window = window;
198
199
200
context->next = _this->gl_data->firstgl;
_this->gl_data->firstgl = context;
Aug 16, 2010
Aug 16, 2010
201
202
SDL_DFB_CHECK(context->context->Unlock(context->context));
203
204
205
206
207
208
209
210
211
212
213
214
215
216
if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
DirectFB_GL_DeleteContext(_this, context);
return NULL;
}
return context;
error:
return NULL;
}
int
DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
Aug 16, 2010
Aug 16, 2010
217
//SDL_DFB_WINDOWDATA(window);
218
219
220
221
DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
DirectFB_GLContext *p;
for (p = _this->gl_data->firstgl; p; p = p->next)
Aug 16, 2010
Aug 16, 2010
222
223
224
225
226
227
{
if (p->is_locked) {
SDL_DFB_CHECKERR(p->context->Unlock(p->context));
p->is_locked = 0;
}
228
229
230
231
}
if (ctx != NULL) {
SDL_DFB_CHECKERR(ctx->context->Lock(ctx->context));
Aug 16, 2010
Aug 16, 2010
232
ctx->is_locked = 1;
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
}
return 0;
error:
return -1;
}
int
DirectFB_GL_SetSwapInterval(_THIS, int interval)
{
SDL_Unsupported();
return -1;
}
int
DirectFB_GL_GetSwapInterval(_THIS)
{
SDL_Unsupported();
return -1;
}
void
DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
{
Aug 16, 2010
Aug 16, 2010
257
//SDL_DFB_DEVICEDATA(_this);
258
259
SDL_DFB_WINDOWDATA(window);
DFBRegion region;
Aug 16, 2010
Aug 16, 2010
260
DirectFB_GLContext *p;
261
262
263
264
265
266
region.x1 = 0;
region.y1 = 0;
region.x2 = window->w;
region.y2 = window->h;
Aug 16, 2010
Aug 16, 2010
267
#if 0
268
269
270
271
if (devdata->glFinish)
devdata->glFinish();
else if (devdata->glFlush)
devdata->glFlush();
Aug 16, 2010
Aug 16, 2010
272
#endif
273
Aug 16, 2010
Aug 16, 2010
274
275
276
277
278
279
for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
if (p->sdl_window == window && p->is_locked)
{
SDL_DFB_CHECKERR(p->context->Unlock(p->context));
p->is_locked = 0;
}
280
Aug 16, 2010
Aug 16, 2010
281
282
283
284
285
286
SDL_DFB_CHECKERR(windata->window_surface->Flip(windata->window_surface,NULL, DSFLIP_PIPELINE |DSFLIP_BLIT | DSFLIP_ONSYNC ));
//if (windata->gl_context) {
//SDL_DFB_CHECKERR(windata->surface->Flip(windata->surface,NULL, DSFLIP_ONSYNC));
//SDL_DFB_CHECKERR(windata->gl_context->context->Lock(windata->gl_context->context));
//}
287
288
289
290
291
292
293
294
295
296
297
298
return;
error:
return;
}
void
DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
{
DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
DirectFB_GLContext *p;
Aug 16, 2010
Aug 16, 2010
299
300
301
if (ctx->is_locked)
SDL_DFB_CHECK(ctx->context->Unlock(ctx->context));
SDL_DFB_RELEASE(ctx->context);
302
Aug 16, 2010
Aug 16, 2010
303
304
for (p = _this->gl_data->firstgl; p && p->next != ctx; p = p->next)
;
305
306
307
308
309
310
if (p)
p->next = ctx->next;
else
_this->gl_data->firstgl = ctx->next;
SDL_DFB_FREE(ctx);
Aug 16, 2010
Aug 16, 2010
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
}
void
DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window)
{
DirectFB_GLContext *p;
for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
if (p->sdl_window == window)
{
if (p->is_locked)
SDL_DFB_CHECK(p->context->Unlock(p->context));
SDL_DFB_RELEASE(p->context);
}
}
void
DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window)
{
DirectFB_GLContext *p;
for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
if (p->sdl_window == window)
{
SDL_DFB_WINDOWDATA(window);
SDL_DFB_CHECK(windata->surface->GetGL(windata->surface,
&p->context));
if (p->is_locked)
SDL_DFB_CHECK(p->context->Lock(p->context));
}
}
void
DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window)
{
DirectFB_GLContext *p;
347
Aug 16, 2010
Aug 16, 2010
348
349
350
for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
if (p->sdl_window == window)
DirectFB_GL_DeleteContext(_this, p);
351
352
353
354
355
}
#endif
/* vi: set ts=4 sw=4 expandtab: */