- made video base code game independent

This commit is contained in:
Christoph Oelckers 2020-04-28 17:22:17 +02:00
commit ddef3f7b98
56 changed files with 251 additions and 241 deletions

View file

@ -29,6 +29,7 @@
#include "templates.h"
#include "bitmap.h"
#include "hw_material.h"
#include "v_draw.h"
class FBurnTexture : public FTexture
{

View file

@ -48,6 +48,7 @@
#include "r_utility.h"
#include "hw_cvars.h"
#include "d_main.h"
#include "v_draw.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

@ -57,6 +57,7 @@
#include "gl_buffers.h"
#include "swrenderer/r_swscene.h"
#include "gl_postprocessstate.h"
#include "v_draw.h"
#include "flatvertices.h"
#include "hw_cvars.h"
@ -522,7 +523,7 @@ void OpenGLFrameBuffer::Draw2D()
if (GLRenderer != nullptr)
{
GLRenderer->mBuffers->BindCurrentFB();
::Draw2D(&m2DDrawer, gl_RenderState);
::Draw2D(twod, gl_RenderState);
}
}

View file

@ -43,6 +43,7 @@
#include "hw_lightbuffer.h"
#include "hw_vrmodes.h"
#include "hw_clipper.h"
#include "v_draw.h"
EXTERN_CVAR(Float, r_visibility)
CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE)

View file

@ -36,6 +36,7 @@
#include "hw_cvars.h"
#include "hw_renderstate.h"
#include "r_videoscale.h"
#include "v_draw.h"
//===========================================================================

View file

@ -28,6 +28,7 @@
#include "g_game.h"
#include "v_text.h"
#include "i_video.h"
#include "v_draw.h"
#include "hwrenderer/utility/hw_clock.h"
#include "hw_vrmodes.h"
@ -171,7 +172,7 @@ void PolyFrameBuffer::Update()
Flush3D.Clock();
Draw2D();
Clear2D();
twod->Clear();
Flush3D.Unclock();
@ -375,7 +376,7 @@ FTexture *PolyFrameBuffer::WipeStartScreen()
FTexture *PolyFrameBuffer::WipeEndScreen()
{
Draw2D();
Clear2D();
twod->Clear();
auto tex = new FWrapperTexture(mScreenViewport.width, mScreenViewport.height, 1);
auto systex = static_cast<PolyHardwareTexture*>(tex->GetSystemTexture());
@ -430,7 +431,7 @@ void PolyFrameBuffer::BeginFrame()
void PolyFrameBuffer::Draw2D()
{
::Draw2D(&m2DDrawer, *mRenderState);
::Draw2D(twod, *mRenderState);
}
unsigned int PolyFrameBuffer::GetLightBufferBlockSize() const

View file

@ -64,6 +64,7 @@
#include "actorinlines.h"
#include "g_game.h"
#include "i_system.h"
#include "v_draw.h"
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
@ -140,7 +141,6 @@ int LocalViewPitch;
bool LocalKeyboardTurner;
int setblocks;
bool setsizeneeded;
unsigned int R_OldBlend = ~0;
int validcount = 1; // increment every time a check is made
@ -368,7 +368,7 @@ CUSTOM_CVAR (Int, screenblocks, 10, CVAR_ARCHIVE)
//==========================================================================
FRenderer *CreateSWRenderer();
FRenderer* SWRenderer;
//==========================================================================
//
@ -1031,30 +1031,6 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
}
//==========================================================================
//
// CVAR transsouls
//
// How translucent things drawn with STYLE_SoulTrans are. Normally, only
// Lost Souls have this render style.
// Values less than 0.25 will automatically be set to
// 0.25 to ensure some degree of visibility. Likewise, values above 1.0 will
// be set to 1.0, because anything higher doesn't make sense.
//
//==========================================================================
CUSTOM_CVAR(Float, transsouls, 0.75f, CVAR_ARCHIVE)
{
if (self < 0.25f)
{
self = 0.25f;
}
else if (self > 1.f)
{
self = 1.f;
}
}
CUSTOM_CVAR(Float, maxviewpitch, 90.f, CVAR_ARCHIVE | CVAR_SERVERINFO)
{
if (self>90.f) self = 90.f;

View file

@ -37,6 +37,7 @@
#include "engineerrors.h"
#include "texturemanager.h"
#include "d_main.h"
#include "v_draw.h"
// [RH] Base blending values (for e.g. underwater)
int BaseBlendR, BaseBlendG, BaseBlendB;
@ -122,11 +123,11 @@ sector_t *SWSceneDrawer::RenderView(player_t *player)
auto map = swrenderer::CameraLight::Instance()->ShaderColormap();
DrawTexture(twod, fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE);
screen->Draw2D();
screen->Clear2D();
twod->Clear();
screen->PostProcessScene(true, CM_DEFAULT, [&]() {
SWRenderer->DrawRemainingPlayerSprites();
screen->Draw2D();
screen->Clear2D();
twod->Clear();
});
}
else
@ -143,7 +144,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player)
SWRenderer->DrawRemainingPlayerSprites();
screen->Draw2D();
screen->Clear2D();
twod->Clear();
}
return r_viewpoint.sector;

View file

@ -36,6 +36,7 @@
#include "c_dispatch.h"
#include "cmdlib.h"
#include "d_net.h"
#include "v_draw.h"
#include "g_level.h"
#include "r_utility.h"
#include "d_player.h"

View file

@ -23,7 +23,7 @@
#include <float.h>
#include "templates.h"
#include "v_draw.h"
#include "filesystem.h"
#include "doomdef.h"
#include "doomstat.h"

View file

@ -66,6 +66,7 @@
#include "swrenderer/r_memory.h"
#include "swrenderer/r_renderthread.h"
#include "g_levellocals.h"
#include "v_draw.h"
EXTERN_CVAR(Bool, r_drawplayersprites)
EXTERN_CVAR(Bool, r_deathcamera)

View file

@ -43,6 +43,7 @@
#include "swrenderer/plane/r_flatplane.h"
#include "swrenderer/drawers/r_draw_pal.h"
#include "swrenderer/drawers/r_draw_rgba.h"
#include "v_draw.h"
CVAR(String, r_viewsize, "", CVAR_NOSET)

View file

@ -35,23 +35,21 @@
#include <stdio.h>
#include "x86.h"
#include "actor.h"
#include "v_video.h"
#include "c_dispatch.h"
#include "sbar.h"
#include "hardware.h"
#include "r_utility.h"
#include "swrenderer/r_renderer.h"
#include "vm.h"
#include "r_videoscale.h"
#include "i_time.h"
#include "hwrenderer/scene/hw_portal.h"
#include "hwrenderer/utility/hw_clock.h"
#include "v_font.h"
#include "v_draw.h"
#include "i_time.h"
#include "v_2ddrawer.h"
#include "vm.h"
#include "i_interface.h"
#include "flatvertices.h"
#include "swrenderer/r_swscene.h"
#include "version.h"
#include "hw_material.h"
#include <chrono>
#include <thread>
@ -60,7 +58,7 @@
CVAR(Bool, gl_scale_viewport, true, CVAR_ARCHIVE);
EXTERN_CVAR(Int, vid_maxfps)
EXTERN_CVAR(Bool, cl_capfps)
CVAR(Bool, cl_capfps, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
EXTERN_CVAR(Int, screenblocks)
//==========================================================================
@ -75,21 +73,16 @@ EXTERN_CVAR(Int, screenblocks)
DFrameBuffer::DFrameBuffer (int width, int height)
{
SetSize(width, height);
mPortalState = new FPortalSceneState;
twod = &m2DDrawer;
}
DFrameBuffer::~DFrameBuffer()
{
if (twod == &m2DDrawer) twod = nullptr;
delete mPortalState;
}
void DFrameBuffer::SetSize(int width, int height)
{
Width = ViewportScaledWidth(width, height);
Height = ViewportScaledHeight(width, height);
m2DDrawer.SetSize(width, height);
}
//==========================================================================
@ -100,8 +93,6 @@ void DFrameBuffer::SetSize(int width, int height)
void DFrameBuffer::Update()
{
CheckBench();
int initialWidth = GetClientWidth();
int initialHeight = GetClientHeight();
int clientWidth = ViewportScaledWidth(initialWidth, initialHeight);
@ -182,19 +173,6 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds)
return;
}
// Special handling so the view with a visible status bar displays properly
int height, width;
if (screenblocks >= 10)
{
height = GetHeight();
width = GetWidth();
}
else
{
height = (screenblocks*GetHeight() / 10) & ~7;
width = (screenblocks*GetWidth() / 10);
}
// Back buffer letterbox for the final output
int clientWidth = GetClientWidth();
int clientHeight = GetClientHeight();
@ -222,10 +200,8 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds)
mScreenViewport.height = screenHeight;
// Viewport for the 3D scene
mSceneViewport.left = viewwindowx;
mSceneViewport.top = screenHeight - (height + viewwindowy - ((height - viewheight) / 2));
mSceneViewport.width = viewwidth;
mSceneViewport.height = height;
if (sysCallbacks && sysCallbacks->GetSceneRect) mSceneViewport = sysCallbacks->GetSceneRect();
else mSceneViewport = mScreenViewport;
// Scale viewports to fit letterbox
bool notScaled = ((mScreenViewport.width == ViewportScaledWidth(mScreenViewport.width, mScreenViewport.height)) &&

View file

@ -39,13 +39,8 @@
#include "c_cvars.h"
#include "x86.h"
#include "i_video.h"
#include "r_state.h"
#include "am_map.h"
#include "doomstat.h"
#include "c_console.h"
#include "hu_stuff.h"
#include "m_argv.h"
@ -54,23 +49,19 @@
#include "sc_man.h"
#include "filesystem.h"
#include "c_dispatch.h"
#include "cmdlib.h"
#include "sbar.h"
#include "hardware.h"
#include "m_png.h"
#include "r_utility.h"
#include "swrenderer/r_renderer.h"
#include "menu/menu.h"
#include "vm.h"
#include "r_videoscale.h"
#include "i_time.h"
#include "version.h"
#include "g_levellocals.h"
#include "am_map.h"
#include "texturemanager.h"
#include "v_palette.h"
#include "i_interface.h"
#include "v_draw.h"
#include "templates.h"
EXTERN_CVAR(Int, menu_resolution_custom_width)
EXTERN_CVAR(Int, menu_resolution_custom_height)
@ -83,37 +74,16 @@ CVAR(Bool, win_maximized, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITC
CUSTOM_CVAR(Int, vid_maxfps, 200, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (vid_maxfps < TICRATE && vid_maxfps != 0)
if (self < GameTicRate && self != 0)
{
vid_maxfps = TICRATE;
self = GameTicRate;
}
else if (vid_maxfps > 1000)
{
vid_maxfps = 1000;
self = 1000;
}
}
CUSTOM_CVAR(Int, vid_rendermode, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
if (self < 0 || self > 4)
{
self = 4;
}
else if (self == 2 || self == 3)
{
self = self - 2; // softpoly to software
}
if (usergame)
{
// [SP] Update pitch limits to the netgame/gamesim.
players[consoleplayer].SendPitchLimits();
}
screen->SetTextureFilterMode();
// No further checks needed. All this changes now is which scene drawer the render backend calls.
}
CUSTOM_CVAR(Int, vid_preferbackend, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
// [SP] This may seem pointless - but I don't want to implement live switching just
@ -146,10 +116,8 @@ CUSTOM_CVAR(Int, uiscale, 0, CVAR_ARCHIVE | CVAR_NOINITCALL)
self = 0;
return;
}
if (StatusBar != NULL)
{
StatusBar->CallScreenSizeChanged();
}
if (sysCallbacks && sysCallbacks->OnScreenSizeChanged)
sysCallbacks->OnScreenSizeChanged();
setsizeneeded = true;
}
@ -159,8 +127,6 @@ EXTERN_CVAR(Bool, r_blendmethod)
int active_con_scale();
FRenderer *SWRenderer;
#define DBGBREAK assert(0)
class DDummyFrameBuffer : public DFrameBuffer
@ -201,7 +167,8 @@ CUSTOM_CVAR (Bool, vid_vsync, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
}
// [RH] Set true when vid_setmode command has been executed
bool setmodeneeded = false;
bool setmodeneeded = false;
bool setsizeneeded = false;
//==========================================================================
//
@ -317,23 +284,15 @@ void V_UpdateModeSize (int width, int height)
DisplayWidth = width;
DisplayHeight = height;
R_OldBlend = ~0;
}
void V_OutputResized (int width, int height)
{
V_UpdateModeSize(width, height);
setsizeneeded = true;
if (StatusBar != NULL)
{
StatusBar->CallScreenSizeChanged();
}
C_NewModeAdjust();
// Reload crosshair if transitioned to a different size
ST_LoadCrosshair(true);
if (primaryLevel && primaryLevel->automap)
primaryLevel->automap->NewResolution();
if (sysCallbacks && sysCallbacks->OnScreenSizeChanged)
sysCallbacks->OnScreenSizeChanged();
}
bool IVideo::SetResolution ()
@ -430,10 +389,8 @@ void V_Init2()
CUSTOM_CVAR (Int, vid_aspect, 0, CVAR_GLOBALCONFIG|CVAR_ARCHIVE)
{
setsizeneeded = true;
if (StatusBar != NULL)
{
StatusBar->CallScreenSizeChanged();
}
if (sysCallbacks && sysCallbacks->OnScreenSizeChanged)
sysCallbacks->OnScreenSizeChanged();
}
DEFINE_ACTION_FUNCTION(_Screen, GetAspectRatio)
@ -460,7 +417,7 @@ void IVideo::DumpAdapters ()
Printf("Multi-monitor support unavailable.\n");
}
CUSTOM_CVAR_NAMED(Bool, vid_fullscreen, fullscreen, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
CUSTOM_CVAR(Bool, vid_fullscreen, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
setmodeneeded = true;
}
@ -496,7 +453,6 @@ DEFINE_GLOBAL(CleanXfac_1)
DEFINE_GLOBAL(CleanYfac_1)
DEFINE_GLOBAL(CleanWidth_1)
DEFINE_GLOBAL(CleanHeight_1)
DEFINE_GLOBAL(generic_ui)
IHardwareTexture* CreateHardwareTexture()
{
@ -505,51 +461,25 @@ IHardwareTexture* CreateHardwareTexture()
//==========================================================================
//
// V_DrawFrame
// CVAR transsouls
//
// Draw a frame around the specified area using the view border
// frame graphics. The border is drawn outside the area, not in it.
// How translucent things drawn with STYLE_SoulTrans are. Normally, only
// Lost Souls have this render style.
// Values less than 0.25 will automatically be set to
// 0.25 to ensure some degree of visibility. Likewise, values above 1.0 will
// be set to 1.0, because anything higher doesn't make sense.
//
//==========================================================================
void DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height)
CUSTOM_CVAR(Float, transsouls, 0.75f, CVAR_ARCHIVE)
{
FGameTexture* p;
const gameborder_t* border = &gameinfo.Border;
// Sanity check for incomplete gameinfo
if (border == NULL)
return;
int offset = border->offset;
int right = left + width;
int bottom = top + height;
// Draw top and bottom sides.
p = TexMan.GetGameTextureByName(border->t);
drawer->AddFlatFill(left, top - (int)p->GetDisplayHeight(), right, top, p, true);
p = TexMan.GetGameTextureByName(border->b);
drawer->AddFlatFill(left, bottom, right, bottom + (int)p->GetDisplayHeight(), p, true);
// Draw left and right sides.
p = TexMan.GetGameTextureByName(border->l);
drawer->AddFlatFill(left - (int)p->GetDisplayWidth(), top, left, bottom, p, true);
p = TexMan.GetGameTextureByName(border->r);
drawer->AddFlatFill(right, top, right + (int)p->GetDisplayWidth(), bottom, p, true);
// Draw beveled corners.
DrawTexture(drawer, TexMan.GetGameTextureByName(border->tl), left - offset, top - offset, TAG_DONE);
DrawTexture(drawer, TexMan.GetGameTextureByName(border->tr), left + width, top - offset, TAG_DONE);
DrawTexture(drawer, TexMan.GetGameTextureByName(border->bl), left - offset, top + height, TAG_DONE);
DrawTexture(drawer, TexMan.GetGameTextureByName(border->br), left + width, top + height, TAG_DONE);
if (self < 0.25f)
{
self = 0.25f;
}
else if (self > 1.f)
{
self = 1.f;
}
}
DEFINE_ACTION_FUNCTION(_Screen, DrawFrame)
{
PARAM_PROLOGUE;
PARAM_INT(x);
PARAM_INT(y);
PARAM_INT(w);
PARAM_INT(h);
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
DrawFrame(twod, x, y, w, h);
return 0;
}

View file

@ -35,8 +35,8 @@
#define __V_VIDEO_H__
#include <functional>
#include "basics.h"
#include "vectors.h"
#include "m_png.h"
#include "renderstyle.h"
#include "c_cvars.h"
@ -44,10 +44,7 @@
#include "intrect.h"
#include "hw_shadowmap.h"
static const int VID_MIN_WIDTH = 320;
static const int VID_MIN_HEIGHT = 200;
class player_t;
struct sector_t;
struct FPortalSceneState;
class FSkyVertexBuffer;
@ -128,9 +125,6 @@ class FTexture;
class DFrameBuffer
{
public:
F2DDrawer m2DDrawer;
private:
int Width = 0;
int Height = 0;
@ -144,7 +138,6 @@ public:
unsigned int uniformblockalignment = 256; // Hardware dependent uniform buffer alignment.
unsigned int maxuniformblock = 65536;
const char *vendorstring; // We have to account for some issues with particular vendors.
FPortalSceneState *mPortalState; // global portal state.
FSkyVertexBuffer *mSkyData = nullptr; // the sky vertex buffer
FFlatVertexBuffer *mVertexData = nullptr; // Global vertex data
HWViewpointBuffer *mViewpoints = nullptr; // Viewpoint render data.
@ -224,14 +217,6 @@ public:
virtual IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) { return nullptr; }
bool BuffersArePersistent() { return !!(hwcaps & RFL_BUFFER_STORAGE); }
// Begin/End 2D drawing operations.
void Begin2D()
{
m2DDrawer.Begin();
m2DDrawer.SetSize(Width, Height);
}
void End2D() { m2DDrawer.End(); }
// This is overridable in case Vulkan does it differently.
virtual bool RenderTextureIsFlipped() const
{
@ -255,7 +240,6 @@ public:
virtual void RenderTextureView(FCanvasTexture* tex, std::function<void(IntRect&)> renderFunc) {}
virtual void SetActiveRenderTarget() {}
// Screen wiping
virtual FTexture *WipeStartScreen();
virtual FTexture *WipeEndScreen();
@ -265,7 +249,6 @@ public:
void ScaleCoordsFromWindow(int16_t &x, int16_t &y);
virtual void Draw2D() {}
void Clear2D() { m2DDrawer.Clear(); }
virtual void SetViewportRects(IntRect *bounds);
int ScreenToWindowX(int x);
@ -310,14 +293,8 @@ void V_Init2 ();
void V_Shutdown ();
class FScanner;
struct FScriptPosition;
inline bool IsRatioWidescreen(int ratio) { return (ratio & 3) != 0; }
#include "v_draw.h"
extern bool setsizeneeded, setmodeneeded;
#endif // __V_VIDEO_H__

View file

@ -31,6 +31,7 @@
#include "g_game.h"
#include "v_text.h"
#include "version.h"
#include "v_draw.h"
#include "hwrenderer/utility/hw_clock.h"
#include "hw_vrmodes.h"
@ -192,7 +193,7 @@ void VulkanFrameBuffer::Update()
GetPostprocess()->SetActiveRenderTarget();
Draw2D();
Clear2D();
twod->Clear();
mRenderState->EndRenderPass();
mRenderState->EndFrame();
@ -480,7 +481,7 @@ FTexture *VulkanFrameBuffer::WipeEndScreen()
{
GetPostprocess()->SetActiveRenderTarget();
Draw2D();
Clear2D();
twod->Clear();
auto tex = new FWrapperTexture(mScreenViewport.width, mScreenViewport.height, 1);
auto systex = static_cast<VkHardwareTexture*>(tex->GetSystemTexture());
@ -643,7 +644,7 @@ void VulkanFrameBuffer::UpdateGpuStats()
void VulkanFrameBuffer::Draw2D()
{
::Draw2D(&m2DDrawer, *mRenderState);
::Draw2D(twod, *mRenderState);
}
VulkanCommandBuffer *VulkanFrameBuffer::GetTransferCommands()