save the gl client state to get a nice 80% fps boost
authorkoda
Wed, 14 Jul 2010 00:43:36 +0200
changeset 3641 98319a621dc8
parent 3640 54676a34b9ad
child 3642 fb39fecca350
save the gl client state to get a nice 80% fps boost tidy rqKillFlakes
hedgewars/GearDrawing.inc
hedgewars/VGSHandlers.inc
hedgewars/uLandObjects.pas
hedgewars/uStore.pas
hedgewars/uVisualGears.pas
hedgewars/uWorld.pas
--- a/hedgewars/GearDrawing.inc	Tue Jul 13 17:39:00 2010 -0400
+++ b/hedgewars/GearDrawing.inc	Wed Jul 14 00:43:36 2010 +0200
@@ -131,7 +131,6 @@
                 VertexBuffer[1].X:= tx + WorldDx;
                 VertexBuffer[1].Y:= ty + WorldDy;
 
-                glEnableClientState(GL_VERTEX_ARRAY);
                 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
                 glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
                 Tint($FF, $FF, $FF, $FF);
--- a/hedgewars/VGSHandlers.inc	Tue Jul 13 17:39:00 2010 -0400
+++ b/hedgewars/VGSHandlers.inc	Wed Jul 14 00:43:36 2010 +0200
@@ -18,7 +18,7 @@
 procedure doStepFlake(Gear: PVisualGear; Steps: Longword);
 var sign: float;
 begin
-if ((cReducedQuality and rqkillFlakes) <> 0) then exit;
+if vobCount = 0 then exit;
 
 sign:= 1;
 with Gear^ do
--- a/hedgewars/uLandObjects.pas	Tue Jul 13 17:39:00 2010 -0400
+++ b/hedgewars/uLandObjects.pas	Wed Jul 14 00:43:36 2010 +0200
@@ -449,7 +449,10 @@
 // snowflakes
 Readln(f, vobCount);
 if vobCount > 0 then
-   Readln(f, vobFramesCount, vobFrameTicks, vobVelocity, vobFallSpeed);
+    Readln(f, vobFramesCount, vobFrameTicks, vobVelocity, vobFallSpeed);
+if (cReducedQuality and rqKillFlakes) <> 0 then
+    vobCount:= 0;
+
 
 for i:= 0 to Pred(vobCount) do
     AddVisualGear( -cScreenWidth + random(cScreenWidth * 2 + LAND_WIDTH), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake);
--- a/hedgewars/uStore.pas	Tue Jul 13 17:39:00 2010 -0400
+++ b/hedgewars/uStore.pas	Wed Jul 14 00:43:36 2010 +0200
@@ -522,15 +522,10 @@
 TextureBuffer[3].X:= _l;
 TextureBuffer[3].Y:= _b;
 
-glEnableClientState(GL_VERTEX_ARRAY);
-glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
-
-glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-glDisableClientState(GL_VERTEX_ARRAY)
 end;
 
 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
@@ -541,16 +536,10 @@
 
 glBindTexture(GL_TEXTURE_2D, Texture^.id);
 
-glEnableClientState(GL_VERTEX_ARRAY);
-glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
 glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb);
 glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
 
-glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-glDisableClientState(GL_VERTEX_ARRAY);
-
 glPopMatrix
 end;
 
@@ -611,17 +600,10 @@
 TextureBuffer[3].X:= fl;
 TextureBuffer[3].Y:= fb;
 
-glEnableClientState(GL_VERTEX_ARRAY);
-glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
-glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-glDisableClientState(GL_VERTEX_ARRAY);
-
-
 glPopMatrix
 end;
 
@@ -674,16 +656,10 @@
 VertexBuffer[3].X:= -hw;
 VertexBuffer[3].Y:= hh;
 
-glEnableClientState(GL_VERTEX_ARRAY);
-glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb);
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
-glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-glDisableClientState(GL_VERTEX_ARRAY);
-
 glPopMatrix
 end;
 
@@ -781,16 +757,10 @@
 TextureBuffer[3].X:= l;
 TextureBuffer[3].Y:= b;
 
-glEnableClientState(GL_VERTEX_ARRAY);
-glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
-glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-glDisableClientState(GL_VERTEX_ARRAY);
-
 glPopMatrix
 end;
 
@@ -810,10 +780,8 @@
 VertexBuffer[3].X:= r.x;
 VertexBuffer[3].Y:= r.y + r.h;
 
-glEnableClientState(GL_VERTEX_ARRAY);
 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
-glDisableClientState(GL_VERTEX_ARRAY);
 
 Tint($FF, $FF, $FF, $FF);
 glEnable(GL_TEXTURE_2D)
@@ -1241,8 +1209,10 @@
     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
     // disable dithering
     glDisable(GL_DITHER);
-    // enable 2d textures by default
+    // enable common states by default as they save a lot
     glEnable(GL_TEXTURE_2D);
+    glEnableClientState(GL_VERTEX_ARRAY);                                                                                        
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);  
 end;
 
 procedure SetScale(f: GLfloat);
--- a/hedgewars/uVisualGears.pas	Tue Jul 13 17:39:00 2010 -0400
+++ b/hedgewars/uVisualGears.pas	Wed Jul 14 00:43:36 2010 +0200
@@ -344,7 +344,7 @@
 var Gear, t: PVisualGear;
     dmg: LongInt;
 begin
-if (vobCount = 0) or (vobCount > 200) or ((cReducedQuality and rqkillFlakes) <> 0) then exit;
+if (vobCount = 0) or (vobCount > 200) then exit;
 t:= VisualGearsList;
 while t <> nil do
       begin
@@ -375,11 +375,10 @@
         begin
         Tint(Gear^.Tint);
         case Gear^.Kind of
-            vgtFlake: if ((cReducedQuality and rqkillFlakes) = 0) then
-                        if vobVelocity = 0 then
-                            DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
-                        else
-                            DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle);
+            vgtFlake: if vobVelocity = 0 then
+                          DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
+                      else
+                          DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle);
             vgtCloud: DrawSprite(sprCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame);
             end;
         Gear:= Gear^.NextGear
--- a/hedgewars/uWorld.pas	Tue Jul 13 17:39:00 2010 -0400
+++ b/hedgewars/uWorld.pas	Wed Jul 14 00:43:36 2010 +0200
@@ -421,17 +421,16 @@
         VertexBuffer[3].X:= -lw;
         VertexBuffer[3].Y:= lh;
 
-        glEnableClientState (GL_COLOR_ARRAY);
+        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+        glEnableClientState(GL_COLOR_ARRAY);
         glColorPointer(4, GL_UNSIGNED_BYTE, 0, @WaterColorArray[0]);
 
-        glEnableClientState(GL_VERTEX_ARRAY);
         glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 
         glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
-        glDisableClientState(GL_VERTEX_ARRAY);
         glDisableClientState(GL_COLOR_ARRAY);
-
+        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
         glColor4ub($FF, $FF, $FF, $FF); // must not be Tint() as color array seems to stay active and color reset is required
         glEnable(GL_TEXTURE_2D);
     end;
@@ -471,15 +470,11 @@
 TextureBuffer[3].X:= TextureBuffer[0].X;
 TextureBuffer[3].Y:= TextureBuffer[2].Y;
 
-glEnableClientState(GL_VERTEX_ARRAY);
-glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
-glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-glDisableClientState(GL_VERTEX_ARRAY);
 Tint($FF, $FF, $FF, $FF);
 
 {for i:= -1 to cWaterSprCount do
@@ -963,10 +958,10 @@
         VertexBuffer[3].Y:= cScreenHeight;
          
         glDisable(GL_TEXTURE_2D);
-        glEnableClientState(GL_VERTEX_ARRAY);
+
         glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
         glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
-        glDisableClientState(GL_VERTEX_ARRAY);
+
         glEnable(GL_TEXTURE_2D);
         Tint($FF, $FF, $FF, $FF);
         if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then ScreenFade:= sfNone