Minor cleanup in r_swrenderer

This commit is contained in:
Magnus Norddahl 2017-01-15 01:36:57 +01:00
parent d707f1c22e
commit 1b043bb46c
3 changed files with 65 additions and 147 deletions

View file

@ -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<PClassActor*, bool> &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))
@ -214,35 +194,31 @@ void FSoftwareRenderer::RenderView(player_t *player)
r_swtruecolor = saved_swtruecolor;
return;
FCanvasTextureInfo::UpdateAll();
}
if (r_swtruecolor != screen->IsBgra())
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<ApplySpecialColormapRGBACommand>(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<ApplySpecialColormapRGBACommand>(realfixedcolormap, screen);
}
R_EndDrawerCommands();
}
//==========================================================================
//
//
//
//==========================================================================
void FSoftwareRenderer::RemapVoxels()
{
for (unsigned i=0; i<Voxels.Size(); i++)
@ -251,12 +227,6 @@ void FSoftwareRenderer::RemapVoxels()
}
}
//===========================================================================
//
// Render the view to a savegame picture
//
//===========================================================================
void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height)
{
DCanvas *pic = new DSimpleCanvas (width, height, false);
@ -277,12 +247,6 @@ void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int wi
delete pic;
}
//===========================================================================
//
//
//
//===========================================================================
void FSoftwareRenderer::DrawRemainingPlayerSprites()
{
if (!r_polyrenderer)
@ -295,16 +259,10 @@ void FSoftwareRenderer::DrawRemainingPlayerSprites()
}
}
//===========================================================================
//
// Get max. view angle (renderer specific information so it goes here now)
//
//===========================================================================
#define MAX_DN_ANGLE 56 // Max looking down angle
#define MAX_UP_ANGLE 32 // Max looking up angle
int FSoftwareRenderer::GetMaxViewPitch(bool down)
{
const int MAX_DN_ANGLE = 56; // Max looking down angle
const int MAX_UP_ANGLE = 32; // Max looking up angle
return (r_polyrenderer) ? int(maxviewpitch) : (down ? MAX_DN_ANGLE : MAX_UP_ANGLE);
}
@ -313,91 +271,48 @@ bool FSoftwareRenderer::RequireGLNodes()
return true;
}
//==========================================================================
//
// OnModeSet
//
// Called from V_SetResolution()
//
//==========================================================================
void FSoftwareRenderer::OnModeSet ()
{
RenderScene::Instance()->ScreenResized();
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();
}

View file

@ -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

View file

@ -188,6 +188,11 @@ namespace swrenderer
void RenderScene::ScreenResized()
{
VisiblePlaneList::Instance()->Init();
RenderTarget = screen;
screen->Lock(true);
R_SetupBuffer();
screen->Unlock();
}
void RenderScene::Init()