rendering tweaks/cleanup cont.
authorsheepluva
Tue, 24 Mar 2015 12:48:55 +0100
changeset 10869 f23763bbac1b
parent 10868 acb03a9712c3
child 10870 5efea5942475
rendering tweaks/cleanup cont.
hedgewars/uGearsRender.pas
hedgewars/uRender.pas
hedgewars/uStore.pas
hedgewars/uWorld.pas
--- a/hedgewars/uGearsRender.pas	Mon Mar 23 02:03:45 2015 +0100
+++ b/hedgewars/uGearsRender.pas	Tue Mar 24 12:48:55 2015 +0100
@@ -254,7 +254,7 @@
                 DrawTextureF(SpritesData[sprBigDigit].Texture, 0.5, x, y, c, 1, sprW, sprH);
                 end
             else
-                DrawCircle(x, y, 20, 3, 0, $FF, 0, $60);
+                DrawCircle(x, y, 20, 3, 0, $FF, $FF, $80);
             end;
         until (i > cMaxHHIndex);
     end
--- a/hedgewars/uRender.pas	Mon Mar 23 02:03:45 2015 +0100
+++ b/hedgewars/uRender.pas	Tue Mar 24 12:48:55 2015 +0100
@@ -59,12 +59,16 @@
 procedure DrawWaves             (Dir, dX, dY, oX: LongInt; tnt: Byte);
 
 procedure RenderClear           ();
-procedure RenderSetClearColor      (r, g, b, a: real);
+procedure RenderClear           (mode: TRenderMode);
+procedure RenderSetClearColor   (r, g, b, a: real);
 procedure Tint                  (r, g, b, a: Byte); inline;
 procedure Tint                  (c: Longword); inline;
 procedure untint(); inline;
 procedure setTintAdd            (f: boolean); inline;
 
+// call this to finish the rendering of current frame
+procedure FinishRender();
+
 function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
 
 // 0 => not offscreen, <0 => left/top of screen >0 => right/below of screen
@@ -74,7 +78,8 @@
 procedure SetScale(f: GLfloat);
 procedure UpdateViewLimits();
 
-procedure RenderSetup();
+procedure RendererSetup();
+procedure RendererCleanup();
 
 // TODO everything below this should not need a public interface
 
@@ -124,6 +129,11 @@
     LastColorPointerN, LastTexCoordPointerN, LastVertexPointerN: Integer;
 {$ENDIF}
 
+{$IFDEF USE_S3D_RENDERING}
+    // texture/vertex buffers for left/right/default eye modes
+    texLRDtb, texLvb, texRvb: array [0..3] of TVertex2f;
+{$ENDIF}
+
 function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
 begin
     isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0);
@@ -148,11 +158,92 @@
     glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
 end;
 
+{$IFDEF USE_S3D_RENDERING}
+procedure RenderClear(mode: TRenderMode);
+var frame: GLuint;
+begin
+    if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
+        begin
+        case mode of
+            rmLeftEye:  frame:= frameL;
+            rmRightEye: frame:= frameR;
+            else
+                frame:= defaultFrame;
+        end;
+
+        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frame);
+
+        RenderClear();
+        end
+    else
+        begin
+        // draw left eye in red channel only
+        if mode = rmLeftEye then
+            begin
+            glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+            RenderClear();
+            if cStereoMode = smGreenRed then
+                glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE)
+            else if cStereoMode = smBlueRed then
+                glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE)
+            else if cStereoMode = smCyanRed then
+                glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE)
+            else
+                glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
+            end
+        else
+            begin
+            // draw right eye in selected channel(s) only
+            if cStereoMode = smRedGreen then
+                glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE)
+            else if cStereoMode = smRedBlue then
+                glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE)
+            else if cStereoMode = smRedCyan then
+                glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE)
+            else
+                glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
+            end;
+        end;
+end;
+{$ENDIF}
+
 procedure RenderSetClearColor(r, g, b, a: real);
 begin
     glClearColor(r, g, b, a);
 end;
 
+procedure FinishRender();
+begin
+
+{$IFDEF USE_S3D_RENDERING}
+if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
+    begin
+    RenderClear(rmDefault);
+
+    SetScale(cDefaultZoomLevel);
+
+
+    // same for all
+    SetTexCoordPointer(@texLRDtb, Length(texLRDtb));
+
+
+    // draw left frame
+    glBindTexture(GL_TEXTURE_2D, texl);
+    SetVertexPointer(@texLvb, Length(texLvb));
+    //UpdateModelviewProjection;
+    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(texLvb));
+
+    // draw right frame
+    glBindTexture(GL_TEXTURE_2D, texl);
+    SetVertexPointer(@texRvb, Length(texRvb));
+    //UpdateModelviewProjection;
+    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(texRvb));
+
+    SetScale(zoom);
+    end;
+{$ENDIF}
+end;
+
 {$IFDEF GL2}
 function CompileShader(shaderFile: string; shaderType: GLenum): GLuint;
 var
@@ -303,14 +394,42 @@
     glDeleteRenderbuffersEXT(1, @depth);
     glDeleteFramebuffersEXT(1, @frame);
 end;
+{$ENDIF}
 
+procedure RendererCleanup();
+begin
+{$IFNDEF PAS2C}
+{$IFDEF USE_VIDEO_RECORDING}
+    if defaultFrame <> 0 then
+        DeleteFramebuffer(defaultFrame, depthv, texv);
 {$ENDIF}
-procedure RenderSetup();
+{$IFDEF USE_S3D_RENDERING}
+    if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
+        begin
+        DeleteFramebuffer(framel, depthl, texl);
+        DeleteFramebuffer(framer, depthr, texr);
+        end
+{$ENDIF}
+{$ENDIF}
+end;
+
+procedure RendererSetup();
 var AuxBufNum: LongInt = 0;
     tmpstr: ansistring;
     tmpint: LongInt;
     tmpn: LongInt;
 begin
+{$IFDEF MOBILE}
+    // TODO: this function creates an opengles1.1 context
+    // un-comment below and add proper logic to support opengles2.0
+    //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+    //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+    if SDLGLcontext = nil then
+        SDLGLcontext:= SDL_GL_CreateContext(SDLwindow);
+    SDLTry(SDLGLcontext <> nil, true);
+    SDL_GL_SetSwapInterval(1);
+{$ENDIF}
+
     // suppress hint/warning
     AuxBufNum:= AuxBufNum;
 
@@ -427,12 +546,66 @@
             CreateFramebuffer(framel, depthl, texl);
             CreateFramebuffer(framer, depthr, texr);
 
+
+
+
             // reset
             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame)
             end
         else
             cStereoMode:= smNone;
     end;
+
+    // set up vertex/texture buffers for frame textures
+    texLRDtb[0].X:= 0.0;
+    texLRDtb[0].Y:= 0.0;
+    texLRDtb[1].X:= 1.0;
+    texLRDtb[1].Y:= 0.0;
+    texLRDtb[2].X:= 1.0;
+    texLRDtb[2].Y:= 1.0;
+    texLRDtb[3].X:= 0.0;
+    texLRDtb[3].Y:= 1.0;
+
+    if cStereoMode = smHorizontal then
+        begin
+        texLvb[0].X:= cScreenWidth / -2;
+        texLvb[0].Y:= cScreenHeight;
+        texLvb[1].X:= 0;
+        texLvb[1].Y:= cScreenHeight;
+        texLvb[2].X:= 0;
+        texLvb[2].Y:= 0;
+        texLvb[3].X:= cScreenWidth / -2;
+        texLvb[3].Y:= 0;
+
+        texRvb[0].X:= 0;
+        texRvb[0].Y:= cScreenHeight;
+        texRvb[1].X:= cScreenWidth / 2;
+        texRvb[1].Y:= cScreenHeight;
+        texRvb[2].X:= cScreenWidth / 2;
+        texRvb[2].Y:= 0;
+        texRvb[3].X:= 0;
+        texRvb[3].Y:= 0;
+        end
+    else
+        begin
+        texLvb[0].X:= cScreenWidth / -2;
+        texLvb[0].Y:= cScreenHeight / 2;
+        texLvb[1].X:= cScreenWidth / 2;
+        texLvb[1].Y:= cScreenHeight / 2;
+        texLvb[2].X:= cScreenWidth / 2;
+        texLvb[2].Y:= 0;
+        texLvb[3].X:= cScreenWidth / -2;
+        texLvb[3].Y:= 0;
+
+        texRvb[0].X:= cScreenWidth / -2;
+        texRvb[0].Y:= cScreenHeight;
+        texRvb[1].X:= cScreenWidth / 2;
+        texRvb[1].Y:= cScreenHeight;
+        texRvb[2].X:= cScreenWidth / 2;
+        texRvb[2].Y:= cScreenHeight / 2;
+        texRvb[3].X:= cScreenWidth / -2;
+        texRvb[3].Y:= cScreenHeight / 2;
+        end;
 {$ENDIF}
 
 // set view port to whole window
--- a/hedgewars/uStore.pas	Mon Mar 23 02:03:45 2015 +0100
+++ b/hedgewars/uStore.pas	Tue Mar 24 12:48:55 2015 +0100
@@ -561,19 +561,8 @@
                 end;
             end;
         end;
-{$IFNDEF PAS2C}
-{$IFDEF USE_VIDEO_RECORDING}
-    if defaultFrame <> 0 then
-        DeleteFramebuffer(defaultFrame, depthv, texv);
-{$ENDIF}
-{$IFDEF USE_S3D_RENDERING}
-    if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
-        begin
-        DeleteFramebuffer(framel, depthl, texl);
-        DeleteFramebuffer(framer, depthr, texr);
-        end
-{$ENDIF}
-{$ENDIF}
+
+RendererCleanup();
 end;
 
 
@@ -756,18 +745,7 @@
     AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_VideoDriverName(buf, sizeof(buf))) + ')');
 {$ENDIF}
 
-{$IFDEF MOBILE}
-    // TODO: this function creates an opengles1.1 context
-    // un-comment below and add proper logic to support opengles2.0
-    //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
-    //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
-    if SDLGLcontext = nil then
-        SDLGLcontext:= SDL_GL_CreateContext(SDLwindow);
-    SDLTry(SDLGLcontext <> nil, true);
-    SDL_GL_SetSwapInterval(1);
-{$ENDIF}
-
-    RenderSetup();
+    RendererSetup();
 end;
 
 (*
--- a/hedgewars/uWorld.pas	Mon Mar 23 02:03:45 2015 +0100
+++ b/hedgewars/uWorld.pas	Tue Mar 24 12:48:55 2015 +0100
@@ -857,119 +857,28 @@
     else
         ZoomValue:= zoom;
 
-    // Sky
-    glClear(GL_COLOR_BUFFER_BIT);
-    //glPushMatrix;
-    //glScalef(1.0, 1.0, 1.0);
-
     if (not isPaused) and (not isAFK) and (GameType <> gmtRecord) then
         MoveCamera;
 
     if cStereoMode = smNone then
         begin
-        glClear(GL_COLOR_BUFFER_BIT);
+        RenderClear();
         DrawWorldStereo(Lag, rmDefault)
         end
 {$IFDEF USE_S3D_RENDERING}
-    else if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
+    else
         begin
-        // create left fb
-        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel);
-        glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
+        // draw frame for left eye
+        RenderClear(rmLeftEye);
         DrawWorldStereo(Lag, rmLeftEye);
 
-        // create right fb
-        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framer);
-        glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
+        // draw frame for right eye
+        RenderClear(rmRightEye);
         DrawWorldStereo(0, rmRightEye);
-
-        // detatch drawing from fbs
-        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame);
-        glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
-        SetScale(cDefaultZoomLevel);
-
-        // draw left frame
-        glBindTexture(GL_TEXTURE_2D, texl);
-        glBegin(GL_QUADS);
-            if cStereoMode = smHorizontal then
-                begin
-                glTexCoord2f(0.0, 0.0);
-                glVertex2d(cScreenWidth / -2, cScreenHeight);
-                glTexCoord2f(1.0, 0.0);
-                glVertex2d(0, cScreenHeight);
-                glTexCoord2f(1.0, 1.0);
-                glVertex2d(0, 0);
-                glTexCoord2f(0.0, 1.0);
-                glVertex2d(cScreenWidth / -2, 0);
-                end
-            else
-                begin
-                glTexCoord2f(0.0, 0.0);
-                glVertex2d(cScreenWidth / -2, cScreenHeight / 2);
-                glTexCoord2f(1.0, 0.0);
-                glVertex2d(cScreenWidth / 2, cScreenHeight / 2);
-                glTexCoord2f(1.0, 1.0);
-                glVertex2d(cScreenWidth / 2, 0);
-                glTexCoord2f(0.0, 1.0);
-                glVertex2d(cScreenWidth / -2, 0);
-                end;
-        glEnd();
+        end;
+{$ENDIF}
 
-        // draw right frame
-        glBindTexture(GL_TEXTURE_2D, texr);
-        glBegin(GL_QUADS);
-            if cStereoMode = smHorizontal then
-                begin
-                glTexCoord2f(0.0, 0.0);
-                glVertex2d(0, cScreenHeight);
-                glTexCoord2f(1.0, 0.0);
-                glVertex2d(cScreenWidth / 2, cScreenHeight);
-                glTexCoord2f(1.0, 1.0);
-                glVertex2d(cScreenWidth / 2, 0);
-                glTexCoord2f(0.0, 1.0);
-                glVertex2d(0, 0);
-                end
-            else
-                begin
-                glTexCoord2f(0.0, 0.0);
-                glVertex2d(cScreenWidth / -2, cScreenHeight);
-                glTexCoord2f(1.0, 0.0);
-                glVertex2d(cScreenWidth / 2, cScreenHeight);
-                glTexCoord2f(1.0, 1.0);
-                glVertex2d(cScreenWidth / 2, cScreenHeight / 2);
-                glTexCoord2f(0.0, 1.0);
-                glVertex2d(cScreenWidth / -2, cScreenHeight / 2);
-                end;
-        glEnd();
-        SetScale(zoom);
-        end
-    else
-        begin
-        // clear scene
-        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-        glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
-        // draw left eye in red channel only
-        if cStereoMode = smGreenRed then
-            glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE)
-        else if cStereoMode = smBlueRed then
-            glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE)
-        else if cStereoMode = smCyanRed then
-            glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE)
-        else
-            glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
-        DrawWorldStereo(Lag, rmLeftEye);
-        // draw right eye in selected channel(s) only
-        if cStereoMode = smRedGreen then
-            glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE)
-        else if cStereoMode = smRedBlue then
-            glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE)
-        else if cStereoMode = smRedCyan then
-            glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE)
-        else
-            glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
-        DrawWorldStereo(Lag, rmRightEye);
-        end
-{$ENDIF}
+FinishRender();
 end;
 
 procedure ChangeDepth(rm: TRenderMode; d: GLfloat);