comparison src/video/photon/SDL_ph_gl.c @ 910:4ab6d1fd028f

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