DEADSOFTWARE

gl: apply r_resolution_scale without videomode reset
[d2df-sdl.git] / src / game / renders / opengl / r_render.pas
index 18b14209101baf408fb40ff20c023eb0a0145220..7ef7d7b95424119026bfd31aee8caf44420976bd 100644 (file)
@@ -73,22 +73,27 @@ interface
   procedure r_Render_StepLoading (incval: Integer);
   procedure r_Render_DrawLoading (force: Boolean);
 
+  {$IFDEF ENABLE_HOLMES}
+    function pmsCurMapX (): Integer;
+    function pmsCurMapY (): Integer;
+    function r_Render_HolmesViewIsSet (): Boolean;
+  {$ENDIF}
+
 implementation
 
   uses
-    {$IFDEF USE_GLES1}
-      GLES11,
-    {$ELSE}
-      GL, GLEXT,
-    {$ENDIF}
+    {$I ../../../nogl/noGLuses.inc}
     {$IFDEF ENABLE_MENU}
       r_gui,
     {$ENDIF}
     {$IFDEF ENABLE_SYSTEM}
       g_system,
     {$ENDIF}
+    {$IFDEF ENABLE_TOUCH}
+      r_touch,
+    {$ENDIF}
     {$IFDEF ENABLE_HOLMES}
-      g_holmes,
+      r_holmes,
     {$ENDIF}
     SysUtils, Classes, Math,
     g_basic,
@@ -196,11 +201,24 @@ implementation
     info.maximized := gRC_Maximized;
     info.major := 1;
     info.minor := 1;
-    info.profile := TGLProfile.Compat;
+    {$IFDEF USE_GLES1}
+      info.profile := TGLProfile.Common;
+    {$ELSE}
+      info.profile := TGLProfile.Compat;
+    {$ENDIF}
     result := info;
   end;
 {$ENDIF}
 
+  procedure r_Render_LogGLInfo;
+  begin
+    e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR)]);
+    e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER)]);
+    e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION)]);
+    e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION)]);
+    e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS)]);
+  end;
+
   procedure r_Render_Initialize;
   begin
     {$IFDEF ENABLE_SYSTEM}
@@ -208,6 +226,10 @@ implementation
         raise Exception.Create('Failed to set videomode on startup.');
       sys_EnableVSync(gVSync);
     {$ENDIF}
+    {$IFDEF NOGL_INIT}
+      nogl_Init;
+    {$ENDIF}
+    r_Render_LogGLInfo;
     r_LoadScreen_Initialize;
     r_Textures_Initialize;
     r_Console_Initialize;
@@ -220,6 +242,9 @@ implementation
     r_Console_Finalize;
     r_Textures_Finalize;
     r_LoadScreen_Finalize;
+    {$IFDEF NOGL_INIT}
+      nogl_Quit;
+    {$ENDIF}
   end;
 
   procedure r_Render_Update;
@@ -280,12 +305,14 @@ implementation
   end;
 
   procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
-    var s: AnsiString;
+    var s: AnsiString; oldy: Integer;
   begin
     r_Common_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
 
     if p <> nil then
     begin
+      oldy := y;
+      if h < 239 then y := y - 32; (* hack: hide nickname on 640x400 *)
       r_Render_DrawHUD(x + w - 196 + 2, y, p);
       if p.Spectator then
       begin
@@ -295,6 +322,7 @@ implementation
         if p.NoRespawn then
           r_Common_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
       end;
+      y := oldy;
     end;
 
     if gShowPing and g_Game_IsClient then
@@ -311,7 +339,7 @@ implementation
 
     if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
     begin
-      (* RED TEAM GOALS *)
+      (* RED TEAM SCORE *)
       fw := 0;
       if gGameSettings.GameMode = GM_CTF then
       begin
@@ -328,7 +356,7 @@ implementation
       end;
       r_Common_DrawText(IntToStr(gTeamStat[TEAM_RED].Score), x + w - 16 - fw, y + 240 - 72 - 4, TEAMCOLOR[TEAM_RED].R, TEAMCOLOR[TEAM_RED].G, TEAMCOLOR[TEAM_RED].B, 255, menufont, TBasePoint.BP_RIGHTUP);
 
-      (* BLUE TEAM GOALS *)
+      (* BLUE TEAM SCORE *)
       fw := 0;
       if gGameSettings.GameMode = GM_CTF then
       begin
@@ -386,7 +414,7 @@ implementation
   end;
 
   procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
-    var l, t, r, b, xx, yy: Integer;
+    var l, t, r, b, xx, yy, cx, cy: Integer;
   begin
     r_Draw_GetRect(l, t, r, b);
     r_Draw_SetRect(x, y, x + w, y + h);
@@ -394,32 +422,32 @@ implementation
     r_Common_GetCameraPos(p, true, xx, yy);
     if p <> nil then
     begin
+      r_Map_Draw(x, y, w, h, xx, yy, p, cx, cy);
       {$IFDEF ENABLE_HOLMES}
         if p = gPlayer1 then
         begin
-          g_Holmes_plrViewPos(x, y);
-          g_Holmes_plrViewSize(w, h);
+          r_Holmes_plrViewPos(cx, cy);
+          r_Holmes_plrViewSize(h, w);
         end;
       {$ENDIF}
-      r_Map_Draw(x, y, w, h, xx, yy, p);
       r_Render_DrawStatsView(x, y, w, h, p);
       if p.Spectator and p.NoRespawn then
         r_Common_DrawText(_lc[I_PLAYER_SPECT4], x div 2 + w div 2, y div 2 + h div 2, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
     end
     else
     begin
-      r_Map_Draw(x, y, w, h, xx, yy, nil);
+      r_Map_Draw(x, y, w, h, xx, yy, nil, cx, cy);
     end;
 
     r_Draw_SetRect(l, t, r, b);
   end;
 
   procedure r_Render_DrawMapView (x, y, w, h, camx, camy: Integer);
-    var l, t, r, b: Integer;
+    var l, t, r, b, cx, cy: Integer;
   begin
     r_Draw_GetRect(l, t, r, b);
     r_Draw_SetRect(x, y, x + w, y + h);
-    r_Map_Draw(x, y, w, h, camx, camy, nil);
+    r_Map_Draw(x, y, w, h, camx, camy, nil, cx, cy);
     r_Draw_SetRect(l, t, r, b);
   end;
 
@@ -545,7 +573,7 @@ implementation
     w3 := cw * 8;           (* frags width *)
     w2 := cw * 12;          (* ping/loss width *)
     w1 := w - w2 - w3 - w4; (* name width *)
-    tw := w1 - cw * 2 - w2; (* team goals *)
+    tw := w1 - cw * 2 - w2; (* team score *)
     if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
     yy := y;
     if cs.GameMode in [GM_TDM, GM_CTF] then
@@ -1036,11 +1064,20 @@ implementation
   end;
 
   procedure r_Render_Draw;
-    var p1, p2: TPlayer; time: LongWord;
+    var p1, p2: TPlayer; time: LongWord; pw, ph: Integer;
   begin
     if gExit = EXIT_QUIT then
       exit;
 
+    {$IFDEF ENABLE_SYSTEM}
+      (* hack: if r_pixel_scale changed, reset menu and other things *)
+      pw := Round(gWinSizeX / r_pixel_scale);
+      ph := Round(gWinSizeY / r_pixel_scale);
+      if (pw <> gScreenWidth) or (ph <> gScreenHeight) then
+        if assigned(sys_ScreenResize) then
+          sys_ScreenResize(gWinSizeX, gWinSizeY);
+    {$ENDIF}
+
     INC(FPSCounter);
     time := GetTickCount64();
     if time - FPSTime >= 1000 then
@@ -1050,10 +1087,10 @@ implementation
       FPSTime := time;
     end;
 
-    r_Draw_Setup(gScreenWidth, gScreenHeight);
+    r_Draw_Setup(gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight);
 
     glClearColor(0.0, 0.0, 0.0, 0.0);
-    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
+    glClear(GL_COLOR_BUFFER_BIT);
 
     p1 := nil;
     p2 := nil;
@@ -1118,8 +1155,7 @@ implementation
         r_Render_DrawMiniMap(0, 0, 160);
 
       {$IFDEF ENABLE_HOLMES}
-        if g_holmes_enabled then
-          g_Holmes_Draw;
+        r_Holmes_Draw;
       {$ENDIF}
 
       if MessageText <> '' then
@@ -1229,10 +1265,13 @@ implementation
     // TODO draw profilers
 
     {$IFDEF ENABLE_HOLMES}
-      g_Holmes_DrawUI;
+      r_Holmes_DrawUI;
     {$ENDIF}
 
-    // TODO draw touch screen controls
+    {$IFDEF ENABLE_TOUCH}
+      glScalef(1 / r_pixel_scale, 1 / r_pixel_scale, 0);
+      r_Touch_Draw;
+    {$ENDIF}
 
     sys_Repaint;
   end;
@@ -1243,8 +1282,8 @@ implementation
     gWinSizeY := h;
     gRC_Width := w;
     gRC_Height := h;
-    gScreenWidth := w;
-    gScreenHeight := h;
+    gScreenWidth := Round(w / r_pixel_scale);
+    gScreenHeight := Round(h / r_pixel_scale);
   end;
 
   procedure r_Render_Apply;
@@ -1254,7 +1293,10 @@ implementation
         e_LogWriteln('resolution changed')
       else
         e_LogWriteln('resolution not changed');
-      sys_EnableVSync(gVSync)
+      sys_EnableVSync(gVSync);
+    {$ENDIF}
+    {$IFDEF NOGL_INIT}
+      nogl_Init;
     {$ENDIF}
   end;
 
@@ -1281,8 +1323,7 @@ implementation
 {$IFDEF ENABLE_TOUCH}
   procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
   begin
-    // TODO implement touchscreen
-    founded := False;
+    r_Touch_GetKeyRect(key, x, y, w, h, founded)
   end;
 {$ENDIF}
 
@@ -1333,4 +1374,21 @@ implementation
     r_Common_DrawLoading(force);
   end;
 
+{$IFDEF ENABLE_HOLMES}
+  function pmsCurMapX (): Integer;
+  begin
+    result := r_holmes.pmsCurMapX();
+  end;
+
+  function pmsCurMapY (): Integer;
+  begin
+    result := r_holmes.pmsCurMapY();
+  end;
+
+  function r_Render_HolmesViewIsSet (): Boolean;
+  begin
+    result := vpSet;
+  end;
+{$ENDIF}
+
 end.