DEADSOFTWARE

decouple repainting from blitting the FBO; draw touch overlay after FBO
authorfgsfds <pvt.fgsfds@gmail.com>
Fri, 6 Mar 2020 22:42:08 +0000 (01:42 +0300)
committerfgsfds <pvt.fgsfds@gmail.com>
Fri, 6 Mar 2020 22:42:08 +0000 (01:42 +0300)
src/engine/e_graphics.pas
src/game/g_game.pas
src/game/g_window.pas
src/game/sdl/g_system.pas
src/game/sdl2/g_system.pas

index af999b19d4d3efb3373fd9ee9042b8395cd287fc..5edceb2c5f9d3c754a4d2f2f8e969fcd46410849 100644 (file)
@@ -64,6 +64,7 @@ procedure e_SetViewPort(X, Y, Width, Height: Word);
 procedure e_ResizeWindow(Width, Height: Integer);
 function e_ResizeFramebuffer(Width, Height: Integer): Boolean;
 procedure e_BlitFramebuffer(WinWidth, WinHeight: Integer);
+procedure e_SetRenderTarget(Framebuffer: Boolean);
 
 procedure e_Draw(ID: DWORD; X, Y: Integer; Alpha: Byte; AlphaChannel: Boolean;
                  Blending: Boolean; Mirror: TMirrorType = TMirrorType.None);
@@ -490,15 +491,22 @@ begin
   glTexCoord2f(u, v); glVertex2i(x1, y0);
 end;
 
+procedure e_SetRenderTarget(Framebuffer: Boolean);
+begin
+  if (e_FBO = 0) or e_NoGraphics then exit;
+  if Framebuffer then
+    glBindFramebuffer(GL_FRAMEBUFFER, e_FBO)
+  else
+    glBindFramebuffer(GL_FRAMEBUFFER, 0);
+end;
+
 procedure e_BlitFramebuffer(WinWidth, WinHeight: Integer);
 begin
   if (e_FBO = 0) or (e_Frame = 0) or e_NoGraphics then exit;
 
   glDisable(GL_BLEND);
   glEnable(GL_TEXTURE_2D);
-  glBindFramebuffer(GL_FRAMEBUFFER, 0);
   glBindTexture(GL_TEXTURE_2D, e_Frame);
-  e_SetViewPort(0, 0, WinWidth, WinHeight);
   glColor4ub(255, 255, 255, 255);
 
   glBegin(GL_QUADS);
@@ -507,9 +515,6 @@ begin
     glTexCoord2f(1, 0); glVertex2i(WinWidth, WinHeight);
     glTexCoord2f(1, 1); glVertex2i(WinWidth,         0);
   glEnd();
-
-  glBindFramebuffer(GL_FRAMEBUFFER, e_FBO);
-  e_SetViewPort(0, 0, e_FrameW, e_FrameH);
 end;
 
 procedure e_Draw(ID: DWORD; X, Y: Integer; Alpha: Byte; AlphaChannel: Boolean;
index ca0bea81dcbceb186b04afd137886b03d74542a6..e3d9b7bb2bed0c13288230a0e9be989c17656068 100644 (file)
@@ -3838,6 +3838,9 @@ begin
     FPSTime := Time;
   end;
 
+  e_SetRendertarget(True);
+  e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
+
   if gGameOn or (gState = STATE_FOLD) then
   begin
     if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
@@ -4168,10 +4171,20 @@ begin
 
   if gGameOn then drawProfilers();
 
+  // TODO: draw this after the FBO and remap mouse click coordinates
+
 {$IFDEF ENABLE_HOLMES}
   g_Holmes_DrawUI();
 {$ENDIF}
 
+  // blit framebuffer to screen
+
+  e_SetRendertarget(False);
+  e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
+  e_BlitFramebuffer(gWinSizeX, gWinSizeY);
+
+  // draw the overlay stuff on top of it
+
   g_Touch_Draw;
 end;
 
index 5d1c59476562a51e5857173ed10021712e2580f1..c4d1b0fb73a7984ce18686733833b6189abbac3e 100644 (file)
@@ -88,11 +88,18 @@ begin
 
     if forceUpdate then
     begin
+      e_SetRendertarget(True);
+      e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
+
       DrawMenuBackground('INTER');
       e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
-
       DrawLoadingStat();
       g_Console_Draw(True);
+
+      e_SetRendertarget(False);
+      e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
+      e_BlitFramebuffer(gWinSizeX, gWinSizeY);
+
       sys_Repaint;
       prevLoadingUpdateTime := getTimeMilli();
     end;
index 68f99188a830691b8f2d149e33ad70873d7a3191..c53a7b347596c44c4331497c94c7ee3a2cb524b0 100644 (file)
@@ -173,8 +173,6 @@ implementation
 
   procedure sys_Repaint;
   begin
-    if glRenderToFBO then
-      e_BlitFramebuffer(gWinSizeX, gWinSizeY);
     SDL_GL_SwapBuffers
   end;
 
index 992d6dc4c7091de9906f6f9808ef695c7553542c..b37ae0bf94c5d168aafc48aaaba0d66989a43c31 100644 (file)
@@ -247,8 +247,6 @@ implementation
 
   procedure sys_Repaint;
   begin
-    if glRenderToFBO then
-      e_BlitFramebuffer(gWinSizeX, gWinSizeY);
     SDL_GL_SwapWindow(window)
   end;