Skip to content

Commit

Permalink
- fix softpoly canvas drawing not restoring all globals properly
Browse files Browse the repository at this point in the history
- add null pointer check on camera
  • Loading branch information
dpjudas committed Apr 15, 2018
1 parent bb03763 commit 21c2d38
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/polyrenderer/poly_renderer.cpp
Expand Up @@ -62,11 +62,6 @@ void PolyRenderer::RenderView(player_t *player, DCanvas *target)

RenderTarget = target;
RenderToCanvas = false;
int width = SCREENWIDTH;
int height = SCREENHEIGHT;
float trueratio;
ActiveRatio(width, height, &trueratio);
//viewport->SetViewport(&Thread, width, height, trueratio);

RenderActorView(player->mo, false);

Expand All @@ -78,24 +73,40 @@ void PolyRenderer::RenderView(player_t *player, DCanvas *target)

void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines)
{
const bool savedviewactive = viewactive;

viewwidth = width;
// Save a bunch of silly globals:
auto savedViewpoint = Viewpoint;
auto savedViewwindow = Viewwindow;
auto savedviewwindowx = viewwindowx;
auto savedviewwindowy = viewwindowy;
auto savedviewwidth = viewwidth;
auto savedviewheight = viewheight;
auto savedviewactive = viewactive;
auto savedRenderTarget = RenderTarget;

// Setup the view:
RenderTarget = canvas;
RenderToCanvas = true;
R_SetWindow(Viewpoint, Viewwindow, 12, width, height, height, true);
//viewport->SetViewport(&Thread, width, height, Viewwindow.WidescreenRatio);
viewwindowx = x;
viewwindowy = y;
viewactive = true;

// Render:
RenderActorView(actor, dontmaplines);
Threads.MainThread()->FlushDrawQueue();
DrawerThreads::WaitForWorkers();

RenderTarget = nullptr;
RenderToCanvas = false;

// Restore silly globals:
Viewpoint = savedViewpoint;
Viewwindow = savedViewwindow;
viewwindowx = savedviewwindowx;
viewwindowy = savedviewwindowy;
viewwidth = savedviewwidth;
viewheight = savedviewheight;
viewactive = savedviewactive;
RenderTarget = savedRenderTarget;
}

void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines)
Expand Down Expand Up @@ -126,10 +137,15 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines)
PolyCameraLight::Instance()->SetCamera(Viewpoint, RenderTarget, actor);
//Viewport->SetupFreelook();

ActorRenderFlags savedflags = Viewpoint.camera->renderflags;
// Never draw the player unless in chasecam mode
if (!Viewpoint.showviewer)
Viewpoint.camera->renderflags |= RF_INVISIBLE;
ActorRenderFlags savedflags = 0;
if (Viewpoint.camera)
{
savedflags = Viewpoint.camera->renderflags;

// Never draw the player unless in chasecam mode
if (!Viewpoint.showviewer)
Viewpoint.camera->renderflags |= RF_INVISIBLE;
}

ScreenTriangle::FuzzStart = (ScreenTriangle::FuzzStart + 14) % FUZZTABLE;

Expand All @@ -147,7 +163,8 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines)
Scene.RenderTranslucent(&mainViewpoint);
PlayerSprites.Render(Threads.MainThread());

Viewpoint.camera->renderflags = savedflags;
if (Viewpoint.camera)
Viewpoint.camera->renderflags = savedflags;
interpolator.RestoreInterpolations ();

NetUpdate();
Expand Down

0 comments on commit 21c2d38

Please sign in to comment.