From 4662e8cdc6778b0cad95ffd022c64e4cc1c8965a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 18 Jul 2004 19:46:38 +0000 Subject: [PATCH] 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 :) --- src/video/SDL_video.c | 37 ++- src/video/photon/Makefile.am | 2 + src/video/photon/SDL_ph_events.c | 1 - src/video/photon/SDL_ph_gl.c | 409 ++++++++++++++++++++++++++++++ src/video/photon/SDL_ph_gl.h | 44 ++++ src/video/photon/SDL_ph_image.c | 130 +++------- src/video/photon/SDL_ph_modes.c | 35 ++- src/video/photon/SDL_ph_modes_c.h | 5 +- src/video/photon/SDL_ph_video.c | 64 +---- src/video/photon/SDL_ph_video.h | 19 +- test/testdyngl.c | 7 +- test/testgl.c | 2 +- 12 files changed, 573 insertions(+), 182 deletions(-) create mode 100644 src/video/photon/SDL_ph_gl.c create mode 100644 src/video/photon/SDL_ph_gl.h diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 8dca27c63..3084f806e 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -564,6 +564,10 @@ static void SDL_CreateShadowSurface(int depth) return; } +#ifdef __QNXNTO__ + #include +#endif /* __QNXNTO__ */ + /* * Set the requested video mode, allocating a shadow buffer if necessary. */ @@ -738,22 +742,31 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) #ifdef HAVE_OPENGL /* Load GL symbols (before MakeCurrent, where we need glGetString). */ if ( flags & (SDL_OPENGL | SDL_OPENGLBLIT) ) { -#ifndef __QNXNTO__ -#define SDL_PROC(ret,func,params) \ -do { \ - video->func = SDL_GL_GetProcAddress(#func); \ - if ( ! video->func ) { \ - SDL_SetError("Couldn't load GL function: %s\n", #func); \ - return(NULL); \ - } \ -} while ( 0 ); -#else -#define SDL_PROC(ret,func,params) video->func=func; + +#ifdef __QNXNTO__ + #if (_NTO_VERSION < 630) + #define __SDL_NOGETPROCADDR__ + #endif /* 6.3.0 */ #endif /* __QNXNTO__ */ + +#ifdef __SDL_NOGETPROCADDR__ + #define SDL_PROC(ret,func,params) video->func=func; +#else + #define SDL_PROC(ret,func,params) \ + do { \ + video->func = SDL_GL_GetProcAddress(#func); \ + if ( ! video->func ) { \ + SDL_SetError("Couldn't load GL function: %s\n", #func); \ + return(NULL); \ + } \ + } while ( 0 ); + +#endif /* __SDL_NOGETPROCADDR__ */ + #include "SDL_glfuncs.h" #undef SDL_PROC } -#endif +#endif /* HAVE_OPENGL */ /* If we're running OpenGL, make the context current */ if ( (video->screen->flags & SDL_OPENGL) && diff --git a/src/video/photon/Makefile.am b/src/video/photon/Makefile.am index 658789416..caa22ea4e 100644 --- a/src/video/photon/Makefile.am +++ b/src/video/photon/Makefile.am @@ -16,6 +16,8 @@ PH_SRCS = \ SDL_ph_mouse_c.h \ SDL_ph_video.c \ SDL_ph_video.h \ + SDL_ph_gl.c \ + SDL_ph_gl.h \ SDL_ph_wm.c \ SDL_ph_wm_c.h \ SDL_phyuv.c \ diff --git a/src/video/photon/SDL_ph_events.c b/src/video/photon/SDL_ph_events.c index 068506fe3..6315a0f3c 100644 --- a/src/video/photon/SDL_ph_events.c +++ b/src/video/photon/SDL_ph_events.c @@ -32,7 +32,6 @@ static char rcsid = #include #include #include -#include #include #include diff --git a/src/video/photon/SDL_ph_gl.c b/src/video/photon/SDL_ph_gl.c new file mode 100644 index 000000000..74ef22a83 --- /dev/null +++ b/src/video/photon/SDL_ph_gl.c @@ -0,0 +1,409 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2004 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifdef SAVE_RCSID + char rcsid = "@(#) $Id$"; +#endif + +#include +#include "SDL.h" +#include "SDL_ph_gl.h" + +#ifdef HAVE_OPENGL + +#if (_NTO_VERSION >= 630) + /* PhotonGL functions */ + GLPH_DECLARE_FUNCS; +#endif /* 6.3.0 */ + +#if (_NTO_VERSION < 630) +void ph_GL_SwapBuffers(_THIS) +{ + PgSetRegion(PtWidgetRid(window)); + PdOpenGLContextSwapBuffers(oglctx); +} +#else +void ph_GL_SwapBuffers(_THIS) +{ + qnxgl_swap_buffers(oglbuffers); +} +#endif /* 6.3.0 */ + +int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) +{ + 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; +#if (_NTO_VERSION >= 630) + 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; +#endif /* 6.3.0 */ + default: + *value=0; + return(-1); + } + return 0; +} + +#if (_NTO_VERSION < 630) +int ph_GL_LoadLibrary(_THIS, const char* path) +{ + /* if code compiled with HAVE_OPENGL, that mean that library already linked */ + this->gl_config.driver_loaded = 1; + + return 0; +} +#else +int ph_GL_LoadLibrary(_THIS, const char* path) +{ + void* handle; + int dlopen_flags=RTLD_WORLD | RTLD_GROUP; + + if (this->gl_config.dll_handle!=NULL) + { + return 0; + } + + handle = dlopen(path, dlopen_flags); + + if (handle==NULL) + { + SDL_SetError("ph_GL_LoadLibrary(): Could not load OpenGL library"); + return -1; + } + + this->gl_config.dll_handle = handle; + this->gl_config.driver_loaded = 1; + + strncpy(this->gl_config.driver_path, path, sizeof(this->gl_config.driver_path)-1); + + return 0; +} +#endif /* 6.3.0 */ + +#if (_NTO_VERSION < 630) +void* ph_GL_GetProcAddress(_THIS, const char* proc) +{ + return NULL; +} +#else +void* ph_GL_GetProcAddress(_THIS, const char* proc) +{ + void* function; + + if (this->gl_config.dll_handle==NULL) + { + ph_GL_LoadLibrary(this, DEFAULT_OPENGL); + if (this->gl_config.dll_handle==NULL) + { + return NULL; + } + } + + function=qnxgl_get_func(proc, oglctx, 0); + if (function==NULL) + { + function=dlsym(this->gl_config.dll_handle, proc); + } + + return function; +} +#endif /* 6.3.0 */ + +#if (_NTO_VERSION < 630) +int ph_GL_MakeCurrent(_THIS) +{ + PgSetRegion(PtWidgetRid(window)); + + if (oglctx!=NULL) + { + PhDCSetCurrent(oglctx); + } + + return 0; +} +#else +int ph_GL_MakeCurrent(_THIS) +{ + PgSetRegion(PtWidgetRid(window)); + + if (oglctx!=NULL) + { + if (qnxgl_set_current(oglctx) == -1) + { + return -1; + } + } + + 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 */ + +int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) +{ + PhDim_t dim; + uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; + int exposepost=0; + int OGLargc; + + 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; + } + } + + OGLargc=0; + if (this->gl_config.depth_size) + { + OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS; + OGLAttrib[OGLargc++]=this->gl_config.depth_size; + } + if (this->gl_config.stencil_size) + { + OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS; + OGLAttrib[OGLargc++]=this->gl_config.stencil_size; + } + 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; + } + OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE; + + if (this->gl_config.double_buffer) + { + oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); + } + else + { + oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); + } + + if (oglctx==NULL) + { + SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n"); + return -1; + } + + PhDCSetCurrent(oglctx); + + PtFlush(); + + oglflags=flags; + oglbpp=bpp; + + if (exposepost!=0) + { + /* OpenGL context has been recreated, so report about this fact */ + SDL_PrivateExpose(); + } + + return 0; +} + +#else /* _NTO_VERSION */ + +/* This code is actual for the built-in PhGL support, which became available since 6.3 */ + +int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) +{ + qnxgl_buf_attrib_t qnxgl_attribs[PH_OGL_MAX_ATTRIBS]; + qnxgl_buf_attrib_t* qnxgl_attribs_slide; + int num_interfaces = 0; + int num_buffers = 0; + + /* Initialize the OpenGL subsystem */ + + num_interfaces = qnxgl_init(NULL, NULL, 0); + + if (num_interfaces < 0) + { + SDL_SetError("ph_SetupOpenGLContext(): cannot initialize OpenGL subsystem !\n"); + return -1; + } + if (num_interfaces == 0) + { + SDL_SetError("ph_SetupOpenGLContext(): there are no available OpenGL renderers was found !\n"); + return -1; + } + + /* Driver is linked */ + this->gl_config.driver_loaded=1; + + /* Initialize the OpenGL context attributes */ + qnxgl_attribs_slide=qnxgl_attribs; + + /* Depth size */ + 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); + } + + /* Stencil size */ + if (this->gl_config.stencil_size) + { + qnxgl_attribs_slide = qnxgl_attrib_set_stencil(qnxgl_attribs_slide, this->gl_config.stencil_size); + } + + /* The sum of the accum bits of each channel */ + 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); + } + + /* Stereo mode */ + if (this->gl_config.stereo) + { + qnxgl_attribs_slide = qnxgl_attrib_set_stereo(qnxgl_attribs_slide); + } + + /* Fullscreen mode */ + if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) + { + qnxgl_attribs_slide = qnxgl_attrib_set_hint_fullscreen(qnxgl_attribs_slide); + } + + /* Double buffering mode */ + if (this->gl_config.double_buffer) + { + num_buffers=2; + } + else + { + num_buffers=1; + } + + /* Loading the function pointers so we can use the extensions */ + GLPH_LOAD_FUNCS_GC(oglctx); + + /* Set the buffers region to be that of our window's region */ + qnxgl_attribs_slide = glph_attrib_set_region(qnxgl_attribs_slide, PtWidgetRid(window)); + + /* End of the attributes array */ + qnxgl_attribs_slide = qnxgl_attrib_set_end(qnxgl_attribs_slide); + + /* Create the buffers with the specified color model */ + 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, +/* __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), */ + num_buffers, width, height, qnxgl_attribs, -1); + + + if (oglbuffers == NULL) + { + SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL buffers !\n"); + qnxgl_finish(); + return -1; + } + + /* Create a QNXGL context for the previously created buffer */ + oglctx = qnxgl_context_create(oglbuffers, NULL); + + if (oglctx == NULL) + { + SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL context !\n"); + qnxgl_buffers_destroy(oglbuffers); + qnxgl_finish(); + return -1; + } + + /* Attempt to make the context current so we can use OpenGL commands */ + 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(); + return -1; + } + + PtFlush(); + + oglflags=flags; + oglbpp=bpp; + + return 0; +} + +#endif /* _NTO_VERSION */ + +#endif /* HAVE_OPENGL */ diff --git a/src/video/photon/SDL_ph_gl.h b/src/video/photon/SDL_ph_gl.h new file mode 100644 index 000000000..afc8a319c --- /dev/null +++ b/src/video/photon/SDL_ph_gl.h @@ -0,0 +1,44 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2004 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifdef SAVE_RCSID + static char rcsid = "@(#) $Id$"; +#endif + +#ifndef __SDL_PH_GL_H__ +#define __SDL_PH_GL_H__ + +#include "SDL_ph_video.h" + +#define DEFAULT_OPENGL "/usr/lib/libGL.so" + +#ifdef HAVE_OPENGL + void ph_GL_SwapBuffers(_THIS); + int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); + int ph_GL_LoadLibrary(_THIS, const char* path); + void* ph_GL_GetProcAddress(_THIS, const char* proc); + int ph_GL_MakeCurrent(_THIS); + + int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags); +#endif /* HAVE_OPENGL */ + +#endif /* __SDL_PH_GL_H__ */ diff --git a/src/video/photon/SDL_ph_image.c b/src/video/photon/SDL_ph_image.c index 38b046c53..60b77da3f 100644 --- a/src/video/photon/SDL_ph_image.c +++ b/src/video/photon/SDL_ph_image.c @@ -26,6 +26,7 @@ static char rcsid = #endif #include + #include #include @@ -34,8 +35,10 @@ static char rcsid = #include "SDL_endian.h" #include "SDL_video.h" #include "SDL_pixels_c.h" +#include "SDL_ph_video.h" #include "SDL_ph_image_c.h" #include "SDL_ph_modes_c.h" +#include "SDL_ph_gl.h" int ph_SetupImage(_THIS, SDL_Surface *screen) { @@ -189,8 +192,8 @@ int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen) { OCImage.flags = screen->flags; - /* Begin direct mode */ - if (!ph_EnterFullScreen(this, screen)) + /* Begin direct and fullscreen mode */ + if (!ph_EnterFullScreen(this, screen, PH_ENTER_DIRECTMODE)) { return -1; } @@ -301,98 +304,30 @@ int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen) #ifdef HAVE_OPENGL -static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) +int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen) { - PhDim_t dim; - uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; - int exposepost=0; - int OGLargc; + this->UpdateRects = ph_OpenGLUpdate; + screen->pixels=NULL; + screen->pitch=NULL; - 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; - } - } - - OGLargc=0; - if (this->gl_config.depth_size) - { - OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS; - OGLAttrib[OGLargc++]=this->gl_config.depth_size; - } - if (this->gl_config.stencil_size) - { - OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS; - OGLAttrib[OGLargc++]=this->gl_config.stencil_size; - } - 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; - } - OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE; - - if (this->gl_config.double_buffer) - { - oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); - } - else - { - oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); - } - - if (oglctx==NULL) - { - SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n"); - return (-1); - } - - PhDCSetCurrent(oglctx); - - PtFlush(); - - oglflags=flags; - oglbpp=bpp; + #if (_NTO_VERSION >= 630) + if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) + { + if (!ph_EnterFullScreen(this, screen, PH_IGNORE_DIRECTMODE)) + { + screen->flags &= ~SDL_FULLSCREEN; + return -1; + } + } + #endif /* 6.3.0 */ - if (exposepost!=0) + if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0) { - /* OpenGL context has been recreated, so report about this fact */ - SDL_PrivateExpose(); + screen->flags &= ~SDL_OPENGL; + return -1; } - - return 0; -} - -int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen) -{ - this->UpdateRects = ph_OpenGLUpdate; - screen->pixels=NULL; - screen->pitch=NULL; - - if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0) - { - screen->flags &= ~SDL_OPENGL; - return -1; - } - return 0; + return 0; } #endif /* HAVE_OPENGL */ @@ -405,12 +340,27 @@ void ph_DestroyImage(_THIS, SDL_Surface* screen) { if (oglctx) { - PhDCSetCurrent(NULL); - PhDCRelease(oglctx); + #if (_NTO_VERSION < 630) + PhDCSetCurrent(NULL); + PhDCRelease(oglctx); + #else + qnxgl_context_destroy(oglctx); + qnxgl_buffers_destroy(oglbuffers); + qnxgl_finish(); + #endif /* 6.3.0 */ oglctx=NULL; + oglbuffers=NULL; oglflags=0; oglbpp=0; } + + #if (_NTO_VERSION >= 630) + if (currently_fullscreen) + { + ph_LeaveFullScreen(this); + } + #endif /* 6.3.0 */ + return; } #endif /* HAVE_OPENGL */ diff --git a/src/video/photon/SDL_ph_modes.c b/src/video/photon/SDL_ph_modes.c index 11ff7364e..2d3c444ef 100644 --- a/src/video/photon/SDL_ph_modes.c +++ b/src/video/photon/SDL_ph_modes.c @@ -253,7 +253,7 @@ int ph_ToggleFullScreen(_THIS, int on) return -1; } -int ph_EnterFullScreen(_THIS, SDL_Surface* screen) +int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode) { PgDisplaySettings_t settings; int mode; @@ -326,24 +326,30 @@ int ph_EnterFullScreen(_THIS, SDL_Surface* screen) if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL) { #ifdef HAVE_OPENGL -#endif /* HAVE_OPENGL */ + #if (_NTO_VERSION < 630) + return 0; + #endif /* 6.3.0 */ +#else return 0; +#endif /* HAVE_OPENGL */ } } - if (OCImage.direct_context==NULL) + if (fmode==0) { - OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); - if (!OCImage.direct_context) + if (OCImage.direct_context==NULL) { - SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n"); - ph_LeaveFullScreen(this); - return 0; + OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); + if (!OCImage.direct_context) + { + SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n"); + ph_LeaveFullScreen(this); + return 0; + } } + OCImage.oldDC=PdDirectStart(OCImage.direct_context); } - OCImage.oldDC=PdDirectStart(OCImage.direct_context); - currently_fullscreen = 1; } PgFlush(); @@ -360,10 +366,15 @@ int ph_LeaveFullScreen(_THIS) if ((this->screen) && ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)) { #ifdef HAVE_OPENGL + #if (_NTO_VERSION < 630) + return 0; + #endif /* 6.3.0 */ +#else + return 0; #endif /* HAVE_OPENGL */ - return 0; } - else + + /* release routines starts here */ { if (OCImage.direct_context) { diff --git a/src/video/photon/SDL_ph_modes_c.h b/src/video/photon/SDL_ph_modes_c.h index 9ec7be465..d57c6fc90 100644 --- a/src/video/photon/SDL_ph_modes_c.h +++ b/src/video/photon/SDL_ph_modes_c.h @@ -32,10 +32,13 @@ static char rcsid = #define PH_MAX_VIDEOMODES 127 +#define PH_ENTER_DIRECTMODE 0 +#define PH_IGNORE_DIRECTMODE 1 + extern SDL_Rect **ph_ListModes(_THIS,SDL_PixelFormat *format, Uint32 flags); extern void ph_FreeVideoModes(_THIS); extern int ph_ResizeFullScreen(_THIS); -extern int ph_EnterFullScreen(_THIS, SDL_Surface* screen); +extern int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode); extern int ph_LeaveFullScreen(_THIS); extern int ph_GetVideoMode(int width, int height, int bpp); extern int get_mode_any_format(int width, int height, int bpp); diff --git a/src/video/photon/SDL_ph_video.c b/src/video/photon/SDL_ph_video.c index 1c608e4f3..d273ed848 100644 --- a/src/video/photon/SDL_ph_video.c +++ b/src/video/photon/SDL_ph_video.c @@ -47,6 +47,7 @@ static char rcsid = #include "SDL_ph_events_c.h" #include "SDL_ph_mouse_c.h" #include "SDL_ph_wm_c.h" +#include "SDL_ph_gl.h" #include "SDL_phyuv_c.h" #include "blank_cursor.h" @@ -56,14 +57,6 @@ static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); static void ph_VideoQuit(_THIS); static void ph_DeleteDevice(SDL_VideoDevice *device); -#ifdef HAVE_OPENGL -static void ph_GL_SwapBuffers(_THIS); -static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); -static int ph_GL_LoadLibrary(_THIS, const char* path); -static void* ph_GL_GetProcAddress(_THIS, const char* proc); -static int ph_GL_MakeCurrent(_THIS); -#endif /* HAVE_OPENGL */ - static int phstatus=-1; static int ph_Available(void) @@ -376,6 +369,7 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat* vformat) #ifdef HAVE_OPENGL oglctx=NULL; + oglbuffers=NULL; oglflags=0; oglbpp=0; #endif /* HAVE_OPENGL */ @@ -663,57 +657,3 @@ static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) return 1; } -#ifdef HAVE_OPENGL - -static void ph_GL_SwapBuffers(_THIS) -{ - PgSetRegion(PtWidgetRid(window)); - PdOpenGLContextSwapBuffers(oglctx); -} - -static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) -{ - 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; - default: - *value=0; - return(-1); - } - return 0; -} - -static int ph_GL_LoadLibrary(_THIS, const char* path) -{ - /* if code compiled with HAVE_OPENGL, that mean that library already linked */ - this->gl_config.driver_loaded = 1; - - return 0; -} - -static void* ph_GL_GetProcAddress(_THIS, const char* proc) -{ - return NULL; -} - -static int ph_GL_MakeCurrent(_THIS) -{ - PgSetRegion(PtWidgetRid(window)); - - if (oglctx!=NULL) - { - PhDCSetCurrent(oglctx); - } - - return 0; -} - -#endif /* HAVE_OPENGL */ diff --git a/src/video/photon/SDL_ph_video.h b/src/video/photon/SDL_ph_video.h index 49a526a52..c40df59ff 100644 --- a/src/video/photon/SDL_ph_video.h +++ b/src/video/photon/SDL_ph_video.h @@ -26,13 +26,20 @@ #include "SDL_mouse.h" #include "SDL_sysvideo.h" +#include + #include #include #include #include #ifdef HAVE_OPENGL - #include + #if (_NTO_VERSION < 630) + #include + #else + #include + #include + #endif /* 6.3.0 */ #endif /* HAVE_OPENGL */ /* Hidden "this" pointer for the video functions */ @@ -68,7 +75,14 @@ struct SDL_PrivateVideoData PtWidget_t *Window; /* used to handle input events */ PhImage_t *image; /* used to display image */ #ifdef HAVE_OPENGL - PdOpenGLContext_t* OGLContext; /* OpenGL context */ + #if (_NTO_VERSION < 630) + PdOpenGLContext_t* OGLContext; /* OpenGL context */ + void* OGLBuffers; /* OpenGL buffers (unused) */ + #else + qnxglc_t* OGLContext; /* OpenGL context for the 6.3 */ + qnxgl_bufs_t* OGLBuffers; /* OpenGL buffers for the 6.3 */ + #endif /* 630 */ + Uint32 OGLFlags; /* OpenGL flags */ Uint32 OGLBPP; /* OpenGL bpp */ #endif /* HAVE_OPENGL */ @@ -134,6 +148,7 @@ struct SDL_PrivateVideoData #ifdef HAVE_OPENGL #define oglctx (this->hidden->OGLContext) + #define oglbuffers (this->hidden->OGLBuffers) #define oglflags (this->hidden->OGLFlags) #define oglbpp (this->hidden->OGLBPP) #endif /* HAVE_OPENGL */ diff --git a/test/testdyngl.c b/test/testdyngl.c index 647774ff5..b9b412686 100644 --- a/test/testdyngl.c +++ b/test/testdyngl.c @@ -89,8 +89,10 @@ int main(int argc,char *argv[]) SDL_Event event; int done=0; GLfloat pixels[NB_PIXELS*3]; -#ifdef _WIN32 +#if defined(_WIN32) char *gl_library = "OpenGL32.DLL"; +#elif defined(__QNXNTO__) + char *gl_library = "libGL.so.3"; #else char *gl_library = "libGL.so.1"; #endif @@ -123,6 +125,9 @@ int main(int argc,char *argv[]) exit(1); } + /* Set the window manager title bar */ + SDL_WM_SetCaption( "SDL Dynamic OpenGL Loading Test", "testdyngl" ); + init_glfuncs(&f); for(i=0;i