From 601ddb270dbaa8c05708bd7474f09dc4873a7e71 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 15 Jan 2017 04:06:52 +0100 Subject: [PATCH] Create a class for the viewport --- src/polyrenderer/poly_renderer.cpp | 8 ++++---- src/swrenderer/scene/r_scene.cpp | 19 +++++++++---------- src/swrenderer/scene/r_viewport.cpp | 18 +++++++++++++----- src/swrenderer/scene/r_viewport.h | 16 ++++++++++++---- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index 6e2e54be3d..06aa3cb0ed 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -63,7 +63,7 @@ void PolyRenderer::RenderView(player_t *player) int stHeight = ST_Y; float trueratio; ActiveRatio(width, height, &trueratio); - R_SWRSetWindow(setblocks, width, height, stHeight, trueratio); + RenderViewport::Instance()->SetViewport(width, height, trueratio); RenderActorView(player->mo, false); @@ -87,7 +87,7 @@ void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int swrenderer::RenderTarget = canvas; swrenderer::bRenderingToCanvas = true; R_SetWindow(12, width, height, height, true); - swrenderer::R_SWRSetWindow(12, width, height, height, WidescreenRatio); + swrenderer::RenderViewport::Instance()->SetViewport(width, height, WidescreenRatio); viewwindowx = x; viewwindowy = y; viewactive = true; @@ -104,7 +104,7 @@ void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int R_ExecuteSetViewSize(); float trueratio; ActiveRatio(width, height, &trueratio); - swrenderer::R_SWRSetWindow(setblocks, width, height, height, WidescreenRatio); + swrenderer::RenderViewport::Instance()->SetViewport(width, height, WidescreenRatio); viewactive = savedviewactive; swrenderer::r_swtruecolor = savedoutputformat; } @@ -119,7 +119,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) PO_LinkToSubsectors(); R_SetupFrame(actor); swrenderer::R_SetupColormap(actor); - swrenderer::R_SetupFreelook(); + swrenderer::RenderViewport::Instance()->SetupFreelook(); ActorRenderFlags savedflags = camera->renderflags; // Never draw the player unless in chasecam mode diff --git a/src/swrenderer/scene/r_scene.cpp b/src/swrenderer/scene/r_scene.cpp index 2dee1eb274..f2f56b8333 100644 --- a/src/swrenderer/scene/r_scene.cpp +++ b/src/swrenderer/scene/r_scene.cpp @@ -72,10 +72,9 @@ namespace swrenderer int width = SCREENWIDTH; int height = SCREENHEIGHT; - int stHeight = ST_Y; float trueratio; ActiveRatio(width, height, &trueratio); - R_SWRSetWindow(setblocks, width, height, stHeight, trueratio); + RenderViewport::Instance()->SetViewport(width, height, trueratio); if (r_swtruecolor != screen->IsBgra()) { @@ -123,10 +122,9 @@ namespace swrenderer clip3d->Cleanup(); clip3d->ResetClip(); // reset clips (floor/ceiling) - R_SetupBuffer(); R_SetupFrame(actor); R_SetupColormap(actor); - R_SetupFreelook(); + RenderViewport::Instance()->SetupFreelook(); RenderPortal::Instance()->CopyStackedViewParameters(); @@ -191,7 +189,6 @@ namespace swrenderer } WallPortals.Clear(); interpolator.RestoreInterpolations(); - R_SetupBuffer(); // If we don't want shadered colormaps, NULL it now so that the // copy to the screen does not use a special colormap shader. @@ -219,11 +216,10 @@ namespace swrenderer bRenderingToCanvas = true; R_SetWindow(12, width, height, height, true); - R_SWRSetWindow(12, width, height, height, WidescreenRatio); - viewwindowx = x; viewwindowy = y; viewactive = true; + RenderViewport::Instance()->SetViewport(width, height, WidescreenRatio); RenderActorView(actor, dontmaplines); @@ -235,9 +231,8 @@ namespace swrenderer R_ExecuteSetViewSize(); float trueratio; ActiveRatio(width, height, &trueratio); - R_SWRSetWindow(setblocks, width, height, height, WidescreenRatio); screen->Lock(true); - R_SetupBuffer(); + RenderViewport::Instance()->SetViewport(width, height, trueratio); screen->Unlock(); viewactive = savedviewactive; @@ -254,8 +249,12 @@ namespace swrenderer VisiblePlaneList::Instance()->Init(); RenderTarget = screen; + int width = SCREENWIDTH; + int height = SCREENHEIGHT; + float trueratio; + ActiveRatio(width, height, &trueratio); screen->Lock(true); - R_SetupBuffer(); + RenderViewport::Instance()->SetViewport(SCREENWIDTH, SCREENHEIGHT, trueratio); screen->Unlock(); } diff --git a/src/swrenderer/scene/r_viewport.cpp b/src/swrenderer/scene/r_viewport.cpp index b45a7ccd61..df5b37f086 100644 --- a/src/swrenderer/scene/r_viewport.cpp +++ b/src/swrenderer/scene/r_viewport.cpp @@ -60,7 +60,13 @@ namespace swrenderer // from clipangle to -clipangle. angle_t xtoviewangle[MAXWIDTH + 1]; - void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, float trueratio) + RenderViewport *RenderViewport::Instance() + { + static RenderViewport instance; + return &instance; + } + + void RenderViewport::SetViewport(int fullWidth, int fullHeight, float trueratio) { int virtheight, virtwidth, virtwidth2, virtheight2; @@ -113,13 +119,15 @@ namespace swrenderer // thing clipping fillshort(screenheightarray, viewwidth, (short)viewheight); - R_InitTextureMapping(); + InitTextureMapping(); // Reset r_*Visibility vars R_SetVisibility(R_GetVisibility()); + + SetupBuffer(); } - void R_SetupFreelook() + void RenderViewport::SetupFreelook() { double dy; @@ -140,7 +148,7 @@ namespace swrenderer RenderFlatPlane::SetupSlope(); } - void R_SetupBuffer() + void RenderViewport::SetupBuffer() { using namespace drawerargs; @@ -168,7 +176,7 @@ namespace swrenderer R_InitParticleTexture(); } - void R_InitTextureMapping() + void RenderViewport::InitTextureMapping() { int i; diff --git a/src/swrenderer/scene/r_viewport.h b/src/swrenderer/scene/r_viewport.h index 3cf3ad0ef5..c6445dba2f 100644 --- a/src/swrenderer/scene/r_viewport.h +++ b/src/swrenderer/scene/r_viewport.h @@ -34,8 +34,16 @@ namespace swrenderer extern double globaldclip; extern angle_t xtoviewangle[MAXWIDTH + 1]; - void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, float trueratio); - void R_InitTextureMapping(); - void R_SetupBuffer(); - void R_SetupFreelook(); + class RenderViewport + { + public: + static RenderViewport *Instance(); + + void SetViewport(int width, int height, float trueratio); + void SetupFreelook(); + + private: + void InitTextureMapping(); + void SetupBuffer(); + }; }