diff src/video/photon/SDL_ph_video.c @ 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 3d8b6b9f1e18
children f6ffac90895c
line wrap: on
line diff
--- 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 */