Ditch the renderer system in sdl1.3 and use the 'old fashioned' sdl/opengl context. This gives us more flexibility and less problem in receiving video events (expecially on mobile platform) as well as not having to care to reset the gl context every time sdl interferes.
authorkoda
Sat, 06 Aug 2011 07:09:30 +0200
changeset 5505 a55aab592950
parent 5503 d8632f589008
child 5507 1040c0946ef8
Ditch the renderer system in sdl1.3 and use the 'old fashioned' sdl/opengl context. This gives us more flexibility and less problem in receiving video events (expecially on mobile platform) as well as not having to care to reset the gl context every time sdl interferes. This is a major sdl1.3 update so it should be tested with care (working great on ios)
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uStore.pas
hedgewars/uVariables.pas
--- a/hedgewars/SDLh.pas	Fri Aug 05 01:22:51 2011 +0200
+++ b/hedgewars/SDLh.pas	Sat Aug 06 07:09:30 2011 +0200
@@ -772,6 +772,7 @@
 function  SDL_GL_CreateContext(window: PSDL_Window): PSDL_GLContext; cdecl; external SDLLibName;
 procedure SDL_GL_DeleteContext(context: PSDL_GLContext); cdecl; external SDLLibName;
 function  SDL_GL_SwapWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
+function  SDL_GL_SetSwapInterval(interval: LongInt): LongInt; cdecl; external SDLLibName;
 
 procedure SDL_VideoQuit; cdecl; external SDLLibName;
 function  SDL_GetNumVideoDisplays: LongInt; cdecl; external SDLLibName;
--- a/hedgewars/hwengine.pas	Fri Aug 05 01:22:51 2011 +0200
+++ b/hedgewars/hwengine.pas	Sat Aug 06 07:09:30 2011 +0200
@@ -104,7 +104,7 @@
         end;
 
 {$IFDEF SDL13}
-    SDL_RenderPresent(SDLrender);
+    SDL_GL_SwapWindow(SDLwindow);
 {$ELSE}
     SDL_GL_SwapBuffers();
 {$ENDIF}
@@ -129,10 +129,9 @@
     CloseIPC();
     TTF_Quit();
 {$IFDEF SDL13}
-    SDL_RenderClear(SDLrender);
-    SDL_DestroyRenderer(SDLrender);
+    SDL_GL_DeleteContext(SDLGLcontext);
     SDL_DestroyWindow(SDLwindow);
-    SDLrender:= nil;
+    SDLGLcontext:= nil;
     SDLwindow:= nil;
 {$ENDIF}
     SDL_Quit();
--- a/hedgewars/uStore.pas	Fri Aug 05 01:22:51 2011 +0200
+++ b/hedgewars/uStore.pas	Sat Aug 06 07:09:30 2011 +0200
@@ -525,17 +525,24 @@
 end;
 
 procedure SetupOpenGL;
-{$IFNDEF IPHONEOS}
-var vendor: shortstring;
+var vendor: shortstring = '';
 {$IFDEF DARWIN}
 const one : LongInt = 1;
 {$ENDIF}
+begin
+{$IFDEF SDL13}
+    // this function creates an opengles1.1 context by default on mobile devices
+    // use SDL_GL_SetAttribute to change this behaviour
+    SDLGLcontext:=SDL_GL_CreateContext(SDLwindow);
+    SDLTry(SDLGLcontext <> nil, true);
+    SDL_GL_SetSwapInterval(1);
 {$ENDIF}
-begin
 
 {$IFDEF IPHONEOS}
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
     SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
+    vendor:= vendor; // avoid hint
+    one:= one; // avoid hint
 {$ELSE}
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
@@ -709,7 +716,7 @@
     DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
 
 {$IFDEF SDL13}
-    SDL_RenderPresent(SDLrender);
+    SDL_GL_SwapWindow(SDLwindow);
 {$ELSE}
     SDL_GL_SwapBuffers();
 {$ENDIF}
@@ -957,24 +964,11 @@
     x:= x or (SDL_GetNumVideoDisplays() - 1);
     y:= y or (SDL_GetNumVideoDisplays() - 1);
 
-    // hardcode the opengles driver as we do our own drawing
-    SDL_SetHint('SDL_RENDER_DRIVER','opengles');
-    flags:= flags or SDL_WINDOW_BORDERLESS;  // do not set SDL_WINDOW_RESIZABLE on iOS
+    flags:= flags or SDL_WINDOW_BORDERLESS or SDL_WINDOW_RESIZABLE;
 {$ENDIF}
 
     SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
     SDLTry(SDLwindow <> nil, true);
-    SDLrender:= SDL_CreateRenderer(SDLwindow, -1, SDL_RENDERER_ACCELERATED or SDL_RENDERER_PRESENTVSYNC);
-    SDLTry(SDLrender <> nil, true);
-
-    // clean the renderer before using it
-    SDL_SetRenderDrawColor(SDLrender, 0, 0, 0, 255);
-    SDL_RenderClear(SDLrender);
-    SDL_RenderPresent(SDLrender);
-
-    // reset the gl context from the one created by SDL (as we have our own drawing system)
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
 {$ELSE}
     if not cOnlyStats then
         begin
--- a/hedgewars/uVariables.pas	Fri Aug 05 01:22:51 2011 +0200
+++ b/hedgewars/uVariables.pas	Sat Aug 06 07:09:30 2011 +0200
@@ -167,7 +167,7 @@
 
 {$IFDEF SDL13}
     SDLwindow       : PSDL_Window;
-    SDLrender       : PSDL_Renderer;
+    SDLGLcontext    : PSDL_GLContext;
 {$ENDIF}
 
     WorldDx: LongInt;
@@ -2492,7 +2492,7 @@
 
 {$IFDEF SDL13}
     SDLwindow       := nil;
-    SDLrender       := nil;
+    SDLGLcontext    := nil;
 {$ENDIF}
 
     // those values still are not perfect