From 1b043bb46c75efa6e068ee01b803cb79ea0220dd Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 15 Jan 2017 01:36:57 +0100 Subject: [PATCH] Minor cleanup in r_swrenderer --- src/swrenderer/r_swrenderer.cpp | 179 ++++++++++--------------------- src/swrenderer/r_swrenderer.h | 28 +---- src/swrenderer/scene/r_scene.cpp | 5 + 3 files changed, 65 insertions(+), 147 deletions(-) diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index a315385a3a..75348772f7 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -54,6 +54,9 @@ void gl_ParseDefs(); void gl_InitData(); +void gl_SetActorLights(AActor *); +void gl_PreprocessLevel(); +void gl_CleanLevelData(); EXTERN_CVAR(Bool, r_shadercolormaps) EXTERN_CVAR(Float, maxviewpitch) // [SP] CVAR from GZDoom @@ -82,12 +85,6 @@ FSoftwareRenderer::~FSoftwareRenderer() { } -//========================================================================== -// -// DCanvas :: Init -// -//========================================================================== - void FSoftwareRenderer::Init() { gl_ParseDefs(); @@ -96,38 +93,28 @@ void FSoftwareRenderer::Init() RenderScene::Instance()->Init(); } -//========================================================================== -// -// DCanvas :: UsesColormap -// -//========================================================================== - bool FSoftwareRenderer::UsesColormap() const { return true; } -//=========================================================================== -// -// Texture precaching -// -//=========================================================================== - void FSoftwareRenderer::PrecacheTexture(FTexture *tex, int cache) { + bool isbgra = screen->IsBgra(); + if (tex != NULL) { if (cache & FTextureManager::HIT_Columnmode) { const FTexture::Span *spanp; - if (r_swtruecolor) + if (isbgra) tex->GetColumnBgra(0, &spanp); else tex->GetColumn(0, &spanp); } else if (cache != 0) { - if (r_swtruecolor) + if (isbgra) tex->GetPixelsBgra(); else tex->GetPixels (); @@ -188,12 +175,6 @@ void FSoftwareRenderer::Precache(BYTE *texhitlist, TMap &act } } -//=========================================================================== -// -// Render the view -// -//=========================================================================== - void FSoftwareRenderer::RenderView(player_t *player) { if (r_polyrenderer) @@ -202,7 +183,6 @@ void FSoftwareRenderer::RenderView(player_t *player) r_swtruecolor = screen->IsBgra(); PolyRenderer::Instance()->RenderActorView(player->mo, false); - FCanvasTextureInfo::UpdateAll(); // Apply special colormap if the target cannot do it if (realfixedcolormap && r_swtruecolor && !(r_shadercolormaps && screen->Accel2D)) @@ -213,36 +193,32 @@ void FSoftwareRenderer::RenderView(player_t *player) } r_swtruecolor = saved_swtruecolor; - - return; - } - if (r_swtruecolor != screen->IsBgra()) + FCanvasTextureInfo::UpdateAll(); + } + else { - r_swtruecolor = screen->IsBgra(); - R_InitColumnDrawers(); + if (r_swtruecolor != screen->IsBgra()) + { + r_swtruecolor = screen->IsBgra(); + R_InitColumnDrawers(); + } + + R_BeginDrawerCommands(); + RenderScene::Instance()->RenderActorView(player->mo); + + // Apply special colormap if the target cannot do it + if (realfixedcolormap && r_swtruecolor && !(r_shadercolormaps && screen->Accel2D)) + { + DrawerCommandQueue::QueueCommand(realfixedcolormap, screen); + } + + R_EndDrawerCommands(); + + FCanvasTextureInfo::UpdateAll(); } - - R_BeginDrawerCommands(); - RenderScene::Instance()->RenderActorView(player->mo); - // [RH] Let cameras draw onto textures that were visible this frame. - FCanvasTextureInfo::UpdateAll (); - - // Apply special colormap if the target cannot do it - if (realfixedcolormap && r_swtruecolor && !(r_shadercolormaps && screen->Accel2D)) - { - DrawerCommandQueue::QueueCommand(realfixedcolormap, screen); - } - - R_EndDrawerCommands(); } -//========================================================================== -// -// -// -//========================================================================== - void FSoftwareRenderer::RemapVoxels() { for (unsigned i=0; iScreenResized(); - - RenderTarget = screen; - screen->Lock (true); - R_SetupBuffer (); - screen->Unlock (); } -//=========================================================================== -// -// -// -//=========================================================================== - void FSoftwareRenderer::ErrorCleanup () { Clip3DFloors::Instance()->Cleanup(); } -//=========================================================================== -// -// -// -//=========================================================================== - void FSoftwareRenderer::ClearBuffer(int color) { - // [SP] For now, for truecolor, this just outputs black. We'll figure out how to get something more meaningful - // later when this actually matters more. This is just to clear HOMs for now. if (!r_swtruecolor) + { memset(RenderTarget->GetBuffer(), color, RenderTarget->GetPitch() * RenderTarget->GetHeight()); + } else - memset(RenderTarget->GetBuffer(), 0, RenderTarget->GetPitch() * RenderTarget->GetHeight() * 4); + { + uint32_t bgracolor = GPalette.BaseColors[color].d; + int size = RenderTarget->GetPitch() * RenderTarget->GetHeight(); + uint32_t *dest = (uint32_t *)RenderTarget->GetBuffer(); + for (int i = 0; i < size; i++) + dest[i] = bgracolor; + } } -//=========================================================================== -// -// -// -//=========================================================================== - void FSoftwareRenderer::SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, float trueratio) { R_SWRSetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio); } -//=========================================================================== -// -// -// -//=========================================================================== - void FSoftwareRenderer::SetupFrame(player_t *player) { R_SetupColormap(player); R_SetupFreelook(); } -//========================================================================== -// -// R_CopyStackedViewParameters -// -//========================================================================== - void FSoftwareRenderer::CopyStackedViewParameters() { RenderPortal::Instance()->CopyStackedViewParameters(); } -//========================================================================== -// -// -// -//========================================================================== - void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) { BYTE *Pixels = r_swtruecolor ? (BYTE*)tex->GetPixelsBgra() : (BYTE*)tex->GetPixels(); @@ -410,10 +325,12 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin DAngle savedfov = FieldOfView; R_SetFOV ((double)fov); + if (r_polyrenderer) PolyRenderer::Instance()->RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); else RenderScene::Instance()->RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); + R_SetFOV (savedfov); if (Canvas->IsBgra()) @@ -473,3 +390,17 @@ sector_t *FSoftwareRenderer::FakeFlat(sector_t *sec, sector_t *tempsec, int *flo return RenderOpaquePass::Instance()->FakeFlat(sec, tempsec, floorlightlevel, ceilinglightlevel, nullptr, 0, 0, 0, 0); } +void FSoftwareRenderer::StateChanged(AActor *actor) +{ + gl_SetActorLights(actor); +} + +void FSoftwareRenderer::PreprocessLevel() +{ + gl_PreprocessLevel(); +} + +void FSoftwareRenderer::CleanLevelData() +{ + gl_CleanLevelData(); +} diff --git a/src/swrenderer/r_swrenderer.h b/src/swrenderer/r_swrenderer.h index c09542959c..87496882ff 100644 --- a/src/swrenderer/r_swrenderer.h +++ b/src/swrenderer/r_swrenderer.h @@ -1,12 +1,8 @@ -#ifndef __R_SWRENDERER_H -#define __R_SWRENDERER_H + +#pragma once #include "r_renderer.h" -void gl_SetActorLights(AActor *); -void gl_PreprocessLevel(); -void gl_CleanLevelData(); - struct FSoftwareRenderer : public FRenderer { FSoftwareRenderer(); @@ -44,22 +40,8 @@ struct FSoftwareRenderer : public FRenderer void RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) override; sector_t *FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel) override; - void StateChanged(AActor *actor) override - { - gl_SetActorLights(actor); - } - - void PreprocessLevel() override - { - gl_PreprocessLevel(); - } - - void CleanLevelData() override - { - gl_CleanLevelData(); - } + void StateChanged(AActor *actor) override; + void PreprocessLevel() override; + void CleanLevelData() override; }; - - -#endif diff --git a/src/swrenderer/scene/r_scene.cpp b/src/swrenderer/scene/r_scene.cpp index 75946f367c..15dfa265a6 100644 --- a/src/swrenderer/scene/r_scene.cpp +++ b/src/swrenderer/scene/r_scene.cpp @@ -188,6 +188,11 @@ namespace swrenderer void RenderScene::ScreenResized() { VisiblePlaneList::Instance()->Init(); + + RenderTarget = screen; + screen->Lock(true); + R_SetupBuffer(); + screen->Unlock(); } void RenderScene::Init()