changeset 291:68a8a8237c09

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. ;-)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 02 Mar 2002 16:50:35 +0000
parents 9a02597bc1b0
children eadc0746dfaf
files 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
diffstat 5 files changed, 160 insertions(+), 140 deletions(-) [+]
line wrap: on
line diff
--- a/README.QNX	Fri Mar 01 18:24:12 2002 +0000
+++ b/README.QNX	Sat Mar 02 16:50:35 2002 +0000
@@ -1,17 +1,17 @@
-README by Mike Gorchak <mike@malva.com.ua>
+README by Mike Gorchak <mike@malva.ua>
 
-    Experimentally added OpenGL support in window mode (in fullscreen
-mode not yet). If you have QNX RtP v6.1.0 w/ or w/o Patch A you  need
-to download new Photon3D runtime from http://developers.qnx.com.  The
-versions of OS before 6.1.0 is not supported.
+    OpenGL support was experimentally added in window mode (in
+fullscreen mode not yet). If you have QNX RtP v6.1.0 w/ or w/o
+Patch A you must download new Photon3D runtime from http://de-
+velopers.qnx.com. The versions of OS before 6.1.0 are not sup-
+ported.
 
 Problems:
-1. OpenGL support is very raw. It is often fail. Update function has
-   not been written yet. Fullscreen mode has not been written yet.
-2. Photon has some errors in detecting how much bits per pixel has
-   videomode, creating images with different color depth.
-3. No shared libraries yet. We need manually set flags as
-   --disable-shared.
+1. Fullscreen mode (in OpenGL mode) has not been  written yet.
+2. Photon has some errors in detecting  how much bits  per pi-
+   xel videomode has.
+3. No  shared  libraries  yet. We  need  manually  set flag to
+   'configure' --disable-shared.
 
 Some building issues:
 
@@ -22,7 +22,7 @@
                 --disable-video-x11 \
                 --disable-shared
 
-    a) without OpenGL support:
+    b) without OpenGL support:
     ./configure --prefix=/usr/local \
                 --disable-video-x11 \
                 --disable-shared    \
--- a/src/video/photon/SDL_ph_image.c	Fri Mar 01 18:24:12 2002 +0000
+++ b/src/video/photon/SDL_ph_image.c	Sat Mar 02 16:50:35 2002 +0000
@@ -33,62 +33,54 @@
 #include "SDL_endian.h"
 #include "SDL_ph_image_c.h"
 
-//printf("%s:%s:%d\n", __FILE__, __PRETTY_FUNCTION__, __LINE__ );
-
-/* Various screen update functions available */
-//static void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
-//static void ph_DummyUpdate(_THIS, int numrects, SDL_Rect *rects);
-
 int ph_SetupImage(_THIS, SDL_Surface *screen)
 {
-	int type = 0;
-
-	/* Determine image type */
-	switch(screen->format->BitsPerPixel)
-	{
-		case 8:{
-			type = Pg_IMAGE_PALETTE_BYTE;
-		}
-		break;
-		case 15:{
-			type = Pg_IMAGE_DIRECT_555; 
-		}
-		break;
-		case 16:{
-			type = Pg_IMAGE_DIRECT_565; 
-		}
-		break;
+    int type = 0;
 
-		case 24:{
-			type = Pg_IMAGE_DIRECT_888;
-		}
-		break;
-		
-		case 32:{
-			type = Pg_IMAGE_DIRECT_8888;
-		}
-		break;
-		default:{
-		/* should never get here */
-			fprintf(stderr,"error: unsupported bbp = %d\n",
-					screen->format->BitsPerPixel);
-			return -1;
-		}
-		break;
-	}
+    /* Determine image type */
+    switch(screen->format->BitsPerPixel)
+    {
+        case 8:{
+            type = Pg_IMAGE_PALETTE_BYTE;
+        }
+        break;
+        case 15:{
+            type = Pg_IMAGE_DIRECT_555; 
+        }
+        break;
+        case 16:{
+            type = Pg_IMAGE_DIRECT_565; 
+        }
+        break;
+        case 24:{
+            type = Pg_IMAGE_DIRECT_888;
+        }
+        break;
+        case 32:{
+            type = Pg_IMAGE_DIRECT_8888;
+        }
+        break;
+        default:{
+            /* should never get here */
+            fprintf(stderr,"error: unsupported bbp = %d\n",
+                    screen->format->BitsPerPixel);
+            return -1;
+        }
+        break;
+    }
 
-	//using shared memory for speed (set last param to 1)
-	if ((SDL_Image = PhCreateImage( NULL, screen->w, screen->h, type, NULL, 0, 1 )) == NULL)
-	{
-		fprintf(stderr,"error: PhCreateImage failed.\n");
-		return -1;
-	}
+    /* using shared memory for speed (set last param to 1) */
+    if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
+    {
+        fprintf(stderr,"error: PhCreateImage failed.\n");
+        return -1;
+    }
 
-	screen->pixels = SDL_Image->image;
-	
-	this->UpdateRects = ph_NormalUpdate;
+    screen->pixels = SDL_Image->image;
 
-	return 0;
+    this->UpdateRects = ph_NormalUpdate;
+
+    return 0;
 }
 
 int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context
@@ -172,39 +164,36 @@
 	return 0;
 }
 
+int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
+{
+   this->UpdateRects = ph_OpenGLUpdate;
+   
+   return 0;
+}
 
 void ph_DestroyImage(_THIS, SDL_Surface *screen)
 {
-#if 0
-   if(SDL_Image == NULL)
-     return;
-#endif
-
-   if (OCImage.offscreen_context != NULL)
-   {
-      PhDCRelease(OCImage.offscreen_context);
-      OCImage.offscreen_context = NULL;
-      free(OCImage.FrameData0);
-      OCImage.FrameData0 = NULL;
-      free(OCImage.FrameData1);
-      OCImage.FrameData1 = NULL;
-   }
+    if (OCImage.offscreen_context != NULL)
+    {
+        PhDCRelease(OCImage.offscreen_context);
+        OCImage.offscreen_context = NULL;
+        free(OCImage.FrameData0);
+        OCImage.FrameData0 = NULL;
+        free(OCImage.FrameData1);
+        OCImage.FrameData1 = NULL;
+    }
 
-	if (SDL_Image)
-	{
-                // SDL_Image->flags=Ph_RELEASE_IMAGE;
-                // PhReleaseImage(SDL_Image);
-		if (SDL_Image->image)
-			PgShmemDestroy(SDL_Image->image); // Use this if you using shared memory, or uncomment
-                                                  // lines above if not (and comment this line ;-)
-                free(SDL_Image);
-		SDL_Image = NULL;
-	}
+    if (SDL_Image)
+    {
+        PgShmemDestroy(SDL_Image->image);
+        free(SDL_Image);
+        SDL_Image = NULL;
+    }
 
-	if ( screen )
-        {
-    	        screen->pixels = NULL;
-	}
+    if (screen)
+    {
+        screen->pixels = NULL;
+    }
 }
 
 int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
@@ -213,12 +202,12 @@
     
     if(  flags & SDL_HWSURFACE)
     {
-       OCImage.flags = flags;  //needed for SDL_DOUBLEBUF check
-       return ph_SetupOCImage(this,screen);
+        OCImage.flags = flags;  /* needed for SDL_DOUBLEBUF check */
+        return ph_SetupOCImage(this, screen);
     }
-    else if(flags & SDL_OPENGL) /* No image when using GL */
+    else if(flags & SDL_OPENGL)
     {
-       return 0;
+       return ph_SetupOpenGLImage(this, screen);
     } 
     else
     {
@@ -260,6 +249,13 @@
 static PhRect_t ph_rect;
 static int i;
 
+void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
+{
+   this->GL_SwapBuffers(this);
+   
+   return;
+}
+
 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
 {
 
--- a/src/video/photon/SDL_ph_image_c.h	Fri Mar 01 18:24:12 2002 +0000
+++ b/src/video/photon/SDL_ph_image_c.h	Sat Mar 02 16:50:35 2002 +0000
@@ -39,4 +39,4 @@
 
 extern void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
 extern void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects);
-extern void ph_DummyUpdate(_THIS, int numrects, SDL_Rect *rects);
+extern void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect *rects);
--- a/src/video/photon/SDL_ph_video.c	Fri Mar 01 18:24:12 2002 +0000
+++ b/src/video/photon/SDL_ph_video.c	Sat Mar 02 16:50:35 2002 +0000
@@ -56,7 +56,11 @@
 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);
+#endif /* HAVE_OPENGL */
 
 #ifdef HAVE_OPENGL
 PdOpenGLContext_t* OGLContext=NULL;
@@ -64,7 +68,7 @@
 
 static int ph_Available(void)
 {
-        return 1;
+    return 1;
 }
 
 static SDL_VideoDevice *ph_CreateDevice(int devindex)
@@ -112,7 +116,7 @@
     device->SetIcon = NULL;
     device->IconifyWindow = ph_IconifyWindow;
     device->GrabInput = ph_GrabInput;
-    device->GetWMInfo = NULL;
+    device->GetWMInfo = ph_GetWMInfo;
     device->FreeWMCursor = ph_FreeWMCursor;
     device->CreateWMCursor = ph_CreateWMCursor;
     device->ShowWMCursor = ph_ShowWMCursor;
@@ -124,12 +128,13 @@
     /* OpenGL support. */
     device->GL_LoadLibrary = NULL;
     device->GL_GetProcAddress = NULL;
-    device->GL_GetAttribute = NULL;
     device->GL_MakeCurrent = NULL;
 #ifdef HAVE_OPENGL
     device->GL_SwapBuffers = ph_GL_SwapBuffers;
+    device->GL_GetAttribute = ph_GL_GetAttribute;
 #else
     device->GL_SwapBuffers = NULL;
+    device->GL_GetAttribute = NULL;
 #endif /* HAVE_OPENGL */
 
     device->free = ph_DeleteDevice;
@@ -271,10 +276,6 @@
                 int width, int height, int bpp, Uint32 flags)
 {
     PgDisplaySettings_t settings;
-/*
-    PgHWCaps_t my_hwcaps;
-    PgVideoModeInfo_t mode_info;
-*/
     int mode, actual_width, actual_height;
     PtArg_t arg[5];
     PhDim_t dim;	
@@ -285,7 +286,8 @@
 
 #ifdef HAVE_OPENGL
     uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
-#endif // HAVE_OPENGL
+    int OGLargc;
+#endif /* HAVE_OPENGL */
 
     actual_width = width;
     actual_height = height;
@@ -312,11 +314,9 @@
         {
             if ((mode = get_mode(width, height, bpp)) == 0)
             {
-                 	fprintf(stderr,"error: get_mode failed\n");
-                	exit(1);
+                fprintf(stderr,"error: get_mode failed\n");
+                exit(1);
             }
-               
-           
         }
         settings.mode = mode;
         settings.refresh = 0;
@@ -327,14 +327,13 @@
             fprintf(stderr,"error: PgSetVideoMode failed\n");
         }
 
-		/* Get the true height and width */
-		
-      current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
+        /* Get the true height and width */
+
+        current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
 
-		 /* Begin direct mode */
-		 ph_EnterFullScreen(this);
+        /* Begin direct mode */
 
-       
+        ph_EnterFullScreen(this);
 
     } /* end fullscreen flag */
     else
@@ -352,17 +351,40 @@
 #ifdef HAVE_OPENGL       
        if (flags & SDL_OPENGL) /* for now support OpenGL in window mode only */
        {
-          OGLAttrib[0]=PHOGL_ATTRIB_DEPTH_BITS;
-          OGLAttrib[1]=bpp;
-          OGLAttrib[2]=PHOGL_ATTRIB_NONE;
-          OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
+          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_NONE;
+          if (this->gl_config.double_buffer)
+          {
+             OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
+          }
+          else
+          {
+             OGLContext=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
+          }
           if (OGLContext==NULL)
           {
-             fprintf(stderr,"error: cannot create OpenGL context\n");
+             fprintf(stderr,"error: cannot create OpenGL context.\n");
              exit(1);
           }
           PhDCSetCurrent(OGLContext);
        }
+#else
+       if (flags & SDL_OPENGL) /* if no OpenGL support */
+       {
+          fprintf(stderr, "error: no OpenGL support, try to recompile library.\n");
+          exit(1);
+       }
+
 #endif /* HAVE_OPENGL */
        
     }
@@ -488,28 +510,28 @@
 #ifdef HAVE_OPENGL
 void ph_GL_SwapBuffers(_THIS)
 {
-   PgSetRegion(PtWidgetRid(window));
-   PdOpenGLContextSwapBuffers(OGLContext);
+    PgSetRegion(PtWidgetRid(window));
+    PdOpenGLContextSwapBuffers(OGLContext);
 }
-#endif // HAVE_OPENGL
-
-/*
-static int ph_ResizeWindow(_THIS,
-            SDL_Surface *screen, int w, int h, Uint32 flags)
-{
-	PhWindowEvent_t winevent;
 
-	memset( &winevent, 0, sizeof(winevent) ); 
-	winevent.event_f = Ph_WM_RESIZE;
-	winevent.size.w = w;
-	winevent.size.h = h;
-	winevent.rid = PtWidgetRid( window );
-	if (PtForwardWindowEvent( &winevent ) < 0)
-	{
-		fprintf(stderr,"error: PtForwardWindowEvent failed.\n");
-	}
-	current_w = w;
-	current_h = h;
-    return(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;
+        default:
+             *value=0;
+             return(-1);
+    }
+    return 0;
 }
-*/
+
+#endif /* HAVE_OPENGL */
--- a/src/video/photon/SDL_ph_wm.c	Fri Mar 01 18:24:12 2002 +0000
+++ b/src/video/photon/SDL_ph_wm.c	Sat Mar 02 16:50:35 2002 +0000
@@ -242,6 +242,8 @@
 	windowevent.rid = PtWidgetRid( window );
 	PtForwardWindowEvent( &windowevent );
 	SDL_Unlock_EventThread();
+        
+        return 0;
 }
 
 SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode)