- moved the frame rate drawer out of DFrameBuffer.

Too much of this is not shareable and all it consists of are drawing operations on the 2D drawer.
This commit is contained in:
Christoph Oelckers 2020-04-27 23:53:26 +02:00
parent 5f3e4a5d0e
commit 2196b4fb04
19 changed files with 155 additions and 162 deletions

View file

@ -47,6 +47,7 @@
#include "p_blockmap.h"
#include "g_game.h"
#include "v_video.h"
#include "d_main.h"
#include "m_cheat.h"
#include "c_dispatch.h"
@ -2139,7 +2140,7 @@ void DAutomap::drawSubsectors()
// is necessary in order to best reproduce Doom's original lighting.
double fadelevel;
if (vid_rendermode != 4 || primaryLevel->lightMode == ELightMode::Doom || primaryLevel->lightMode == ELightMode::ZDoomSoftware || primaryLevel->lightMode == ELightMode::DoomSoftware)
if (!V_IsHardwareRenderer() || primaryLevel->lightMode == ELightMode::Doom || primaryLevel->lightMode == ELightMode::ZDoomSoftware || primaryLevel->lightMode == ELightMode::DoomSoftware)
{
double map = (NUMCOLORMAPS * 2.) - ((floorlight + 12) * (NUMCOLORMAPS / 128.));
fadelevel = clamp((map - 12) / NUMCOLORMAPS, 0.0, 1.0);

View file

@ -12,6 +12,7 @@ struct SystemCallbacks
void (*CrashInfo)(char* buffer, size_t bufflen, const char* lfstr);
void (*PlayStartupSound)(const char* name);
bool (*IsSpecialUI)();
bool (*DisableTextureFilter)();
};
extern SystemCallbacks *sysCallbacks;

View file

@ -41,6 +41,7 @@
#include "gl/renderer/gl_renderer.h"
#include "gl_samplers.h"
#include "hw_material.h"
#include "i_interface.h"
namespace OpenGLRenderer
{
@ -98,7 +99,7 @@ uint8_t FSamplerManager::Bind(int texunit, int num, int lastval)
void FSamplerManager::SetTextureFilterMode()
{
UnbindAll();
int filter = V_IsHardwareRenderer() ? gl_texture_filter : 0;
int filter = sysCallbacks && sysCallbacks->DisableTextureFilter && sysCallbacks->DisableTextureFilter() ? 0 : gl_texture_filter;
for (int i = 0; i < 4; i++)
{

View file

@ -30,6 +30,7 @@
#include "hw_vrmodes.h"
#include "v_video.h"
#include "version.h"
#include "i_interface.h"
// Set up 3D-specific console variables:
CVAR(Int, vr_mode, 0, CVAR_GLOBALCONFIG)
@ -60,7 +61,9 @@ static VRMode vrmi_checker = { 2, isqrt2, isqrt2, 1.f,{ { -.5f, 1.f },{ .5f, 1.f
const VRMode *VRMode::GetVRMode(bool toscreen)
{
#ifdef VR3D_ENABLED
switch (toscreen && vid_rendermode == 4 ? vr_mode : 0)
int mode = !toscreen || (sysCallbacks && sysCallbacks->DisableTextureFilter && sysCallbacks->DisableTextureFilter()) ? 0 : vr_mode;
switch (mode)
{
default:
case VR_MONO:

View file

@ -182,6 +182,7 @@ EXTERN_CVAR (Bool, sv_cheats)
EXTERN_CVAR (Bool, sv_unlimited_pickup)
EXTERN_CVAR (Bool, r_drawplayersprites)
EXTERN_CVAR (Bool, show_messages)
EXTERN_CVAR(Bool, ticker)
extern bool setmodeneeded;
extern bool demorecording;
@ -260,6 +261,8 @@ CVAR (Bool, disableautoload, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBAL
CVAR (Bool, autoloadbrightmaps, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR (Bool, autoloadlights, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR (Bool, r_debug_disable_vis_filter, false, 0)
CVAR(Bool, vid_fps, false, 0)
CVAR(Int, vid_showpalette, 0, 0)
bool hud_toggled = false;
bool wantToRestart;
@ -832,6 +835,111 @@ static uint32_t GetCaps()
return (uint32_t)FlagSet;
}
//==========================================================================
//
//
//
//==========================================================================
static void DrawPaletteTester(int paletteno)
{
int blocksize = screen->GetHeight() / 50;
int t = paletteno;
int k = 0;
for (int i = 0; i < 16; ++i)
{
for (int j = 0; j < 16; ++j)
{
PalEntry pe;
if (t > 1)
{
auto palette = GPalette.GetTranslation(TRANSLATION_Standard, t - 2)->Palette;
pe = palette[k];
}
else GPalette.BaseColors[k];
k++;
Dim(twod, pe, 1.f, j * blocksize, i * blocksize, blocksize, blocksize);
}
}
}
//==========================================================================
//
// DFrameBuffer :: DrawRateStuff
//
// Draws the fps counter, dot ticker, and palette debug.
//
//==========================================================================
uint64_t LastCount;
static void DrawRateStuff()
{
static uint64_t LastMS = 0, LastSec = 0, FrameCount = 0, LastTic = 0;
// Draws frame time and cumulative fps
if (vid_fps)
{
uint64_t ms = screen->FrameTime;
uint64_t howlong = ms - LastMS;
if ((signed)howlong >= 0)
{
char fpsbuff[40];
int chars;
int rate_x;
int textScale = active_con_scale(twod);
chars = mysnprintf(fpsbuff, countof(fpsbuff), "%2llu ms (%3llu fps)", (unsigned long long)howlong, (unsigned long long)LastCount);
rate_x = screen->GetWidth() / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]);
ClearRect(twod, rate_x * textScale, 0, screen->GetWidth(), NewConsoleFont->GetHeight() * textScale, GPalette.BlackIndex, 0);
DrawText(twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char*)&fpsbuff[0],
DTA_VirtualWidth, screen->GetWidth() / textScale,
DTA_VirtualHeight, screen->GetHeight() / textScale,
DTA_KeepRatio, true, TAG_DONE);
uint32_t thisSec = (uint32_t)(ms / 1000);
if (LastSec < thisSec)
{
LastCount = FrameCount / (thisSec - LastSec);
LastSec = thisSec;
FrameCount = 0;
}
FrameCount++;
}
LastMS = ms;
}
int Height = screen->GetHeight();
// draws little dots on the bottom of the screen
if (ticker)
{
int64_t t = I_GetTime();
int64_t tics = t - LastTic;
LastTic = t;
if (tics > 20) tics = 20;
int i;
for (i = 0; i < tics * 2; i += 2) ClearRect(twod, i, Height - 1, i + 1, Height, 255, 0);
for (; i < 20 * 2; i += 2) ClearRect(twod, i, Height - 1, i + 1, Height, 0, 0);
}
// draws the palette for debugging
if (vid_showpalette)
{
DrawPaletteTester(vid_showpalette);
}
}
static void End2DAndUpdate()
{
DrawRateStuff();
twod->End();
screen->Update();
}
//==========================================================================
//
// D_Display
@ -1016,7 +1124,7 @@ void D_Display ()
screen->Begin2D();
C_DrawConsole ();
M_Drawer ();
screen->End2DAndUpdate ();
End2DAndUpdate ();
return;
case GS_INTERMISSION:
@ -1089,7 +1197,7 @@ void D_Display ()
M_Drawer (); // menu is drawn even on top of everything
if (!hud_toggled)
FStat::PrintStat (twod);
screen->End2DAndUpdate ();
End2DAndUpdate ();
}
else
{
@ -1120,7 +1228,7 @@ void D_Display ()
done = wiper->Run(1);
C_DrawConsole (); // console and
M_Drawer (); // menu are drawn even on top of wipes
screen->End2DAndUpdate ();
End2DAndUpdate ();
NetUpdate (); // [RH] not sure this is needed anymore
} while (!done);
delete wiper;
@ -2685,6 +2793,11 @@ static bool System_IsSpecialUI()
}
static bool System_DisableTextureFilter()
{
return !V_IsHardwareRenderer();
}
//==========================================================================
//
// DoomSpecificInfo
@ -2890,6 +3003,7 @@ static int D_DoomMain_Internal (void)
System_CrashInfo,
System_PlayStartupSound,
System_IsSpecialUI,
System_DisableTextureFilter,
};
sysCallbacks = &syscb;

View file

@ -31,6 +31,7 @@
#include "doomtype.h"
#include "gametype.h"
#include "startupinfo.h"
#include "c_cvars.h"
struct event_t;
@ -136,6 +137,19 @@ public:
else return 0;
}
};
EXTERN_CVAR(Int, vid_rendermode)
inline bool V_IsHardwareRenderer()
{
return vid_rendermode == 4;
}
inline bool V_IsTrueColor()
{
return vid_rendermode == 1 || vid_rendermode == 4;
}
#endif

View file

@ -79,6 +79,7 @@
#include "animations.h"
#include "texturemanager.h"
#include "p_lnspec.h"
#include "d_main.h"
extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position);

View file

@ -93,6 +93,7 @@
#include "v_video.h"
#include "gstrings.h"
#include "s_music.h"
#include "d_main.h"
static FRandom pr_skullpop ("SkullPop");
@ -632,7 +633,7 @@ void player_t::SendPitchLimits() const
{
int uppitch, downpitch;
if (V_IsSoftwareRenderer())
if (!V_IsHardwareRenderer())
{
uppitch = GetSoftPitch(false);
downpitch = GetSoftPitch(true);

View file

@ -47,6 +47,7 @@
#include "v_palette.h"
#include "r_utility.h"
#include "hw_cvars.h"
#include "d_main.h"
CVAR(Float, underwater_fade_scalar, 1.0f, CVAR_ARCHIVE) // [Nash] user-settable underwater blend intensity
CVAR( Float, blood_fade_scalar, 1.0f, CVAR_ARCHIVE ) // [SP] Pulled from Skulltag - changed default from 0.5 to 1.0

View file

@ -40,6 +40,7 @@
#include "hwrenderer/utility/hw_clock.h"
#include "flatvertices.h"
#include "v_palette.h"
#include "d_main.h"
#include "hw_lightbuffer.h"
#include "hw_cvars.h"

View file

@ -333,3 +333,5 @@ void CleanSWDrawer();
sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen);
void WriteSavePic(player_t* player, FileWriter* file, int width, int height);
sector_t* RenderView(player_t* player);

View file

@ -38,6 +38,7 @@
#include "v_font.h"
#include "texturemanager.h"
#include "modelrenderer.h"
#include "d_main.h"
EXTERN_CVAR(Bool, gl_precache)

View file

@ -154,6 +154,7 @@ ADD_STAT(lightstats)
static int printstats;
static bool switchfps;
static uint64_t waitstart;
extern uint64_t LastCount;
EXTERN_CVAR(Bool, vid_fps)
void CheckBench()
@ -175,7 +176,7 @@ void CheckBench()
AppendRenderTimes(compose);
AppendLightStats(compose);
//AppendMissingTextureStats(compose);
compose.AppendFormat("%llu fps\n\n", (unsigned long long)screen->GetLastFPS());
compose.AppendFormat("%llu fps\n\n", (unsigned long long)LastCount);
FILE *f = fopen("benchmarks.txt", "at");
if (f != NULL)

View file

@ -53,6 +53,7 @@
#include "image.h"
#include "imagehelpers.h"
#include "texturemanager.h"
#include "d_main.h"
// [BB] Use ZDoom's freelook limit for the sotfware renderer.
// Note: ZDoom's limit is chosen such that the sky is rendered properly.

View file

@ -36,6 +36,7 @@
#include "image.h"
#include "engineerrors.h"
#include "texturemanager.h"
#include "d_main.h"
// [RH] Base blending values (for e.g. underwater)
int BaseBlendR, BaseBlendG, BaseBlendB;

View file

@ -2,6 +2,7 @@
#include "textures.h"
#include "v_video.h"
#include "g_levellocals.h"
#include "d_main.h"
struct FSoftwareTextureSpan

View file

@ -58,36 +58,11 @@
CVAR(Bool, gl_scale_viewport, true, CVAR_ARCHIVE);
CVAR(Bool, vid_fps, false, 0)
CVAR(Int, vid_showpalette, 0, 0)
EXTERN_CVAR(Bool, ticker)
EXTERN_CVAR(Float, vid_brightness)
EXTERN_CVAR(Float, vid_contrast)
EXTERN_CVAR(Int, vid_maxfps)
EXTERN_CVAR(Bool, cl_capfps)
EXTERN_CVAR(Int, screenblocks)
//==========================================================================
//
// DCanvas :: CalcGamma
//
//==========================================================================
void DFrameBuffer::CalcGamma (float gamma, uint8_t gammalookup[256])
{
// I found this formula on the web at
// <http://panda.mostang.com/sane/sane-gamma.html>,
// but that page no longer exits.
double invgamma = 1.f / gamma;
int i;
for (i = 0; i < 256; i++)
{
gammalookup[i] = (uint8_t)(255.0 * pow (i / 255.0, invgamma) + 0.5);
}
}
//==========================================================================
//
// DFrameBuffer Constructor
@ -117,99 +92,6 @@ void DFrameBuffer::SetSize(int width, int height)
m2DDrawer.SetSize(width, height);
}
//==========================================================================
//
//
//
//==========================================================================
void V_DrawPaletteTester(int paletteno)
{
int blocksize = screen->GetHeight() / 50;
int t = paletteno;
int k = 0;
for (int i = 0; i < 16; ++i)
{
for (int j = 0; j < 16; ++j)
{
PalEntry pe;
if (t > 1)
{
auto palette = GPalette.GetTranslation(TRANSLATION_Standard, t - 2)->Palette;
pe = palette[k];
}
else GPalette.BaseColors[k];
k++;
Dim(twod, pe, 1.f, j*blocksize, i*blocksize, blocksize, blocksize);
}
}
}
//==========================================================================
//
// DFrameBuffer :: DrawRateStuff
//
// Draws the fps counter, dot ticker, and palette debug.
//
//==========================================================================
void DFrameBuffer::DrawRateStuff ()
{
// Draws frame time and cumulative fps
if (vid_fps)
{
uint64_t ms = screen->FrameTime;
uint64_t howlong = ms - LastMS;
if ((signed)howlong >= 0)
{
char fpsbuff[40];
int chars;
int rate_x;
int textScale = active_con_scale(twod);
chars = mysnprintf (fpsbuff, countof(fpsbuff), "%2llu ms (%3llu fps)", (unsigned long long)howlong, (unsigned long long)LastCount);
rate_x = Width / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]);
ClearRect (twod, rate_x * textScale, 0, Width, NewConsoleFont->GetHeight() * textScale, GPalette.BlackIndex, 0);
DrawText (twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char *)&fpsbuff[0],
DTA_VirtualWidth, screen->GetWidth() / textScale,
DTA_VirtualHeight, screen->GetHeight() / textScale,
DTA_KeepRatio, true, TAG_DONE);
uint32_t thisSec = (uint32_t)(ms/1000);
if (LastSec < thisSec)
{
LastCount = FrameCount / (thisSec - LastSec);
LastSec = thisSec;
FrameCount = 0;
}
FrameCount++;
}
LastMS = ms;
}
// draws little dots on the bottom of the screen
if (ticker)
{
int64_t t = I_GetTime();
int64_t tics = t - LastTic;
LastTic = t;
if (tics > 20) tics = 20;
int i;
for (i = 0; i < tics*2; i += 2) ClearRect(twod, i, Height-1, i+1, Height, 255, 0);
for ( ; i < 20*2; i += 2) ClearRect(twod, i, Height-1, i+1, Height, 0, 0);
}
// draws the palette for debugging
if (vid_showpalette)
{
V_DrawPaletteTester(vid_showpalette);
}
}
//==========================================================================
//
// Palette stuff.

View file

@ -83,7 +83,6 @@ extern int DisplayWidth, DisplayHeight;
void V_UpdateModeSize (int width, int height);
void V_OutputResized (int width, int height);
EXTERN_CVAR(Int, vid_rendermode)
EXTERN_CVAR(Bool, vid_fullscreen)
EXTERN_CVAR(Int, win_x)
EXTERN_CVAR(Int, win_y)
@ -91,23 +90,6 @@ EXTERN_CVAR(Int, win_w)
EXTERN_CVAR(Int, win_h)
EXTERN_CVAR(Bool, win_maximized)
inline bool V_IsHardwareRenderer()
{
return vid_rendermode == 4;
}
inline bool V_IsSoftwareRenderer()
{
return vid_rendermode < 2;
}
inline bool V_IsTrueColor()
{
return vid_rendermode == 1 || vid_rendermode == 4;
}
struct FColormap;
class FileWriter;
enum FTextureFormat : uint32_t;
@ -250,13 +232,6 @@ public:
}
void End2D() { m2DDrawer.End(); }
void End2DAndUpdate()
{
DrawRateStuff();
m2DDrawer.End();
Update();
}
// This is overridable in case Vulkan does it differently.
virtual bool RenderTextureIsFlipped() const
{
@ -289,14 +264,9 @@ public:
void ScaleCoordsFromWindow(int16_t &x, int16_t &y);
uint64_t GetLastFPS() const { return LastCount; }
virtual void Draw2D() {}
void Clear2D() { m2DDrawer.Clear(); }
// Calculate gamma table
void CalcGamma(float gamma, uint8_t gammalookup[256]);
virtual void SetViewportRects(IntRect *bounds);
int ScreenToWindowX(int x);
int ScreenToWindowY(int y);
@ -314,14 +284,9 @@ public:
// The original size of the framebuffer as selected in the video menu.
uint64_t FrameTime = 0;
protected:
void DrawRateStuff ();
private:
uint64_t fpsLimitTime = 0;
uint64_t LastMS = 0, LastSec = 0, FrameCount = 0, LastCount = 0, LastTic = 0;
bool isIn2D = false;
};

View file

@ -29,6 +29,7 @@
#include "vulkan/system/vk_builders.h"
#include "vk_samplers.h"
#include "hw_material.h"
#include "i_interface.h"
struct VkTexFilter
{
@ -83,7 +84,7 @@ void VkSamplerManager::SetTextureFilterMode()
void VkSamplerManager::Create()
{
int filter = V_IsHardwareRenderer() ? gl_texture_filter : 0;
int filter = sysCallbacks && sysCallbacks->DisableTextureFilter && sysCallbacks->DisableTextureFilter()? 0 : gl_texture_filter;
for(int i = 0; i < 7; i++)
{