From: fgsfds Date: Fri, 6 Mar 2020 22:42:08 +0000 (+0300) Subject: decouple repainting from blitting the FBO; draw touch overlay after FBO X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=c7a5223f1e2520ab13b480b937af1e208201de15;p=d2df-sdl.git decouple repainting from blitting the FBO; draw touch overlay after FBO --- diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas index af999b1..5edceb2 100644 --- a/src/engine/e_graphics.pas +++ b/src/engine/e_graphics.pas @@ -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; diff --git a/src/game/g_game.pas b/src/game/g_game.pas index ca0bea8..e3d9b7b 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -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; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 5d1c594..c4d1b0f 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -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; diff --git a/src/game/sdl/g_system.pas b/src/game/sdl/g_system.pas index 68f9918..c53a7b3 100644 --- a/src/game/sdl/g_system.pas +++ b/src/game/sdl/g_system.pas @@ -173,8 +173,6 @@ implementation procedure sys_Repaint; begin - if glRenderToFBO then - e_BlitFramebuffer(gWinSizeX, gWinSizeY); SDL_GL_SwapBuffers end; diff --git a/src/game/sdl2/g_system.pas b/src/game/sdl2/g_system.pas index 992d6dc..b37ae0b 100644 --- a/src/game/sdl2/g_system.pas +++ b/src/game/sdl2/g_system.pas @@ -247,8 +247,6 @@ implementation procedure sys_Repaint; begin - if glRenderToFBO then - e_BlitFramebuffer(gWinSizeX, gWinSizeY); SDL_GL_SwapWindow(window) end;