yay, finally osx (and likely windows) fullscreen switch works like on linux! ALL textures had to be destroyed and recreated only after the new window got created. In other news, the new window must be cleaned with glClear to skip a first frame of garbage and AddProgress is only called the first time.
authorkoda
Fri, 18 Nov 2011 00:32:52 +0100
changeset 6394 f0a9042e7387
parent 6393 701eb3f3556a
child 6395 bb04d7a9f7e2
yay, finally osx (and likely windows) fullscreen switch works like on linux! ALL textures had to be destroyed and recreated only after the new window got created. In other news, the new window must be cleaned with glClear to skip a first frame of garbage and AddProgress is only called the first time.
hedgewars/uCaptions.pas
hedgewars/uRender.pas
hedgewars/uStore.pas
hedgewars/uTextures.pas
hedgewars/uVariables.pas
hedgewars/uWorld.pas
--- a/hedgewars/uCaptions.pas	Thu Nov 17 23:14:24 2011 +0300
+++ b/hedgewars/uCaptions.pas	Fri Nov 18 00:32:52 2011 +0100
@@ -25,7 +25,7 @@
 
 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
 procedure DrawCaptions;
-procedure ReloadCaptions;
+procedure ReloadCaptions(unload: boolean);
 
 procedure initModule;
 procedure freeModule;
@@ -65,15 +65,13 @@
 end;
 
 // For uStore texture recreation
-procedure ReloadCaptions;
+procedure ReloadCaptions(unload: boolean);
 var Group: TCapGroup;
 begin
 for Group:= Low(TCapGroup) to High(TCapGroup) do
-    begin
-    FreeTexture(Captions[Group].Tex);
-    if Captions[Group].Text <> '' then
+    if unload then FreeTexture(Captions[Group].Tex)
+    else if Captions[Group].Text <> '' then
         Captions[Group].Tex:= RenderStringTex(Captions[Group].Text, Captions[Group].Color, fntBig)
-    end
 end;
 
 procedure DrawCaptions;
--- a/hedgewars/uRender.pas	Thu Nov 17 23:14:24 2011 +0300
+++ b/hedgewars/uRender.pas	Fri Nov 18 00:32:52 2011 +0100
@@ -45,8 +45,6 @@
 procedure Tint(r, g, b, a: Byte); inline;
 procedure Tint(c: Longword); inline;
 
-var
-    HHTexture: PTexture;
 
 implementation
 uses uVariables;
--- a/hedgewars/uStore.pas	Thu Nov 17 23:14:24 2011 +0300
+++ b/hedgewars/uStore.pas	Fri Nov 18 00:32:52 2011 +0100
@@ -42,7 +42,7 @@
 procedure MakeCrossHairs;
 
 implementation
-uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, uDebug;
+uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, uDebug, uWorld;
 
 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
 
@@ -277,8 +277,9 @@
 WriteNames(fnt16);
 MakeCrossHairs;
 LoadGraves;
+if not reload then
+    AddProgress;
 
-AddProgress;
 for ii:= Low(TSprite) to High(TSprite) do
     with SpritesData[ii] do
         // FIXME - add a sprite attribute to match on rq flags?
@@ -358,7 +359,8 @@
                 Surface:= nil
         end;
 
-AddProgress;
+if not reload then
+    AddProgress;
 
 tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent);
 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
@@ -371,7 +373,8 @@
 ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig);
 SyncTexture:= RenderStringTex(trmsg[sidSync], cYellowColor, fntBig);
 
-AddProgress;
+if not reload then
+    AddProgress;
 
 // name of weapons in ammo menu
 for ai:= Low(TAmmoType) to High(TAmmoType) do
@@ -396,7 +399,8 @@
     SDL_FreeSurface(tmpsurf)
 end;
 
-AddProgress;
+if not reload then
+    AddProgress;
 IMG_Quit();
 end;
 
@@ -416,16 +420,21 @@
             end
         end;
     SDL_FreeSurface(MissionIcons);
+
+    // free the textures declared in uVariables
+    FreeTexture(WeaponTooltipTex);
+    WeaponTooltipTex:= nil;
+    FreeTexture(PauseTexture);
+    PauseTexture:= nil;
+    FreeTexture(SyncTexture);
+    SyncTexture:= nil;
+    FreeTexture(ConfirmTexture);
+    ConfirmTexture:= nil;
     FreeTexture(ropeIconTex);
     ropeIconTex:= nil;
     FreeTexture(HHTexture);
     HHTexture:= nil;
-    FreeTexture(PauseTexture);
-    PauseTexture:= nil;
-    FreeTexture(ConfirmTexture);
-    ConfirmTexture:= nil;
-    FreeTexture(SyncTexture);
-    SyncTexture:= nil;
+
     // free all ammo name textures
     for ai:= Low(TAmmoType) to High(TAmmoType) do
         begin
@@ -760,9 +769,10 @@
 
 procedure FinishProgress;
 begin
+    uMobile.GameLoaded();
     WriteLnToConsole('Freeing progress surface... ');
     FreeTexture(ProgrTex);
-    uMobile.GameLoaded();
+    ProgrTex:= nil;
     Step:= 0
 end;
 
@@ -973,6 +983,10 @@
         SetScale(cDefaultZoomLevel);
 {$IF DEFINED(DARWIN) OR DEFINED(WIN32)}
         reinit:= true;
+        StoreRelease(true);
+        ResetLand;
+        ResetWorldTex;
+        //uTextures.freeModule; //DEBUG ONLY
 {$ENDIF}
         AddFileLog('Freeing old primary surface...');
         SDL_FreeSurface(SDLPrimSurface);
@@ -1027,18 +1041,19 @@
     SetupOpenGL();
     if reinit then
         begin
+        // clean the window from any previous content
+        glClear(GL_COLOR_BUFFER_BIT);
         if SuddenDeathDmg then
              glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99)
         else if ((cReducedQuality and rqNoBackground) = 0) then 
              glClearColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255, 0.99)
         else glClearColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255, 0.99);
 
-        StoreRelease(true);
-        ReloadCaptions;
+        // reload everything we had before
+        ReloadCaptions(false);
         ReloadLines;
         StoreLoad(true);
-
-        ResetLand;
+        // redraw all land
         UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT);
         end;
 end;
--- a/hedgewars/uTextures.pas	Thu Nov 17 23:14:24 2011 +0300
+++ b/hedgewars/uTextures.pas	Fri Nov 18 00:32:52 2011 +0100
@@ -31,7 +31,7 @@
 procedure freeModule;
 
 implementation
-uses GLunit, uUtils, uVariables, uConsts, uDebug;
+uses GLunit, uUtils, uVariables, uConsts, uDebug, uConsole;
 
 var TextureList: PTexture;
 
@@ -226,7 +226,7 @@
 
 procedure freeModule;
 begin
-    if TextureList <> nil then AddFileLog('FIXME FIXME FIXME. App shutdown without full cleanup of texture list.');
+    if TextureList <> nil then WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem');
     while TextureList <> nil do 
         begin
         AddFileLog('Texture not freed: width='+inttostr(LongInt(TextureList^.w))+' height='+inttostr(LongInt(TextureList^.h))+' priority='+inttostr(round(TextureList^.priority*1000)));
--- a/hedgewars/uVariables.pas	Thu Nov 17 23:14:24 2011 +0300
+++ b/hedgewars/uVariables.pas	Fri Nov 18 00:32:52 2011 +0100
@@ -150,7 +150,8 @@
     cLaserSighting  : boolean;
     cVampiric       : boolean;
     cArtillery      : boolean;
-    WeaponTooltipTex : PTexture;
+    WeaponTooltipTex: PTexture;
+    HHTexture       : PTexture;
 
     flagMakeCapture : boolean;
 
--- a/hedgewars/uWorld.pas	Thu Nov 17 23:14:24 2011 +0300
+++ b/hedgewars/uWorld.pas	Fri Nov 18 00:32:52 2011 +0100
@@ -27,6 +27,8 @@
 procedure freeModule;
 
 procedure InitWorld;
+procedure ResetWorldTex;
+
 procedure DrawWorld(Lag: LongInt);
 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
@@ -212,6 +214,17 @@
 cGearScrEdgesDist:= min(2 * cScreenHeight div 5, 2 * cScreenWidth div 5);
 end;
 
+// for uStore texture resetting
+procedure ResetWorldTex;
+begin
+    FreeTexture(fpsTexture);
+    fpsTexture:= nil;
+    FreeTexture(timeTexture);
+    timeTexture:= nil;
+    FreeTexture(missionTex);
+    missionTex:= nil;
+end;
+
 procedure ShowAmmoMenu;
 const MENUSPEED = 15;
 const BORDERSIZE = 2;