From fcc33f0a09f0298f26dccd6b68ce2bcf7010be05 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 3 Apr 2018 22:50:47 +0200 Subject: [PATCH] - moved around more stuff from the FRenderer interface. --- src/d_main.cpp | 7 ++-- src/gl/scene/gl_scene.cpp | 56 ----------------------------- src/gl/system/gl_framebuffer.cpp | 61 ++++++++++++++++++++++++++++++++ src/gl/system/gl_framebuffer.h | 17 +++++---- src/p_setup.cpp | 6 ++-- src/r_renderer.h | 19 +++++----- src/r_utility.cpp | 3 +- src/swrenderer/r_swrenderer.cpp | 25 ++----------- src/swrenderer/r_swrenderer.h | 4 +-- src/v_video.cpp | 49 +++++++++++++++++-------- src/v_video.h | 15 +++----- 11 files changed, 133 insertions(+), 129 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 14766fe09..b3b4bf995 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -680,7 +680,7 @@ void D_Display () cycles.Clock(); r_UseVanillaTransparency = UseVanillaTransparency(); // [SP] Cache UseVanillaTransparency() call - r_renderercaps = Renderer->GetCaps(); // [SP] Get the current capabilities of the renderer + r_renderercaps = screen->GetCaps(); // [SP] Get the current capabilities of the renderer if (players[consoleplayer].camera == NULL) { @@ -808,8 +808,9 @@ void D_Display () Renderer->RenderView(&players[consoleplayer]); screen->Begin2D(viewactive); - Renderer->DrawRemainingPlayerSprites(); - screen->DrawBlendingRect(); + // todo: These need to go into RenderView. + //Renderer->DrawRemainingPlayerSprites(); + //screen->DrawBlendingRect(); if (automapactive) { AM_Drawer (hud_althud? viewheight : StatusBar->GetTopOfStatusbar()); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 986578b1c..9f6e75961 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -1003,10 +1003,6 @@ struct FGLInterface : public FRenderer void RenderView(player_t *player) override; void WriteSavePic (player_t *player, FileWriter *file, int width, int height) override; void RenderTextureView (FCanvasTexture *self, AActor *viewpoint, double fov) override; - void PreprocessLevel() override; - - void SetClearColor(int color) override; - uint32_t GetCaps() override; }; //========================================================================== @@ -1021,20 +1017,6 @@ void FGLInterface::Precache(uint8_t *texhitlist, TMap &actor gl_PrecacheTexture(texhitlist, actorhitlist); } -//=========================================================================== -// -// -// -//=========================================================================== - -void FGLInterface::SetClearColor(int color) -{ - PalEntry pe = GPalette.BaseColors[color]; - GLRenderer->mSceneClearColor[0] = pe.r / 255.f; - GLRenderer->mSceneClearColor[1] = pe.g / 255.f; - GLRenderer->mSceneClearColor[2] = pe.b / 255.f; -} - //=========================================================================== // // Render the view to a savegame picture @@ -1110,44 +1092,6 @@ void FGLInterface::RenderTextureView (FCanvasTexture *tex, AActor *Viewpoint, do camtexcount++; } -//=========================================================================== -// -// -// -//=========================================================================== -void FGLInterface::PreprocessLevel() -{ - if (GLRenderer != NULL) - { - GLRenderer->SetupLevel(); - } -} - -uint32_t FGLInterface::GetCaps() -{ - // describe our basic feature set - ActorRenderFeatureFlags FlagSet = RFF_FLATSPRITES | RFF_MODELS | RFF_SLOPE3DFLOORS | - RFF_TILTPITCH | RFF_ROLLSPRITES | RFF_POLYGONAL; - if (r_drawvoxels) - FlagSet |= RFF_VOXELS; - if (gl_legacy_mode) - { - // legacy mode always has truecolor because palette tonemap is not available - FlagSet |= RFF_TRUECOLOR; - } - else if (!(FGLRenderBuffers::IsEnabled())) - { - // truecolor is always available when renderbuffers are unavailable because palette tonemap is not possible - FlagSet |= RFF_TRUECOLOR | RFF_MATSHADER | RFF_BRIGHTMAP; - } - else - { - if (gl_tonemap != 5) // not running palette tonemap shader - FlagSet |= RFF_TRUECOLOR; - FlagSet |= RFF_MATSHADER | RFF_POSTSHADER | RFF_BRIGHTMAP; - } - return (uint32_t)FlagSet; -} //=========================================================================== // // diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index d7e362c5f..8bc3f3021 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -40,6 +40,7 @@ #include "gl/system/gl_interface.h" #include "gl/system/gl_framebuffer.h" #include "gl/renderer/gl_renderer.h" +#include "gl/renderer/gl_renderbuffers.h" #include "gl/renderer/gl_renderstate.h" #include "gl/renderer/gl_lightdata.h" #include "gl/textures/gl_hwtexture.h" @@ -189,6 +190,43 @@ void OpenGLFrameBuffer::Update() GLRenderer->SetOutputViewport(nullptr); } +//=========================================================================== +// +// +// +//=========================================================================== + +EXTERN_CVAR(Bool, r_drawvoxels) +EXTERN_CVAR(Int, gl_tonemap) +extern int currentrenderer; + +uint32_t OpenGLFrameBuffer::GetCaps() +{ + if (currentrenderer == 0) return Super::GetCaps(); + + // describe our basic feature set + ActorRenderFeatureFlags FlagSet = RFF_FLATSPRITES | RFF_MODELS | RFF_SLOPE3DFLOORS | + RFF_TILTPITCH | RFF_ROLLSPRITES | RFF_POLYGONAL; + if (r_drawvoxels) + FlagSet |= RFF_VOXELS; + if (gl.legacyMode) + { + // legacy mode always has truecolor because palette tonemap is not available + FlagSet |= RFF_TRUECOLOR; + } + else if (!(FGLRenderBuffers::IsEnabled())) + { + // truecolor is always available when renderbuffers are unavailable because palette tonemap is not possible + FlagSet |= RFF_TRUECOLOR | RFF_MATSHADER | RFF_BRIGHTMAP; + } + else + { + if (gl_tonemap != 5) // not running palette tonemap shader + FlagSet |= RFF_TRUECOLOR; + FlagSet |= RFF_MATSHADER | RFF_POSTSHADER | RFF_BRIGHTMAP; + } + return (uint32_t)FlagSet; +} //========================================================================== // @@ -329,6 +367,29 @@ void OpenGLFrameBuffer::GetFlash(PalEntry &rgb, int &amount) amount = Flash.a; } +void OpenGLFrameBuffer::InitForLevel() +{ + if (GLRenderer != NULL) + { + GLRenderer->SetupLevel(); + } +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void OpenGLFrameBuffer::SetClearColor(int color) +{ + PalEntry pe = GPalette.BaseColors[color]; + GLRenderer->mSceneClearColor[0] = pe.r / 255.f; + GLRenderer->mSceneClearColor[1] = pe.g / 255.f; + GLRenderer->mSceneClearColor[2] = pe.b / 255.f; +} + + //========================================================================== // // diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index c0274e3d8..378a083ad 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -39,13 +39,16 @@ public: bool SetContrast(float contrast); void DoSetGamma(); - void UpdatePalette(); - void GetFlashedPalette (PalEntry pal[256]); - PalEntry *GetPalette (); - bool SetFlash(PalEntry rgb, int amount); - void GetFlash(PalEntry &rgb, int &amount); - bool Begin2D(bool copy3d); - void GameRestart(); + void UpdatePalette() override; + void GetFlashedPalette (PalEntry pal[256]) override; + PalEntry *GetPalette () override; + bool SetFlash(PalEntry rgb, int amount) override; + void GetFlash(PalEntry &rgb, int &amount) override; + bool Begin2D(bool copy3d) override; + void GameRestart() override; + void InitForLevel() override; + void SetClearColor(int color) override; + uint32_t GetCaps() override; // Retrieves a buffer containing image data for a screenshot. // Hint: Pitch can be negative for upside-down images, in which case buffer diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 47877784a..f881e8eee 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -4128,9 +4128,9 @@ void P_SetupLevel (const char *lumpname, int position) } // This must be done BEFORE the PolyObj Spawn!!! - InitRenderInfo(); - Renderer->PreprocessLevel(); - SWRenderer->PreprocessLevel(); + InitRenderInfo(); // create hardware independent renderer resources for the level. + screen->InitForLevel(); // create hardware dependent level resources (e.g. the vertex buffer) + SWRenderer->SetColormap(); //The SW renderer needs to do some special setup for the level's default colormap. InitPortalGroups(); times[16].Clock(); diff --git a/src/r_renderer.h b/src/r_renderer.h index 1853e7f3a..3a2328396 100644 --- a/src/r_renderer.h +++ b/src/r_renderer.h @@ -18,23 +18,26 @@ class FileWriter; struct FRenderer { // precache one texture - virtual void Precache(uint8_t *texhitlist, TMap &actorhitlist) = 0; +virtual void Precache(uint8_t *texhitlist, TMap &actorhitlist) = 0; // render 3D view - virtual void RenderView(player_t *player) = 0; +virtual void RenderView(player_t *player) = 0; // renders view to a savegame picture - virtual void WriteSavePic (player_t *player, FileWriter *file, int width, int height) = 0; +virtual void WriteSavePic (player_t *player, FileWriter *file, int width, int height) = 0; + + // render to a camera texture +virtual void RenderTextureView(FCanvasTexture *tex, AActor *viewpoint, double fov) = 0; // draws player sprites with hardware acceleration (only useful for software rendering) virtual void DrawRemainingPlayerSprites() {} - virtual void OnModeSet () {} - virtual void SetClearColor(int color) = 0; - virtual void RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, double fov) = 0; - virtual void PreprocessLevel() {} + // set up the colormap for a newly loaded level. + virtual void SetColormap() {} - virtual uint32_t GetCaps() { return 0; } + virtual void OnModeSet () {} + + virtual void SetClearColor(int color) {}; }; diff --git a/src/r_utility.cpp b/src/r_utility.cpp index f3479bf6f..82f8f6caf 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -994,7 +994,8 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor { color = pr_hom(); } - Renderer->SetClearColor(color); + screen->SetClearColor(color); + SWRenderer->SetClearColor(color); } } diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index 583582d26..e2917300b 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -90,10 +90,11 @@ FRenderer *CreateSWRenderer() return new FSoftwareRenderer; } +EXTERN_CVAR(Bool, swtruecolor) void FSoftwareRenderer::PrecacheTexture(FTexture *tex, int cache) { - bool isbgra = screen->IsBgra(); + bool isbgra = swtruecolor; if (tex != NULL) { @@ -329,7 +330,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin r_viewwindow = cameraViewwindow; } -void FSoftwareRenderer::PreprocessLevel() +void FSoftwareRenderer::SetColormap() { // This just sets the default colormap for the spftware renderer. NormalLight.Maps = realcolormaps.Maps; @@ -341,23 +342,3 @@ void FSoftwareRenderer::PreprocessLevel() } } -uint32_t FSoftwareRenderer::GetCaps() -{ - ActorRenderFeatureFlags FlagSet = 0; - - if (r_polyrenderer) - FlagSet |= RFF_POLYGONAL | RFF_TILTPITCH | RFF_SLOPE3DFLOORS; - else - { - FlagSet |= RFF_UNCLIPPEDTEX; - if (r_drawvoxels) - FlagSet |= RFF_VOXELS; - } - - if (screen && screen->IsBgra()) - FlagSet |= RFF_TRUECOLOR; - else - FlagSet |= RFF_COLORMAP; - - return (uint32_t)FlagSet; -} diff --git a/src/swrenderer/r_swrenderer.h b/src/swrenderer/r_swrenderer.h index e5ac43628..113ce72a7 100644 --- a/src/swrenderer/r_swrenderer.h +++ b/src/swrenderer/r_swrenderer.h @@ -24,9 +24,7 @@ struct FSoftwareRenderer : public FRenderer void SetClearColor(int color) override; void RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, double fov) override; - void PreprocessLevel() override; - - uint32_t GetCaps() override; + void SetColormap() override; private: void PrecacheTexture(FTexture *tex, int cache); diff --git a/src/v_video.cpp b/src/v_video.cpp index 1c4319813..ecb4fba07 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -868,20 +868,6 @@ bool DFrameBuffer::Begin2D (bool copy3d) return false; } -//========================================================================== -// -// DFrameBuffer :: DrawBlendingRect -// -// In hardware 2D modes, the blending rect needs to be drawn separately -// from transferring the 3D scene to video memory, because the weapon -// sprite is drawn on top of that. -// -//========================================================================== - -void DFrameBuffer::DrawBlendingRect() -{ -} - //========================================================================== // // DFrameBuffer :: WipeStartScreen @@ -945,6 +931,37 @@ void DFrameBuffer::GameRestart() { } +//========================================================================== +// +// DFrameBuffer :: GetCaps +// +//========================================================================== + +EXTERN_CVAR(Bool, r_polyrenderer) +EXTERN_CVAR(Bool, r_drawvoxels) + +uint32_t DFrameBuffer::GetCaps() +{ + ActorRenderFeatureFlags FlagSet = 0; + + if (r_polyrenderer) + FlagSet |= RFF_POLYGONAL | RFF_TILTPITCH | RFF_SLOPE3DFLOORS; + else + { + FlagSet |= RFF_UNCLIPPEDTEX; + if (r_drawvoxels) + FlagSet |= RFF_VOXELS; + } + + if (swtruecolor) + FlagSet |= RFF_TRUECOLOR; + else + FlagSet |= RFF_COLORMAP; + + return (uint32_t)FlagSet; +} + + CCMD(clean) { Printf ("CleanXfac: %d\nCleanYfac: %d\n", CleanXfac, CleanYfac); @@ -1018,7 +1035,9 @@ void V_UpdateModeSize (int width, int height) DisplayHeight = height; R_OldBlend = ~0; - Renderer->OnModeSet(); + + // the software renderer also needs to be notified + SWRenderer->OnModeSet(); } void V_OutputResized (int width, int height) diff --git a/src/v_video.h b/src/v_video.h index a8ed14db1..84f1307e5 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -290,7 +290,6 @@ public: inline int GetWidth() const { return Width; } inline int GetHeight() const { return Height; } - inline bool IsBgra() const { return Bgra; } virtual DCanvas *GetCanvas() { return nullptr; } @@ -343,10 +342,7 @@ public: virtual bool LockCanvas() { return true; } virtual void UnlockCanvas() {} - // Begin 2D drawing operations. This is like Update, but it doesn't end - // the scene, and it doesn't present the image yet. If you are going to - // be covering the entire screen with 2D elements, then pass false to - // avoid copying the software buffer to the screen. + // Begin 2D drawing operations. // Returns true if hardware-accelerated 2D has been entered, false if not. virtual bool Begin2D(bool copy3d); void End2D() { isIn2D = false; } @@ -356,14 +352,11 @@ public: // DrawTexture calls after Begin2D use native textures. - // Draws the blending rectangle over the viewwindow if in hardware- - // accelerated 2D mode. - virtual void DrawBlendingRect(); - - // Precaches or unloads a texture - // Report a game restart virtual void GameRestart(); + virtual void InitForLevel() {} + virtual void SetClearColor(int color) {} + virtual uint32_t GetCaps(); // Screen wiping virtual bool WipeStartScreen(int type);