hedgewars/uRender.pas
branchios-develop
changeset 13418 ba39a1d396c0
parent 12903 8a40ce061d94
child 13500 b5f8864a38d3
--- a/hedgewars/uRender.pas	Sun Jun 10 18:56:51 2018 +0200
+++ b/hedgewars/uRender.pas	Sun Jun 10 19:12:26 2018 +0200
@@ -68,7 +68,7 @@
 procedure Tint                  (r, g, b, a: Byte); inline;
 procedure Tint                  (c: Longword); inline;
 procedure untint(); inline;
-procedure setTintAdd            (f: boolean); inline;
+procedure setTintAdd            (enable: boolean); inline;
 
 // call this to finish the rendering of current frame
 procedure FinishRender();
@@ -106,7 +106,7 @@
 
 implementation
 uses {$IFNDEF PAS2C} StrUtils, {$ENDIF}uVariables, uUtils
-     {$IFDEF GL2}, uMatrix, uConsole{$ENDIF}, uConsts;
+     {$IFDEF GL2}, uMatrix, uConsole, uPhysFSLayer, uDebug{$ENDIF}, uConsts;
 
 {$IFDEF USE_TOUCH_INTERFACE}
 const
@@ -123,9 +123,8 @@
 var VertexBuffer : array [0 ..59] of TVertex2f;
     TextureBuffer: array [0 .. 7] of TVertex2f;
     LastTint: LongWord = 0;
+{$IFNDEF GL2}
     LastColorPointer , LastTexCoordPointer , LastVertexPointer : Pointer;
-{$IFDEF GL2}
-    LastColorPointerN, LastTexCoordPointerN, LastVertexPointerN: Integer;
 {$ENDIF}
 
 {$IFDEF USE_S3D_RENDERING}
@@ -740,8 +739,8 @@
         {$ELSE}
         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
         glEnableClientState(GL_COLOR_ARRAY);
+        LastTexCoordPointer:= nil;
         {$ENDIF}
-        LastTexCoordPointer:= nil;
         end
     else
         begin
@@ -751,8 +750,8 @@
         {$ELSE}
         glDisableClientState(GL_COLOR_ARRAY);
         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+        LastColorPointer:= nil;
         {$ENDIF}
-        LastColorPointer:= nil;
         end;
     EnableTexture(not b);
 end;
@@ -775,58 +774,49 @@
 procedure SetTexCoordPointer(p: Pointer; n: Integer); inline;
 begin
 {$IFDEF GL2}
-    if (p = LastTexCoordPointer) and (n = LastTexCoordPointerN) then
-        exit;
     glBindBuffer(GL_ARRAY_BUFFER, tBuffer);
     glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
     glEnableVertexAttribArray(aTexCoord);
     glVertexAttribPointer(aTexCoord, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
-    LastTexCoordPointerN:= n;
 {$ELSE}
     if p = LastTexCoordPointer then
         exit;
     n:= n;
     glTexCoordPointer(2, GL_FLOAT, 0, p);
+    LastTexCoordPointer:= p;
 {$ENDIF}
-    LastTexCoordPointer:= p;
 end;
 
 procedure SetVertexPointer(p: Pointer; n: Integer); inline;
 begin
 {$IFDEF GL2}
-    if (p = LastVertexPointer) and (n = LastVertexPointerN) then
-        exit;
     glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
     glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
     glEnableVertexAttribArray(aVertex);
     glVertexAttribPointer(aVertex, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
-    LastVertexPointerN:= n;
 {$ELSE}
     if p = LastVertexPointer then
         exit;
     n:= n;
     glVertexPointer(2, GL_FLOAT, 0, p);
+    LastVertexPointer:= p;
 {$ENDIF}
-    LastVertexPointer:= p;
 end;
 
 procedure SetColorPointer(p: Pointer; n: Integer); inline;
 begin
 {$IFDEF GL2}
-    if (p = LastColorPointer) and (n = LastColorPointerN) then
-        exit;
     glBindBuffer(GL_ARRAY_BUFFER, cBuffer);
     glBufferData(GL_ARRAY_BUFFER, n * 4, p, GL_STATIC_DRAW);
     glEnableVertexAttribArray(aColor);
     glVertexAttribPointer(aColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, pointer(0));
-    LastColorPointerN:= n;
 {$ELSE}
     if p = LastColorPointer then
         exit;
     n:= n;
     glColorPointer(4, GL_UNSIGNED_BYTE, 0, p);
+    LastColorPointer:= p;
 {$ENDIF}
-    LastColorPointer:= p;
 end;
 
 procedure EnableTexture(enable:Boolean);
@@ -883,7 +873,10 @@
         end
     else
         begin
-        openglPushMatrix; // save default scaling in matrix
+        if cScaleFactor = cDefaultZoomLevel then
+            begin
+            openglPushMatrix; // save default scaling in matrix;
+            end;
         openglLoadIdentity();
         openglScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
         openglTranslatef(0, -cScreenHeight div 2, 0);
@@ -944,7 +937,6 @@
 _t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
 _b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
 
-glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
 
 xw:= X + W;
 yh:= Y + H;
@@ -967,9 +959,13 @@
 TextureBuffer[3].X:= _l;
 TextureBuffer[3].Y:= _b;
 
+
+glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
 SetVertexPointer(@VertexBuffer[0], 4);
 SetTexCoordPointer(@TextureBuffer[0], 4);
+
 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
 end;
 
 procedure DrawTexture(X, Y: LongInt; Texture: PTexture); inline;
@@ -979,7 +975,6 @@
 
 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
 begin
-
 openglPushMatrix;
 openglTranslatef(X, Y, 0);
 
@@ -996,6 +991,7 @@
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
 openglPopMatrix;
 
+UpdateModelviewProjection;
 end;
 
 { this contains tweaks in order to avoid land tile borders in blurry land mode }
@@ -1025,6 +1021,8 @@
 
 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 openglPopMatrix;
+
+UpdateModelviewProjection;
 end;
 
 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
@@ -1132,6 +1130,8 @@
 
 openglPopMatrix;
 
+UpdateModelviewProjection;
+
 end;
 
 procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
@@ -1148,7 +1148,7 @@
 if Angle <> 0  then
     begin
     // Check the bounding circle 
-    if isCircleOffscreen(X, Y, sqr(SpritesData[Sprite].Width) + sqr(SpritesData[Sprite].Height)) then
+    if isCircleOffscreen(X, Y, (sqr(SpritesData[Sprite].Width) + sqr(SpritesData[Sprite].Height)) div 4) then
         exit;
     end
 else
@@ -1171,10 +1171,14 @@
 if Angle <> 0  then
     openglRotatef(Angle, 0, 0, 1);
 
+UpdateModelviewProjection;
+
 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
 
 openglPopMatrix;
 
+UpdateModelviewProjection;
+
 end;
 
 procedure DrawSpritePivotedF(Sprite: TSprite; X, Y, Frame, Dir, PivotX, PivotY: LongInt; Angle: real);
@@ -1212,6 +1216,8 @@
 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
 
 openglPopMatrix;
+
+UpdateModelviewProjection;
 end;
 
 procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
@@ -1259,6 +1265,7 @@
 
 openglPopMatrix;
 
+UpdateModelviewProjection;
 end;
 
 procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
@@ -1342,6 +1349,8 @@
     DrawLineOnScreen(X0, Y0, X1, Y1, Width, r, g, b, a);
 
     openglPopMatrix();
+
+    UpdateModelviewProjection;
 end;
 
 procedure DrawLineOnScreen(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
@@ -1376,7 +1385,6 @@
     exit;
 
 EnableTexture(False);
-
 Tint(r, g, b, a);
 
 with rect do
@@ -1510,6 +1518,8 @@
     glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
     openglPopMatrix;
+
+    UpdateModelviewProjection;
 end;
 
 procedure DrawScreenWidget(widget: POnScreenWidget);
@@ -1904,8 +1914,6 @@
 SetVertexPointer(@VertexBuffer[0], 8);
 SetTexCoordPointer(@TextureBuffer[0], 8);
 
-UpdateModelviewProjection;
-
 glDrawArrays(GL_TRIANGLE_STRIP, first, count);
 
 untint;
@@ -1961,12 +1969,19 @@
     LastTint:= cWhiteColor;
 end;
 
-procedure setTintAdd(f: boolean); inline;
+procedure setTintAdd(enable: boolean); inline;
 begin
-    if f then
+    {$IFDEF GL2}
+        if enable then
+            glUniform1i(glGetUniformLocation(shaderMain, pchar('tintAdd')), 1)
+        else
+            glUniform1i(glGetUniformLocation(shaderMain, pchar('tintAdd')), 0);
+    {$ELSE}
+    if enable then
         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD)
     else
         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+    {$ENDIF}
 end;
 
 procedure ChangeDepth(rm: TRenderMode; d: GLfloat);
@@ -2008,13 +2023,10 @@
 procedure initModule;
 begin
     LastTint:= cWhiteColor + 1;
+{$IFNDEF GL2}
     LastColorPointer    := nil;
     LastTexCoordPointer := nil;
     LastVertexPointer   := nil;
-{$IFDEF GL2}
-    LastColorPointerN   :=   0;
-    LastTexCoordPointerN:=   0;
-    LastVertexPointerN  :=   0;
 {$ENDIF}
 end;