From 1bed6feadce05b5f41624f5eb6925feae7a43d02 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 1 Dec 2016 00:42:14 +0100 Subject: [PATCH] Detach poly renderer from r_main --- src/r_main.cpp | 28 ++++------------------ src/r_poly.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++-- src/r_poly.h | 6 ++++- src/r_swrenderer.cpp | 41 ++++++++++++++++++++++++++++--- 4 files changed, 102 insertions(+), 30 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index e0773718fa..5c7ab39bcb 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -59,18 +59,9 @@ #include "v_font.h" #include "r_data/colormaps.h" #include "p_maputl.h" -#include "r_poly.h" #include "p_setup.h" #include "version.h" -CUSTOM_CVAR(Bool, r_polyrenderer, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) -{ - if (self == 1 && !hasglnodes) - { - Printf("No GL BSP detected. You must restart the map before rendering will be correct\n"); - } -} - // MACROS ------------------------------------------------------------------ #if 0 @@ -915,14 +906,7 @@ void R_RenderActorView (AActor *actor, bool dontmaplines) // Link the polyobjects right before drawing the scene to reduce the amounts of calls to this function PO_LinkToSubsectors(); InSubsector = NULL; - if (!r_polyrenderer) - { - R_RenderBSPNode(nodes + numnodes - 1); // The head node is the last node output. - } - else - { - RenderPolyScene::Instance()->Render(); - } + R_RenderBSPNode(nodes + numnodes - 1); // The head node is the last node output. R_3D_ResetClip(); // reset clips (floor/ceiling) camera->renderflags = savedflags; WallCycles.Unclock(); @@ -932,11 +916,8 @@ void R_RenderActorView (AActor *actor, bool dontmaplines) if (viewactive) { PlaneCycles.Clock(); - if (!r_polyrenderer) - { - R_DrawPlanes(); - R_DrawPortals(); - } + R_DrawPlanes(); + R_DrawPortals(); PlaneCycles.Unclock(); // [RH] Walk through mirrors @@ -953,8 +934,7 @@ void R_RenderActorView (AActor *actor, bool dontmaplines) NetUpdate (); MaskedCycles.Clock(); - if (!r_polyrenderer) - R_DrawMasked (); + R_DrawMasked (); MaskedCycles.Unclock(); NetUpdate (); diff --git a/src/r_poly.cpp b/src/r_poly.cpp index 186077806c..3809c56391 100644 --- a/src/r_poly.cpp +++ b/src/r_poly.cpp @@ -25,11 +25,15 @@ #include "doomdef.h" #include "sbar.h" #include "r_data/r_translate.h" +#include "r_data/r_interpolate.h" #include "r_poly.h" #include "gl/data/gl_data.h" +#include "d_net.h" +#include "po_man.h" EXTERN_CVAR(Int, screenblocks) void InitGLRMapinfoData(); +extern bool r_showviewer; ///////////////////////////////////////////////////////////////////////////// @@ -39,8 +43,50 @@ RenderPolyScene *RenderPolyScene::Instance() return &scene; } -void RenderPolyScene::Render() +void RenderPolyScene::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines) { + const bool savedviewactive = viewactive; + const bool savedoutputformat = r_swtruecolor; + + viewwidth = width; + RenderTarget = canvas; + bRenderingToCanvas = true; + R_SetWindow(12, width, height, height, true); + viewwindowx = x; + viewwindowy = y; + viewactive = true; + r_swtruecolor = canvas->IsBgra(); + + canvas->Lock(true); + + RenderActorView(actor, dontmaplines); + + canvas->Unlock(); + + RenderTarget = screen; + bRenderingToCanvas = false; + R_ExecuteSetViewSize(); + viewactive = savedviewactive; + r_swtruecolor = savedoutputformat; +} + +void RenderPolyScene::RenderActorView(AActor *actor, bool dontmaplines) +{ + NetUpdate(); + + r_dontmaplines = dontmaplines; + + P_FindParticleSubsectors(); + PO_LinkToSubsectors(); + R_SetupFrame(actor); + + ActorRenderFlags savedflags = camera->renderflags; + // Never draw the player unless in chasecam mode + if (!r_showviewer) + camera->renderflags |= RF_INVISIBLE; + + R_BeginDrawerCommands(); + ClearBuffers(); SetSceneViewport(); SetupPerspectiveMatrix(); @@ -50,7 +96,14 @@ void RenderPolyScene::Render() MainPortal.RenderTranslucent(0); PlayerSprites.Render(); - DrawerCommandQueue::WaitForWorkers(); + camera->renderflags = savedflags; + interpolator.RestoreInterpolations (); + + NetUpdate(); + + R_EndDrawerCommands(); + + NetUpdate(); } void RenderPolyScene::RenderRemainingPlayerSprites() diff --git a/src/r_poly.h b/src/r_poly.h index 3bd9bb319a..d67e395708 100644 --- a/src/r_poly.h +++ b/src/r_poly.h @@ -33,11 +33,15 @@ #include "r_poly_playersprite.h" #include "r_poly_sky.h" +class AActor; +class DCanvas; + // Renders a scene class RenderPolyScene { public: - void Render(); + void RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines); + void RenderActorView(AActor *actor, bool dontmaplines); void RenderRemainingPlayerSprites(); static RenderPolyScene *Instance(); diff --git a/src/r_swrenderer.cpp b/src/r_swrenderer.cpp index 74a6da8232..0f30fc3dff 100644 --- a/src/r_swrenderer.cpp +++ b/src/r_swrenderer.cpp @@ -45,11 +45,19 @@ #include "r_draw_rgba.h" #include "r_drawers.h" #include "r_poly.h" +#include "p_setup.h" EXTERN_CVAR(Bool, r_shadercolormaps) -EXTERN_CVAR(Bool, r_polyrenderer) // [SP] dpJudas's new renderer EXTERN_CVAR(Float, maxviewpitch) // [SP] CVAR from GZDoom +CUSTOM_CVAR(Bool, r_polyrenderer, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) +{ + if (self == 1 && !hasglnodes) + { + Printf("No GL BSP detected. You must restart the map before rendering will be correct\n"); + } +} + void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, float trueratio); void R_SetupColormap(player_t *); void R_SetupFreelook(); @@ -175,6 +183,27 @@ void FSoftwareRenderer::Precache(BYTE *texhitlist, TMap &act void FSoftwareRenderer::RenderView(player_t *player) { + if (r_polyrenderer) + { + bool saved_swtruecolor = r_swtruecolor; + r_swtruecolor = screen->IsBgra(); + + RenderPolyScene::Instance()->RenderActorView(player->mo, false); + FCanvasTextureInfo::UpdateAll(); + + // Apply special colormap if the target cannot do it + if (realfixedcolormap && r_swtruecolor && !(r_shadercolormaps && screen->Accel2D)) + { + R_BeginDrawerCommands(); + DrawerCommandQueue::QueueCommand(realfixedcolormap, screen); + R_EndDrawerCommands(); + } + + r_swtruecolor = saved_swtruecolor; + + return; + } + if (r_swtruecolor != screen->IsBgra()) { r_swtruecolor = screen->IsBgra(); @@ -223,7 +252,10 @@ void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int wi // Take a snapshot of the player's view pic->ObjectFlags |= OF_Fixed; pic->Lock (); - R_RenderViewToCanvas (player->mo, pic, 0, 0, width, height); + if (r_polyrenderer) + RenderPolyScene::Instance()->RenderViewToCanvas(player->mo, pic, 0, 0, width, height, true); + else + R_RenderViewToCanvas (player->mo, pic, 0, 0, width, height); screen->GetFlashedPalette (palette); M_CreatePNG (file, pic->GetBuffer(), palette, SS_PAL, width, height, pic->GetPitch()); pic->Unlock (); @@ -373,7 +405,10 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin DAngle savedfov = FieldOfView; R_SetFOV ((double)fov); - R_RenderViewToCanvas (viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); + if (r_polyrenderer) + RenderPolyScene::Instance()->RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); + else + R_RenderViewToCanvas (viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); R_SetFOV (savedfov); if (Canvas->IsBgra())