From 1e2a3da5fdd61eaada9d52b9e79485dc572d6c4f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 28 Apr 2020 22:55:37 +0200 Subject: [PATCH] - video base code unified. # Conflicts: # source/core/rendering/v_video.cpp --- source/blood/src/screen.cpp | 2 +- source/build/include/build.h | 2 +- source/build/src/engine.cpp | 12 ++ source/core/gamecontrol.cpp | 15 +++ .../rendering/gl/renderer/gl_renderer.cpp | 3 +- .../rendering/gl/system/gl_framebuffer.cpp | 37 ------ source/core/rendering/v_framebuffer.cpp | 29 ++--- source/core/rendering/v_video.cpp | 115 ++++++++++++------ source/core/rendering/v_video.h | 2 +- source/duke3d/src/game.cpp | 2 +- source/exhumed/src/init.cpp | 2 +- source/glbackend/glbackend.cpp | 39 ++++++ source/rr/src/game.cpp | 2 +- source/sw/src/game.cpp | 2 +- 14 files changed, 158 insertions(+), 106 deletions(-) diff --git a/source/blood/src/screen.cpp b/source/blood/src/screen.cpp index c89d4242c..7a27f893f 100644 --- a/source/blood/src/screen.cpp +++ b/source/blood/src/screen.cpp @@ -135,7 +135,7 @@ void scrInit(void) void scrSetGameMode(int vidMode, int XRes, int YRes, int nBits) { - V_Init2(); + videoInit(); videoClearViewableArea(0); videoNextPage(); scrSetPalette(curPalette); diff --git a/source/build/include/build.h b/source/build/include/build.h index c2eba99d4..e4cfe1503 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -852,6 +852,7 @@ static FORCE_INLINE int32_t drawrooms(int32_t daposx, int32_t daposy, int32_t da } void renderDrawMasks(void); +void videoInit(); void videoClearViewableArea(int32_t dacol); void videoClearScreen(int32_t dacol); void renderDrawMapView(int32_t dax, int32_t day, int32_t zoome, int16_t ang); @@ -1297,7 +1298,6 @@ extern void(*PolymostProcessVoxels_Callback)(void); class F2DDrawer; -extern F2DDrawer twodgen; extern F2DDrawer twodpsp; extern F2DDrawer* twod; diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 131512a4c..aaa84183b 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -4074,6 +4074,8 @@ void videoNextPage(void) beforedrawrooms = 1; numframes++; + twod->SetSize(screen->GetWidth(), screen->GetHeight()); + twodpsp.SetSize(screen->GetWidth(), screen->GetHeight()); } // @@ -5342,6 +5344,16 @@ void rotatesprite_(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, +void videoInit() +{ + V_Init2(); + videoSetGameMode(vid_fullscreen, SCREENWIDTH, SCREENHEIGHT, 32, 1); + + Polymost_Startup(); + GLInterface.Init(SCREENHEIGHT); + GLInterface.InitGLState(4, 4/*glmultisample*/); + screen->SetTextureFilterMode(); +} // // clearview diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index e269842b6..9d396409e 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -192,6 +192,19 @@ static bool System_DisableTextureFilter() return hw_useindexedcolortextures; } +static IntRect System_GetSceneRect() +{ + // Special handling so the view with a visible status bar displays properly + int height = windowxy2.y - windowxy1.y + 1, width = windowxy2.x - windowxy1.x + 1; + + IntRect mSceneViewport; + mSceneViewport.left = windowxy1.x; + mSceneViewport.top = windowxy1.y; + mSceneViewport.width = width; + mSceneViewport.height = height; + return mSceneViewport; +} + //========================================================================== // // DoomSpecificInfo @@ -481,6 +494,8 @@ int GameMain() nullptr, nullptr, System_DisableTextureFilter, + nullptr, + System_GetSceneRect, }; sysCallbacks = &syscb; diff --git a/source/core/rendering/gl/renderer/gl_renderer.cpp b/source/core/rendering/gl/renderer/gl_renderer.cpp index 1f716c891..1b3ea328f 100644 --- a/source/core/rendering/gl/renderer/gl_renderer.cpp +++ b/source/core/rendering/gl/renderer/gl_renderer.cpp @@ -42,6 +42,7 @@ #include "m_png.h" #include "version.h" #include "texturemanager.h" +#include "model.h" //#include "hwrenderer/utility/hw_clock.h" #include "gl_load/gl_interface.h" @@ -113,7 +114,7 @@ void FGLRenderer::Initialize(int width, int height) FGLRenderer::~FGLRenderer() { - //FlushModels(); + FlushModels(); TexMan.FlushAll(); if (mShaderManager != nullptr) delete mShaderManager; if (mSamplerManager != nullptr) delete mSamplerManager; diff --git a/source/core/rendering/gl/system/gl_framebuffer.cpp b/source/core/rendering/gl/system/gl_framebuffer.cpp index 513258cd5..6c1d307fd 100644 --- a/source/core/rendering/gl/system/gl_framebuffer.cpp +++ b/source/core/rendering/gl/system/gl_framebuffer.cpp @@ -431,40 +431,3 @@ void OpenGLFrameBuffer::PostProcessScene(bool swscene, int fixedcm, const std::f } -void videoShowFrame(int32_t w) -{ - static GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 }; - - if (gl_ssao) - { - glDrawBuffers(1, buffers); - OpenGLRenderer::GLRenderer->AmbientOccludeScene(GLInterface.GetProjectionM5()); - glViewport(screen->mSceneViewport.left, screen->mSceneViewport.top, screen->mSceneViewport.width, screen->mSceneViewport.height); - OpenGLRenderer::GLRenderer->mBuffers->BindSceneFB(true); - glDrawBuffers(3, buffers); - - // To do: the translucent part of the scene should be drawn here - - glDrawBuffers(1, buffers); - } - - OpenGLRenderer::GLRenderer->mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture - screen->PostProcessScene(false, 0, []() { - GLInterface.Draw2D(&twodpsp); // draws the weapon sprites - }); - screen->Update(); - // After finishing the frame, reset everything for the next frame. This needs to be done better. - screen->BeginFrame(); - if (gl_ssao) - { - OpenGLRenderer::GLRenderer->mBuffers->BindSceneFB(true); - glDrawBuffers(3, buffers); - } - else - { - OpenGLRenderer::GLRenderer->mBuffers->BindSceneFB(false); - } - twodpsp.Clear(); - twod->Clear(); - GLInterface.ResetFrame(); -} diff --git a/source/core/rendering/v_framebuffer.cpp b/source/core/rendering/v_framebuffer.cpp index 2262c5737..1568fa61f 100644 --- a/source/core/rendering/v_framebuffer.cpp +++ b/source/core/rendering/v_framebuffer.cpp @@ -45,16 +45,11 @@ #include "v_draw.h" #include "i_time.h" #include "v_2ddrawer.h" -#include "build.h" #include "vm.h" -#include "../glbackend/glbackend.h" -#include "hw_material.h" -/* -#include "hwrenderer/scene/hw_portal.h" -#include "hwrenderer/utility/hw_clock.h" -*/ -#include "hwrenderer/data/flatvertices.h" +#include "i_interface.h" +#include "flatvertices.h" #include "version.h" +#include "hw_material.h" #include #include @@ -63,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) //========================================================================== @@ -77,6 +72,7 @@ EXTERN_CVAR(Int, screenblocks) DFrameBuffer::DFrameBuffer (int width, int height) { + twod = &m2DDrawer; SetSize(width, height); } @@ -88,8 +84,6 @@ void DFrameBuffer::SetSize(int width, int height) { Width = ViewportScaledWidth(width, height); Height = ViewportScaledHeight(width, height); - twodgen.SetSize(Width, Height); - twodpsp.SetSize(Width, Height); } //========================================================================== @@ -100,8 +94,6 @@ void DFrameBuffer::SetSize(int width, int height) void DFrameBuffer::Update() { - //CheckBench(); - int initialWidth = GetClientWidth(); int initialHeight = GetClientHeight(); int clientWidth = ViewportScaledWidth(initialWidth, initialHeight); @@ -182,9 +174,6 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds) return; } - // Special handling so the view with a visible status bar displays properly - int height = windowxy2.y - windowxy1.y + 1, width = windowxy2.x - windowxy1.x + 1; - // Back buffer letterbox for the final output int clientWidth = GetClientWidth(); int clientHeight = GetClientHeight(); @@ -212,10 +201,8 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds) mScreenViewport.height = screenHeight; // Viewport for the 3D scene - mSceneViewport.left = windowxy1.x; - mSceneViewport.top = windowxy1.y; - mSceneViewport.width = width; - 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)) && @@ -261,7 +248,6 @@ void DFrameBuffer::ScaleCoordsFromWindow(int16_t &x, int16_t &y) void DFrameBuffer::FPSLimit() { -#if 0 // This doesn't work with Build games. using namespace std::chrono; using namespace std::this_thread; @@ -292,7 +278,6 @@ void DFrameBuffer::FPSLimit() sleep_for(microseconds(timeToWait - 2'000)); } } -#endif } FMaterial* DFrameBuffer::CreateMaterial(FGameTexture* tex, int scaleflags) diff --git a/source/core/rendering/v_video.cpp b/source/core/rendering/v_video.cpp index 978a9b9fc..47697c655 100644 --- a/source/core/rendering/v_video.cpp +++ b/source/core/rendering/v_video.cpp @@ -48,21 +48,24 @@ #include "v_text.h" #include "sc_man.h" +#include "filesystem.h" #include "c_dispatch.h" #include "cmdlib.h" #include "hardware.h" #include "m_png.h" #include "menu/menu.h" +#include "vm.h" #include "r_videoscale.h" #include "i_time.h" #include "version.h" -#include "filesystem.h" -#include "build.h" -#include "glbackend/glbackend.h" +#include "texturemanager.h" +#include "i_interface.h" +#include "v_draw.h" +#include "templates.h" +#include "palette.h" EXTERN_CVAR(Int, menu_resolution_custom_width) EXTERN_CVAR(Int, menu_resolution_custom_height) -CVAR(Int, vid_aspect, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Int, win_x, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Int, win_y, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) @@ -70,38 +73,17 @@ CVAR(Int, win_w, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Int, win_h, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, win_maximized, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) -#if 0 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; } } -#endif - -CUSTOM_CVAR(Int, vid_rendermode, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) -{ - if (self < 0 || self > 4) - { - self = 4; - } - -#if 0 - if (usergame) - { - // [SP] Update pitch limits to the netgame/gamesim. - players[consoleplayer].SendPitchLimits(); - } -#endif - 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) { @@ -128,6 +110,19 @@ CUSTOM_CVAR(Int, vid_preferbackend, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_N CVAR(Int, vid_renderer, 1, 0) // for some stupid mods which threw caution out of the window... +CUSTOM_CVAR(Int, uiscale, 0, CVAR_ARCHIVE | CVAR_NOINITCALL) +{ + if (self < 0) + { + self = 0; + return; + } + if (sysCallbacks && sysCallbacks->OnScreenSizeChanged) + sysCallbacks->OnScreenSizeChanged(); + setsizeneeded = true; +} + + EXTERN_CVAR(Bool, r_blendmethod) @@ -297,6 +292,8 @@ void V_OutputResized (int width, int height) V_UpdateModeSize(width, height); setsizeneeded = true; C_NewModeAdjust(); + if (sysCallbacks && sysCallbacks->OnScreenSizeChanged) + sysCallbacks->OnScreenSizeChanged(); } bool IVideo::SetResolution () @@ -362,7 +359,6 @@ void V_InitScreen() void V_Init2() { lookups.postLoadLookups(); - twod = &twodgen; float gamma = static_cast(screen)->Gamma; @@ -390,14 +386,14 @@ void V_Init2() screen->SetVSync(vid_vsync); FBaseCVar::ResetColors (); C_NewModeAdjust(); - videoSetGameMode(vid_fullscreen, SCREENWIDTH, SCREENHEIGHT, 32, 1); + setsizeneeded = true; +} - Polymost_Startup(); - GLInterface.Init(SCREENHEIGHT); - GLInterface.InitGLState(4, 4/*glmultisample*/); - screen->SetTextureFilterMode(); - - //setsizeneeded = true; +CUSTOM_CVAR (Int, vid_aspect, 0, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) +{ + setsizeneeded = true; + if (sysCallbacks && sysCallbacks->OnScreenSizeChanged) + sysCallbacks->OnScreenSizeChanged(); } @@ -438,6 +434,47 @@ CCMD(vid_listadapters) } bool vid_hdr_active = false; -F2DDrawer twodpsp, twodgen; -CVAR(Float, transsouls, 1, 0) -CVAR(Int, uiscale, 0, CVAR_ARCHIVE) \ No newline at end of file + +DEFINE_GLOBAL(SmallFont) +DEFINE_GLOBAL(SmallFont2) +DEFINE_GLOBAL(BigFont) +DEFINE_GLOBAL(ConFont) +DEFINE_GLOBAL(NewConsoleFont) +DEFINE_GLOBAL(NewSmallFont) +DEFINE_GLOBAL(AlternativeSmallFont) +DEFINE_GLOBAL(OriginalSmallFont) +DEFINE_GLOBAL(OriginalBigFont) +DEFINE_GLOBAL(IntermissionFont) +DEFINE_GLOBAL(CleanXfac) +DEFINE_GLOBAL(CleanYfac) +DEFINE_GLOBAL(CleanWidth) +DEFINE_GLOBAL(CleanHeight) +DEFINE_GLOBAL(CleanXfac_1) +DEFINE_GLOBAL(CleanYfac_1) +DEFINE_GLOBAL(CleanWidth_1) +DEFINE_GLOBAL(CleanHeight_1) + +//========================================================================== +// +// 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; + } +} + diff --git a/source/core/rendering/v_video.h b/source/core/rendering/v_video.h index 336262e77..44769dd79 100644 --- a/source/core/rendering/v_video.h +++ b/source/core/rendering/v_video.h @@ -127,7 +127,7 @@ class DFrameBuffer { protected: - //F2DDrawer m2DDrawer; + F2DDrawer m2DDrawer; private: int Width = 0; int Height = 0; diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 186b65d69..aa4c28deb 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -5779,7 +5779,7 @@ int GameInterface::app_main() if (g_networkMode != NET_DEDICATED_SERVER) { - V_Init2(); + videoInit(); videoSetPalette(0, myplayer.palette, 0); } diff --git a/source/exhumed/src/init.cpp b/source/exhumed/src/init.cpp index 5497a0c21..8d20abed1 100644 --- a/source/exhumed/src/init.cpp +++ b/source/exhumed/src/init.cpp @@ -219,7 +219,7 @@ void InstallEngine() } uploadCinemaPalettes(); LoadPaletteLookups(); - V_Init2(); + videoInit(); enginecompatibility_mode = ENGINECOMPATIBILITY_19950829; } diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 9b005e9c7..9d8758342 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -54,6 +54,8 @@ #include "v_draw.h" #include "v_font.h" +F2DDrawer twodpsp; + float shadediv[MAXPALOOKUPS]; static int blendstyles[] = { GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA }; @@ -633,3 +635,40 @@ void DrawRateStuff() } } +void videoShowFrame(int32_t w) +{ + static GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 }; + + if (gl_ssao) + { + glDrawBuffers(1, buffers); + OpenGLRenderer::GLRenderer->AmbientOccludeScene(GLInterface.GetProjectionM5()); + glViewport(screen->mSceneViewport.left, screen->mSceneViewport.top, screen->mSceneViewport.width, screen->mSceneViewport.height); + OpenGLRenderer::GLRenderer->mBuffers->BindSceneFB(true); + glDrawBuffers(3, buffers); + + // To do: the translucent part of the scene should be drawn here + + glDrawBuffers(1, buffers); + } + + OpenGLRenderer::GLRenderer->mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture + screen->PostProcessScene(false, 0, []() { + GLInterface.Draw2D(&twodpsp); // draws the weapon sprites + }); + screen->Update(); + // After finishing the frame, reset everything for the next frame. This needs to be done better. + screen->BeginFrame(); + if (gl_ssao) + { + OpenGLRenderer::GLRenderer->mBuffers->BindSceneFB(true); + glDrawBuffers(3, buffers); + } + else + { + OpenGLRenderer::GLRenderer->mBuffers->BindSceneFB(false); + } + twodpsp.Clear(); + twod->Clear(); + GLInterface.ResetFrame(); +} diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index b2e48e747..7151cbed0 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -7171,7 +7171,7 @@ int GameInterface::app_main() g_clipMapFiles.Reset(); #endif - V_Init2(); + videoInit(); videoSetPalette(0, g_player[myconnectindex].ps->palette, 0); // check if the minifont will support lowercase letters (3136-3161) diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 2bc8ad0dd..3d92d3802 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -816,7 +816,7 @@ bool InitGame() enginePostInit(); - V_Init2(); + videoInit(); DemoModeMenuInit = TRUE; // precache as much stuff as you can