2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 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"
26 #include "SDL_ph_gl.h"
30 #if (_NTO_VERSION >= 630)
31 /* PhotonGL functions */
35 #if (_NTO_VERSION < 630)
36 void ph_GL_SwapBuffers(_THIS)
38 PgSetRegion(PtWidgetRid(window));
39 PdOpenGLContextSwapBuffers(oglctx);
42 void ph_GL_SwapBuffers(_THIS)
44 qnxgl_swap_buffers(oglbuffers);
48 int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
52 case SDL_GL_DOUBLEBUFFER:
53 *value=this->gl_config.double_buffer;
55 case SDL_GL_STENCIL_SIZE:
56 *value=this->gl_config.stencil_size;
58 case SDL_GL_DEPTH_SIZE:
59 *value=this->gl_config.depth_size;
61 #if (_NTO_VERSION >= 630)
63 *value=this->gl_config.red_size;
65 case SDL_GL_GREEN_SIZE:
66 *value=this->gl_config.green_size;
68 case SDL_GL_BLUE_SIZE:
69 *value=this->gl_config.blue_size;
71 case SDL_GL_ALPHA_SIZE:
72 *value=this->gl_config.alpha_size;
74 case SDL_GL_ACCUM_RED_SIZE:
75 *value=this->gl_config.accum_red_size;
77 case SDL_GL_ACCUM_GREEN_SIZE:
78 *value=this->gl_config.accum_green_size;
80 case SDL_GL_ACCUM_BLUE_SIZE:
81 *value=this->gl_config.accum_blue_size;
83 case SDL_GL_ACCUM_ALPHA_SIZE:
84 *value=this->gl_config.accum_alpha_size;
87 *value=this->gl_config.stereo;
97 #if (_NTO_VERSION < 630)
98 int ph_GL_LoadLibrary(_THIS, const char* path)
100 /* if code compiled with SDL_VIDEO_OPENGL, that mean that library already linked */
101 this->gl_config.driver_loaded = 1;
106 int ph_GL_LoadLibrary(_THIS, const char* path)
109 int dlopen_flags=RTLD_WORLD | RTLD_GROUP;
111 if (this->gl_config.dll_handle!=NULL)
116 handle = dlopen(path, dlopen_flags);
120 SDL_SetError("ph_GL_LoadLibrary(): Could not load OpenGL library");
124 this->gl_config.dll_handle = handle;
125 this->gl_config.driver_loaded = 1;
127 SDL_strlcpy(this->gl_config.driver_path, path, SDL_arraysize(this->gl_config.driver_path));
133 #if (_NTO_VERSION < 630)
134 void* ph_GL_GetProcAddress(_THIS, const char* proc)
139 void* ph_GL_GetProcAddress(_THIS, const char* proc)
143 if (this->gl_config.dll_handle==NULL)
145 ph_GL_LoadLibrary(this, DEFAULT_OPENGL);
146 if (this->gl_config.dll_handle==NULL)
152 function=qnxgl_get_func(proc, oglctx, 0);
155 function=dlsym(this->gl_config.dll_handle, proc);
162 #if (_NTO_VERSION < 630)
163 int ph_GL_MakeCurrent(_THIS)
165 PgSetRegion(PtWidgetRid(window));
169 PhDCSetCurrent(oglctx);
175 int ph_GL_MakeCurrent(_THIS)
177 PgSetRegion(PtWidgetRid(window));
181 if (qnxgl_set_current(oglctx) == -1)
191 #if (_NTO_VERSION < 630)
193 /* This code is actual for the Photon3D Runtime which was available prior to 6.3 only */
195 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
198 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
205 if ((oglctx!=NULL) && (oglflags==flags) && (oglbpp==bpp))
207 PdOpenGLContextResize(oglctx, &dim);
208 PhDCSetCurrent(oglctx);
215 PhDCSetCurrent(NULL);
223 if (this->gl_config.depth_size)
225 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
226 OGLAttrib[OGLargc++]=this->gl_config.depth_size;
228 if (this->gl_config.stencil_size)
230 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
231 OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
233 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
234 if (flags & SDL_FULLSCREEN)
236 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;
237 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;
238 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;
239 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;
241 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
243 if (this->gl_config.double_buffer)
245 oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
249 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
254 SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
258 PhDCSetCurrent(oglctx);
267 /* OpenGL context has been recreated, so report about this fact */
274 #else /* _NTO_VERSION */
276 /* This code is actual for the built-in PhGL support, which became available since 6.3 */
278 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
280 qnxgl_buf_attrib_t qnxgl_attribs[PH_OGL_MAX_ATTRIBS];
281 qnxgl_buf_attrib_t* qnxgl_attribs_slide;
282 int num_interfaces = 0;
285 /* Initialize the OpenGL subsystem */
287 num_interfaces = qnxgl_init(NULL, NULL, 0);
289 if (num_interfaces < 0)
291 SDL_SetError("ph_SetupOpenGLContext(): cannot initialize OpenGL subsystem !\n");
294 if (num_interfaces == 0)
296 SDL_SetError("ph_SetupOpenGLContext(): there are no available OpenGL renderers was found !\n");
300 /* Driver is linked */
301 this->gl_config.driver_loaded=1;
303 /* Initialize the OpenGL context attributes */
304 qnxgl_attribs_slide=qnxgl_attribs;
307 if (this->gl_config.depth_size)
309 fprintf(stderr, "setted depth size %d\n", this->gl_config.depth_size);
310 qnxgl_attribs_slide = qnxgl_attrib_set_depth(qnxgl_attribs_slide, this->gl_config.depth_size);
314 if (this->gl_config.stencil_size)
316 qnxgl_attribs_slide = qnxgl_attrib_set_stencil(qnxgl_attribs_slide, this->gl_config.stencil_size);
319 /* The sum of the accum bits of each channel */
320 if ((this->gl_config.accum_red_size != 0) && (this->gl_config.accum_blue_size != 0) &&
321 (this->gl_config.accum_green_size != 0))
323 qnxgl_attribs_slide = qnxgl_attrib_set_accum(qnxgl_attribs_slide,
324 this->gl_config.accum_red_size + this->gl_config.accum_blue_size +
325 this->gl_config.accum_green_size + this->gl_config.accum_alpha_size);
329 if (this->gl_config.stereo)
331 qnxgl_attribs_slide = qnxgl_attrib_set_stereo(qnxgl_attribs_slide);
334 /* Fullscreen mode */
335 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
337 qnxgl_attribs_slide = qnxgl_attrib_set_hint_fullscreen(qnxgl_attribs_slide);
340 /* Double buffering mode */
341 if (this->gl_config.double_buffer)
350 /* Loading the function pointers so we can use the extensions */
351 GLPH_LOAD_FUNCS_GC(oglctx);
353 /* Set the buffers region to be that of our window's region */
354 qnxgl_attribs_slide = glph_attrib_set_region(qnxgl_attribs_slide, PtWidgetRid(window));
356 /* End of the attributes array */
357 qnxgl_attribs_slide = qnxgl_attrib_set_end(qnxgl_attribs_slide);
359 /* Create the buffers with the specified color model */
360 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);
361 oglbuffers = qnxgl_buffers_create(
362 QNXGL_FORMAT_BEST_RGB,
363 /* __QNXGL_BUILD_FORMAT(0, __QNXGL_COLOR_MODEL_RGB, this->gl_config.alpha_size,
364 this->gl_config.red_size, this->gl_config.green_size, this->gl_config.blue_size), */
365 num_buffers, width, height, qnxgl_attribs, -1);
368 if (oglbuffers == NULL)
370 SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL buffers !\n");
375 /* Create a QNXGL context for the previously created buffer */
376 oglctx = qnxgl_context_create(oglbuffers, NULL);
380 SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL context !\n");
381 qnxgl_buffers_destroy(oglbuffers);
386 /* Attempt to make the context current so we can use OpenGL commands */
387 if (qnxgl_set_current(oglctx) == -1)
389 SDL_SetError("ph_SetupOpenGLContext(): failed to make the OpenGL context current !\n");
390 qnxgl_context_destroy(oglctx);
391 qnxgl_buffers_destroy(oglbuffers);
404 #endif /* _NTO_VERSION */
406 #endif /* SDL_VIDEO_OPENGL */