diff src/video/photon/SDL_ph_image.c @ 701:aaf3b8af6616

Date: Sat, 30 Aug 2003 16:28:10 +0300 From: "Mike Gorchak" Subject: Re: SDL 1.2.6 - minor changes about shared library building under QNX6 into README.QNX - added forgotten libSDLmain.a into distribution, SDL.qpg.in - added header guards to the all headers. - fixed fullscreen double buffered mode. - fixed Photon crashes after/during using fullscreen OpenGL modes. - added GL_MakeCurrent function. - added SDL_VIDEOEXPOSE event, when OpenGL window have been resized - added more HAVE_OPENGL checks to avoid dead code compilation without using OpenGL - finished code reorganization (began into previous patches).
author Sam Lantinga <slouken@libsdl.org>
date Sat, 30 Aug 2003 17:07:59 +0000
parents 04dd6c6d7c30
children b8d311d90021
line wrap: on
line diff
--- a/src/video/photon/SDL_ph_image.c	Sat Aug 30 09:09:09 2003 +0000
+++ b/src/video/photon/SDL_ph_image.c	Sat Aug 30 17:07:59 2003 +0000
@@ -186,13 +186,6 @@
     return 0;
 }
 
-int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
-{
-   this->UpdateRects = ph_OpenGLUpdate;
-   
-   return 0;
-}
-
 int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen)
 {
     OCImage.flags = screen->flags;
@@ -210,7 +203,7 @@
         PgGetPalette(syspalph);
     }
 
-    OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY);
+    OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY | Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE);
     if (OCImage.offscreen_context == NULL)
     {
         SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext() function failed !\n");
@@ -219,7 +212,7 @@
     
     if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
     {
-        OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_CRTC_SAFE);
+        OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_CRTC_SAFE | Pg_OSC_MEM_PAGE_ALIGN);
         if (OCImage.offscreen_backcontext == NULL)
         {
             SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n");
@@ -272,8 +265,122 @@
     return 0;
 }
 
-void ph_DestroyImage(_THIS, SDL_Surface *screen)
+#ifdef HAVE_OPENGL
+
+static 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;
+}
+
+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;
+}
+
+#endif /* HAVE_OPENGL */
+
+void ph_DestroyImage(_THIS, SDL_Surface* screen)
+{
+
+#ifdef HAVE_OPENGL
+    if ((screen->flags & SDL_OPENGL)==SDL_OPENGL)
+    {
+        if (oglctx)
+        {
+            PhDCSetCurrent(NULL);
+            PhDCRelease(oglctx);
+            oglctx=NULL;
+            oglflags=0;
+            oglbpp=0;
+        }
+        return;
+    }
+#endif /* HAVE_OPENGL */
+
     if (currently_fullscreen)
     {
         /* if we right now in 8bpp fullscreen we must release palette */
@@ -320,10 +427,16 @@
     }
 }
 
-int ph_SetupUpdateFunction(_THIS, SDL_Surface *screen, Uint32 flags)
+int ph_SetupUpdateFunction(_THIS, SDL_Surface* screen, Uint32 flags)
 {
     ph_DestroyImage(this, screen);
     
+#ifdef HAVE_OPENGL
+    if ((flags & SDL_OPENGL)==SDL_OPENGL)
+    {
+        return ph_SetupOpenGLImage(this, screen);
+    }
+#endif /* HAVE_OPENGL */
     if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)
     {
         return ph_SetupFullScreenImage(this, screen);
@@ -332,43 +445,31 @@
     {
         return ph_SetupOCImage(this, screen);
     }
-    if ((flags & SDL_OPENGL)==SDL_OPENGL)
-    {
-        return ph_SetupOpenGLImage(this, screen);
-    } 
 
     return ph_SetupImage(this, screen);
 }
 
-int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
+int ph_AllocHWSurface(_THIS, SDL_Surface* surface)
 {
     return(-1);
 }
 
-void ph_FreeHWSurface(_THIS, SDL_Surface *surface)
+void ph_FreeHWSurface(_THIS, SDL_Surface* surface)
 {
     return;
 }
 
-int ph_FlipHWSurface(_THIS, SDL_Surface *screen)
+int ph_FlipHWSurface(_THIS, SDL_Surface* screen)
 {
-    PhArea_t area;
-
-    area.pos.x=0;
-    area.pos.y=0;
-    area.size.w=screen->w;
-    area.size.h=screen->h;
-
     if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
     {
+        PgWaitHWIdle();
         if (OCImage.current==0)
         {
             PgSwapDisplay(OCImage.offscreen_context, 0);
             OCImage.current=1;
             screen->pitch = OCImage.offscreen_backcontext->pitch;
             screen->pixels = OCImage.FrameData1;
-//            memcpy(OCImage.FrameData1, OCImage.FrameData0, OCImage.offscreen_context->shared_size);
-            PgContextBlitArea(OCImage.offscreen_context, &area, OCImage.offscreen_backcontext, &area);
             PhDCSetCurrent(OCImage.offscreen_backcontext);
             PgFlush();
         }
@@ -378,8 +479,6 @@
             OCImage.current=0;
             screen->pitch = OCImage.offscreen_context->pitch;
             screen->pixels = OCImage.FrameData0;
-//            memcpy(OCImage.FrameData0, OCImage.FrameData1, OCImage.offscreen_context->shared_size);
-            PgContextBlitArea(OCImage.offscreen_backcontext, &area, OCImage.offscreen_context, &area);
             PhDCSetCurrent(OCImage.offscreen_context);
             PgFlush();
         }
@@ -397,12 +496,14 @@
     return;
 }
 
+#ifdef HAVE_OPENGL
 void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
 {
    this->GL_SwapBuffers(this);
    
    return;
 }
+#endif /* HAVE_OPENGL */
 
 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
 {