Date: Sat, 26 Jun 2004 14:58:42 +0300
authorSam Lantinga <slouken@libsdl.org>
Sun, 18 Jul 2004 19:46:38 +0000
changeset 9104ab6d1fd028f
parent 909 e247a0139900
child 911 04a403e4ccf5
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
src/video/photon/Makefile.am
src/video/photon/SDL_ph_events.c
src/video/photon/SDL_ph_gl.c
src/video/photon/SDL_ph_gl.h
src/video/photon/SDL_ph_image.c
src/video/photon/SDL_ph_modes.c
src/video/photon/SDL_ph_modes_c.h
src/video/photon/SDL_ph_video.c
src/video/photon/SDL_ph_video.h
test/testdyngl.c
test/testgl.c
     1.1 --- a/src/video/SDL_video.c	Sun Jul 18 19:44:06 2004 +0000
     1.2 +++ b/src/video/SDL_video.c	Sun Jul 18 19:46:38 2004 +0000
     1.3 @@ -564,6 +564,10 @@
     1.4  	return;
     1.5  }
     1.6  
     1.7 +#ifdef __QNXNTO__
     1.8 +    #include <sys/neutrino.h>
     1.9 +#endif /* __QNXNTO__ */
    1.10 +
    1.11  /*
    1.12   * Set the requested video mode, allocating a shadow buffer if necessary.
    1.13   */
    1.14 @@ -738,22 +742,31 @@
    1.15  #ifdef HAVE_OPENGL
    1.16  	/* Load GL symbols (before MakeCurrent, where we need glGetString). */
    1.17  	if ( flags & (SDL_OPENGL | SDL_OPENGLBLIT) ) {
    1.18 -#ifndef __QNXNTO__
    1.19 -#define SDL_PROC(ret,func,params) \
    1.20 -do { \
    1.21 -	video->func = SDL_GL_GetProcAddress(#func); \
    1.22 -	if ( ! video->func ) { \
    1.23 -		SDL_SetError("Couldn't load GL function: %s\n", #func); \
    1.24 -		return(NULL); \
    1.25 -	} \
    1.26 -} while ( 0 );
    1.27 +
    1.28 +#ifdef __QNXNTO__
    1.29 +    #if (_NTO_VERSION < 630)
    1.30 +       #define __SDL_NOGETPROCADDR__
    1.31 +    #endif /* 6.3.0 */
    1.32 +#endif /* __QNXNTO__ */
    1.33 +
    1.34 +#ifdef __SDL_NOGETPROCADDR__
    1.35 +    #define SDL_PROC(ret,func,params) video->func=func;
    1.36  #else
    1.37 -#define SDL_PROC(ret,func,params) video->func=func;
    1.38 -#endif /* __QNXNTO__ */
    1.39 +    #define SDL_PROC(ret,func,params) \
    1.40 +    do { \
    1.41 +        video->func = SDL_GL_GetProcAddress(#func); \
    1.42 +        if ( ! video->func ) { \
    1.43 +            SDL_SetError("Couldn't load GL function: %s\n", #func); \
    1.44 +        return(NULL); \
    1.45 +        } \
    1.46 +    } while ( 0 );
    1.47 +
    1.48 +#endif /* __SDL_NOGETPROCADDR__ */
    1.49 +
    1.50  #include "SDL_glfuncs.h"
    1.51  #undef SDL_PROC	
    1.52  	}
    1.53 -#endif
    1.54 +#endif /* HAVE_OPENGL */
    1.55  
    1.56  	/* If we're running OpenGL, make the context current */
    1.57  	if ( (video->screen->flags & SDL_OPENGL) &&
     2.1 --- a/src/video/photon/Makefile.am	Sun Jul 18 19:44:06 2004 +0000
     2.2 +++ b/src/video/photon/Makefile.am	Sun Jul 18 19:46:38 2004 +0000
     2.3 @@ -16,6 +16,8 @@
     2.4  	SDL_ph_mouse_c.h	\
     2.5  	SDL_ph_video.c		\
     2.6  	SDL_ph_video.h		\
     2.7 +	SDL_ph_gl.c		\
     2.8 +	SDL_ph_gl.h		\
     2.9  	SDL_ph_wm.c		\
    2.10  	SDL_ph_wm_c.h		\
    2.11  	SDL_phyuv.c		\
     3.1 --- a/src/video/photon/SDL_ph_events.c	Sun Jul 18 19:44:06 2004 +0000
     3.2 +++ b/src/video/photon/SDL_ph_events.c	Sun Jul 18 19:46:38 2004 +0000
     3.3 @@ -32,7 +32,6 @@
     3.4  #include <stdio.h>
     3.5  #include <setjmp.h>
     3.6  #include <sys/time.h>
     3.7 -#include <sys/neutrino.h>
     3.8  
     3.9  #include <Ph.h>
    3.10  #include <photon/PkKeyDef.h>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/photon/SDL_ph_gl.c	Sun Jul 18 19:46:38 2004 +0000
     4.3 @@ -0,0 +1,409 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2004 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Library General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Library General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Library General Public
    4.19 +    License along with this library; if not, write to the Free
    4.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +
    4.26 +#ifdef SAVE_RCSID
    4.27 +    char rcsid = "@(#) $Id$";
    4.28 +#endif
    4.29 +
    4.30 +#include <dlfcn.h>
    4.31 +#include "SDL.h"
    4.32 +#include "SDL_ph_gl.h"
    4.33 +
    4.34 +#ifdef HAVE_OPENGL
    4.35 +
    4.36 +#if (_NTO_VERSION >= 630)
    4.37 +    /* PhotonGL functions */
    4.38 +    GLPH_DECLARE_FUNCS;
    4.39 +#endif /* 6.3.0 */
    4.40 +
    4.41 +#if (_NTO_VERSION < 630)
    4.42 +void ph_GL_SwapBuffers(_THIS)
    4.43 +{
    4.44 +    PgSetRegion(PtWidgetRid(window));
    4.45 +    PdOpenGLContextSwapBuffers(oglctx);
    4.46 +}
    4.47 +#else
    4.48 +void ph_GL_SwapBuffers(_THIS)
    4.49 +{
    4.50 +    qnxgl_swap_buffers(oglbuffers);
    4.51 +}
    4.52 +#endif /* 6.3.0 */
    4.53 +
    4.54 +int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
    4.55 +{
    4.56 +    switch (attrib)
    4.57 +    {
    4.58 +        case SDL_GL_DOUBLEBUFFER:
    4.59 +             *value=this->gl_config.double_buffer;
    4.60 +             break;
    4.61 +        case SDL_GL_STENCIL_SIZE:
    4.62 +             *value=this->gl_config.stencil_size;
    4.63 +             break;
    4.64 +        case SDL_GL_DEPTH_SIZE:
    4.65 +             *value=this->gl_config.depth_size;
    4.66 +             break;
    4.67 +#if (_NTO_VERSION >= 630)
    4.68 +        case SDL_GL_RED_SIZE:
    4.69 +             *value=this->gl_config.red_size;
    4.70 +             break;
    4.71 +        case SDL_GL_GREEN_SIZE:
    4.72 +             *value=this->gl_config.green_size;
    4.73 +             break;
    4.74 +        case SDL_GL_BLUE_SIZE:
    4.75 +             *value=this->gl_config.blue_size;
    4.76 +             break;
    4.77 +        case SDL_GL_ALPHA_SIZE:
    4.78 +             *value=this->gl_config.alpha_size;
    4.79 +             break;
    4.80 +        case SDL_GL_ACCUM_RED_SIZE:
    4.81 +             *value=this->gl_config.accum_red_size;
    4.82 +             break;
    4.83 +        case SDL_GL_ACCUM_GREEN_SIZE:
    4.84 +             *value=this->gl_config.accum_green_size;
    4.85 +             break;
    4.86 +        case SDL_GL_ACCUM_BLUE_SIZE:
    4.87 +             *value=this->gl_config.accum_blue_size;
    4.88 +             break;
    4.89 +        case SDL_GL_ACCUM_ALPHA_SIZE:
    4.90 +             *value=this->gl_config.accum_alpha_size;
    4.91 +             break;
    4.92 +        case SDL_GL_STEREO:
    4.93 +             *value=this->gl_config.stereo;
    4.94 +             break;
    4.95 +#endif /* 6.3.0 */
    4.96 +        default:
    4.97 +             *value=0;
    4.98 +             return(-1);
    4.99 +    }
   4.100 +    return 0;
   4.101 +}
   4.102 +
   4.103 +#if (_NTO_VERSION < 630)
   4.104 +int ph_GL_LoadLibrary(_THIS, const char* path)
   4.105 +{
   4.106 +    /* if code compiled with HAVE_OPENGL, that mean that library already linked */
   4.107 +    this->gl_config.driver_loaded = 1;
   4.108 +
   4.109 +    return 0;
   4.110 +}
   4.111 +#else
   4.112 +int ph_GL_LoadLibrary(_THIS, const char* path)
   4.113 +{
   4.114 +    void* handle;
   4.115 +    int dlopen_flags=RTLD_WORLD | RTLD_GROUP;
   4.116 +
   4.117 +    if (this->gl_config.dll_handle!=NULL)
   4.118 +    {
   4.119 +        return 0;
   4.120 +    }
   4.121 +
   4.122 +    handle = dlopen(path, dlopen_flags);
   4.123 +
   4.124 +    if (handle==NULL)
   4.125 +    {
   4.126 +        SDL_SetError("ph_GL_LoadLibrary(): Could not load OpenGL library");
   4.127 +        return -1;
   4.128 +    }
   4.129 +
   4.130 +    this->gl_config.dll_handle = handle;
   4.131 +    this->gl_config.driver_loaded = 1;
   4.132 +
   4.133 +    strncpy(this->gl_config.driver_path, path, sizeof(this->gl_config.driver_path)-1);
   4.134 +
   4.135 +    return 0;
   4.136 +}
   4.137 +#endif /* 6.3.0 */
   4.138 +
   4.139 +#if (_NTO_VERSION < 630)
   4.140 +void* ph_GL_GetProcAddress(_THIS, const char* proc)
   4.141 +{
   4.142 +    return NULL;
   4.143 +}
   4.144 +#else
   4.145 +void* ph_GL_GetProcAddress(_THIS, const char* proc)
   4.146 +{
   4.147 +    void* function;
   4.148 +
   4.149 +    if (this->gl_config.dll_handle==NULL)
   4.150 +    {
   4.151 +        ph_GL_LoadLibrary(this, DEFAULT_OPENGL);
   4.152 +        if (this->gl_config.dll_handle==NULL)
   4.153 +        {
   4.154 +            return NULL;
   4.155 +        }
   4.156 +    }
   4.157 +   
   4.158 +    function=qnxgl_get_func(proc, oglctx, 0);
   4.159 +    if (function==NULL)
   4.160 +    {
   4.161 +        function=dlsym(this->gl_config.dll_handle, proc);
   4.162 +    }
   4.163 +
   4.164 +    return function;
   4.165 +}
   4.166 +#endif /* 6.3.0 */
   4.167 +
   4.168 +#if (_NTO_VERSION < 630)
   4.169 +int ph_GL_MakeCurrent(_THIS)
   4.170 +{
   4.171 +    PgSetRegion(PtWidgetRid(window));
   4.172 +
   4.173 +    if (oglctx!=NULL)
   4.174 +    {
   4.175 +        PhDCSetCurrent(oglctx);
   4.176 +    }
   4.177 +
   4.178 +    return 0;
   4.179 +}
   4.180 +#else
   4.181 +int ph_GL_MakeCurrent(_THIS)
   4.182 +{
   4.183 +    PgSetRegion(PtWidgetRid(window));
   4.184 +
   4.185 +    if (oglctx!=NULL)
   4.186 +    {
   4.187 +        if (qnxgl_set_current(oglctx) == -1)
   4.188 +        {
   4.189 +           return -1;
   4.190 +        }
   4.191 +    }
   4.192 +
   4.193 +    return 0;
   4.194 +}
   4.195 +#endif /* 6.3.0 */
   4.196 +
   4.197 +#if (_NTO_VERSION < 630)
   4.198 +
   4.199 +/* This code is actual for the Photon3D Runtime which was available prior to 6.3 only */
   4.200 +
   4.201 +int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
   4.202 +{
   4.203 +    PhDim_t dim;
   4.204 +    uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
   4.205 +    int exposepost=0;
   4.206 +    int OGLargc;
   4.207 +
   4.208 +    dim.w=width;
   4.209 +    dim.h=height;
   4.210 +    
   4.211 +    if ((oglctx!=NULL) && (oglflags==flags) && (oglbpp==bpp))
   4.212 +    {
   4.213 +       PdOpenGLContextResize(oglctx, &dim);
   4.214 +       PhDCSetCurrent(oglctx);
   4.215 +       return 0;
   4.216 +    }
   4.217 +    else
   4.218 +    {
   4.219 +       if (oglctx!=NULL)
   4.220 +       {
   4.221 +          PhDCSetCurrent(NULL);
   4.222 +          PhDCRelease(oglctx);
   4.223 +          oglctx=NULL;
   4.224 +          exposepost=1;
   4.225 +       }
   4.226 +    }
   4.227 +
   4.228 +    OGLargc=0;
   4.229 +    if (this->gl_config.depth_size)
   4.230 +    {
   4.231 +        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
   4.232 +        OGLAttrib[OGLargc++]=this->gl_config.depth_size;
   4.233 +    }
   4.234 +    if (this->gl_config.stencil_size)
   4.235 +    {
   4.236 +        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
   4.237 +        OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
   4.238 +    }
   4.239 +    OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
   4.240 +    if (flags & SDL_FULLSCREEN)
   4.241 +    {
   4.242 +        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;
   4.243 +        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;
   4.244 +        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;
   4.245 +        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;
   4.246 +    }
   4.247 +    OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
   4.248 +
   4.249 +    if (this->gl_config.double_buffer)
   4.250 +    {
   4.251 +        oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
   4.252 +    }
   4.253 +    else
   4.254 +    {
   4.255 +        oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
   4.256 +    }
   4.257 +
   4.258 +    if (oglctx==NULL)
   4.259 +    {
   4.260 +        SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
   4.261 +        return -1;
   4.262 +    }
   4.263 +
   4.264 +    PhDCSetCurrent(oglctx);
   4.265 +
   4.266 +    PtFlush();
   4.267 +
   4.268 +    oglflags=flags;
   4.269 +    oglbpp=bpp;
   4.270 +
   4.271 +    if (exposepost!=0)
   4.272 +    {
   4.273 +        /* OpenGL context has been recreated, so report about this fact */
   4.274 +        SDL_PrivateExpose();
   4.275 +    }
   4.276 +
   4.277 +    return 0;
   4.278 +}
   4.279 +
   4.280 +#else /* _NTO_VERSION */
   4.281 +
   4.282 +/* This code is actual for the built-in PhGL support, which became available since 6.3 */
   4.283 +
   4.284 +int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
   4.285 +{
   4.286 +    qnxgl_buf_attrib_t qnxgl_attribs[PH_OGL_MAX_ATTRIBS];
   4.287 +    qnxgl_buf_attrib_t* qnxgl_attribs_slide;
   4.288 +    int num_interfaces = 0;
   4.289 +    int num_buffers = 0;
   4.290 +
   4.291 +    /* Initialize the OpenGL subsystem */
   4.292 +
   4.293 +    num_interfaces = qnxgl_init(NULL, NULL, 0);
   4.294 +
   4.295 +    if (num_interfaces < 0)
   4.296 +    {
   4.297 +        SDL_SetError("ph_SetupOpenGLContext(): cannot initialize OpenGL subsystem !\n");
   4.298 +        return -1;
   4.299 +    }
   4.300 +    if (num_interfaces == 0)
   4.301 +    {
   4.302 +        SDL_SetError("ph_SetupOpenGLContext(): there are no available OpenGL renderers was found !\n");
   4.303 +        return -1;
   4.304 +    }
   4.305 +
   4.306 +    /* Driver is linked */
   4.307 +    this->gl_config.driver_loaded=1;
   4.308 +
   4.309 +    /* Initialize the OpenGL context attributes */
   4.310 +    qnxgl_attribs_slide=qnxgl_attribs;
   4.311 +
   4.312 +    /* Depth size */
   4.313 +    if (this->gl_config.depth_size)
   4.314 +    {
   4.315 +        fprintf(stderr, "setted depth size %d\n", this->gl_config.depth_size);
   4.316 +        qnxgl_attribs_slide = qnxgl_attrib_set_depth(qnxgl_attribs_slide, this->gl_config.depth_size);
   4.317 +    }
   4.318 +
   4.319 +    /* Stencil size */
   4.320 +    if (this->gl_config.stencil_size)
   4.321 +    {
   4.322 +        qnxgl_attribs_slide = qnxgl_attrib_set_stencil(qnxgl_attribs_slide, this->gl_config.stencil_size);
   4.323 +    }
   4.324 +
   4.325 +    /* The sum of the accum bits of each channel */
   4.326 +    if ((this->gl_config.accum_red_size != 0) && (this->gl_config.accum_blue_size != 0) &&
   4.327 +        (this->gl_config.accum_green_size != 0))
   4.328 +    {
   4.329 +        qnxgl_attribs_slide = qnxgl_attrib_set_accum(qnxgl_attribs_slide,
   4.330 +           this->gl_config.accum_red_size + this->gl_config.accum_blue_size +
   4.331 +           this->gl_config.accum_green_size + this->gl_config.accum_alpha_size);
   4.332 +    }
   4.333 +    
   4.334 +    /* Stereo mode */
   4.335 +    if (this->gl_config.stereo)
   4.336 +    {
   4.337 +        qnxgl_attribs_slide = qnxgl_attrib_set_stereo(qnxgl_attribs_slide);
   4.338 +    }
   4.339 +
   4.340 +    /* Fullscreen mode */
   4.341 +    if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
   4.342 +    {
   4.343 +        qnxgl_attribs_slide = qnxgl_attrib_set_hint_fullscreen(qnxgl_attribs_slide);
   4.344 +    }
   4.345 +    
   4.346 +    /* Double buffering mode */
   4.347 +    if (this->gl_config.double_buffer)
   4.348 +    {
   4.349 +        num_buffers=2;
   4.350 +    }
   4.351 +    else
   4.352 +    {
   4.353 +        num_buffers=1;
   4.354 +    }
   4.355 +
   4.356 +    /* Loading the function pointers so we can use the extensions */
   4.357 +    GLPH_LOAD_FUNCS_GC(oglctx);
   4.358 +
   4.359 +    /* Set the buffers region to be that of our window's region */
   4.360 +    qnxgl_attribs_slide = glph_attrib_set_region(qnxgl_attribs_slide, PtWidgetRid(window));
   4.361 +
   4.362 +    /* End of the attributes array */
   4.363 +    qnxgl_attribs_slide = qnxgl_attrib_set_end(qnxgl_attribs_slide);
   4.364 +    
   4.365 +    /* Create the buffers with the specified color model */
   4.366 +    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);
   4.367 +    oglbuffers = qnxgl_buffers_create(
   4.368 +                   QNXGL_FORMAT_BEST_RGB,
   4.369 +/*                 __QNXGL_BUILD_FORMAT(0, __QNXGL_COLOR_MODEL_RGB, this->gl_config.alpha_size,
   4.370 +                     this->gl_config.red_size, this->gl_config.green_size, this->gl_config.blue_size), */
   4.371 +                 num_buffers, width, height, qnxgl_attribs, -1);
   4.372 +
   4.373 +
   4.374 +    if (oglbuffers == NULL)
   4.375 +    {
   4.376 +        SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL buffers !\n");
   4.377 +        qnxgl_finish();
   4.378 +        return -1;
   4.379 +    }
   4.380 +
   4.381 +    /* Create a QNXGL context for the previously created buffer */
   4.382 +    oglctx = qnxgl_context_create(oglbuffers, NULL);
   4.383 +
   4.384 +    if (oglctx == NULL)
   4.385 +    {
   4.386 +        SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL context !\n");
   4.387 +        qnxgl_buffers_destroy(oglbuffers);
   4.388 +        qnxgl_finish();
   4.389 +        return -1;
   4.390 +    }
   4.391 +
   4.392 +    /* Attempt to make the context current so we can use OpenGL commands */
   4.393 +    if (qnxgl_set_current(oglctx) == -1)
   4.394 +    {
   4.395 +        SDL_SetError("ph_SetupOpenGLContext(): failed to make the OpenGL context current !\n");
   4.396 +        qnxgl_context_destroy(oglctx);
   4.397 +        qnxgl_buffers_destroy(oglbuffers);
   4.398 +        qnxgl_finish();
   4.399 +        return -1;
   4.400 +    }
   4.401 +
   4.402 +    PtFlush();
   4.403 +
   4.404 +    oglflags=flags;
   4.405 +    oglbpp=bpp;
   4.406 +
   4.407 +    return 0;
   4.408 +}
   4.409 +
   4.410 +#endif /* _NTO_VERSION */
   4.411 +
   4.412 +#endif /* HAVE_OPENGL */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/video/photon/SDL_ph_gl.h	Sun Jul 18 19:46:38 2004 +0000
     5.3 @@ -0,0 +1,44 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2004 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Library General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Library General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Library General Public
    5.19 +    License along with this library; if not, write to the Free
    5.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +
    5.26 +#ifdef SAVE_RCSID
    5.27 +    static char rcsid = "@(#) $Id$";
    5.28 +#endif
    5.29 +
    5.30 +#ifndef __SDL_PH_GL_H__
    5.31 +#define __SDL_PH_GL_H__
    5.32 +
    5.33 +#include "SDL_ph_video.h"
    5.34 +
    5.35 +#define DEFAULT_OPENGL "/usr/lib/libGL.so"
    5.36 +
    5.37 +#ifdef HAVE_OPENGL
    5.38 +    void  ph_GL_SwapBuffers(_THIS);
    5.39 +    int   ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
    5.40 +    int   ph_GL_LoadLibrary(_THIS, const char* path);
    5.41 +    void* ph_GL_GetProcAddress(_THIS, const char* proc);
    5.42 +    int   ph_GL_MakeCurrent(_THIS);
    5.43 +
    5.44 +    int   ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags);
    5.45 +#endif /* HAVE_OPENGL */
    5.46 +
    5.47 +#endif /* __SDL_PH_GL_H__ */
     6.1 --- a/src/video/photon/SDL_ph_image.c	Sun Jul 18 19:44:06 2004 +0000
     6.2 +++ b/src/video/photon/SDL_ph_image.c	Sun Jul 18 19:46:38 2004 +0000
     6.3 @@ -26,6 +26,7 @@
     6.4  #endif
     6.5  
     6.6  #include <stdlib.h>
     6.7 +
     6.8  #include <Ph.h>
     6.9  #include <photon/Pg.h>
    6.10  
    6.11 @@ -34,8 +35,10 @@
    6.12  #include "SDL_endian.h"
    6.13  #include "SDL_video.h"
    6.14  #include "SDL_pixels_c.h"
    6.15 +#include "SDL_ph_video.h"
    6.16  #include "SDL_ph_image_c.h"
    6.17  #include "SDL_ph_modes_c.h"
    6.18 +#include "SDL_ph_gl.h"
    6.19  
    6.20  int ph_SetupImage(_THIS, SDL_Surface *screen)
    6.21  {
    6.22 @@ -189,8 +192,8 @@
    6.23  {
    6.24      OCImage.flags = screen->flags;
    6.25  
    6.26 -    /* Begin direct mode */
    6.27 -    if (!ph_EnterFullScreen(this, screen))
    6.28 +    /* Begin direct and fullscreen mode */
    6.29 +    if (!ph_EnterFullScreen(this, screen, PH_ENTER_DIRECTMODE))
    6.30      {
    6.31          return -1;
    6.32      }
    6.33 @@ -301,98 +304,30 @@
    6.34  
    6.35  #ifdef HAVE_OPENGL
    6.36  
    6.37 -static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
    6.38 -{
    6.39 -    PhDim_t dim;
    6.40 -    uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
    6.41 -    int exposepost=0;
    6.42 -    int OGLargc;
    6.43 -
    6.44 -    dim.w=width;
    6.45 -    dim.h=height;
    6.46 -    
    6.47 -    if ((oglctx!=NULL) && (oglflags==flags) && (oglbpp==bpp))
    6.48 -    {
    6.49 -       PdOpenGLContextResize(oglctx, &dim);
    6.50 -       PhDCSetCurrent(oglctx);
    6.51 -       return 0;
    6.52 -    }
    6.53 -    else
    6.54 -    {
    6.55 -       if (oglctx!=NULL)
    6.56 -       {
    6.57 -          PhDCSetCurrent(NULL);
    6.58 -          PhDCRelease(oglctx);
    6.59 -          oglctx=NULL;
    6.60 -          exposepost=1;
    6.61 -       }
    6.62 -    }
    6.63 -
    6.64 -    OGLargc=0;
    6.65 -    if (this->gl_config.depth_size)
    6.66 -    {
    6.67 -        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
    6.68 -        OGLAttrib[OGLargc++]=this->gl_config.depth_size;
    6.69 -    }
    6.70 -    if (this->gl_config.stencil_size)
    6.71 -    {
    6.72 -        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
    6.73 -        OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
    6.74 -    }
    6.75 -    OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
    6.76 -    if (flags & SDL_FULLSCREEN)
    6.77 -    {
    6.78 -        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;
    6.79 -        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;
    6.80 -        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;
    6.81 -        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;
    6.82 -    }
    6.83 -    OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
    6.84 -
    6.85 -    if (this->gl_config.double_buffer)
    6.86 -    {
    6.87 -        oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
    6.88 -    }
    6.89 -    else
    6.90 -    {
    6.91 -        oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
    6.92 -    }
    6.93 -
    6.94 -    if (oglctx==NULL)
    6.95 -    {
    6.96 -        SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
    6.97 -        return (-1);
    6.98 -    }
    6.99 -
   6.100 -    PhDCSetCurrent(oglctx);
   6.101 -
   6.102 -    PtFlush();
   6.103 -
   6.104 -    oglflags=flags;
   6.105 -    oglbpp=bpp;
   6.106 -
   6.107 -    if (exposepost!=0)
   6.108 -    {
   6.109 -        /* OpenGL context has been recreated, so report about this fact */
   6.110 -        SDL_PrivateExpose();
   6.111 -    }
   6.112 -
   6.113 -    return 0;
   6.114 -}
   6.115 -
   6.116  int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
   6.117  {
   6.118 -   this->UpdateRects = ph_OpenGLUpdate;
   6.119 -   screen->pixels=NULL;
   6.120 -   screen->pitch=NULL;
   6.121 +    this->UpdateRects = ph_OpenGLUpdate;
   6.122 +    screen->pixels=NULL;
   6.123 +    screen->pitch=NULL;
   6.124  
   6.125 -   if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0)
   6.126 -   {
   6.127 -      screen->flags &= ~SDL_OPENGL;
   6.128 -      return -1;
   6.129 -   }
   6.130 +    #if (_NTO_VERSION >= 630)
   6.131 +        if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
   6.132 +        {
   6.133 +            if (!ph_EnterFullScreen(this, screen, PH_IGNORE_DIRECTMODE))
   6.134 +            {
   6.135 +                screen->flags &= ~SDL_FULLSCREEN;
   6.136 +                return -1;
   6.137 +            }
   6.138 +        }
   6.139 +    #endif /* 6.3.0 */
   6.140 +
   6.141 +    if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0)
   6.142 +    {
   6.143 +        screen->flags &= ~SDL_OPENGL;
   6.144 +        return -1;
   6.145 +    }
   6.146     
   6.147 -   return 0;
   6.148 +    return 0;
   6.149  }
   6.150  
   6.151  #endif /* HAVE_OPENGL */
   6.152 @@ -405,12 +340,27 @@
   6.153      {
   6.154          if (oglctx)
   6.155          {
   6.156 -            PhDCSetCurrent(NULL);
   6.157 -            PhDCRelease(oglctx);
   6.158 +            #if (_NTO_VERSION < 630)
   6.159 +                PhDCSetCurrent(NULL);
   6.160 +                PhDCRelease(oglctx);
   6.161 +            #else
   6.162 +                qnxgl_context_destroy(oglctx);
   6.163 +                qnxgl_buffers_destroy(oglbuffers);
   6.164 +                qnxgl_finish();
   6.165 +            #endif /* 6.3.0 */
   6.166              oglctx=NULL;
   6.167 +            oglbuffers=NULL;
   6.168              oglflags=0;
   6.169              oglbpp=0;
   6.170          }
   6.171 +
   6.172 +        #if (_NTO_VERSION >= 630)
   6.173 +            if (currently_fullscreen)
   6.174 +            {
   6.175 +                ph_LeaveFullScreen(this);
   6.176 +            }
   6.177 +        #endif /* 6.3.0 */
   6.178 +
   6.179          return;
   6.180      }
   6.181  #endif /* HAVE_OPENGL */
     7.1 --- a/src/video/photon/SDL_ph_modes.c	Sun Jul 18 19:44:06 2004 +0000
     7.2 +++ b/src/video/photon/SDL_ph_modes.c	Sun Jul 18 19:46:38 2004 +0000
     7.3 @@ -253,7 +253,7 @@
     7.4      return -1;
     7.5  }
     7.6  
     7.7 -int ph_EnterFullScreen(_THIS, SDL_Surface* screen)
     7.8 +int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode)
     7.9  {
    7.10      PgDisplaySettings_t settings;
    7.11      int mode;
    7.12 @@ -326,24 +326,30 @@
    7.13              if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
    7.14              {
    7.15  #ifdef HAVE_OPENGL
    7.16 +    #if (_NTO_VERSION < 630)
    7.17 +                return 0;
    7.18 +    #endif /* 6.3.0 */
    7.19 +#else
    7.20 +                return 0;
    7.21  #endif /* HAVE_OPENGL */
    7.22 -                return 0;
    7.23              }
    7.24          }
    7.25  
    7.26 -        if (OCImage.direct_context==NULL)
    7.27 +        if (fmode==0)
    7.28          {
    7.29 -            OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
    7.30 -            if (!OCImage.direct_context)
    7.31 +            if (OCImage.direct_context==NULL)
    7.32              {
    7.33 -                SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n");
    7.34 -                ph_LeaveFullScreen(this);
    7.35 -                return 0;
    7.36 +                OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
    7.37 +                if (!OCImage.direct_context)
    7.38 +                {
    7.39 +                    SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n");
    7.40 +                    ph_LeaveFullScreen(this);
    7.41 +                    return 0;
    7.42 +                }
    7.43              }
    7.44 +            OCImage.oldDC=PdDirectStart(OCImage.direct_context);
    7.45          }
    7.46  
    7.47 -        OCImage.oldDC=PdDirectStart(OCImage.direct_context);
    7.48 -
    7.49          currently_fullscreen = 1;
    7.50      }
    7.51      PgFlush();
    7.52 @@ -360,10 +366,15 @@
    7.53          if ((this->screen) && ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
    7.54          {
    7.55  #ifdef HAVE_OPENGL
    7.56 +    #if (_NTO_VERSION < 630)
    7.57 +            return 0;
    7.58 +    #endif /* 6.3.0 */
    7.59 +#else
    7.60 +            return 0;
    7.61  #endif /* HAVE_OPENGL */
    7.62 -           return 0;
    7.63          }
    7.64 -        else
    7.65 +
    7.66 +        /* release routines starts here */
    7.67          {
    7.68              if (OCImage.direct_context)
    7.69              {
     8.1 --- a/src/video/photon/SDL_ph_modes_c.h	Sun Jul 18 19:44:06 2004 +0000
     8.2 +++ b/src/video/photon/SDL_ph_modes_c.h	Sun Jul 18 19:46:38 2004 +0000
     8.3 @@ -32,10 +32,13 @@
     8.4  
     8.5  #define PH_MAX_VIDEOMODES 127
     8.6  
     8.7 +#define PH_ENTER_DIRECTMODE  0
     8.8 +#define PH_IGNORE_DIRECTMODE 1
     8.9 +
    8.10  extern SDL_Rect **ph_ListModes(_THIS,SDL_PixelFormat *format, Uint32 flags);
    8.11  extern void ph_FreeVideoModes(_THIS);
    8.12  extern int ph_ResizeFullScreen(_THIS);
    8.13 -extern int ph_EnterFullScreen(_THIS, SDL_Surface* screen);
    8.14 +extern int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode);
    8.15  extern int ph_LeaveFullScreen(_THIS);
    8.16  extern int ph_GetVideoMode(int width, int height, int bpp);
    8.17  extern int get_mode_any_format(int width, int height, int bpp);
     9.1 --- a/src/video/photon/SDL_ph_video.c	Sun Jul 18 19:44:06 2004 +0000
     9.2 +++ b/src/video/photon/SDL_ph_video.c	Sun Jul 18 19:46:38 2004 +0000
     9.3 @@ -47,6 +47,7 @@
     9.4  #include "SDL_ph_events_c.h"
     9.5  #include "SDL_ph_mouse_c.h"
     9.6  #include "SDL_ph_wm_c.h"
     9.7 +#include "SDL_ph_gl.h"
     9.8  #include "SDL_phyuv_c.h"
     9.9  #include "blank_cursor.h"
    9.10  
    9.11 @@ -56,14 +57,6 @@
    9.12  static void ph_VideoQuit(_THIS);
    9.13  static void ph_DeleteDevice(SDL_VideoDevice *device);
    9.14  
    9.15 -#ifdef HAVE_OPENGL
    9.16 -static void  ph_GL_SwapBuffers(_THIS);
    9.17 -static int   ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
    9.18 -static int   ph_GL_LoadLibrary(_THIS, const char* path);
    9.19 -static void* ph_GL_GetProcAddress(_THIS, const char* proc);
    9.20 -static int   ph_GL_MakeCurrent(_THIS);
    9.21 -#endif /* HAVE_OPENGL */
    9.22 -
    9.23  static int phstatus=-1;
    9.24  
    9.25  static int ph_Available(void)
    9.26 @@ -376,6 +369,7 @@
    9.27  
    9.28  #ifdef HAVE_OPENGL
    9.29      oglctx=NULL;
    9.30 +    oglbuffers=NULL;
    9.31      oglflags=0;
    9.32      oglbpp=0;
    9.33  #endif /* HAVE_OPENGL */
    9.34 @@ -663,57 +657,3 @@
    9.35      return 1;
    9.36  }
    9.37  
    9.38 -#ifdef HAVE_OPENGL
    9.39 -
    9.40 -static void ph_GL_SwapBuffers(_THIS)
    9.41 -{
    9.42 -    PgSetRegion(PtWidgetRid(window));
    9.43 -    PdOpenGLContextSwapBuffers(oglctx);
    9.44 -}
    9.45 -
    9.46 -static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
    9.47 -{
    9.48 -    switch (attrib)
    9.49 -    {
    9.50 -        case SDL_GL_DOUBLEBUFFER:
    9.51 -             *value=this->gl_config.double_buffer;
    9.52 -             break;
    9.53 -        case SDL_GL_STENCIL_SIZE:
    9.54 -             *value=this->gl_config.stencil_size;
    9.55 -             break;
    9.56 -        case SDL_GL_DEPTH_SIZE:
    9.57 -             *value=this->gl_config.depth_size;
    9.58 -             break;
    9.59 -        default:
    9.60 -             *value=0;
    9.61 -             return(-1);
    9.62 -    }
    9.63 -    return 0;
    9.64 -}
    9.65 -
    9.66 -static int ph_GL_LoadLibrary(_THIS, const char* path)
    9.67 -{
    9.68 -   /* if code compiled with HAVE_OPENGL, that mean that library already linked */
    9.69 -   this->gl_config.driver_loaded = 1;
    9.70 -
    9.71 -   return 0;
    9.72 -}
    9.73 -
    9.74 -static void* ph_GL_GetProcAddress(_THIS, const char* proc)
    9.75 -{
    9.76 -   return NULL;
    9.77 -}
    9.78 -
    9.79 -static int ph_GL_MakeCurrent(_THIS)
    9.80 -{
    9.81 -    PgSetRegion(PtWidgetRid(window));
    9.82 -
    9.83 -    if (oglctx!=NULL)
    9.84 -    {
    9.85 -        PhDCSetCurrent(oglctx);
    9.86 -    }
    9.87 -
    9.88 -    return 0;
    9.89 -}
    9.90 -
    9.91 -#endif /* HAVE_OPENGL */
    10.1 --- a/src/video/photon/SDL_ph_video.h	Sun Jul 18 19:44:06 2004 +0000
    10.2 +++ b/src/video/photon/SDL_ph_video.h	Sun Jul 18 19:46:38 2004 +0000
    10.3 @@ -26,13 +26,20 @@
    10.4  #include "SDL_mouse.h"
    10.5  #include "SDL_sysvideo.h"
    10.6  
    10.7 +#include <sys/neutrino.h>
    10.8 +
    10.9  #include <Ph.h>
   10.10  #include <Pt.h>
   10.11  #include <photon/Pg.h>
   10.12  #include <photon/PdDirect.h>
   10.13  
   10.14  #ifdef HAVE_OPENGL
   10.15 -    #include <photon/PdGL.h>
   10.16 +    #if (_NTO_VERSION < 630)
   10.17 +        #include <photon/PdGL.h>
   10.18 +    #else
   10.19 +        #include <GL/qnxgl.h>
   10.20 +        #include <GL/GLPh.h>
   10.21 +    #endif /* 6.3.0 */
   10.22  #endif /* HAVE_OPENGL */
   10.23  
   10.24  /* Hidden "this" pointer for the video functions */
   10.25 @@ -68,7 +75,14 @@
   10.26      PtWidget_t *Window;                  /* used to handle input events */
   10.27      PhImage_t *image;	                 /* used to display image       */
   10.28  #ifdef HAVE_OPENGL
   10.29 -    PdOpenGLContext_t* OGLContext;       /* OpenGL context              */
   10.30 +    #if (_NTO_VERSION < 630)
   10.31 +        PdOpenGLContext_t* OGLContext;   /* OpenGL context              */
   10.32 +        void* OGLBuffers;                /* OpenGL buffers (unused)     */
   10.33 +    #else
   10.34 +        qnxglc_t* OGLContext;            /* OpenGL context for the 6.3  */
   10.35 +        qnxgl_bufs_t* OGLBuffers;        /* OpenGL buffers for the 6.3  */
   10.36 +    #endif /* 630 */
   10.37 +
   10.38      Uint32 OGLFlags;                     /* OpenGL flags                */
   10.39      Uint32 OGLBPP;                       /* OpenGL bpp                  */
   10.40  #endif /* HAVE_OPENGL */
   10.41 @@ -134,6 +148,7 @@
   10.42  
   10.43  #ifdef HAVE_OPENGL
   10.44       #define oglctx               (this->hidden->OGLContext)
   10.45 +     #define oglbuffers           (this->hidden->OGLBuffers)
   10.46       #define oglflags             (this->hidden->OGLFlags)
   10.47       #define oglbpp               (this->hidden->OGLBPP)
   10.48  #endif /* HAVE_OPENGL */
    11.1 --- a/test/testdyngl.c	Sun Jul 18 19:44:06 2004 +0000
    11.2 +++ b/test/testdyngl.c	Sun Jul 18 19:46:38 2004 +0000
    11.3 @@ -89,8 +89,10 @@
    11.4  	SDL_Event event;
    11.5  	int done=0;
    11.6  	GLfloat pixels[NB_PIXELS*3];
    11.7 -#ifdef _WIN32
    11.8 +#if defined(_WIN32)
    11.9  	char *gl_library = "OpenGL32.DLL";
   11.10 +#elif defined(__QNXNTO__)
   11.11 +	char *gl_library = "libGL.so.3";
   11.12  #else
   11.13  	char *gl_library = "libGL.so.1";
   11.14  #endif
   11.15 @@ -123,6 +125,9 @@
   11.16  		exit(1);
   11.17  	}
   11.18  
   11.19 +	/* Set the window manager title bar */
   11.20 +	SDL_WM_SetCaption( "SDL Dynamic OpenGL Loading Test", "testdyngl" );
   11.21 +
   11.22  	init_glfuncs(&f);
   11.23  
   11.24  	for(i=0;i<NB_PIXELS;i++)
    12.1 --- a/test/testgl.c	Sun Jul 18 19:44:06 2004 +0000
    12.2 +++ b/test/testgl.c	Sun Jul 18 19:46:38 2004 +0000
    12.3 @@ -744,7 +744,7 @@
    12.4  		}
    12.5  		if ( strncmp(argv[i], "-h", 2) == 0 ) {
    12.6   		       printf(
    12.7 -"Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa]\n",
    12.8 +"Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-fullscreen]\n",
    12.9   			      argv[0]);
   12.10  			exit(0);
   12.11  		}