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

Latest commit

 

History

History
407 lines (340 loc) · 11 KB

SDL_ph_gl.c

File metadata and controls

407 lines (340 loc) · 11 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
23
24
25
26
27
#include <dlfcn.h>
#include "SDL.h"
#include "SDL_ph_gl.h"
Feb 16, 2006
Feb 16, 2006
28
#if SDL_VIDEO_OPENGL
29
30
31
#if (_NTO_VERSION >= 630)
/* PhotonGL functions */
May 28, 2006
May 28, 2006
32
GLPH_DECLARE_FUNCS;
33
34
35
#endif /* 6.3.0 */
#if (_NTO_VERSION < 630)
May 28, 2006
May 28, 2006
36
37
void
ph_GL_SwapBuffers (_THIS)
38
{
May 28, 2006
May 28, 2006
39
40
PgSetRegion (PtWidgetRid (window));
PdOpenGLContextSwapBuffers (oglctx);
41
42
}
#else
May 28, 2006
May 28, 2006
43
44
void
ph_GL_SwapBuffers (_THIS)
45
{
May 28, 2006
May 28, 2006
46
qnxgl_swap_buffers (oglbuffers);
47
48
49
}
#endif /* 6.3.0 */
May 28, 2006
May 28, 2006
50
51
int
ph_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value)
52
{
May 28, 2006
May 28, 2006
53
54
55
56
57
58
59
60
61
62
switch (attrib) {
case SDL_GL_DOUBLEBUFFER:
*value = this->gl_config.double_buffer;
break;
case SDL_GL_STENCIL_SIZE:
*value = this->gl_config.stencil_size;
break;
case SDL_GL_DEPTH_SIZE:
*value = this->gl_config.depth_size;
break;
63
#if (_NTO_VERSION >= 630)
May 28, 2006
May 28, 2006
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
case SDL_GL_RED_SIZE:
*value = this->gl_config.red_size;
break;
case SDL_GL_GREEN_SIZE:
*value = this->gl_config.green_size;
break;
case SDL_GL_BLUE_SIZE:
*value = this->gl_config.blue_size;
break;
case SDL_GL_ALPHA_SIZE:
*value = this->gl_config.alpha_size;
break;
case SDL_GL_ACCUM_RED_SIZE:
*value = this->gl_config.accum_red_size;
break;
case SDL_GL_ACCUM_GREEN_SIZE:
*value = this->gl_config.accum_green_size;
break;
case SDL_GL_ACCUM_BLUE_SIZE:
*value = this->gl_config.accum_blue_size;
break;
case SDL_GL_ACCUM_ALPHA_SIZE:
*value = this->gl_config.accum_alpha_size;
break;
case SDL_GL_STEREO:
*value = this->gl_config.stereo;
break;
91
#endif /* 6.3.0 */
May 28, 2006
May 28, 2006
92
93
94
default:
*value = 0;
return (-1);
95
96
97
98
99
}
return 0;
}
#if (_NTO_VERSION < 630)
May 28, 2006
May 28, 2006
100
101
int
ph_GL_LoadLibrary (_THIS, const char *path)
102
{
Feb 16, 2006
Feb 16, 2006
103
/* if code compiled with SDL_VIDEO_OPENGL, that mean that library already linked */
104
105
106
107
108
this->gl_config.driver_loaded = 1;
return 0;
}
#else
May 28, 2006
May 28, 2006
109
110
int
ph_GL_LoadLibrary (_THIS, const char *path)
111
{
May 28, 2006
May 28, 2006
112
113
void *handle;
int dlopen_flags = RTLD_WORLD | RTLD_GROUP;
114
May 28, 2006
May 28, 2006
115
if (this->gl_config.dll_handle != NULL) {
116
117
118
return 0;
}
May 28, 2006
May 28, 2006
119
handle = dlopen (path, dlopen_flags);
120
May 28, 2006
May 28, 2006
121
122
if (handle == NULL) {
SDL_SetError ("ph_GL_LoadLibrary(): Could not load OpenGL library");
123
124
125
126
127
128
return -1;
}
this->gl_config.dll_handle = handle;
this->gl_config.driver_loaded = 1;
May 28, 2006
May 28, 2006
129
130
SDL_strlcpy (this->gl_config.driver_path, path,
SDL_arraysize (this->gl_config.driver_path));
131
132
133
134
135
136
return 0;
}
#endif /* 6.3.0 */
#if (_NTO_VERSION < 630)
May 28, 2006
May 28, 2006
137
138
void *
ph_GL_GetProcAddress (_THIS, const char *proc)
139
140
141
142
{
return NULL;
}
#else
May 28, 2006
May 28, 2006
143
144
void *
ph_GL_GetProcAddress (_THIS, const char *proc)
145
{
May 28, 2006
May 28, 2006
146
void *function;
147
May 28, 2006
May 28, 2006
148
149
150
if (this->gl_config.dll_handle == NULL) {
ph_GL_LoadLibrary (this, DEFAULT_OPENGL);
if (this->gl_config.dll_handle == NULL) {
151
152
153
return NULL;
}
}
May 28, 2006
May 28, 2006
154
155
156
157
function = qnxgl_get_func (proc, oglctx, 0);
if (function == NULL) {
function = dlsym (this->gl_config.dll_handle, proc);
158
159
160
161
162
163
164
}
return function;
}
#endif /* 6.3.0 */
#if (_NTO_VERSION < 630)
May 28, 2006
May 28, 2006
165
166
int
ph_GL_MakeCurrent (_THIS)
167
{
May 28, 2006
May 28, 2006
168
PgSetRegion (PtWidgetRid (window));
169
May 28, 2006
May 28, 2006
170
171
if (oglctx != NULL) {
PhDCSetCurrent (oglctx);
172
173
174
175
176
}
return 0;
}
#else
May 28, 2006
May 28, 2006
177
178
int
ph_GL_MakeCurrent (_THIS)
179
{
May 28, 2006
May 28, 2006
180
PgSetRegion (PtWidgetRid (window));
181
May 28, 2006
May 28, 2006
182
183
184
if (oglctx != NULL) {
if (qnxgl_set_current (oglctx) == -1) {
return -1;
185
186
187
188
189
190
191
192
193
194
195
}
}
return 0;
}
#endif /* 6.3.0 */
#if (_NTO_VERSION < 630)
/* This code is actual for the Photon3D Runtime which was available prior to 6.3 only */
May 28, 2006
May 28, 2006
196
197
int
ph_SetupOpenGLContext (_THIS, int width, int height, int bpp, Uint32 flags)
198
199
200
{
PhDim_t dim;
uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
May 28, 2006
May 28, 2006
201
int exposepost = 0;
202
203
int OGLargc;
May 28, 2006
May 28, 2006
204
205
206
207
208
209
210
211
212
213
214
215
216
217
dim.w = width;
dim.h = height;
if ((oglctx != NULL) && (oglflags == flags) && (oglbpp == bpp)) {
PdOpenGLContextResize (oglctx, &dim);
PhDCSetCurrent (oglctx);
return 0;
} else {
if (oglctx != NULL) {
PhDCSetCurrent (NULL);
PhDCRelease (oglctx);
oglctx = NULL;
exposepost = 1;
}
218
219
}
May 28, 2006
May 28, 2006
220
221
222
223
OGLargc = 0;
if (this->gl_config.depth_size) {
OGLAttrib[OGLargc++] = PHOGL_ATTRIB_DEPTH_BITS;
OGLAttrib[OGLargc++] = this->gl_config.depth_size;
224
}
May 28, 2006
May 28, 2006
225
226
227
if (this->gl_config.stencil_size) {
OGLAttrib[OGLargc++] = PHOGL_ATTRIB_STENCIL_BITS;
OGLAttrib[OGLargc++] = this->gl_config.stencil_size;
228
}
May 28, 2006
May 28, 2006
229
230
231
232
233
234
OGLAttrib[OGLargc++] = PHOGL_ATTRIB_FORCE_SW;
if (flags & SDL_FULLSCREEN) {
OGLAttrib[OGLargc++] = PHOGL_ATTRIB_FULLSCREEN;
OGLAttrib[OGLargc++] = PHOGL_ATTRIB_DIRECT;
OGLAttrib[OGLargc++] = PHOGL_ATTRIB_FULLSCREEN_BEST;
OGLAttrib[OGLargc++] = PHOGL_ATTRIB_FULLSCREEN_CENTER;
235
}
May 28, 2006
May 28, 2006
236
OGLAttrib[OGLargc++] = PHOGL_ATTRIB_NONE;
237
May 28, 2006
May 28, 2006
238
239
240
241
if (this->gl_config.double_buffer) {
oglctx = PdCreateOpenGLContext (2, &dim, 0, OGLAttrib);
} else {
oglctx = PdCreateOpenGLContext (1, &dim, 0, OGLAttrib);
242
243
}
May 28, 2006
May 28, 2006
244
245
246
if (oglctx == NULL) {
SDL_SetError
("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
247
248
249
return -1;
}
May 28, 2006
May 28, 2006
250
PhDCSetCurrent (oglctx);
251
May 28, 2006
May 28, 2006
252
PtFlush ();
253
May 28, 2006
May 28, 2006
254
255
oglflags = flags;
oglbpp = bpp;
256
May 28, 2006
May 28, 2006
257
if (exposepost != 0) {
258
/* OpenGL context has been recreated, so report about this fact */
May 28, 2006
May 28, 2006
259
SDL_PrivateExpose ();
260
261
262
263
264
265
266
267
268
}
return 0;
}
#else /* _NTO_VERSION */
/* This code is actual for the built-in PhGL support, which became available since 6.3 */
May 28, 2006
May 28, 2006
269
270
int
ph_SetupOpenGLContext (_THIS, int width, int height, int bpp, Uint32 flags)
271
272
{
qnxgl_buf_attrib_t qnxgl_attribs[PH_OGL_MAX_ATTRIBS];
May 28, 2006
May 28, 2006
273
qnxgl_buf_attrib_t *qnxgl_attribs_slide;
274
275
276
277
278
int num_interfaces = 0;
int num_buffers = 0;
/* Initialize the OpenGL subsystem */
May 28, 2006
May 28, 2006
279
num_interfaces = qnxgl_init (NULL, NULL, 0);
280
May 28, 2006
May 28, 2006
281
282
283
if (num_interfaces < 0) {
SDL_SetError
("ph_SetupOpenGLContext(): cannot initialize OpenGL subsystem !\n");
284
285
return -1;
}
May 28, 2006
May 28, 2006
286
287
288
if (num_interfaces == 0) {
SDL_SetError
("ph_SetupOpenGLContext(): there are no available OpenGL renderers was found !\n");
289
290
291
292
return -1;
}
/* Driver is linked */
May 28, 2006
May 28, 2006
293
this->gl_config.driver_loaded = 1;
294
295
/* Initialize the OpenGL context attributes */
May 28, 2006
May 28, 2006
296
qnxgl_attribs_slide = qnxgl_attribs;
297
298
/* Depth size */
May 28, 2006
May 28, 2006
299
300
301
302
303
304
if (this->gl_config.depth_size) {
fprintf (stderr, "setted depth size %d\n",
this->gl_config.depth_size);
qnxgl_attribs_slide =
qnxgl_attrib_set_depth (qnxgl_attribs_slide,
this->gl_config.depth_size);
305
306
307
}
/* Stencil size */
May 28, 2006
May 28, 2006
308
309
310
311
if (this->gl_config.stencil_size) {
qnxgl_attribs_slide =
qnxgl_attrib_set_stencil (qnxgl_attribs_slide,
this->gl_config.stencil_size);
312
313
314
}
/* The sum of the accum bits of each channel */
May 28, 2006
May 28, 2006
315
316
317
318
319
320
321
322
323
324
325
326
if ((this->gl_config.accum_red_size != 0)
&& (this->gl_config.accum_blue_size != 0)
&& (this->gl_config.accum_green_size != 0)) {
qnxgl_attribs_slide = qnxgl_attrib_set_accum (qnxgl_attribs_slide,
this->gl_config.
accum_red_size +
this->gl_config.
accum_blue_size +
this->gl_config.
accum_green_size +
this->gl_config.
accum_alpha_size);
327
}
May 28, 2006
May 28, 2006
328
329
/* Stereo mode */
May 28, 2006
May 28, 2006
330
331
if (this->gl_config.stereo) {
qnxgl_attribs_slide = qnxgl_attrib_set_stereo (qnxgl_attribs_slide);
332
333
334
}
/* Fullscreen mode */
May 28, 2006
May 28, 2006
335
336
337
if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
qnxgl_attribs_slide =
qnxgl_attrib_set_hint_fullscreen (qnxgl_attribs_slide);
338
}
May 28, 2006
May 28, 2006
339
340
/* Double buffering mode */
May 28, 2006
May 28, 2006
341
342
343
344
if (this->gl_config.double_buffer) {
num_buffers = 2;
} else {
num_buffers = 1;
345
346
347
}
/* Loading the function pointers so we can use the extensions */
May 28, 2006
May 28, 2006
348
GLPH_LOAD_FUNCS_GC (oglctx);
349
350
/* Set the buffers region to be that of our window's region */
May 28, 2006
May 28, 2006
351
352
qnxgl_attribs_slide =
glph_attrib_set_region (qnxgl_attribs_slide, PtWidgetRid (window));
353
354
/* End of the attributes array */
May 28, 2006
May 28, 2006
355
356
qnxgl_attribs_slide = qnxgl_attrib_set_end (qnxgl_attribs_slide);
357
/* Create the buffers with the specified color model */
May 28, 2006
May 28, 2006
358
359
360
361
fprintf (stderr, "ARGB: %d, %d, %d, %d\n", this->gl_config.alpha_size,
this->gl_config.red_size, this->gl_config.green_size,
this->gl_config.blue_size);
oglbuffers = qnxgl_buffers_create (QNXGL_FORMAT_BEST_RGB,
362
363
/* __QNXGL_BUILD_FORMAT(0, __QNXGL_COLOR_MODEL_RGB, this->gl_config.alpha_size,
this->gl_config.red_size, this->gl_config.green_size, this->gl_config.blue_size), */
May 28, 2006
May 28, 2006
364
365
num_buffers, width, height,
qnxgl_attribs, -1);
366
367
May 28, 2006
May 28, 2006
368
369
370
371
if (oglbuffers == NULL) {
SDL_SetError
("ph_SetupOpenGLContext(): failed to create OpenGL buffers !\n");
qnxgl_finish ();
372
373
374
375
return -1;
}
/* Create a QNXGL context for the previously created buffer */
May 28, 2006
May 28, 2006
376
oglctx = qnxgl_context_create (oglbuffers, NULL);
377
May 28, 2006
May 28, 2006
378
379
380
381
382
if (oglctx == NULL) {
SDL_SetError
("ph_SetupOpenGLContext(): failed to create OpenGL context !\n");
qnxgl_buffers_destroy (oglbuffers);
qnxgl_finish ();
383
384
385
386
return -1;
}
/* Attempt to make the context current so we can use OpenGL commands */
May 28, 2006
May 28, 2006
387
388
389
390
391
392
if (qnxgl_set_current (oglctx) == -1) {
SDL_SetError
("ph_SetupOpenGLContext(): failed to make the OpenGL context current !\n");
qnxgl_context_destroy (oglctx);
qnxgl_buffers_destroy (oglbuffers);
qnxgl_finish ();
393
394
395
return -1;
}
May 28, 2006
May 28, 2006
396
PtFlush ();
397
May 28, 2006
May 28, 2006
398
399
oglflags = flags;
oglbpp = bpp;
400
401
402
403
404
405
return 0;
}
#endif /* _NTO_VERSION */
Feb 16, 2006
Feb 16, 2006
406
#endif /* SDL_VIDEO_OPENGL */
May 28, 2006
May 28, 2006
407
/* vi: set ts=4 sw=4 expandtab: */