Date: Thu, 21 Feb 2002 09:18:24 +0200
authorSam Lantinga <slouken@libsdl.org>
Sat, 02 Mar 2002 16:50:35 +0000
changeset 29168a8a8237c09
parent 290 9a02597bc1b0
child 292 eadc0746dfaf
Date: Thu, 21 Feb 2002 09:18:24 +0200
From: "Mike Gorchak" <mike@malva.ua>
Subject: Re: Patches for QNX RtP again.

SDL_ph_image.c - Added OpenGL update functions - fixed some application
crashes.
Some dead code removed, reformatting some functions.
SDL_ph_image_c.h - Added OpenGL update function prototype.
SDL_ph_video.c - Added GL_GetAttribute and GL_SetAttribute functions
with next supported flags: SDL_GL_DOUBLEBUFFER,
SDL_GL_STENCIL_SIZE, SDL_GL_DEPTH_SIZE
GetWMInfo function (stub) has been implemented by me,
but not listed in device structure - fixed.
SDL_ph_wm.c - fixed warning 'no return in non-void function'.
README.QNX - Updating readme. Some spellcheck. ;-)
README.QNX
src/video/photon/SDL_ph_image.c
src/video/photon/SDL_ph_image_c.h
src/video/photon/SDL_ph_video.c
src/video/photon/SDL_ph_wm.c
     1.1 --- a/README.QNX	Fri Mar 01 18:24:12 2002 +0000
     1.2 +++ b/README.QNX	Sat Mar 02 16:50:35 2002 +0000
     1.3 @@ -1,17 +1,17 @@
     1.4 -README by Mike Gorchak <mike@malva.com.ua>
     1.5 +README by Mike Gorchak <mike@malva.ua>
     1.6  
     1.7 -    Experimentally added OpenGL support in window mode (in fullscreen
     1.8 -mode not yet). If you have QNX RtP v6.1.0 w/ or w/o Patch A you  need
     1.9 -to download new Photon3D runtime from http://developers.qnx.com.  The
    1.10 -versions of OS before 6.1.0 is not supported.
    1.11 +    OpenGL support was experimentally added in window mode (in
    1.12 +fullscreen mode not yet). If you have QNX RtP v6.1.0 w/ or w/o
    1.13 +Patch A you must download new Photon3D runtime from http://de-
    1.14 +velopers.qnx.com. The versions of OS before 6.1.0 are not sup-
    1.15 +ported.
    1.16  
    1.17  Problems:
    1.18 -1. OpenGL support is very raw. It is often fail. Update function has
    1.19 -   not been written yet. Fullscreen mode has not been written yet.
    1.20 -2. Photon has some errors in detecting how much bits per pixel has
    1.21 -   videomode, creating images with different color depth.
    1.22 -3. No shared libraries yet. We need manually set flags as
    1.23 -   --disable-shared.
    1.24 +1. Fullscreen mode (in OpenGL mode) has not been  written yet.
    1.25 +2. Photon has some errors in detecting  how much bits  per pi-
    1.26 +   xel videomode has.
    1.27 +3. No  shared  libraries  yet. We  need  manually  set flag to
    1.28 +   'configure' --disable-shared.
    1.29  
    1.30  Some building issues:
    1.31  
    1.32 @@ -22,7 +22,7 @@
    1.33                  --disable-video-x11 \
    1.34                  --disable-shared
    1.35  
    1.36 -    a) without OpenGL support:
    1.37 +    b) without OpenGL support:
    1.38      ./configure --prefix=/usr/local \
    1.39                  --disable-video-x11 \
    1.40                  --disable-shared    \
     2.1 --- a/src/video/photon/SDL_ph_image.c	Fri Mar 01 18:24:12 2002 +0000
     2.2 +++ b/src/video/photon/SDL_ph_image.c	Sat Mar 02 16:50:35 2002 +0000
     2.3 @@ -33,62 +33,54 @@
     2.4  #include "SDL_endian.h"
     2.5  #include "SDL_ph_image_c.h"
     2.6  
     2.7 -//printf("%s:%s:%d\n", __FILE__, __PRETTY_FUNCTION__, __LINE__ );
     2.8 -
     2.9 -/* Various screen update functions available */
    2.10 -//static void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
    2.11 -//static void ph_DummyUpdate(_THIS, int numrects, SDL_Rect *rects);
    2.12 -
    2.13  int ph_SetupImage(_THIS, SDL_Surface *screen)
    2.14  {
    2.15 -	int type = 0;
    2.16 +    int type = 0;
    2.17  
    2.18 -	/* Determine image type */
    2.19 -	switch(screen->format->BitsPerPixel)
    2.20 -	{
    2.21 -		case 8:{
    2.22 -			type = Pg_IMAGE_PALETTE_BYTE;
    2.23 -		}
    2.24 -		break;
    2.25 -		case 15:{
    2.26 -			type = Pg_IMAGE_DIRECT_555; 
    2.27 -		}
    2.28 -		break;
    2.29 -		case 16:{
    2.30 -			type = Pg_IMAGE_DIRECT_565; 
    2.31 -		}
    2.32 -		break;
    2.33 +    /* Determine image type */
    2.34 +    switch(screen->format->BitsPerPixel)
    2.35 +    {
    2.36 +        case 8:{
    2.37 +            type = Pg_IMAGE_PALETTE_BYTE;
    2.38 +        }
    2.39 +        break;
    2.40 +        case 15:{
    2.41 +            type = Pg_IMAGE_DIRECT_555; 
    2.42 +        }
    2.43 +        break;
    2.44 +        case 16:{
    2.45 +            type = Pg_IMAGE_DIRECT_565; 
    2.46 +        }
    2.47 +        break;
    2.48 +        case 24:{
    2.49 +            type = Pg_IMAGE_DIRECT_888;
    2.50 +        }
    2.51 +        break;
    2.52 +        case 32:{
    2.53 +            type = Pg_IMAGE_DIRECT_8888;
    2.54 +        }
    2.55 +        break;
    2.56 +        default:{
    2.57 +            /* should never get here */
    2.58 +            fprintf(stderr,"error: unsupported bbp = %d\n",
    2.59 +                    screen->format->BitsPerPixel);
    2.60 +            return -1;
    2.61 +        }
    2.62 +        break;
    2.63 +    }
    2.64  
    2.65 -		case 24:{
    2.66 -			type = Pg_IMAGE_DIRECT_888;
    2.67 -		}
    2.68 -		break;
    2.69 -		
    2.70 -		case 32:{
    2.71 -			type = Pg_IMAGE_DIRECT_8888;
    2.72 -		}
    2.73 -		break;
    2.74 -		default:{
    2.75 -		/* should never get here */
    2.76 -			fprintf(stderr,"error: unsupported bbp = %d\n",
    2.77 -					screen->format->BitsPerPixel);
    2.78 -			return -1;
    2.79 -		}
    2.80 -		break;
    2.81 -	}
    2.82 +    /* using shared memory for speed (set last param to 1) */
    2.83 +    if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
    2.84 +    {
    2.85 +        fprintf(stderr,"error: PhCreateImage failed.\n");
    2.86 +        return -1;
    2.87 +    }
    2.88  
    2.89 -	//using shared memory for speed (set last param to 1)
    2.90 -	if ((SDL_Image = PhCreateImage( NULL, screen->w, screen->h, type, NULL, 0, 1 )) == NULL)
    2.91 -	{
    2.92 -		fprintf(stderr,"error: PhCreateImage failed.\n");
    2.93 -		return -1;
    2.94 -	}
    2.95 +    screen->pixels = SDL_Image->image;
    2.96  
    2.97 -	screen->pixels = SDL_Image->image;
    2.98 -	
    2.99 -	this->UpdateRects = ph_NormalUpdate;
   2.100 +    this->UpdateRects = ph_NormalUpdate;
   2.101  
   2.102 -	return 0;
   2.103 +    return 0;
   2.104  }
   2.105  
   2.106  int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context
   2.107 @@ -172,39 +164,36 @@
   2.108  	return 0;
   2.109  }
   2.110  
   2.111 +int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
   2.112 +{
   2.113 +   this->UpdateRects = ph_OpenGLUpdate;
   2.114 +   
   2.115 +   return 0;
   2.116 +}
   2.117  
   2.118  void ph_DestroyImage(_THIS, SDL_Surface *screen)
   2.119  {
   2.120 -#if 0
   2.121 -   if(SDL_Image == NULL)
   2.122 -     return;
   2.123 -#endif
   2.124 +    if (OCImage.offscreen_context != NULL)
   2.125 +    {
   2.126 +        PhDCRelease(OCImage.offscreen_context);
   2.127 +        OCImage.offscreen_context = NULL;
   2.128 +        free(OCImage.FrameData0);
   2.129 +        OCImage.FrameData0 = NULL;
   2.130 +        free(OCImage.FrameData1);
   2.131 +        OCImage.FrameData1 = NULL;
   2.132 +    }
   2.133  
   2.134 -   if (OCImage.offscreen_context != NULL)
   2.135 -   {
   2.136 -      PhDCRelease(OCImage.offscreen_context);
   2.137 -      OCImage.offscreen_context = NULL;
   2.138 -      free(OCImage.FrameData0);
   2.139 -      OCImage.FrameData0 = NULL;
   2.140 -      free(OCImage.FrameData1);
   2.141 -      OCImage.FrameData1 = NULL;
   2.142 -   }
   2.143 +    if (SDL_Image)
   2.144 +    {
   2.145 +        PgShmemDestroy(SDL_Image->image);
   2.146 +        free(SDL_Image);
   2.147 +        SDL_Image = NULL;
   2.148 +    }
   2.149  
   2.150 -	if (SDL_Image)
   2.151 -	{
   2.152 -                // SDL_Image->flags=Ph_RELEASE_IMAGE;
   2.153 -                // PhReleaseImage(SDL_Image);
   2.154 -		if (SDL_Image->image)
   2.155 -			PgShmemDestroy(SDL_Image->image); // Use this if you using shared memory, or uncomment
   2.156 -                                                  // lines above if not (and comment this line ;-)
   2.157 -                free(SDL_Image);
   2.158 -		SDL_Image = NULL;
   2.159 -	}
   2.160 -
   2.161 -	if ( screen )
   2.162 -        {
   2.163 -    	        screen->pixels = NULL;
   2.164 -	}
   2.165 +    if (screen)
   2.166 +    {
   2.167 +        screen->pixels = NULL;
   2.168 +    }
   2.169  }
   2.170  
   2.171  int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
   2.172 @@ -213,12 +202,12 @@
   2.173      
   2.174      if(  flags & SDL_HWSURFACE)
   2.175      {
   2.176 -       OCImage.flags = flags;  //needed for SDL_DOUBLEBUF check
   2.177 -       return ph_SetupOCImage(this,screen);
   2.178 +        OCImage.flags = flags;  /* needed for SDL_DOUBLEBUF check */
   2.179 +        return ph_SetupOCImage(this, screen);
   2.180      }
   2.181 -    else if(flags & SDL_OPENGL) /* No image when using GL */
   2.182 +    else if(flags & SDL_OPENGL)
   2.183      {
   2.184 -       return 0;
   2.185 +       return ph_SetupOpenGLImage(this, screen);
   2.186      } 
   2.187      else
   2.188      {
   2.189 @@ -260,6 +249,13 @@
   2.190  static PhRect_t ph_rect;
   2.191  static int i;
   2.192  
   2.193 +void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
   2.194 +{
   2.195 +   this->GL_SwapBuffers(this);
   2.196 +   
   2.197 +   return;
   2.198 +}
   2.199 +
   2.200  void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
   2.201  {
   2.202  
     3.1 --- a/src/video/photon/SDL_ph_image_c.h	Fri Mar 01 18:24:12 2002 +0000
     3.2 +++ b/src/video/photon/SDL_ph_image_c.h	Sat Mar 02 16:50:35 2002 +0000
     3.3 @@ -39,4 +39,4 @@
     3.4  
     3.5  extern void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
     3.6  extern void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects);
     3.7 -extern void ph_DummyUpdate(_THIS, int numrects, SDL_Rect *rects);
     3.8 +extern void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect *rects);
     4.1 --- a/src/video/photon/SDL_ph_video.c	Fri Mar 01 18:24:12 2002 +0000
     4.2 +++ b/src/video/photon/SDL_ph_video.c	Sat Mar 02 16:50:35 2002 +0000
     4.3 @@ -56,7 +56,11 @@
     4.4  static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
     4.5  static void ph_VideoQuit(_THIS);
     4.6  static void ph_DeleteDevice(SDL_VideoDevice *device);
     4.7 +
     4.8 +#ifdef HAVE_OPENGL
     4.9  static void ph_GL_SwapBuffers(_THIS);
    4.10 +static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
    4.11 +#endif /* HAVE_OPENGL */
    4.12  
    4.13  #ifdef HAVE_OPENGL
    4.14  PdOpenGLContext_t* OGLContext=NULL;
    4.15 @@ -64,7 +68,7 @@
    4.16  
    4.17  static int ph_Available(void)
    4.18  {
    4.19 -        return 1;
    4.20 +    return 1;
    4.21  }
    4.22  
    4.23  static SDL_VideoDevice *ph_CreateDevice(int devindex)
    4.24 @@ -112,7 +116,7 @@
    4.25      device->SetIcon = NULL;
    4.26      device->IconifyWindow = ph_IconifyWindow;
    4.27      device->GrabInput = ph_GrabInput;
    4.28 -    device->GetWMInfo = NULL;
    4.29 +    device->GetWMInfo = ph_GetWMInfo;
    4.30      device->FreeWMCursor = ph_FreeWMCursor;
    4.31      device->CreateWMCursor = ph_CreateWMCursor;
    4.32      device->ShowWMCursor = ph_ShowWMCursor;
    4.33 @@ -124,12 +128,13 @@
    4.34      /* OpenGL support. */
    4.35      device->GL_LoadLibrary = NULL;
    4.36      device->GL_GetProcAddress = NULL;
    4.37 -    device->GL_GetAttribute = NULL;
    4.38      device->GL_MakeCurrent = NULL;
    4.39  #ifdef HAVE_OPENGL
    4.40      device->GL_SwapBuffers = ph_GL_SwapBuffers;
    4.41 +    device->GL_GetAttribute = ph_GL_GetAttribute;
    4.42  #else
    4.43      device->GL_SwapBuffers = NULL;
    4.44 +    device->GL_GetAttribute = NULL;
    4.45  #endif /* HAVE_OPENGL */
    4.46  
    4.47      device->free = ph_DeleteDevice;
    4.48 @@ -271,10 +276,6 @@
    4.49                  int width, int height, int bpp, Uint32 flags)
    4.50  {
    4.51      PgDisplaySettings_t settings;
    4.52 -/*
    4.53 -    PgHWCaps_t my_hwcaps;
    4.54 -    PgVideoModeInfo_t mode_info;
    4.55 -*/
    4.56      int mode, actual_width, actual_height;
    4.57      PtArg_t arg[5];
    4.58      PhDim_t dim;	
    4.59 @@ -285,7 +286,8 @@
    4.60  
    4.61  #ifdef HAVE_OPENGL
    4.62      uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
    4.63 -#endif // HAVE_OPENGL
    4.64 +    int OGLargc;
    4.65 +#endif /* HAVE_OPENGL */
    4.66  
    4.67      actual_width = width;
    4.68      actual_height = height;
    4.69 @@ -312,11 +314,9 @@
    4.70          {
    4.71              if ((mode = get_mode(width, height, bpp)) == 0)
    4.72              {
    4.73 -                 	fprintf(stderr,"error: get_mode failed\n");
    4.74 -                	exit(1);
    4.75 +                fprintf(stderr,"error: get_mode failed\n");
    4.76 +                exit(1);
    4.77              }
    4.78 -               
    4.79 -           
    4.80          }
    4.81          settings.mode = mode;
    4.82          settings.refresh = 0;
    4.83 @@ -327,14 +327,13 @@
    4.84              fprintf(stderr,"error: PgSetVideoMode failed\n");
    4.85          }
    4.86  
    4.87 -		/* Get the true height and width */
    4.88 -		
    4.89 -      current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
    4.90 +        /* Get the true height and width */
    4.91  
    4.92 -		 /* Begin direct mode */
    4.93 -		 ph_EnterFullScreen(this);
    4.94 +        current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
    4.95  
    4.96 -       
    4.97 +        /* Begin direct mode */
    4.98 +
    4.99 +        ph_EnterFullScreen(this);
   4.100  
   4.101      } /* end fullscreen flag */
   4.102      else
   4.103 @@ -352,17 +351,40 @@
   4.104  #ifdef HAVE_OPENGL       
   4.105         if (flags & SDL_OPENGL) /* for now support OpenGL in window mode only */
   4.106         {
   4.107 -          OGLAttrib[0]=PHOGL_ATTRIB_DEPTH_BITS;
   4.108 -          OGLAttrib[1]=bpp;
   4.109 -          OGLAttrib[2]=PHOGL_ATTRIB_NONE;
   4.110 -          OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
   4.111 +          OGLargc=0;
   4.112 +          if (this->gl_config.depth_size)
   4.113 +          {
   4.114 +             OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
   4.115 +             OGLAttrib[OGLargc++]=this->gl_config.depth_size;
   4.116 +          }
   4.117 +          if (this->gl_config.stencil_size)
   4.118 +          {
   4.119 +             OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
   4.120 +             OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
   4.121 +          }
   4.122 +          OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
   4.123 +          if (this->gl_config.double_buffer)
   4.124 +          {
   4.125 +             OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
   4.126 +          }
   4.127 +          else
   4.128 +          {
   4.129 +             OGLContext=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
   4.130 +          }
   4.131            if (OGLContext==NULL)
   4.132            {
   4.133 -             fprintf(stderr,"error: cannot create OpenGL context\n");
   4.134 +             fprintf(stderr,"error: cannot create OpenGL context.\n");
   4.135               exit(1);
   4.136            }
   4.137            PhDCSetCurrent(OGLContext);
   4.138         }
   4.139 +#else
   4.140 +       if (flags & SDL_OPENGL) /* if no OpenGL support */
   4.141 +       {
   4.142 +          fprintf(stderr, "error: no OpenGL support, try to recompile library.\n");
   4.143 +          exit(1);
   4.144 +       }
   4.145 +
   4.146  #endif /* HAVE_OPENGL */
   4.147         
   4.148      }
   4.149 @@ -488,28 +510,28 @@
   4.150  #ifdef HAVE_OPENGL
   4.151  void ph_GL_SwapBuffers(_THIS)
   4.152  {
   4.153 -   PgSetRegion(PtWidgetRid(window));
   4.154 -   PdOpenGLContextSwapBuffers(OGLContext);
   4.155 +    PgSetRegion(PtWidgetRid(window));
   4.156 +    PdOpenGLContextSwapBuffers(OGLContext);
   4.157  }
   4.158 -#endif // HAVE_OPENGL
   4.159  
   4.160 -/*
   4.161 -static int ph_ResizeWindow(_THIS,
   4.162 -            SDL_Surface *screen, int w, int h, Uint32 flags)
   4.163 +int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
   4.164  {
   4.165 -	PhWindowEvent_t winevent;
   4.166 +    switch (attrib)
   4.167 +    {
   4.168 +        case SDL_GL_DOUBLEBUFFER:
   4.169 +             *value=this->gl_config.double_buffer;
   4.170 +             break;
   4.171 +        case SDL_GL_STENCIL_SIZE:
   4.172 +             *value=this->gl_config.stencil_size;
   4.173 +             break;
   4.174 +        case SDL_GL_DEPTH_SIZE:
   4.175 +             *value=this->gl_config.depth_size;
   4.176 +             break;
   4.177 +        default:
   4.178 +             *value=0;
   4.179 +             return(-1);
   4.180 +    }
   4.181 +    return 0;
   4.182 +}
   4.183  
   4.184 -	memset( &winevent, 0, sizeof(winevent) ); 
   4.185 -	winevent.event_f = Ph_WM_RESIZE;
   4.186 -	winevent.size.w = w;
   4.187 -	winevent.size.h = h;
   4.188 -	winevent.rid = PtWidgetRid( window );
   4.189 -	if (PtForwardWindowEvent( &winevent ) < 0)
   4.190 -	{
   4.191 -		fprintf(stderr,"error: PtForwardWindowEvent failed.\n");
   4.192 -	}
   4.193 -	current_w = w;
   4.194 -	current_h = h;
   4.195 -    return(0);
   4.196 -}
   4.197 -*/
   4.198 +#endif /* HAVE_OPENGL */
     5.1 --- a/src/video/photon/SDL_ph_wm.c	Fri Mar 01 18:24:12 2002 +0000
     5.2 +++ b/src/video/photon/SDL_ph_wm.c	Sat Mar 02 16:50:35 2002 +0000
     5.3 @@ -242,6 +242,8 @@
     5.4  	windowevent.rid = PtWidgetRid( window );
     5.5  	PtForwardWindowEvent( &windowevent );
     5.6  	SDL_Unlock_EventThread();
     5.7 +        
     5.8 +        return 0;
     5.9  }
    5.10  
    5.11  SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode)