diff --git a/src/polyrenderer/drawers/poly_draw_args.cpp b/src/polyrenderer/drawers/poly_draw_args.cpp index 1f3556064..8d7687f64 100644 --- a/src/polyrenderer/drawers/poly_draw_args.cpp +++ b/src/polyrenderer/drawers/poly_draw_args.cpp @@ -48,7 +48,7 @@ void PolyDrawArgs::SetTexture(FTexture *texture) { textureWidth = texture->GetWidth(); textureHeight = texture->GetHeight(); - auto viewport = swrenderer::RenderViewport::Instance(); + auto viewport = PolyRenderer::Instance()->Thread.Viewport.get(); if (viewport->RenderTarget->IsBgra()) texturePixels = (const uint8_t *)texture->GetPixelsBgra(); else @@ -63,7 +63,7 @@ void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool fo FRemapTable *table = TranslationToTable(translationID); if (table != nullptr && !table->Inactive) { - if (swrenderer::RenderViewport::Instance()->RenderTarget->IsBgra()) + if (PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra()) translation = (uint8_t*)table->Palette; else translation = table->Remap; diff --git a/src/polyrenderer/math/tri_matrix.cpp b/src/polyrenderer/math/tri_matrix.cpp index b924322ad..85a211797 100644 --- a/src/polyrenderer/math/tri_matrix.cpp +++ b/src/polyrenderer/math/tri_matrix.cpp @@ -132,24 +132,23 @@ TriMatrix TriMatrix::frustum(float left, float right, float bottom, float top, f return m; } -TriMatrix TriMatrix::worldToView() +TriMatrix TriMatrix::worldToView(const FRenderViewpoint &viewpoint) { TriMatrix m = null(); - m.matrix[0 + 0 * 4] = (float)r_viewpoint.Sin; - m.matrix[0 + 1 * 4] = (float)-r_viewpoint.Cos; + m.matrix[0 + 0 * 4] = (float)viewpoint.Sin; + m.matrix[0 + 1 * 4] = (float)-viewpoint.Cos; m.matrix[1 + 2 * 4] = 1.0f; - m.matrix[2 + 0 * 4] = (float)-r_viewpoint.Cos; - m.matrix[2 + 1 * 4] = (float)-r_viewpoint.Sin; + m.matrix[2 + 0 * 4] = (float)-viewpoint.Cos; + m.matrix[2 + 1 * 4] = (float)-viewpoint.Sin; m.matrix[3 + 3 * 4] = 1.0f; - return m * translate((float)-r_viewpoint.Pos.X, (float)-r_viewpoint.Pos.Y, (float)-r_viewpoint.Pos.Z); + return m * translate((float)-viewpoint.Pos.X, (float)-viewpoint.Pos.Y, (float)-viewpoint.Pos.Z); } -TriMatrix TriMatrix::viewToClip() +TriMatrix TriMatrix::viewToClip(swrenderer::RenderViewport *viewport) { - auto viewport = swrenderer::RenderViewport::Instance(); float near = 5.0f; float far = 65536.0f; - float width = (float)(r_viewwindow.FocalTangent * near); + float width = (float)(viewport->viewwindow.FocalTangent * near); float top = (float)(viewport->CenterY / viewport->InvZtoScale * near); float bottom = (float)(top - viewheight / viewport->InvZtoScale * near); return frustum(-width, width, bottom, top, near, far); diff --git a/src/polyrenderer/math/tri_matrix.h b/src/polyrenderer/math/tri_matrix.h index c1eabcce8..aaf7c0073 100644 --- a/src/polyrenderer/math/tri_matrix.h +++ b/src/polyrenderer/math/tri_matrix.h @@ -24,6 +24,7 @@ struct TriVertex; struct ShadedTriVertex; +namespace swrenderer { class RenderViewport; } struct TriMatrix { @@ -36,8 +37,8 @@ struct TriMatrix static TriMatrix perspective(float fovy, float aspect, float near, float far); static TriMatrix frustum(float left, float right, float bottom, float top, float near, float far); - static TriMatrix worldToView(); // Software renderer world to view space transform - static TriMatrix viewToClip(); // Software renderer shearing projection + static TriMatrix worldToView(const FRenderViewpoint &viewpoint); // Software renderer world to view space transform + static TriMatrix viewToClip(swrenderer::RenderViewport *viewport); // Software renderer shearing projection ShadedTriVertex operator*(TriVertex v) const; TriMatrix operator*(const TriMatrix &m) const; diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index 83fc03704..1545e6a24 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -57,7 +57,7 @@ void PolyRenderer::RenderView(player_t *player) { using namespace swrenderer; - auto viewport = RenderViewport::Instance(); + auto viewport = Thread.Viewport.get(); viewport->RenderTarget = screen; @@ -82,14 +82,14 @@ void PolyRenderer::RenderView(player_t *player) void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines) { - auto viewport = swrenderer::RenderViewport::Instance(); + auto viewport = Thread.Viewport.get(); const bool savedviewactive = viewactive; viewwidth = width; viewport->RenderTarget = canvas; - R_SetWindow(r_viewpoint, r_viewwindow, 12, width, height, height, true); - viewport->SetViewport(width, height, r_viewwindow.WidescreenRatio); + R_SetWindow(viewport->viewpoint, viewport->viewwindow, 12, width, height, height, true); + viewport->SetViewport(width, height, viewport->viewwindow.WidescreenRatio); viewwindowx = x; viewwindowy = y; viewactive = true; @@ -102,10 +102,10 @@ void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int canvas->Unlock(); viewport->RenderTarget = screen; - R_ExecuteSetViewSize(r_viewpoint, r_viewwindow); + R_ExecuteSetViewSize(viewport->viewpoint, viewport->viewwindow); float trueratio; ActiveRatio(width, height, &trueratio); - viewport->SetViewport(width, height, r_viewwindow.WidescreenRatio); + viewport->SetViewport(width, height, viewport->viewwindow.WidescreenRatio); viewactive = savedviewactive; } @@ -117,14 +117,14 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) P_FindParticleSubsectors(); PO_LinkToSubsectors(); - R_SetupFrame(r_viewpoint, r_viewwindow, actor); - swrenderer::CameraLight::Instance()->SetCamera(actor); - swrenderer::RenderViewport::Instance()->SetupFreelook(); + R_SetupFrame(Thread.Viewport->viewpoint, Thread.Viewport->viewwindow, actor); + swrenderer::CameraLight::Instance()->SetCamera(Thread.Viewport.get(), actor); + Thread.Viewport->SetupFreelook(); - ActorRenderFlags savedflags = r_viewpoint.camera->renderflags; + ActorRenderFlags savedflags = Thread.Viewport->viewpoint.camera->renderflags; // Never draw the player unless in chasecam mode - if (!r_viewpoint.showviewer) - r_viewpoint.camera->renderflags |= RF_INVISIBLE; + if (!Thread.Viewport->viewpoint.showviewer) + Thread.Viewport->viewpoint.camera->renderflags |= RF_INVISIBLE; ClearBuffers(); SetSceneViewport(); @@ -135,7 +135,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) MainPortal.RenderTranslucent(0); PlayerSprites.Render(); - r_viewpoint.camera->renderflags = savedflags; + Thread.Viewport->viewpoint.camera->renderflags = savedflags; interpolator.RestoreInterpolations (); NetUpdate(); @@ -149,7 +149,7 @@ void PolyRenderer::RenderRemainingPlayerSprites() void PolyRenderer::ClearBuffers() { PolyVertexBuffer::Clear(); - auto viewport = swrenderer::RenderViewport::Instance(); + auto viewport = Thread.Viewport.get(); PolyStencilBuffer::Instance()->Clear(viewport->RenderTarget->GetWidth(), viewport->RenderTarget->GetHeight(), 0); PolySubsectorGBuffer::Instance()->Resize(viewport->RenderTarget->GetPitch(), viewport->RenderTarget->GetHeight()); NextStencilValue = 0; @@ -161,7 +161,7 @@ void PolyRenderer::SetSceneViewport() { using namespace swrenderer; - auto viewport = RenderViewport::Instance(); + auto viewport = Thread.Viewport.get(); if (viewport->RenderTarget == screen) // Rendering to screen { @@ -192,23 +192,25 @@ void PolyRenderer::SetupPerspectiveMatrix() // Code provided courtesy of Graf Zahl. Now we just have to plug it into the viewmatrix code... // We have to scale the pitch to account for the pixel stretching, because the playsim doesn't know about this and treats it as 1:1. - double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians(); + const auto &viewpoint = Thread.Viewport->viewpoint; + const auto &viewwindow = Thread.Viewport->viewwindow; + double radPitch = viewpoint.Angles.Pitch.Normalized180().Radians(); double angx = cos(radPitch); double angy = sin(radPitch) * glset.pixelstretch; double alen = sqrt(angx*angx + angy*angy); float adjustedPitch = (float)asin(angy / alen); - float adjustedViewAngle = (float)(r_viewpoint.Angles.Yaw - 90).Radians(); + float adjustedViewAngle = (float)(viewpoint.Angles.Yaw - 90).Radians(); - float ratio = r_viewwindow.WidescreenRatio; - float fovratio = (r_viewwindow.WidescreenRatio >= 1.3f) ? 1.333333f : ratio; - float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(r_viewpoint.FieldOfView.Radians() / 2) / fovratio)).Degrees); + float ratio = viewwindow.WidescreenRatio; + float fovratio = (viewwindow.WidescreenRatio >= 1.3f) ? 1.333333f : ratio; + float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(viewpoint.FieldOfView.Radians() / 2) / fovratio)).Degrees); TriMatrix worldToView = TriMatrix::rotate(adjustedPitch, 1.0f, 0.0f, 0.0f) * TriMatrix::rotate(adjustedViewAngle, 0.0f, -1.0f, 0.0f) * TriMatrix::scale(1.0f, glset.pixelstretch, 1.0f) * TriMatrix::swapYZ() * - TriMatrix::translate((float)-r_viewpoint.Pos.X, (float)-r_viewpoint.Pos.Y, (float)-r_viewpoint.Pos.Z); + TriMatrix::translate((float)-viewpoint.Pos.X, (float)-viewpoint.Pos.Y, (float)-viewpoint.Pos.Z); WorldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView; } diff --git a/src/polyrenderer/scene/poly_cull.cpp b/src/polyrenderer/scene/poly_cull.cpp index 8e0348a32..de579d799 100644 --- a/src/polyrenderer/scene/poly_cull.cpp +++ b/src/polyrenderer/scene/poly_cull.cpp @@ -50,7 +50,7 @@ void PolyCull::CullNode(void *node) node_t *bsp = (node_t *)node; // Decide which side the view point is on. - int side = PointOnSide(r_viewpoint.Pos, bsp); + int side = PointOnSide(PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos, bsp); // Recursively divide front space (toward the viewer). CullNode(bsp->children[side]); @@ -84,8 +84,8 @@ void PolyCull::CullSubsector(subsector_t *sub) if ((line->sidedef == nullptr || !(line->sidedef->Flags & WALLF_POLYOBJ)) && line->backsector == nullptr) { // Skip lines not facing viewer - DVector2 pt1 = line->v1->fPos() - r_viewpoint.Pos; - DVector2 pt2 = line->v2->fPos() - r_viewpoint.Pos; + DVector2 pt1 = line->v1->fPos() - PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos; + DVector2 pt2 = line->v2->fPos() - PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos; if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0) continue; @@ -179,7 +179,7 @@ bool PolyCull::CheckBBox(float *bspcoord) { // Start using a quick frustum AABB test: - AxisAlignedBoundingBox aabb(Vec3f(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM], (float)r_viewpoint.Pos.Z - 1000.0f), Vec3f(bspcoord[BOXRIGHT], bspcoord[BOXTOP], (float)r_viewpoint.Pos.Z + 1000.0f)); + AxisAlignedBoundingBox aabb(Vec3f(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM], (float)PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos.Z - 1000.0f), Vec3f(bspcoord[BOXRIGHT], bspcoord[BOXTOP], (float)PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos.Z + 1000.0f)); auto result = IntersectionTest::frustum_aabb(frustumPlanes, aabb); if (result == IntersectionTest::outside) return false; @@ -266,14 +266,15 @@ LineSegmentRange PolyCull::GetSegmentRangeForLine(double x1, double y1, double x } // Transform to 2D view space: - x1 = x1 - r_viewpoint.Pos.X; - y1 = y1 - r_viewpoint.Pos.Y; - x2 = x2 - r_viewpoint.Pos.X; - y2 = y2 - r_viewpoint.Pos.Y; - double rx1 = x1 * r_viewpoint.Sin - y1 * r_viewpoint.Cos; - double rx2 = x2 * r_viewpoint.Sin - y2 * r_viewpoint.Cos; - double ry1 = x1 * r_viewpoint.Cos + y1 * r_viewpoint.Sin; - double ry2 = x2 * r_viewpoint.Cos + y2 * r_viewpoint.Sin; + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + x1 = x1 - viewpoint.Pos.X; + y1 = y1 - viewpoint.Pos.Y; + x2 = x2 - viewpoint.Pos.X; + y2 = y2 - viewpoint.Pos.Y; + double rx1 = x1 * viewpoint.Sin - y1 * viewpoint.Cos; + double rx2 = x2 * viewpoint.Sin - y2 * viewpoint.Cos; + double ry1 = x1 * viewpoint.Cos + y1 * viewpoint.Sin; + double ry2 = x2 * viewpoint.Cos + y2 * viewpoint.Sin; // Is it potentially visible when looking straight up or down? if (!(ry1 < updownnear && ry2 < updownnear) && !(ry1 > znear && ry2 > znear) && diff --git a/src/polyrenderer/scene/poly_decal.cpp b/src/polyrenderer/scene/poly_decal.cpp index 3f4c22285..c73def6d0 100644 --- a/src/polyrenderer/scene/poly_decal.cpp +++ b/src/polyrenderer/scene/poly_decal.cpp @@ -107,7 +107,7 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan return; bool foggy = false; - int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; + int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Thread.Viewport->viewpoint.extralight << 4; std::pair offsets[4] = { @@ -151,7 +151,7 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan } args.uniforms.subsectorDepth = subsectorDepth; - if (swrenderer::RenderViewport::Instance()->RenderTarget->IsBgra()) + if (PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra()) { args.uniforms.color = 0xff000000 | decal->AlphaColor; } diff --git a/src/polyrenderer/scene/poly_particle.cpp b/src/polyrenderer/scene/poly_particle.cpp index 229bbb233..b3887792e 100644 --- a/src/polyrenderer/scene/poly_particle.cpp +++ b/src/polyrenderer/scene/poly_particle.cpp @@ -35,10 +35,12 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP double psize = particle->size / 8.0; double zpos = pos.Z; + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + DVector2 points[2] = { - { pos.X - r_viewpoint.Sin * psize, pos.Y + r_viewpoint.Cos * psize }, - { pos.X + r_viewpoint.Sin * psize, pos.Y - r_viewpoint.Cos * psize } + { pos.X - viewpoint.Sin * psize, pos.Y + viewpoint.Cos * psize }, + { pos.X + viewpoint.Sin * psize, pos.Y - viewpoint.Cos * psize } }; TriVertex *vertices = PolyVertexBuffer::GetVertices(4); @@ -46,7 +48,7 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP return; bool foggy = false; - int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; + int actualextralight = foggy ? 0 : viewpoint.extralight << 4; std::pair offsets[4] = { @@ -90,7 +92,7 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP uint32_t alpha = (uint32_t)clamp(particle->alpha * 255.0f + 0.5f, 0.0f, 255.0f); - if (swrenderer::RenderViewport::Instance()->RenderTarget->IsBgra()) + if (PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra()) { args.uniforms.color = (alpha << 24) | (particle->color & 0xffffff); } diff --git a/src/polyrenderer/scene/poly_plane.cpp b/src/polyrenderer/scene/poly_plane.cpp index 8eddd52a7..f37e707c7 100644 --- a/src/polyrenderer/scene/poly_plane.cpp +++ b/src/polyrenderer/scene/poly_plane.cpp @@ -39,6 +39,8 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const Vec4f &cl if (r_3dfloors) { + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + auto frontsector = sub->sector; auto &ffloors = frontsector->e->XFloor.ffloors; @@ -57,7 +59,7 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const Vec4f &cl //fakeFloor->alpha double fakeHeight = fakeFloor->top.plane->ZatPoint(frontsector->centerspot); - if (fakeHeight < r_viewpoint.Pos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot)) + if (fakeHeight < viewpoint.Pos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot)) { plane.Render3DFloor(worldToClip, clipPlane, sub, subsectorDepth, stencilValue, false, fakeFloor); } @@ -78,7 +80,7 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const Vec4f &cl //fakeFloor->alpha double fakeHeight = fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot); - if (fakeHeight > r_viewpoint.Pos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot)) + if (fakeHeight > viewpoint.Pos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot)) { plane.Render3DFloor(worldToClip, clipPlane, sub, subsectorDepth, stencilValue, true, fakeFloor); } @@ -154,6 +156,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector> §orPortals) { + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; std::vector portalSegments; FSectorPortal *portal = nullptr;// sub->sector->ValidatePortal(ceiling ? sector_t::ceiling : sector_t::floor); bool foggy = false; @@ -187,8 +190,8 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan { seg_t *line = &sub->firstline[i]; - DVector2 pt1 = line->v1->fPos() - r_viewpoint.Pos; - DVector2 pt2 = line->v2->fPos() - r_viewpoint.Pos; + DVector2 pt1 = line->v1->fPos() - viewpoint.Pos; + DVector2 pt2 = line->v2->fPos() - viewpoint.Pos; if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0) inside = false; @@ -218,7 +221,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan else if(polyportal->PortalPlane == Vec4f(0.0f) || Vec4f::dot(polyportal->PortalPlane, Vec4f((float)v.X, (float)v.Y, 0.0f, 1.0f)) > 0.0f) { DVector2 planePos = v; - DVector2 planeNormal = v - r_viewpoint.Pos; + DVector2 planeNormal = v - viewpoint.Pos; planeNormal.MakeUnit(); double planeD = -(planeNormal | (planePos + planeNormal * 0.001)); polyportal->PortalPlane = Vec4f((float)planeNormal.X, (float)planeNormal.Y, 0.0f, (float)planeD); @@ -238,7 +241,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan { // Floor and ceiling texture needs to be swapped sometimes? Why?? :( - if (r_viewpoint.Pos.Z < fakesector->floorplane.Zat0()) // In water + if (viewpoint.Pos.Z < fakesector->floorplane.Zat0()) // In water { if (ceiling) { @@ -254,7 +257,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan ccw = true; } } - else if (r_viewpoint.Pos.Z >= fakesector->ceilingplane.Zat0() && !fakeflooronly) // In ceiling water + else if (viewpoint.Pos.Z >= fakesector->ceilingplane.Zat0() && !fakeflooronly) // In ceiling water { if (ceiling) { diff --git a/src/polyrenderer/scene/poly_playersprite.cpp b/src/polyrenderer/scene/poly_playersprite.cpp index a8354f8cc..eb40b05d2 100644 --- a/src/polyrenderer/scene/poly_playersprite.cpp +++ b/src/polyrenderer/scene/poly_playersprite.cpp @@ -42,19 +42,21 @@ void RenderPolyPlayerSprites::Render() // This code cannot be moved directly to RenderRemainingSprites because the engine // draws the canvas textures between this call and the final call to RenderRemainingSprites.. + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + if (!r_drawplayersprites || - !r_viewpoint.camera || - !r_viewpoint.camera->player || + !viewpoint.camera || + !viewpoint.camera->player || (players[consoleplayer].cheats & CF_CHASECAM) || - (r_deathcamera && r_viewpoint.camera->health <= 0)) + (r_deathcamera && viewpoint.camera->health <= 0)) return; float bobx, boby; - P_BobWeapon(r_viewpoint.camera->player, &bobx, &boby, r_viewpoint.TicFrac); + P_BobWeapon(viewpoint.camera->player, &bobx, &boby, viewpoint.TicFrac); // Interpolate the main weapon layer once so as to be able to add it to other layers. double wx, wy; - DPSprite *weapon = r_viewpoint.camera->player->FindPSprite(PSP_WEAPON); + DPSprite *weapon = viewpoint.camera->player->FindPSprite(PSP_WEAPON); if (weapon) { if (weapon->firstTic) @@ -64,8 +66,8 @@ void RenderPolyPlayerSprites::Render() } else { - wx = weapon->oldx + (weapon->x - weapon->oldx) * r_viewpoint.TicFrac; - wy = weapon->oldy + (weapon->y - weapon->oldy) * r_viewpoint.TicFrac; + wx = weapon->oldx + (weapon->x - weapon->oldx) * viewpoint.TicFrac; + wy = weapon->oldy + (weapon->y - weapon->oldy) * viewpoint.TicFrac; } } else @@ -74,7 +76,7 @@ void RenderPolyPlayerSprites::Render() wy = 0; } - for (DPSprite *sprite = r_viewpoint.camera->player->psprites; sprite != nullptr; sprite = sprite->GetNext()) + for (DPSprite *sprite = viewpoint.camera->player->psprites; sprite != nullptr; sprite = sprite->GetNext()) { // [RH] Don't draw the targeter's crosshair if the player already has a crosshair set. // It's possible this psprite's caller is now null but the layer itself hasn't been destroyed @@ -82,7 +84,7 @@ void RenderPolyPlayerSprites::Render() // In this case let's simply not draw it to avoid crashing. if ((sprite->GetID() != PSP_TARGETCENTER || CrosshairImage == nullptr) && sprite->GetCaller() != nullptr) { - RenderSprite(sprite, r_viewpoint.camera, bobx, boby, wx, wy, r_viewpoint.TicFrac); + RenderSprite(sprite, viewpoint.camera, bobx, boby, wx, wy, viewpoint.TicFrac); } } } @@ -141,9 +143,10 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa sy += wy; } - auto viewport = swrenderer::RenderViewport::Instance(); + auto viewport = PolyRenderer::Instance()->Thread.Viewport.get(); + const auto &viewpoint = viewport->viewpoint; - double pspritexscale = r_viewwindow.centerxwide / 160.0; + double pspritexscale = PolyRenderer::Instance()->Thread.Viewport->viewwindow.centerxwide / 160.0; double pspriteyscale = pspritexscale * viewport->YaspectMul; double pspritexiscale = 1 / pspritexscale; @@ -167,7 +170,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa double texturemid = (BaseYCenter - sy) * tex->Scale.Y + tex->TopOffset; // Adjust PSprite for fullscreen views - if (r_viewpoint.camera->player && (viewport->RenderTarget != screen || viewheight == viewport->RenderTarget->GetHeight() || (viewport->RenderTarget->GetWidth() > (BaseXCenter * 2) && !st_scale))) + if (viewpoint.camera->player && (viewport->RenderTarget != screen || viewheight == viewport->RenderTarget->GetHeight() || (viewport->RenderTarget->GetWidth() > (BaseXCenter * 2) && !st_scale))) { AWeapon *weapon = dyn_cast(sprite->GetCaller()); if (weapon != nullptr && weapon->YAdjust != 0) @@ -186,7 +189,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa // Move the weapon down for 1280x1024. if (sprite->GetID() < PSP_TARGETCENTER) { - texturemid -= AspectPspriteOffset(r_viewwindow.WidescreenRatio); + texturemid -= AspectPspriteOffset(PolyRenderer::Instance()->Thread.Viewport->viewwindow.WidescreenRatio); } int clipped_x1 = MAX(x1, 0); @@ -212,7 +215,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa bool noaccel = false; - FDynamicColormap *basecolormap = r_viewpoint.sector->ColorMap; + FDynamicColormap *basecolormap = viewpoint.sector->ColorMap; FDynamicColormap *colormap_to_use = basecolormap; int ColormapNum = 0; @@ -222,7 +225,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa RenderStyle = STYLE_Normal; bool foggy = false; - int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; + int actualextralight = foggy ? 0 : viewpoint.extralight << 4; int spriteshade = swrenderer::LightVisibility::LightLevelToShade(owner->Sector->lightlevel + actualextralight, foggy); double minz = double((2048 * 4) / double(1 << 20)); ColormapNum = GETPALOOKUP(swrenderer::LightVisibility::Instance()->SpriteGlobVis(foggy) / minz, spriteshade); @@ -287,14 +290,14 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa } */ - if (r_viewpoint.camera->Inventory != nullptr) + if (viewpoint.camera->Inventory != nullptr) { visstyle_t visstyle; visstyle.Alpha = Alpha; visstyle.RenderStyle = STYLE_Count; visstyle.Invert = false; - r_viewpoint.camera->Inventory->AlterWeaponSprite(&visstyle); + viewpoint.camera->Inventory->AlterWeaponSprite(&visstyle); Alpha = visstyle.Alpha; @@ -345,7 +348,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa // Check for hardware-assisted 2D. If it's available, and this sprite is not // fuzzy, don't draw it until after the switch to 2D mode. - if (!noaccel && swrenderer::RenderViewport::Instance()->RenderTarget == screen && (DFrameBuffer *)screen->Accel2D) + if (!noaccel && PolyRenderer::Instance()->Thread.Viewport->RenderTarget == screen && (DFrameBuffer *)screen->Accel2D) { FRenderStyle style = RenderStyle; style.CheckFuzz(); diff --git a/src/polyrenderer/scene/poly_portal.cpp b/src/polyrenderer/scene/poly_portal.cpp index a225b5477..d89793646 100644 --- a/src/polyrenderer/scene/poly_portal.cpp +++ b/src/polyrenderer/scene/poly_portal.cpp @@ -47,21 +47,23 @@ void PolyDrawSectorPortal::Render(int portalDepth) SaveGlobals(); // To do: get this information from PolyRenderer instead of duplicating the code.. - double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians(); + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow; + double radPitch = viewpoint.Angles.Pitch.Normalized180().Radians(); double angx = cos(radPitch); double angy = sin(radPitch) * glset.pixelstretch; double alen = sqrt(angx*angx + angy*angy); float adjustedPitch = (float)asin(angy / alen); - float adjustedViewAngle = (float)(r_viewpoint.Angles.Yaw - 90).Radians(); - float ratio = r_viewwindow.WidescreenRatio; - float fovratio = (r_viewwindow.WidescreenRatio >= 1.3f) ? 1.333333f : ratio; - float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(r_viewpoint.FieldOfView.Radians() / 2) / fovratio)).Degrees); + float adjustedViewAngle = (float)(viewpoint.Angles.Yaw - 90).Radians(); + float ratio = viewwindow.WidescreenRatio; + float fovratio = (viewwindow.WidescreenRatio >= 1.3f) ? 1.333333f : ratio; + float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(viewpoint.FieldOfView.Radians() / 2) / fovratio)).Degrees); TriMatrix worldToView = TriMatrix::rotate(adjustedPitch, 1.0f, 0.0f, 0.0f) * TriMatrix::rotate(adjustedViewAngle, 0.0f, -1.0f, 0.0f) * TriMatrix::scale(1.0f, glset.pixelstretch, 1.0f) * TriMatrix::swapYZ() * - TriMatrix::translate((float)-r_viewpoint.Pos.X, (float)-r_viewpoint.Pos.Y, (float)-r_viewpoint.Pos.Z); + TriMatrix::translate((float)-viewpoint.Pos.X, (float)-viewpoint.Pos.Y, (float)-viewpoint.Pos.Z); TriMatrix worldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView; RenderPortal.SetViewpoint(worldToClip, PortalPlane, StencilValue); @@ -85,33 +87,36 @@ void PolyDrawSectorPortal::RenderTranslucent(int portalDepth) void PolyDrawSectorPortal::SaveGlobals() { - savedextralight = r_viewpoint.extralight; - savedpos = r_viewpoint.Pos; - savedangles = r_viewpoint.Angles; + auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow; + + savedextralight = viewpoint.extralight; + savedpos = viewpoint.Pos; + savedangles = viewpoint.Angles; savedvisibility = swrenderer::LightVisibility::Instance()->GetVisibility(); - savedcamera = r_viewpoint.camera; - savedsector = r_viewpoint.sector; + savedcamera = viewpoint.camera; + savedsector = viewpoint.sector; if (Portal->mType == PORTS_SKYVIEWPOINT) { // Don't let gun flashes brighten the sky box AActor *sky = Portal->mSkybox; - r_viewpoint.extralight = 0; - swrenderer::LightVisibility::Instance()->SetVisibility(sky->args[0] * 0.25f); - r_viewpoint.Pos = sky->InterpolatedPosition(r_viewpoint.TicFrac); - r_viewpoint.Angles.Yaw = savedangles.Yaw + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_viewpoint.TicFrac); + viewpoint.extralight = 0; + swrenderer::LightVisibility::Instance()->SetVisibility(PolyRenderer::Instance()->Thread.Viewport.get(), sky->args[0] * 0.25f); + viewpoint.Pos = sky->InterpolatedPosition(viewpoint.TicFrac); + viewpoint.Angles.Yaw = savedangles.Yaw + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * viewpoint.TicFrac); } else //if (Portal->mType == PORTS_STACKEDSECTORTHING || Portal->mType == PORTS_PORTAL || Portal->mType == PORTS_LINKEDPORTAL) { //extralight = pl->extralight; //swrenderer::R_SetVisibility(pl->visibility); - r_viewpoint.Pos.X += Portal->mDisplacement.X; - r_viewpoint.Pos.Y += Portal->mDisplacement.Y; + viewpoint.Pos.X += Portal->mDisplacement.X; + viewpoint.Pos.Y += Portal->mDisplacement.Y; } - r_viewpoint.camera = nullptr; - r_viewpoint.sector = Portal->mDestination; - R_SetViewAngle(r_viewpoint, r_viewwindow); + viewpoint.camera = nullptr; + viewpoint.sector = Portal->mDestination; + R_SetViewAngle(viewpoint, viewwindow); Portal->mFlags |= PORTSF_INSKYBOX; if (Portal->mPartner > 0) level.sectorPortals[Portal->mPartner].mFlags |= PORTSF_INSKYBOX; @@ -122,13 +127,16 @@ void PolyDrawSectorPortal::RestoreGlobals() Portal->mFlags &= ~PORTSF_INSKYBOX; if (Portal->mPartner > 0) level.sectorPortals[Portal->mPartner].mFlags &= ~PORTSF_INSKYBOX; - r_viewpoint.camera = savedcamera; - r_viewpoint.sector = savedsector; - r_viewpoint.Pos = savedpos; - swrenderer::LightVisibility::Instance()->SetVisibility(savedvisibility); - r_viewpoint.extralight = savedextralight; - r_viewpoint.Angles = savedangles; - R_SetViewAngle(r_viewpoint, r_viewwindow); + auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow; + + viewpoint.camera = savedcamera; + viewpoint.sector = savedsector; + viewpoint.Pos = savedpos; + swrenderer::LightVisibility::Instance()->SetVisibility(PolyRenderer::Instance()->Thread.Viewport.get(), savedvisibility); + viewpoint.extralight = savedextralight; + viewpoint.Angles = savedangles; + R_SetViewAngle(viewpoint, viewwindow); } ///////////////////////////////////////////////////////////////////////////// @@ -148,21 +156,23 @@ void PolyDrawLinePortal::Render(int portalDepth) SaveGlobals(); // To do: get this information from PolyRenderer instead of duplicating the code.. - double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians(); + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow; + double radPitch = viewpoint.Angles.Pitch.Normalized180().Radians(); double angx = cos(radPitch); double angy = sin(radPitch) * glset.pixelstretch; double alen = sqrt(angx*angx + angy*angy); float adjustedPitch = (float)asin(angy / alen); - float adjustedViewAngle = (float)(r_viewpoint.Angles.Yaw - 90).Radians(); - float ratio = r_viewwindow.WidescreenRatio; - float fovratio = (r_viewwindow.WidescreenRatio >= 1.3f) ? 1.333333f : ratio; - float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(r_viewpoint.FieldOfView.Radians() / 2) / fovratio)).Degrees); + float adjustedViewAngle = (float)(viewpoint.Angles.Yaw - 90).Radians(); + float ratio = viewwindow.WidescreenRatio; + float fovratio = (viewwindow.WidescreenRatio >= 1.3f) ? 1.333333f : ratio; + float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(viewpoint.FieldOfView.Radians() / 2) / fovratio)).Degrees); TriMatrix worldToView = TriMatrix::rotate(adjustedPitch, 1.0f, 0.0f, 0.0f) * TriMatrix::rotate(adjustedViewAngle, 0.0f, -1.0f, 0.0f) * TriMatrix::scale(1.0f, glset.pixelstretch, 1.0f) * TriMatrix::swapYZ() * - TriMatrix::translate((float)-r_viewpoint.Pos.X, (float)-r_viewpoint.Pos.Y, (float)-r_viewpoint.Pos.Z); + TriMatrix::translate((float)-viewpoint.Pos.X, (float)-viewpoint.Pos.Y, (float)-viewpoint.Pos.Z); if (Mirror) worldToView = TriMatrix::scale(-1.0f, 1.0f, 1.0f) * worldToView; TriMatrix worldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView; @@ -191,30 +201,33 @@ void PolyDrawLinePortal::RenderTranslucent(int portalDepth) void PolyDrawLinePortal::SaveGlobals() { - savedextralight = r_viewpoint.extralight; - savedpos = r_viewpoint.Pos; - savedangles = r_viewpoint.Angles; - savedcamera = r_viewpoint.camera; - savedsector = r_viewpoint.sector; - savedinvisibility = r_viewpoint.camera ? (r_viewpoint.camera->renderflags & RF_INVISIBLE) == RF_INVISIBLE : false; - savedViewPath[0] = r_viewpoint.Path[0]; - savedViewPath[1] = r_viewpoint.Path[1]; + auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow; + + savedextralight = viewpoint.extralight; + savedpos = viewpoint.Pos; + savedangles = viewpoint.Angles; + savedcamera = viewpoint.camera; + savedsector = viewpoint.sector; + savedinvisibility = viewpoint.camera ? (viewpoint.camera->renderflags & RF_INVISIBLE) == RF_INVISIBLE : false; + savedViewPath[0] = viewpoint.Path[0]; + savedViewPath[1] = viewpoint.Path[1]; if (Mirror) { - DAngle startang = r_viewpoint.Angles.Yaw; - DVector3 startpos = r_viewpoint.Pos; + DAngle startang = viewpoint.Angles.Yaw; + DVector3 startpos = viewpoint.Pos; vertex_t *v1 = Mirror->v1; // Reflect the current view behind the mirror. if (Mirror->Delta().X == 0) { // vertical mirror - r_viewpoint.Pos.X = v1->fX() - startpos.X + v1->fX(); + viewpoint.Pos.X = v1->fX() - startpos.X + v1->fX(); } else if (Mirror->Delta().Y == 0) { // horizontal mirror - r_viewpoint.Pos.Y = v1->fY() - startpos.Y + v1->fY(); + viewpoint.Pos.Y = v1->fY() - startpos.Y + v1->fY(); } else { // any mirror @@ -230,36 +243,36 @@ void PolyDrawLinePortal::SaveGlobals() // the above two cases catch len == 0 double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy); - r_viewpoint.Pos.X = (x1 + r * dx) * 2 - x; - r_viewpoint.Pos.Y = (y1 + r * dy) * 2 - y; + viewpoint.Pos.X = (x1 + r * dx) * 2 - x; + viewpoint.Pos.Y = (y1 + r * dy) * 2 - y; } - r_viewpoint.Angles.Yaw = Mirror->Delta().Angle() * 2 - startang; + viewpoint.Angles.Yaw = Mirror->Delta().Angle() * 2 - startang; - if (r_viewpoint.camera) - r_viewpoint.camera->renderflags &= ~RF_INVISIBLE; + if (viewpoint.camera) + viewpoint.camera->renderflags &= ~RF_INVISIBLE; } else { auto src = Portal->mOrigin; auto dst = Portal->mDestination; - P_TranslatePortalXY(src, r_viewpoint.Pos.X, r_viewpoint.Pos.Y); - P_TranslatePortalZ(src, r_viewpoint.Pos.Z); - P_TranslatePortalAngle(src, r_viewpoint.Angles.Yaw); - P_TranslatePortalXY(src, r_viewpoint.Path[0].X, r_viewpoint.Path[0].Y); - P_TranslatePortalXY(src, r_viewpoint.Path[1].X, r_viewpoint.Path[1].Y); + P_TranslatePortalXY(src, viewpoint.Pos.X, viewpoint.Pos.Y); + P_TranslatePortalZ(src, viewpoint.Pos.Z); + P_TranslatePortalAngle(src, viewpoint.Angles.Yaw); + P_TranslatePortalXY(src, viewpoint.Path[0].X, viewpoint.Path[0].Y); + P_TranslatePortalXY(src, viewpoint.Path[1].X, viewpoint.Path[1].Y); - if (!r_viewpoint.showviewer && r_viewpoint.camera && P_PointOnLineSidePrecise(r_viewpoint.Path[0], dst) != P_PointOnLineSidePrecise(r_viewpoint.Path[1], dst)) + if (!viewpoint.showviewer && viewpoint.camera && P_PointOnLineSidePrecise(viewpoint.Path[0], dst) != P_PointOnLineSidePrecise(viewpoint.Path[1], dst)) { - double distp = (r_viewpoint.Path[0] - r_viewpoint.Path[1]).Length(); + double distp = (viewpoint.Path[0] - viewpoint.Path[1]).Length(); if (distp > EQUAL_EPSILON) { - double dist1 = (r_viewpoint.Pos - r_viewpoint.Path[0]).Length(); - double dist2 = (r_viewpoint.Pos - r_viewpoint.Path[1]).Length(); + double dist1 = (viewpoint.Pos - viewpoint.Path[0]).Length(); + double dist2 = (viewpoint.Pos - viewpoint.Path[1]).Length(); if (dist1 + dist2 < distp + 1) { - r_viewpoint.camera->renderflags |= RF_INVISIBLE; + viewpoint.camera->renderflags |= RF_INVISIBLE; } } } @@ -267,7 +280,7 @@ void PolyDrawLinePortal::SaveGlobals() //camera = nullptr; //viewsector = R_PointInSubsector(ViewPos)->sector; - R_SetViewAngle(r_viewpoint, r_viewwindow); + R_SetViewAngle(viewpoint, viewwindow); if (Mirror) PolyTriangleDrawer::toggle_mirror(); @@ -275,21 +288,23 @@ void PolyDrawLinePortal::SaveGlobals() void PolyDrawLinePortal::RestoreGlobals() { - if (r_viewpoint.camera) + auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow; + if (viewpoint.camera) { if (savedinvisibility) - r_viewpoint.camera->renderflags |= RF_INVISIBLE; + viewpoint.camera->renderflags |= RF_INVISIBLE; else - r_viewpoint.camera->renderflags &= ~RF_INVISIBLE; + viewpoint.camera->renderflags &= ~RF_INVISIBLE; } - r_viewpoint.camera = savedcamera; - r_viewpoint.sector = savedsector; - r_viewpoint.Pos = savedpos; - r_viewpoint.extralight = savedextralight; - r_viewpoint.Angles = savedangles; - r_viewpoint.Path[0] = savedViewPath[0]; - r_viewpoint.Path[1] = savedViewPath[1]; - R_SetViewAngle(r_viewpoint, r_viewwindow); + viewpoint.camera = savedcamera; + viewpoint.sector = savedsector; + viewpoint.Pos = savedpos; + viewpoint.extralight = savedextralight; + viewpoint.Angles = savedangles; + viewpoint.Path[0] = savedViewPath[0]; + viewpoint.Path[1] = savedViewPath[1]; + R_SetViewAngle(viewpoint, viewwindow); if (Mirror) PolyTriangleDrawer::toggle_mirror(); diff --git a/src/polyrenderer/scene/poly_scene.cpp b/src/polyrenderer/scene/poly_scene.cpp index 4be2e90d9..50d1143d2 100644 --- a/src/polyrenderer/scene/poly_scene.cpp +++ b/src/polyrenderer/scene/poly_scene.cpp @@ -186,9 +186,11 @@ void RenderPolyScene::RenderSprite(AActor *thing, double sortDistance, DVector2 void RenderPolyScene::RenderLine(subsector_t *sub, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth) { + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + // Reject lines not facing viewer - DVector2 pt1 = line->v1->fPos() - r_viewpoint.Pos; - DVector2 pt2 = line->v2->fPos() - r_viewpoint.Pos; + DVector2 pt1 = line->v1->fPos() - viewpoint.Pos; + DVector2 pt2 = line->v2->fPos() - viewpoint.Pos; if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0) return; @@ -328,6 +330,7 @@ void RenderPolyScene::RenderTranslucent(int portalDepth) } } + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; for (sector_t *sector : SeenSectors) { for (AActor *thing = sector->thinglist; thing != nullptr; thing = thing->snext) @@ -335,7 +338,7 @@ void RenderPolyScene::RenderTranslucent(int portalDepth) DVector2 left, right; if (!RenderPolySprite::GetLine(thing, left, right)) continue; - double distanceSquared = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); + double distanceSquared = (thing->Pos() - viewpoint.Pos).LengthSquared(); RenderSprite(thing, distanceSquared, left, right); } } diff --git a/src/polyrenderer/scene/poly_sky.cpp b/src/polyrenderer/scene/poly_sky.cpp index 2bf4601a6..ac5647f73 100644 --- a/src/polyrenderer/scene/poly_sky.cpp +++ b/src/polyrenderer/scene/poly_sky.cpp @@ -50,7 +50,8 @@ void PolySkyDome::Render(const TriMatrix &worldToClip) if (level.flags & LEVEL_DOUBLESKY) backskytex = TexMan(sky2tex, true); - TriMatrix objectToWorld = TriMatrix::translate((float)r_viewpoint.Pos.X, (float)r_viewpoint.Pos.Y, (float)r_viewpoint.Pos.Z); + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + TriMatrix objectToWorld = TriMatrix::translate((float)viewpoint.Pos.X, (float)viewpoint.Pos.Y, (float)viewpoint.Pos.Z); objectToClip = worldToClip * objectToWorld; int rc = mRows + 1; @@ -95,7 +96,7 @@ void PolySkyDome::RenderRow(PolyDrawArgs &args, int row, uint32_t capcolor) void PolySkyDome::RenderCapColorRow(PolyDrawArgs &args, FTexture *skytex, int row, bool bottomCap) { uint32_t solid = skytex->GetSkyCapColor(bottomCap); - if (!swrenderer::RenderViewport::Instance()->RenderTarget->IsBgra()) + if (!PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra()) solid = RGB32k.RGB[(RPART(solid) >> 3)][(GPART(solid) >> 3)][(BPART(solid) >> 3)]; args.vinput = &mVertices[mPrimStart[row]]; diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index a96ac88a9..dbc4387c5 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -38,7 +38,8 @@ bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right) if (IsThingCulled(thing)) return false; - DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac); bool flipTextureX = false; FTexture *tex = GetSpriteTexture(thing, flipTextureX); @@ -59,8 +60,8 @@ bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right) pos.X += spriteHalfWidth; - left = DVector2(pos.X - r_viewpoint.Sin * spriteHalfWidth, pos.Y + r_viewpoint.Cos * spriteHalfWidth); - right = DVector2(pos.X + r_viewpoint.Sin * spriteHalfWidth, pos.Y - r_viewpoint.Cos * spriteHalfWidth); + left = DVector2(pos.X - viewpoint.Sin * spriteHalfWidth, pos.Y + viewpoint.Cos * spriteHalfWidth); + right = DVector2(pos.X + viewpoint.Sin * spriteHalfWidth, pos.Y - viewpoint.Cos * spriteHalfWidth); return true; } @@ -70,8 +71,9 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla if (!GetLine(thing, line[0], line[1])) return; - DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); - pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac); + pos.Z += thing->GetBobOffset(viewpoint.TicFrac); bool flipTextureX = false; FTexture *tex = GetSpriteTexture(thing, flipTextureX); @@ -105,7 +107,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla return; bool foggy = false; - int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; + int actualextralight = foggy ? 0 : viewpoint.extralight << 4; std::pair offsets[4] = { @@ -250,7 +252,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla args.SetTexture(tex, thing->Translation, true); } - if (!swrenderer::RenderViewport::Instance()->RenderTarget->IsBgra()) + if (!PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra()) { uint32_t r = (args.uniforms.color >> 16) & 0xff; uint32_t g = (args.uniforms.color >> 8) & 0xff; @@ -273,7 +275,7 @@ bool RenderPolySprite::IsThingCulled(AActor *thing) FIntCVar *cvar = thing->GetClass()->distancecheck; if (cvar != nullptr && *cvar >= 0) { - double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); + double dist = (thing->Pos() - PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos).LengthSquared(); double check = (double)**cvar; if (dist >= check * check) return true; @@ -372,6 +374,7 @@ visstyle_t RenderPolySprite::GetSpriteVisStyle(AActor *thing, double z) FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX) { + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; flipX = false; if (thing->picnum.isValid()) { @@ -385,9 +388,9 @@ FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX) { // choose a different rotation based on player view spriteframe_t *sprframe = &SpriteFrames[tex->Rotations]; - DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); - pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); - DAngle ang = (pos - r_viewpoint.Pos).Angle(); + DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac); + pos.Z += thing->GetBobOffset(viewpoint.TicFrac); + DAngle ang = (pos - viewpoint.Pos).Angle(); angle_t rot; if (sprframe->Texture[0] == sprframe->Texture[1]) { @@ -420,9 +423,9 @@ FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX) //picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0]; // choose a different rotation based on player view spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame]; - DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); - pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); - DAngle ang = (pos - r_viewpoint.Pos).Angle(); + DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac); + pos.Z += thing->GetBobOffset(viewpoint.TicFrac); + DAngle ang = (pos - viewpoint.Pos).Angle(); angle_t rot; if (sprframe->Texture[0] == sprframe->Texture[1]) { diff --git a/src/polyrenderer/scene/poly_wall.cpp b/src/polyrenderer/scene/poly_wall.cpp index 4ce7e5f8e..6defccc8d 100644 --- a/src/polyrenderer/scene/poly_wall.cpp +++ b/src/polyrenderer/scene/poly_wall.cpp @@ -362,7 +362,7 @@ int RenderPolyWall::GetLightLevel() else { bool foggy = false; - int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; + int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Thread.Viewport->viewpoint.extralight << 4; return clamp(Side->GetLightLevel(foggy, LineSeg->frontsector->lightlevel) + actualextralight, 0, 255); } } diff --git a/src/polyrenderer/scene/poly_wallsprite.cpp b/src/polyrenderer/scene/poly_wallsprite.cpp index a249bc14a..02ed751f1 100644 --- a/src/polyrenderer/scene/poly_wallsprite.cpp +++ b/src/polyrenderer/scene/poly_wallsprite.cpp @@ -34,8 +34,9 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli if (RenderPolySprite::IsThingCulled(thing)) return; - DVector3 pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); - pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); + const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac); + pos.Z += thing->GetBobOffset(viewpoint.TicFrac); bool flipTextureX = false; FTexture *tex = RenderPolySprite::GetSpriteTexture(thing, flipTextureX); @@ -73,7 +74,7 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli return; bool foggy = false; - int actualextralight = foggy ? 0 : r_viewpoint.extralight << 4; + int actualextralight = foggy ? 0 : viewpoint.extralight << 4; std::pair offsets[4] = { diff --git a/src/r_renderer.h b/src/r_renderer.h index 922ccabec..69ba8e6cf 100644 --- a/src/r_renderer.h +++ b/src/r_renderer.h @@ -62,6 +62,8 @@ struct FRenderer virtual void CleanLevelData() {} virtual bool RequireGLNodes() { return false; } + virtual double GetVisibility() { return 8.f; } + virtual void SetVisibility(double vis) { } }; diff --git a/src/swrenderer/drawers/r_draw.h b/src/swrenderer/drawers/r_draw.h index 3d8d58dc5..f4c7ec11e 100644 --- a/src/swrenderer/drawers/r_draw.h +++ b/src/swrenderer/drawers/r_draw.h @@ -84,9 +84,9 @@ namespace swrenderer virtual void DrawSpanAddClamp(const SpanDrawerArgs &args) = 0; virtual void DrawSpanMaskedAddClamp(const SpanDrawerArgs &args) = 0; virtual void FillSpan(const SpanDrawerArgs &args) = 0; - virtual void DrawTiltedSpan(const SpanDrawerArgs &args, int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) = 0; - virtual void DrawColoredSpan(const SpanDrawerArgs &args, int y, int x1, int x2) = 0; - virtual void DrawFogBoundaryLine(const SpanDrawerArgs &args, int y, int x1, int x2) = 0; + virtual void DrawTiltedSpan(const SpanDrawerArgs &args, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) = 0; + virtual void DrawColoredSpan(const SpanDrawerArgs &args) = 0; + virtual void DrawFogBoundaryLine(const SpanDrawerArgs &args) = 0; DrawerCommandQueuePtr Queue; }; diff --git a/src/swrenderer/drawers/r_draw_pal.cpp b/src/swrenderer/drawers/r_draw_pal.cpp index 50762072f..5bfcf8d77 100644 --- a/src/swrenderer/drawers/r_draw_pal.cpp +++ b/src/swrenderer/drawers/r_draw_pal.cpp @@ -157,12 +157,12 @@ namespace swrenderer { uint32_t fracstep = args.TextureVStep(); uint32_t frac = args.TextureVPos(); - uint8_t *colormap = args.Colormap(); + uint8_t *colormap = args.Colormap(args.Viewport()); int count = args.Count(); const uint8_t *source = args.TexturePixels(); uint8_t *dest = args.Dest(); int bits = args.TextureFracBits(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); DrawerLight *dynlights = args.dc_lights; int num_dynlights = args.dc_num_lights; float viewpos_z = args.dc_viewpos.Z; @@ -208,12 +208,12 @@ namespace swrenderer { uint32_t fracstep = args.TextureVStep(); uint32_t frac = args.TextureVPos(); - uint8_t *colormap = args.Colormap(); + uint8_t *colormap = args.Colormap(args.Viewport()); int count = args.Count(); const uint8_t *source = args.TexturePixels(); uint8_t *dest = args.Dest(); int bits = args.TextureFracBits(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); DrawerLight *dynlights = args.dc_lights; int num_dynlights = args.dc_num_lights; float viewpos_z = args.dc_viewpos.Z; @@ -267,12 +267,12 @@ namespace swrenderer { uint32_t fracstep = args.TextureVStep(); uint32_t frac = args.TextureVPos(); - uint8_t *colormap = args.Colormap(); + uint8_t *colormap = args.Colormap(args.Viewport()); int count = args.Count(); const uint8_t *source = args.TexturePixels(); uint8_t *dest = args.Dest(); int bits = args.TextureFracBits(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); uint32_t *fg2rgb = args.SrcBlend(); uint32_t *bg2rgb = args.DestBlend(); @@ -329,12 +329,12 @@ namespace swrenderer { uint32_t fracstep = args.TextureVStep(); uint32_t frac = args.TextureVPos(); - uint8_t *colormap = args.Colormap(); + uint8_t *colormap = args.Colormap(args.Viewport()); int count = args.Count(); const uint8_t *source = args.TexturePixels(); uint8_t *dest = args.Dest(); int bits = args.TextureFracBits(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); DrawerLight *dynlights = args.dc_lights; int num_dynlights = args.dc_num_lights; float viewpos_z = args.dc_viewpos.Z; @@ -403,12 +403,12 @@ namespace swrenderer { uint32_t fracstep = args.TextureVStep(); uint32_t frac = args.TextureVPos(); - uint8_t *colormap = args.Colormap(); + uint8_t *colormap = args.Colormap(args.Viewport()); int count = args.Count(); const uint8_t *source = args.TexturePixels(); uint8_t *dest = args.Dest(); int bits = args.TextureFracBits(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); DrawerLight *dynlights = args.dc_lights; int num_dynlights = args.dc_num_lights; float viewpos_z = args.dc_viewpos.Z; @@ -476,12 +476,12 @@ namespace swrenderer { uint32_t fracstep = args.TextureVStep(); uint32_t frac = args.TextureVPos(); - uint8_t *colormap = args.Colormap(); + uint8_t *colormap = args.Colormap(args.Viewport()); int count = args.Count(); const uint8_t *source = args.TexturePixels(); uint8_t *dest = args.Dest(); int bits = args.TextureFracBits(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); DrawerLight *dynlights = args.dc_lights; int num_dynlights = args.dc_num_lights; float viewpos_z = args.dc_viewpos.Z; @@ -555,7 +555,7 @@ namespace swrenderer { uint8_t *dest = args.Dest(); int count = args.Count(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); const uint8_t *source0 = args.FrontTexturePixels(); int textureheight0 = args.FrontTextureHeight(); @@ -689,7 +689,7 @@ namespace swrenderer { uint8_t *dest = args.Dest(); int count = args.Count(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); const uint8_t *source0 = args.FrontTexturePixels(); const uint8_t *source1 = args.BackTexturePixels(); int textureheight0 = args.FrontTextureHeight(); @@ -887,7 +887,7 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; @@ -895,7 +895,7 @@ namespace swrenderer // [RH] Get local copies of these variables so that the compiler // has a better chance of optimizing this well. - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *source = args.TexturePixels(); uint32_t dynlight = args.DynamicLight(); @@ -948,7 +948,7 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); pitch *= thread->num_cores; @@ -972,7 +972,7 @@ namespace swrenderer bg2rgb = args.DestBlend(); fg = args.SrcColorIndex(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); count = thread->count_for_thread(args.DestY(), count); if (count <= 0) @@ -1025,7 +1025,7 @@ namespace swrenderer bg2rgb = args.DestBlend(); fg = args.SrcColorIndex(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); count = thread->count_for_thread(args.DestY(), count); if (count <= 0) @@ -1082,7 +1082,7 @@ namespace swrenderer uint32_t *bg2rgb = args.DestBlend(); uint32_t fg = args.SrcColorIndex(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); count = thread->count_for_thread(args.DestY(), count); if (count <= 0) @@ -1142,7 +1142,7 @@ namespace swrenderer uint32_t *bg2rgb = args.DestBlend(); uint32_t fg = args.SrcColorIndex(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); count = thread->count_for_thread(args.DestY(), count); if (count <= 0) @@ -1206,7 +1206,7 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; @@ -1214,7 +1214,7 @@ namespace swrenderer uint32_t *fg2rgb = args.SrcBlend(); uint32_t *bg2rgb = args.DestBlend(); - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *source = args.TexturePixels(); const PalEntry *palette = GPalette.BaseColors; @@ -1270,14 +1270,14 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; pitch *= thread->num_cores; // [RH] Local copies of global vars to improve compiler optimizations - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *translation = args.TranslationMap(); const uint8_t *source = args.TexturePixels(); @@ -1307,7 +1307,7 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; @@ -1316,7 +1316,7 @@ namespace swrenderer uint32_t *fg2rgb = args.SrcBlend(); uint32_t *bg2rgb = args.DestBlend(); const uint8_t *translation = args.TranslationMap(); - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *source = args.TexturePixels(); const PalEntry *palette = GPalette.BaseColors; @@ -1370,14 +1370,14 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; pitch *= thread->num_cores; const uint8_t *source = args.TexturePixels(); - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); uint32_t *fgstart = &Col2RGB8[0][args.SolidColor()]; const PalEntry *palette = GPalette.BaseColors; @@ -1429,13 +1429,13 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; pitch *= thread->num_cores; - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *source = args.TexturePixels(); uint32_t *fg2rgb = args.SrcBlend(); uint32_t *bg2rgb = args.DestBlend(); @@ -1493,14 +1493,14 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; pitch *= thread->num_cores; const uint8_t *translation = args.TranslationMap(); - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *source = args.TexturePixels(); uint32_t *fg2rgb = args.SrcBlend(); uint32_t *bg2rgb = args.DestBlend(); @@ -1558,13 +1558,13 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; pitch *= thread->num_cores; - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *source = args.TexturePixels(); uint32_t *fg2rgb = args.SrcBlend(); uint32_t *bg2rgb = args.DestBlend(); @@ -1621,14 +1621,14 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; pitch *= thread->num_cores; const uint8_t *translation = args.TranslationMap(); - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *source = args.TexturePixels(); uint32_t *fg2rgb = args.SrcBlend(); uint32_t *bg2rgb = args.DestBlend(); @@ -1685,13 +1685,13 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; pitch *= thread->num_cores; - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *source = args.TexturePixels(); uint32_t *fg2rgb = args.SrcBlend(); uint32_t *bg2rgb = args.DestBlend(); @@ -1748,14 +1748,14 @@ namespace swrenderer if (count <= 0) return; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); dest = thread->dest_for_thread(args.DestY(), pitch, dest); frac += fracstep * thread->skipped_by_thread(args.DestY()); fracstep *= thread->num_cores; pitch *= thread->num_cores; const uint8_t *translation = args.TranslationMap(); - const uint8_t *colormap = args.Colormap(); + const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *source = args.TexturePixels(); uint32_t *fg2rgb = args.SrcBlend(); uint32_t *bg2rgb = args.DestBlend(); @@ -1802,7 +1802,8 @@ namespace swrenderer _yl = args.FuzzY1(); _yh = args.FuzzY2(); _x = args.FuzzX(); - _destorg = RenderViewport::Instance()->GetDest(0, 0); + _destorg = args.Viewport()->GetDest(0, 0); + _pitch = args.Viewport()->RenderTarget->GetPitch(); _fuzzpos = fuzzpos; _fuzzviewheight = fuzzviewheight; } @@ -1820,7 +1821,7 @@ namespace swrenderer uint8_t *map = &NormalLight.Maps[6 * 256]; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = _pitch; uint8_t *dest = thread->dest_for_thread(yl, pitch, yl * pitch + _x + _destorg); pitch = pitch * thread->num_cores; @@ -1887,13 +1888,13 @@ namespace swrenderer PalSpanCommand::PalSpanCommand(const SpanDrawerArgs &args) { _source = args.TexturePixels(); - _colormap = args.Colormap(); + _colormap = args.Colormap(args.Viewport()); _xfrac = args.TextureUPos(); _yfrac = args.TextureVPos(); _y = args.DestY(); _x1 = args.DestX1(); _x2 = args.DestX2(); - _dest = RenderViewport::Instance()->GetDest(_x1, _y); + _dest = args.Viewport()->GetDest(_x1, _y); _xstep = args.TextureUStep(); _ystep = args.TextureVStep(); _xbits = args.TextureWidthBits(); @@ -2662,11 +2663,15 @@ namespace swrenderer ///////////////////////////////////////////////////////////////////////// - DrawTiltedSpanPalCommand::DrawTiltedSpanPalCommand(const SpanDrawerArgs &args, int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) - : y(y), x1(x1), x2(x2), plane_sz(plane_sz), plane_su(plane_su), plane_sv(plane_sv), plane_shade(plane_shade), planeshade(planeshade), planelightfloat(planelightfloat), pviewx(pviewx), pviewy(pviewy) + DrawTiltedSpanPalCommand::DrawTiltedSpanPalCommand(const SpanDrawerArgs &args, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) + : plane_sz(plane_sz), plane_su(plane_su), plane_sv(plane_sv), plane_shade(plane_shade), planeshade(planeshade), planelightfloat(planelightfloat), pviewx(pviewx), pviewy(pviewy) { - _colormap = args.Colormap(); - _dest = RenderViewport::Instance()->GetDest(x1, y); + y = args.DestY(); + x1 = args.DestX1(); + x2 = args.DestX2(); + viewport = args.Viewport(); + _colormap = args.Colormap(args.Viewport()); + _dest = args.Viewport()->GetDest(x1, y); _ybits = args.TextureHeightBits(); _xbits = args.TextureWidthBits(); _source = args.TexturePixels(); @@ -2686,7 +2691,7 @@ namespace swrenderer uint32_t u, v; int i; - iz = plane_sz[2] + plane_sz[1] * (r_viewwindow.centery - y) + plane_sz[0] * (x1 - r_viewwindow.centerx); + iz = plane_sz[2] + plane_sz[1] * (viewport->viewwindow.centery - y) + plane_sz[0] * (x1 - viewport->viewwindow.centerx); // Lighting is simple. It's just linear interpolation from start to end if (plane_shade) @@ -2703,8 +2708,8 @@ namespace swrenderer } } - uz = plane_su[2] + plane_su[1] * (r_viewwindow.centery - y) + plane_su[0] * (x1 - r_viewwindow.centerx); - vz = plane_sv[2] + plane_sv[1] * (r_viewwindow.centery - y) + plane_sv[0] * (x1 - r_viewwindow.centerx); + uz = plane_su[2] + plane_su[1] * (viewport->viewwindow.centery - y) + plane_su[0] * (x1 - viewport->viewwindow.centerx); + vz = plane_sv[2] + plane_sv[1] * (viewport->viewwindow.centery - y) + plane_sv[0] * (x1 - viewport->viewwindow.centerx); fb = _dest; @@ -2838,10 +2843,13 @@ namespace swrenderer ///////////////////////////////////////////////////////////////////////// - DrawColoredSpanPalCommand::DrawColoredSpanPalCommand(const SpanDrawerArgs &args, int y, int x1, int x2) : PalSpanCommand(args), y(y), x1(x1), x2(x2) + DrawColoredSpanPalCommand::DrawColoredSpanPalCommand(const SpanDrawerArgs &args) : PalSpanCommand(args) { + y = args.DestY(); + x1 = args.DestX1(); + x2 = args.DestX2(); color = args.SolidColor(); - dest = RenderViewport::Instance()->GetDest(x1, y); + dest = args.Viewport()->GetDest(x1, y); } void DrawColoredSpanPalCommand::Execute(DrawerThread *thread) @@ -2854,10 +2862,13 @@ namespace swrenderer ///////////////////////////////////////////////////////////////////////// - DrawFogBoundaryLinePalCommand::DrawFogBoundaryLinePalCommand(const SpanDrawerArgs &args, int y, int x1, int x2) : PalSpanCommand(args), y(y), x1(x1), x2(x2) + DrawFogBoundaryLinePalCommand::DrawFogBoundaryLinePalCommand(const SpanDrawerArgs &args) : PalSpanCommand(args) { - _colormap = args.Colormap(); - _dest = RenderViewport::Instance()->GetDest(0, y); + y = args.DestY(); + x1 = args.DestX1(); + x2 = args.DestX2(); + _colormap = args.Colormap(args.Viewport()); + _dest = args.Viewport()->GetDest(0, y); } void DrawFogBoundaryLinePalCommand::Execute(DrawerThread *thread) diff --git a/src/swrenderer/drawers/r_draw_pal.h b/src/swrenderer/drawers/r_draw_pal.h index b57bfdf30..cca11e934 100644 --- a/src/swrenderer/drawers/r_draw_pal.h +++ b/src/swrenderer/drawers/r_draw_pal.h @@ -84,6 +84,7 @@ namespace swrenderer int _yh; int _x; uint8_t *_destorg; + int _pitch; int _fuzzpos; int _fuzzviewheight; }; @@ -131,7 +132,7 @@ namespace swrenderer class DrawTiltedSpanPalCommand : public DrawerCommand { public: - DrawTiltedSpanPalCommand(const SpanDrawerArgs &args, int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap); + DrawTiltedSpanPalCommand(const SpanDrawerArgs &args, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap); void Execute(DrawerThread *thread) override; FString DebugInfo() override { return "DrawTiltedSpanPalCommand"; } @@ -156,12 +157,13 @@ namespace swrenderer int _xbits; const uint8_t *_source; uint8_t *basecolormapdata; + RenderViewport *viewport; }; class DrawColoredSpanPalCommand : public PalSpanCommand { public: - DrawColoredSpanPalCommand(const SpanDrawerArgs &args, int y, int x1, int x2); + DrawColoredSpanPalCommand(const SpanDrawerArgs &args); void Execute(DrawerThread *thread) override; FString DebugInfo() override { return "DrawColoredSpanPalCommand"; } @@ -176,7 +178,7 @@ namespace swrenderer class DrawFogBoundaryLinePalCommand : public PalSpanCommand { public: - DrawFogBoundaryLinePalCommand(const SpanDrawerArgs &args, int y, int x1, int x2); + DrawFogBoundaryLinePalCommand(const SpanDrawerArgs &args); void Execute(DrawerThread *thread) override; private: @@ -248,12 +250,12 @@ namespace swrenderer void DrawSpanMaskedAddClamp(const SpanDrawerArgs &args) override { Queue->Push(args); } void FillSpan(const SpanDrawerArgs &args) override { Queue->Push(args); } - void DrawTiltedSpan(const SpanDrawerArgs &args, int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) override + void DrawTiltedSpan(const SpanDrawerArgs &args, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) override { - Queue->Push(args, y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap); + Queue->Push(args, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap); } - void DrawColoredSpan(const SpanDrawerArgs &args, int y, int x1, int x2) override { Queue->Push(args, y, x1, x2); } - void DrawFogBoundaryLine(const SpanDrawerArgs &args, int y, int x1, int x2) override { Queue->Push(args, y, x1, x2); } + void DrawColoredSpan(const SpanDrawerArgs &args) override { Queue->Push(args); } + void DrawFogBoundaryLine(const SpanDrawerArgs &args) override { Queue->Push(args); } }; } diff --git a/src/swrenderer/drawers/r_draw_rgba.cpp b/src/swrenderer/drawers/r_draw_rgba.cpp index 011d50903..daf4fba7f 100644 --- a/src/swrenderer/drawers/r_draw_rgba.cpp +++ b/src/swrenderer/drawers/r_draw_rgba.cpp @@ -233,8 +233,8 @@ namespace swrenderer _x = drawerargs.FuzzX(); _yl = drawerargs.FuzzY1(); _yh = drawerargs.FuzzY2(); - _destorg = RenderViewport::Instance()->GetDest(0, 0); - _pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + _destorg = drawerargs.Viewport()->GetDest(0, 0); + _pitch = drawerargs.Viewport()->RenderTarget->GetPitch(); _fuzzpos = fuzzpos; _fuzzviewheight = fuzzviewheight; } @@ -341,7 +341,7 @@ namespace swrenderer _x1 = drawerargs.DestX1(); _x2 = drawerargs.DestX2(); _y = drawerargs.DestY(); - _dest = RenderViewport::Instance()->GetDest(_x1, _y); + _dest = drawerargs.Viewport()->GetDest(_x1, _y); _light = drawerargs.Light(); _color = drawerargs.SolidColor(); } @@ -366,13 +366,12 @@ namespace swrenderer ///////////////////////////////////////////////////////////////////////////// - DrawFogBoundaryLineRGBACommand::DrawFogBoundaryLineRGBACommand(const SpanDrawerArgs &drawerargs, int y, int x, int x2) + DrawFogBoundaryLineRGBACommand::DrawFogBoundaryLineRGBACommand(const SpanDrawerArgs &drawerargs) { - _y = y; - _x = x; - _x2 = x2; - - _line = RenderViewport::Instance()->GetDest(0, y); + _y = drawerargs.DestY(); + _x = drawerargs.DestX1(); + _x2 = drawerargs.DestX2(); + _line = drawerargs.Viewport()->GetDest(0, _y); _light = drawerargs.Light(); _shade_constants = drawerargs.ColormapConstants(); } @@ -434,12 +433,12 @@ namespace swrenderer ///////////////////////////////////////////////////////////////////////////// - DrawTiltedSpanRGBACommand::DrawTiltedSpanRGBACommand(const SpanDrawerArgs &drawerargs, int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy) + DrawTiltedSpanRGBACommand::DrawTiltedSpanRGBACommand(const SpanDrawerArgs &drawerargs, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy) { - _x1 = x1; - _x2 = x2; - _y = y; - _dest = RenderViewport::Instance()->GetDest(_x1, _y); + _x1 = drawerargs.DestX1(); + _x2 = drawerargs.DestX2(); + _y = drawerargs.DestY(); + _dest = drawerargs.Viewport()->GetDest(_x1, _y); _light = drawerargs.Light(); _shade_constants = drawerargs.ColormapConstants(); _plane_sz = plane_sz; @@ -453,6 +452,7 @@ namespace swrenderer _source = (const uint32_t*)drawerargs.TexturePixels(); _xbits = drawerargs.TextureWidthBits(); _ybits = drawerargs.TextureHeightBits(); + viewport = drawerargs.Viewport(); } void DrawTiltedSpanRGBACommand::Execute(DrawerThread *thread) @@ -474,7 +474,7 @@ namespace swrenderer int count = _x2 - _x1 + 1; // Depth (Z) change across the span - double iz = _plane_sz[2] + _plane_sz[1] * (r_viewwindow.centery - _y) + _plane_sz[0] * (_x1 - r_viewwindow.centerx); + double iz = _plane_sz[2] + _plane_sz[1] * (viewport->viewwindow.centery - _y) + _plane_sz[0] * (_x1 - viewport->viewwindow.centerx); // Light change across the span fixed_t lightstart = _light; @@ -491,8 +491,8 @@ namespace swrenderer fixed_t steplight = (lightend - lightstart) / count; // Texture coordinates - double uz = _plane_su[2] + _plane_su[1] * (r_viewwindow.centery - _y) + _plane_su[0] * (_x1 - r_viewwindow.centerx); - double vz = _plane_sv[2] + _plane_sv[1] * (r_viewwindow.centery - _y) + _plane_sv[0] * (_x1 - r_viewwindow.centerx); + double uz = _plane_su[2] + _plane_su[1] * (viewport->viewwindow.centery - _y) + _plane_su[0] * (_x1 - viewport->viewwindow.centerx); + double vz = _plane_sv[2] + _plane_sv[1] * (viewport->viewwindow.centery - _y) + _plane_sv[0] * (_x1 - viewport->viewwindow.centerx); double startz = 1.f / iz; double startu = uz*startz; double startv = vz*startz; @@ -568,13 +568,12 @@ namespace swrenderer ///////////////////////////////////////////////////////////////////////////// - DrawColoredSpanRGBACommand::DrawColoredSpanRGBACommand(const SpanDrawerArgs &drawerargs, int y, int x1, int x2) + DrawColoredSpanRGBACommand::DrawColoredSpanRGBACommand(const SpanDrawerArgs &drawerargs) { - _y = y; - _x1 = x1; - _x2 = x2; - - _dest = RenderViewport::Instance()->GetDest(_x1, _y); + _y = drawerargs.DestY(); + _x1 = drawerargs.DestX1(); + _x2 = drawerargs.DestX2(); + _dest = drawerargs.Viewport()->GetDest(_x1, _y); _light = drawerargs.Light(); _color = drawerargs.SolidColor(); } @@ -603,67 +602,6 @@ namespace swrenderer ///////////////////////////////////////////////////////////////////////////// - FillTransColumnRGBACommand::FillTransColumnRGBACommand(const DrawerArgs &drawerargs, int x, int y1, int y2, int color, int a) - { - _x = x; - _y1 = y1; - _y2 = y2; - _color = color; - _a = a; - - _destorg = RenderViewport::Instance()->GetDest(0, 0); - _pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); - } - - void FillTransColumnRGBACommand::Execute(DrawerThread *thread) - { - int x = _x; - int y1 = _y1; - int y2 = _y2; - int color = _color; - int a = _a; - - int ycount = thread->count_for_thread(y1, y2 - y1 + 1); - if (ycount <= 0) - return; - - uint32_t fg = GPalette.BaseColors[color].d; - uint32_t fg_red = (fg >> 16) & 0xff; - uint32_t fg_green = (fg >> 8) & 0xff; - uint32_t fg_blue = fg & 0xff; - - uint32_t alpha = a + 1; - uint32_t inv_alpha = 256 - alpha; - - fg_red *= alpha; - fg_green *= alpha; - fg_blue *= alpha; - - int spacing = _pitch * thread->num_cores; - uint32_t *dest = thread->dest_for_thread(y1, _pitch, _pitch * y1 + x + (uint32_t*)_destorg); - - for (int y = 0; y < ycount; y++) - { - uint32_t bg_red = (*dest >> 16) & 0xff; - uint32_t bg_green = (*dest >> 8) & 0xff; - uint32_t bg_blue = (*dest) & 0xff; - - uint32_t red = (fg_red + bg_red * inv_alpha) / 256; - uint32_t green = (fg_green + bg_green * inv_alpha) / 256; - uint32_t blue = (fg_blue + bg_blue * inv_alpha) / 256; - - *dest = 0xff000000 | (red << 16) | (green << 8) | blue; - dest += spacing; - } - } - - FString FillTransColumnRGBACommand::DebugInfo() - { - return "FillTransColumn"; - } - - ///////////////////////////////////////////////////////////////////////////// - ApplySpecialColormapRGBACommand::ApplySpecialColormapRGBACommand(FSpecialColormap *colormap, DFrameBuffer *screen) { buffer = screen->GetBuffer(); diff --git a/src/swrenderer/drawers/r_draw_rgba.h b/src/swrenderer/drawers/r_draw_rgba.h index 263a5a643..67768fb3b 100644 --- a/src/swrenderer/drawers/r_draw_rgba.h +++ b/src/swrenderer/drawers/r_draw_rgba.h @@ -115,7 +115,7 @@ namespace swrenderer ShadeConstants _shade_constants; public: - DrawFogBoundaryLineRGBACommand(const SpanDrawerArgs &drawerargs, int y, int x, int x2); + DrawFogBoundaryLineRGBACommand(const SpanDrawerArgs &drawerargs); void Execute(DrawerThread *thread) override; FString DebugInfo() override; }; @@ -139,9 +139,10 @@ namespace swrenderer int _xbits; int _ybits; const uint32_t * RESTRICT _source; + RenderViewport *viewport; public: - DrawTiltedSpanRGBACommand(const SpanDrawerArgs &drawerargs, int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy); + DrawTiltedSpanRGBACommand(const SpanDrawerArgs &drawerargs, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy); void Execute(DrawerThread *thread) override; FString DebugInfo() override; }; @@ -156,29 +157,12 @@ namespace swrenderer int _color; public: - DrawColoredSpanRGBACommand(const SpanDrawerArgs &drawerargs, int y, int x1, int x2); + DrawColoredSpanRGBACommand(const SpanDrawerArgs &drawerargs); void Execute(DrawerThread *thread) override; FString DebugInfo() override; }; - class FillTransColumnRGBACommand : public DrawerCommand - { - int _x; - int _y1; - int _y2; - int _color; - int _a; - uint8_t * RESTRICT _destorg; - int _pitch; - fixed_t _light; - - public: - FillTransColumnRGBACommand(const DrawerArgs &drawerargs, int x, int y1, int y2, int color, int a); - void Execute(DrawerThread *thread) override; - FString DebugInfo() override; - }; - class ApplySpecialColormapRGBACommand : public DrawerCommand { uint8_t *buffer; @@ -273,13 +257,13 @@ namespace swrenderer void DrawSpanMaskedAddClamp(const SpanDrawerArgs &args) override; void FillSpan(const SpanDrawerArgs &args) override { Queue->Push(args); } - void DrawTiltedSpan(const SpanDrawerArgs &args, int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) override + void DrawTiltedSpan(const SpanDrawerArgs &args, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) override { - Queue->Push(args, y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy); + Queue->Push(args, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy); } - void DrawColoredSpan(const SpanDrawerArgs &args, int y, int x1, int x2) override { Queue->Push(args, y, x1, x2); } - void DrawFogBoundaryLine(const SpanDrawerArgs &args, int y, int x1, int x2) override { Queue->Push(args, y, x1, x2); } + void DrawColoredSpan(const SpanDrawerArgs &args) override { Queue->Push(args); } + void DrawFogBoundaryLine(const SpanDrawerArgs &args) override { Queue->Push(args); } }; ///////////////////////////////////////////////////////////////////////////// diff --git a/src/swrenderer/drawers/r_draw_sky32_sse2.h b/src/swrenderer/drawers/r_draw_sky32_sse2.h index f047c7795..997aac030 100644 --- a/src/swrenderer/drawers/r_draw_sky32_sse2.h +++ b/src/swrenderer/drawers/r_draw_sky32_sse2.h @@ -39,7 +39,7 @@ namespace swrenderer { uint32_t *dest = (uint32_t *)args.Dest(); int count = args.Count(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); const uint32_t *source0 = (const uint32_t *)args.FrontTexturePixels(); int textureheight0 = args.FrontTextureHeight(); @@ -169,7 +169,7 @@ namespace swrenderer { uint32_t *dest = (uint32_t *)args.Dest(); int count = args.Count(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); const uint32_t *source0 = (const uint32_t *)args.FrontTexturePixels(); const uint32_t *source1 = (const uint32_t *)args.BackTexturePixels(); int textureheight0 = args.FrontTextureHeight(); diff --git a/src/swrenderer/drawers/r_draw_span32_sse2.h b/src/swrenderer/drawers/r_draw_span32_sse2.h index 94d5b278c..68d68ec82 100644 --- a/src/swrenderer/drawers/r_draw_span32_sse2.h +++ b/src/swrenderer/drawers/r_draw_span32_sse2.h @@ -188,8 +188,8 @@ namespace swrenderer __m128 step_viewpos_x = _mm_set1_ps(stepvpx * 2.0f); int count = args.DestX2() - args.DestX1() + 1; - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); - uint32_t *dest = (uint32_t*)RenderViewport::Instance()->GetDest(args.DestX1(), args.DestY()); + int pitch = args.Viewport()->RenderTarget->GetPitch(); + uint32_t *dest = (uint32_t*)args.Viewport()->GetDest(args.DestX1(), args.DestY()); if (FilterModeT::Mode == (int)FilterModes::Linear) { diff --git a/src/swrenderer/drawers/r_draw_sprite32_sse2.h b/src/swrenderer/drawers/r_draw_sprite32_sse2.h index dc4a42172..3f10a86f8 100644 --- a/src/swrenderer/drawers/r_draw_sprite32_sse2.h +++ b/src/swrenderer/drawers/r_draw_sprite32_sse2.h @@ -113,7 +113,7 @@ namespace swrenderer { source = (const uint32_t*)args.TexturePixels(); source2 = nullptr; - colormap = args.Colormap(); + colormap = args.Colormap(args.Viewport()); translation = (const uint32_t*)args.TranslationMap(); } else @@ -162,7 +162,7 @@ namespace swrenderer } int count = args.Count(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); uint32_t fracstep = args.TextureVStep(); uint32_t frac = args.TextureVPos(); uint32_t texturefracx = args.TextureUPos(); diff --git a/src/swrenderer/drawers/r_draw_wall32_sse2.h b/src/swrenderer/drawers/r_draw_wall32_sse2.h index 31ab06e86..8ac116da4 100644 --- a/src/swrenderer/drawers/r_draw_wall32_sse2.h +++ b/src/swrenderer/drawers/r_draw_wall32_sse2.h @@ -112,7 +112,7 @@ namespace swrenderer } int count = args.Count(); - int pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); + int pitch = args.Viewport()->RenderTarget->GetPitch(); uint32_t fracstep = args.TextureVStep(); uint32_t frac = args.TextureVPos(); uint32_t texturefracx = args.TextureUPos(); diff --git a/src/swrenderer/line/r_line.cpp b/src/swrenderer/line/r_line.cpp index d8eee70bb..0352a879f 100644 --- a/src/swrenderer/line/r_line.cpp +++ b/src/swrenderer/line/r_line.cpp @@ -73,8 +73,8 @@ namespace swrenderer basecolormap = colormap; mLineSegment = line; - DVector2 pt1 = line->v1->fPos() - r_viewpoint.Pos; - DVector2 pt2 = line->v2->fPos() - r_viewpoint.Pos; + DVector2 pt1 = line->v1->fPos() - Thread->Viewport->viewpoint.Pos; + DVector2 pt2 = line->v2->fPos() - Thread->Viewport->viewpoint.Pos; // Reject lines not facing viewer if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0) @@ -98,7 +98,7 @@ namespace swrenderer // reject lines that aren't seen from the portal (if any) // [ZZ] 10.01.2016: lines inside a skybox shouldn't be clipped, although this imposes some limitations on portals in skyboxes. - if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, r_viewpoint.Pos)) + if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, Thread->Viewport->viewpoint.Pos)) return; vertex_t *v1 = line->linedef->v1; @@ -114,7 +114,7 @@ namespace swrenderer { swapvalues(v1, v2); } - WallT.InitFromLine(Thread, v1->fPos() - r_viewpoint.Pos, v2->fPos() - r_viewpoint.Pos); + WallT.InitFromLine(Thread, v1->fPos() - Thread->Viewport->viewpoint.Pos, v2->fPos() - Thread->Viewport->viewpoint.Pos); } mFrontCeilingZ1 = mFrontSector->ceilingplane.ZatPoint(line->v1); @@ -363,13 +363,13 @@ namespace swrenderer draw_segment->silhouette = 0; if (mFrontFloorZ1 > mBackFloorZ1 || mFrontFloorZ2 > mBackFloorZ2 || - mBackSector->floorplane.PointOnSide(r_viewpoint.Pos) < 0) + mBackSector->floorplane.PointOnSide(Thread->Viewport->viewpoint.Pos) < 0) { draw_segment->silhouette = SIL_BOTTOM; } if (mFrontCeilingZ1 < mBackCeilingZ1 || mFrontCeilingZ2 < mBackCeilingZ2 || - mBackSector->ceilingplane.PointOnSide(r_viewpoint.Pos) < 0) + mBackSector->ceilingplane.PointOnSide(Thread->Viewport->viewpoint.Pos) < 0) { draw_segment->silhouette |= SIL_TOP; } @@ -496,7 +496,7 @@ namespace swrenderer } else { - draw_segment->shade = LightVisibility::LightLevelToShade(mLineSegment->sidedef->GetLightLevel(foggy, mLineSegment->frontsector->lightlevel) + LightVisibility::ActualExtraLight(foggy), foggy); + draw_segment->shade = LightVisibility::LightLevelToShade(mLineSegment->sidedef->GetLightLevel(foggy, mLineSegment->frontsector->lightlevel) + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy); } if (draw_segment->bFogBoundary || draw_segment->maskedtexturecol != nullptr) @@ -564,7 +564,7 @@ namespace swrenderer // deep water check if (mFrontSector->GetHeightSec() == nullptr) { - int planeside = mFrontSector->floorplane.PointOnSide(r_viewpoint.Pos); + int planeside = mFrontSector->floorplane.PointOnSide(Thread->Viewport->viewpoint.Pos); if (mFrontSector->floorplane.fC() < 0) // 3D floors have the floor backwards planeside = -planeside; if (planeside <= 0) // above view plane @@ -621,7 +621,7 @@ namespace swrenderer // deep water check if (mFrontSector->GetHeightSec() == nullptr && mFrontSector->GetTexture(sector_t::ceiling) != skyflatnum) { - int planeside = mFrontSector->ceilingplane.PointOnSide(r_viewpoint.Pos); + int planeside = mFrontSector->ceilingplane.PointOnSide(Thread->Viewport->viewpoint.Pos); if (mFrontSector->ceilingplane.fC() > 0) // 3D floors have the ceiling backwards planeside = -planeside; if (planeside <= 0) // below view plane @@ -706,25 +706,25 @@ namespace swrenderer if (mFrontCeilingZ1 > mBackCeilingZ1 || mFrontCeilingZ2 > mBackCeilingZ2) { rw_havehigh = true; - wallupper.Project(mBackSector->ceilingplane, &WallC, mLineSegment, renderportal->MirrorFlags & RF_XFLIP); + wallupper.Project(Thread->Viewport.get(), mBackSector->ceilingplane, &WallC, mLineSegment, renderportal->MirrorFlags & RF_XFLIP); } if (mFrontFloorZ1 < mBackFloorZ1 || mFrontFloorZ2 < mBackFloorZ2) { rw_havelow = true; - walllower.Project(mBackSector->floorplane, &WallC, mLineSegment, renderportal->MirrorFlags & RF_XFLIP); + walllower.Project(Thread->Viewport.get(), mBackSector->floorplane, &WallC, mLineSegment, renderportal->MirrorFlags & RF_XFLIP); } } if (mLineSegment->linedef->special == Line_Horizon) { // Be aware: Line_Horizon does not work properly with sloped planes - fillshort(walltop.ScreenY + WallC.sx1, WallC.sx2 - WallC.sx1, r_viewwindow.centery); - fillshort(wallbottom.ScreenY + WallC.sx1, WallC.sx2 - WallC.sx1, r_viewwindow.centery); + fillshort(walltop.ScreenY + WallC.sx1, WallC.sx2 - WallC.sx1, Thread->Viewport->viewwindow.centery); + fillshort(wallbottom.ScreenY + WallC.sx1, WallC.sx2 - WallC.sx1, Thread->Viewport->viewwindow.centery); } else { - mCeilingClipped = walltop.Project(mFrontSector->ceilingplane, &WallC, mLineSegment, renderportal->MirrorFlags & RF_XFLIP); - mFloorClipped = wallbottom.Project(mFrontSector->floorplane, &WallC, mLineSegment, renderportal->MirrorFlags & RF_XFLIP); + mCeilingClipped = walltop.Project(Thread->Viewport.get(), mFrontSector->ceilingplane, &WallC, mLineSegment, renderportal->MirrorFlags & RF_XFLIP); + mFloorClipped = wallbottom.Project(Thread->Viewport.get(), mFrontSector->floorplane, &WallC, mLineSegment, renderportal->MirrorFlags & RF_XFLIP); } side_t *sidedef = mLineSegment->sidedef; @@ -758,7 +758,7 @@ namespace swrenderer // wall but nothing to draw for it. // Recalculate walltop so that the wall is clipped by the back sector's // ceiling instead of the front sector's ceiling. - walltop.Project(mBackSector->ceilingplane, &WallC, mLineSegment, Thread->Portal->MirrorFlags & RF_XFLIP); + walltop.Project(Thread->Viewport.get(), mBackSector->ceilingplane, &WallC, mLineSegment, Thread->Portal->MirrorFlags & RF_XFLIP); } } } @@ -776,12 +776,12 @@ namespace swrenderer mBottomPart.Texture ? (mBottomPart.Texture->Scale.X * sidedef->GetTextureXScale(side_t::bottom)) : 1.; - walltexcoords.Project(sidedef->TexelLength * lwallscale, WallC.sx1, WallC.sx2, WallT); + walltexcoords.Project(Thread->Viewport.get(), sidedef->TexelLength * lwallscale, WallC.sx1, WallC.sx2, WallT); CameraLight *cameraLight = CameraLight::Instance(); if (cameraLight->FixedColormap() == nullptr && cameraLight->FixedLightLevel() < 0) { - wallshade = LightVisibility::LightLevelToShade(mLineSegment->sidedef->GetLightLevel(foggy, mFrontSector->lightlevel) + LightVisibility::ActualExtraLight(foggy), foggy); + wallshade = LightVisibility::LightLevelToShade(mLineSegment->sidedef->GetLightLevel(foggy, mFrontSector->lightlevel) + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy); double GlobVis = LightVisibility::Instance()->WallGlobVis(foggy); rw_lightleft = float(GlobVis / WallC.sz1); rw_lightstep = float((GlobVis / WallC.sz2 - rw_lightleft) / (WallC.sx2 - WallC.sx1)); @@ -819,7 +819,7 @@ namespace swrenderer { // normal orientation if (linedef->flags & ML_DONTPEGTOP) { // top of texture at top - mTopPart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat; + mTopPart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat; if (rowoffset < 0 && mTopPart.Texture != NULL) { rowoffset += mTopPart.Texture->GetHeight(); @@ -827,7 +827,7 @@ namespace swrenderer } else { // bottom of texture at bottom - mTopPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat + mTopPart.Texture->GetHeight(); + mTopPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::ceiling) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat + mTopPart.Texture->GetHeight(); } } else @@ -835,11 +835,11 @@ namespace swrenderer rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGTOP) { // bottom of texture at top - mTopPart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat + mTopPart.Texture->GetHeight(); + mTopPart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat + mTopPart.Texture->GetHeight(); } else { // top of texture at bottom - mTopPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat; + mTopPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::ceiling) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat; } } if (mTopPart.Texture->bWorldPanning) @@ -875,11 +875,11 @@ namespace swrenderer { // normal orientation if (linedef->flags & ML_DONTPEGBOTTOM) { // bottom of texture at bottom - mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::floor) - r_viewpoint.Pos.Z) * yrepeat + mMiddlePart.Texture->GetHeight(); + mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::floor) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat + mMiddlePart.Texture->GetHeight(); } else { // top of texture at top - mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat; + mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat; if (rowoffset < 0 && mMiddlePart.Texture != NULL) { rowoffset += mMiddlePart.Texture->GetHeight(); @@ -891,11 +891,11 @@ namespace swrenderer rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGBOTTOM) { // top of texture at bottom - mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::floor) - r_viewpoint.Pos.Z) * yrepeat; + mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::floor) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat; } else { // bottom of texture at top - mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - r_viewpoint.Pos.Z) * yrepeat + mMiddlePart.Texture->GetHeight(); + mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat + mMiddlePart.Texture->GetHeight(); } } if (mMiddlePart.Texture->bWorldPanning) @@ -940,11 +940,11 @@ namespace swrenderer { // normal orientation if (linedef->flags & ML_DONTPEGBOTTOM) { // bottom of texture at bottom - mBottomPart.TextureMid = (frontlowertop - r_viewpoint.Pos.Z) * yrepeat; + mBottomPart.TextureMid = (frontlowertop - Thread->Viewport->viewpoint.Pos.Z) * yrepeat; } else { // top of texture at top - mBottomPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::floor) - r_viewpoint.Pos.Z) * yrepeat; + mBottomPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::floor) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat; if (rowoffset < 0 && mBottomPart.Texture != NULL) { rowoffset += mBottomPart.Texture->GetHeight(); @@ -956,11 +956,11 @@ namespace swrenderer rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGBOTTOM) { // top of texture at bottom - mBottomPart.TextureMid = (frontlowertop - r_viewpoint.Pos.Z) * yrepeat; + mBottomPart.TextureMid = (frontlowertop - Thread->Viewport->viewpoint.Pos.Z) * yrepeat; } else { // bottom of texture at top - mBottomPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::floor) - r_viewpoint.Pos.Z) * yrepeat + mBottomPart.Texture->GetHeight(); + mBottomPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::floor) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat + mBottomPart.Texture->GetHeight(); } } if (mBottomPart.Texture->bWorldPanning) @@ -1134,7 +1134,7 @@ namespace swrenderer double yscale = rw_pic->Scale.Y * mTopPart.TextureScaleV; if (xscale != lwallscale) { - walltexcoords.ProjectPos(mLineSegment->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2, WallT); + walltexcoords.ProjectPos(Thread->Viewport.get(), mLineSegment->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2, WallT); lwallscale = xscale; } fixed_t offset; @@ -1181,7 +1181,7 @@ namespace swrenderer double yscale = rw_pic->Scale.Y * mMiddlePart.TextureScaleV; if (xscale != lwallscale) { - walltexcoords.ProjectPos(mLineSegment->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2, WallT); + walltexcoords.ProjectPos(Thread->Viewport.get(), mLineSegment->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2, WallT); lwallscale = xscale; } fixed_t offset; @@ -1229,7 +1229,7 @@ namespace swrenderer double yscale = rw_pic->Scale.Y * mBottomPart.TextureScaleV; if (xscale != lwallscale) { - walltexcoords.ProjectPos(mLineSegment->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2, WallT); + walltexcoords.ProjectPos(Thread->Viewport.get(), mLineSegment->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2, WallT); lwallscale = xscale; } fixed_t offset; @@ -1271,14 +1271,14 @@ namespace swrenderer // Transform and clip coordinates. Returns true if it was clipped away bool FWallCoords::Init(RenderThread *thread, const DVector2 &pt1, const DVector2 &pt2, double too_close) { - tleft.X = float(pt1.X * r_viewpoint.Sin - pt1.Y * r_viewpoint.Cos); - tright.X = float(pt2.X * r_viewpoint.Sin - pt2.Y * r_viewpoint.Cos); - - tleft.Y = float(pt1.X * r_viewpoint.TanCos + pt1.Y * r_viewpoint.TanSin); - tright.Y = float(pt2.X * r_viewpoint.TanCos + pt2.Y * r_viewpoint.TanSin); - + auto viewport = thread->Viewport.get(); RenderPortal *renderportal = thread->Portal.get(); - auto viewport = RenderViewport::Instance(); + + tleft.X = float(pt1.X * viewport->viewpoint.Sin - pt1.Y * viewport->viewpoint.Cos); + tright.X = float(pt2.X * viewport->viewpoint.Sin - pt2.Y * viewport->viewpoint.Cos); + + tleft.Y = float(pt1.X * viewport->viewpoint.TanCos + pt1.Y * viewport->viewpoint.TanSin); + tright.Y = float(pt2.X * viewport->viewpoint.TanCos + pt2.Y * viewport->viewpoint.TanSin); if (renderportal->MirrorFlags & RF_XFLIP) { @@ -1342,9 +1342,9 @@ namespace swrenderer { swapvalues(left, right); } - UoverZorg = left->X * r_viewwindow.centerx; + UoverZorg = left->X * thread->Viewport->viewwindow.centerx; UoverZstep = -left->Y; - InvZorg = (left->X - right->X) * r_viewwindow.centerx; + InvZorg = (left->X - right->X) * thread->Viewport->viewwindow.centerx; InvZstep = right->Y - left->Y; } @@ -1352,10 +1352,12 @@ namespace swrenderer { // Coordinates should have already had viewx,viewy subtracted - double fullx1 = left.X * r_viewpoint.Sin - left.Y * r_viewpoint.Cos; - double fullx2 = right.X * r_viewpoint.Sin - right.Y * r_viewpoint.Cos; - double fully1 = left.X * r_viewpoint.TanCos + left.Y * r_viewpoint.TanSin; - double fully2 = right.X * r_viewpoint.TanCos + right.Y * r_viewpoint.TanSin; + auto viewport = thread->Viewport.get(); + + double fullx1 = left.X * viewport->viewpoint.Sin - left.Y * viewport->viewpoint.Cos; + double fullx2 = right.X * viewport->viewpoint.Sin - right.Y * viewport->viewpoint.Cos; + double fully1 = left.X * viewport->viewpoint.TanCos + left.Y * viewport->viewpoint.TanSin; + double fully2 = right.X * viewport->viewpoint.TanCos + right.Y * viewport->viewpoint.TanSin; RenderPortal *renderportal = thread->Portal.get(); @@ -1365,9 +1367,9 @@ namespace swrenderer fullx2 = -fullx2; } - UoverZorg = float(fullx1 * r_viewwindow.centerx); + UoverZorg = float(fullx1 * viewport->viewwindow.centerx); UoverZstep = float(-fully1); - InvZorg = float((fullx1 - fullx2) * r_viewwindow.centerx); + InvZorg = float((fullx1 - fullx2) * viewport->viewwindow.centerx); InvZstep = float(fully2 - fully1); } } diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index 2d18a79fa..b84568b2d 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -56,7 +56,7 @@ namespace swrenderer void RenderDrawSegment::Render(DrawSegment *ds, int x1, int x2) { - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); RenderFogBoundary renderfog; float *MaskedSWall = nullptr, MaskedScaleY = 0, rw_scalestep = 0; fixed_t *maskedtexturecol = nullptr; @@ -83,7 +83,7 @@ namespace swrenderer SpriteDrawerArgs columndrawerargs; FDynamicColormap *patchstylecolormap = nullptr; - bool visible = columndrawerargs.SetStyle(LegacyRenderStyles[additive ? STYLE_Add : STYLE_Translucent], alpha, 0, 0, patchstylecolormap); + bool visible = columndrawerargs.SetStyle(viewport, LegacyRenderStyles[additive ? STYLE_Add : STYLE_Translucent], alpha, 0, 0, patchstylecolormap); if (!visible && !ds->bFogBoundary && !ds->bFakeBoundary) { @@ -118,7 +118,7 @@ namespace swrenderer { if (!(clip3d->fake3D & FAKE3D_CLIPTOP)) { - clip3d->sclipTop = sec->ceilingplane.ZatPoint(r_viewpoint.Pos); + clip3d->sclipTop = sec->ceilingplane.ZatPoint(Thread->Viewport->viewpoint.Pos); } for (i = frontsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { @@ -127,7 +127,7 @@ namespace swrenderer lightlist_t *lit = &frontsector->e->XFloor.lightlist[i]; basecolormap = lit->extra_colormap; bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag - wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy), foggy); + wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, viewport), foggy); break; } } @@ -202,7 +202,7 @@ namespace swrenderer { // rowoffset is added before the multiply so that the masked texture will // still be positioned in world units rather than texels. - texturemid += rowoffset - r_viewpoint.Pos.Z; + texturemid += rowoffset - Thread->Viewport->viewpoint.Pos.Z; textop = texturemid; texturemid *= MaskedScaleY; } @@ -210,8 +210,8 @@ namespace swrenderer { // rowoffset is added outside the multiply so that it positions the texture // by texels instead of world units. - textop = texturemid + rowoffset / MaskedScaleY - r_viewpoint.Pos.Z; - texturemid = (texturemid - r_viewpoint.Pos.Z) * MaskedScaleY + rowoffset; + textop = texturemid + rowoffset / MaskedScaleY - Thread->Viewport->viewpoint.Pos.Z; + texturemid = (texturemid - Thread->Viewport->viewpoint.Pos.Z) * MaskedScaleY + rowoffset; } if (sprflipvert) { @@ -230,12 +230,12 @@ namespace swrenderer goto clearfog; } - if ((clip3d->fake3D & FAKE3D_CLIPBOTTOM) && textop < clip3d->sclipBottom - r_viewpoint.Pos.Z) + if ((clip3d->fake3D & FAKE3D_CLIPBOTTOM) && textop < clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z) { notrelevant = true; goto clearfog; } - if ((clip3d->fake3D & FAKE3D_CLIPTOP) && textop - texheight > clip3d->sclipTop - r_viewpoint.Pos.Z) + if ((clip3d->fake3D & FAKE3D_CLIPTOP) && textop - texheight > clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z) { notrelevant = true; goto clearfog; @@ -248,19 +248,19 @@ namespace swrenderer if (clip3d->fake3D & FAKE3D_CLIPTOP) { - wallupper.Project(textop < clip3d->sclipTop - r_viewpoint.Pos.Z ? textop : clip3d->sclipTop - r_viewpoint.Pos.Z, &WallC); + wallupper.Project(Thread->Viewport.get(), textop < clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z ? textop : clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); } else { - wallupper.Project(textop, &WallC); + wallupper.Project(Thread->Viewport.get(), textop, &WallC); } if (clip3d->fake3D & FAKE3D_CLIPBOTTOM) { - walllower.Project(textop - texheight > clip3d->sclipBottom - r_viewpoint.Pos.Z ? textop - texheight : clip3d->sclipBottom - r_viewpoint.Pos.Z, &WallC); + walllower.Project(Thread->Viewport.get(), textop - texheight > clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z ? textop - texheight : clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); } else { - walllower.Project(textop - texheight, &WallC); + walllower.Project(Thread->Viewport.get(), textop - texheight, &WallC); } for (i = x1; i < x2; i++) @@ -319,13 +319,13 @@ namespace swrenderer { // rowoffset is added before the multiply so that the masked texture will // still be positioned in world units rather than texels. - texturemid = (texturemid - r_viewpoint.Pos.Z + rowoffset) * MaskedScaleY; + texturemid = (texturemid - Thread->Viewport->viewpoint.Pos.Z + rowoffset) * MaskedScaleY; } else { // rowoffset is added outside the multiply so that it positions the texture // by texels instead of world units. - texturemid = (texturemid - r_viewpoint.Pos.Z) * MaskedScaleY + rowoffset; + texturemid = (texturemid - Thread->Viewport->viewpoint.Pos.Z) * MaskedScaleY + rowoffset; } WallC.sz1 = ds->sz1; @@ -347,7 +347,7 @@ namespace swrenderer if (clip3d->fake3D & FAKE3D_CLIPTOP) { - wallupper.Project(clip3d->sclipTop - r_viewpoint.Pos.Z, &WallC); + wallupper.Project(Thread->Viewport.get(), clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); for (i = x1; i < x2; i++) { if (wallupper.ScreenY[i] < mceilingclip[i]) @@ -357,7 +357,7 @@ namespace swrenderer } if (clip3d->fake3D & FAKE3D_CLIPBOTTOM) { - walllower.Project(clip3d->sclipBottom - r_viewpoint.Pos.Z, &WallC); + walllower.Project(Thread->Viewport.get(), clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); for (i = x1; i < x2; i++) { if (walllower.ScreenY[i] > mfloorclip[i]) @@ -450,7 +450,7 @@ namespace swrenderer { rowoffset += rw_pic->GetHeight(); } - double texturemid = (planez - r_viewpoint.Pos.Z) * yscale; + double texturemid = (planez - Thread->Viewport->viewpoint.Pos.Z) * yscale; if (rw_pic->bWorldPanning) { // rowoffset is added before the multiply so that the masked texture will @@ -483,8 +483,8 @@ namespace swrenderer WallT = ds->tmapvals; Clip3DFloors *clip3d = Thread->Clip3D.get(); - wallupper.Project(clip3d->sclipTop - r_viewpoint.Pos.Z, &WallC); - walllower.Project(clip3d->sclipBottom - r_viewpoint.Pos.Z, &WallC); + wallupper.Project(Thread->Viewport.get(), clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); + walllower.Project(Thread->Viewport.get(), clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); for (i = x1; i < x2; i++) { @@ -498,7 +498,7 @@ namespace swrenderer } ProjectedWallTexcoords walltexcoords; - walltexcoords.ProjectPos(curline->sidedef->TexelLength*xscale, ds->sx1, ds->sx2, WallT); + walltexcoords.ProjectPos(Thread->Viewport.get(), curline->sidedef->TexelLength*xscale, ds->sx1, ds->sx2, WallT); double top, bot; GetMaskedWallTopBottom(ds, top, bot); @@ -704,7 +704,7 @@ namespace swrenderer lightlist_t *lit = &backsector->e->XFloor.lightlist[j]; basecolormap = lit->extra_colormap; bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag - wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy), foggy); + wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, Thread->Viewport.get()), foggy); break; } } @@ -718,7 +718,7 @@ namespace swrenderer lightlist_t *lit = &frontsector->e->XFloor.lightlist[j]; basecolormap = lit->extra_colormap; bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag - wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy), foggy); + wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, Thread->Viewport.get()), foggy); break; } } @@ -881,7 +881,7 @@ namespace swrenderer lightlist_t *lit = &backsector->e->XFloor.lightlist[j]; basecolormap = lit->extra_colormap; bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag - wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy), foggy); + wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, Thread->Viewport.get()), foggy); break; } } @@ -895,7 +895,7 @@ namespace swrenderer lightlist_t *lit = &frontsector->e->XFloor.lightlist[j]; basecolormap = lit->extra_colormap; bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag - wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy), foggy); + wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, Thread->Viewport.get()), foggy); break; } } @@ -923,13 +923,13 @@ namespace swrenderer RenderPortal *renderportal = Thread->Portal.get(); - most.Project(curline->frontsector->ceilingplane, &WallC, curline, renderportal->MirrorFlags & RF_XFLIP); + most.Project(Thread->Viewport.get(), curline->frontsector->ceilingplane, &WallC, curline, renderportal->MirrorFlags & RF_XFLIP); for (int i = x1; i < x2; ++i) { if (wallupper.ScreenY[i] < most.ScreenY[i]) wallupper.ScreenY[i] = most.ScreenY[i]; } - most.Project(curline->frontsector->floorplane, &WallC, curline, renderportal->MirrorFlags & RF_XFLIP); + most.Project(Thread->Viewport.get(), curline->frontsector->floorplane, &WallC, curline, renderportal->MirrorFlags & RF_XFLIP); for (int i = x1; i < x2; ++i) { if (walllower.ScreenY[i] > most.ScreenY[i]) diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index 8dce6c4ab..d5eacce39 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -44,10 +44,8 @@ namespace swrenderer { - WallSampler::WallSampler(int y1, double texturemid, float swal, double yrepeat, fixed_t xoffset, double xmagnitude, FTexture *texture) + WallSampler::WallSampler(RenderViewport *viewport, int y1, double texturemid, float swal, double yrepeat, fixed_t xoffset, double xmagnitude, FTexture *texture) { - auto viewport = RenderViewport::Instance(); - xoffset += FLOAT2FIXED(xmagnitude * 0.5); if (!viewport->RenderTarget->IsBgra()) @@ -175,7 +173,7 @@ namespace swrenderer { if (r_dynlights && light_list) { - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); // Find column position in view space float w1 = 1.0f / WallC.sz1; @@ -207,12 +205,12 @@ namespace swrenderer { if (!(cur_node->lightsource->flags2&MF2_DORMANT)) { - double lightX = cur_node->lightsource->X() - r_viewpoint.Pos.X; - double lightY = cur_node->lightsource->Y() - r_viewpoint.Pos.Y; - double lightZ = cur_node->lightsource->Z() - r_viewpoint.Pos.Z; + double lightX = cur_node->lightsource->X() - Thread->Viewport->viewpoint.Pos.X; + double lightY = cur_node->lightsource->Y() - Thread->Viewport->viewpoint.Pos.Y; + double lightZ = cur_node->lightsource->Z() - Thread->Viewport->viewpoint.Pos.Z; - float lx = (float)(lightX * r_viewpoint.Sin - lightY * r_viewpoint.Cos) - drawerargs.dc_viewpos.X; - float ly = (float)(lightX * r_viewpoint.TanCos + lightY * r_viewpoint.TanSin) - drawerargs.dc_viewpos.Y; + float lx = (float)(lightX * Thread->Viewport->viewpoint.Sin - lightY * Thread->Viewport->viewpoint.Cos) - drawerargs.dc_viewpos.X; + float ly = (float)(lightX * Thread->Viewport->viewpoint.TanCos + lightY * Thread->Viewport->viewpoint.TanSin) - drawerargs.dc_viewpos.Y; float lz = (float)lightZ; // Precalculate the constant part of the dot here so the drawer doesn't have to. @@ -245,13 +243,13 @@ namespace swrenderer drawerargs.dc_num_lights = 0; } - if (RenderViewport::Instance()->RenderTarget->IsBgra()) + if (Thread->Viewport->RenderTarget->IsBgra()) { int count = y2 - y1; drawerargs.SetTexture(sampler.source, sampler.source2, sampler.height); drawerargs.SetTextureUPos(sampler.texturefracx); - drawerargs.SetDest(x, y1); + drawerargs.SetDest(Thread->Viewport.get(), x, y1); drawerargs.SetCount(count); drawerargs.SetTextureVStep(sampler.uv_step); drawerargs.SetTextureVPos(sampler.uv_pos); @@ -269,7 +267,7 @@ namespace swrenderer drawerargs.SetTexture(sampler.source, sampler.source2, sampler.height); drawerargs.SetTextureUPos(sampler.texturefracx); - drawerargs.SetDest(x, y1); + drawerargs.SetDest(Thread->Viewport.get(), x, y1); drawerargs.SetCount(count); drawerargs.SetTextureVStep(sampler.uv_step); drawerargs.SetTextureVPos(sampler.uv_pos); @@ -294,7 +292,7 @@ namespace swrenderer drawerargs.SetTexture(sampler.source, sampler.source2, sampler.height); drawerargs.SetTextureUPos(sampler.texturefracx); - drawerargs.SetDest(x, y1); + drawerargs.SetDest(Thread->Viewport.get(), x, y1); drawerargs.SetCount(count); drawerargs.SetTextureVStep(sampler.uv_step); drawerargs.SetTextureVPos(uv_pos); @@ -325,7 +323,7 @@ namespace swrenderer texturemid = 0; } - drawerargs.SetTextureFracBits(RenderViewport::Instance()->RenderTarget->IsBgra() ? FRACBITS : fracbits); + drawerargs.SetTextureFracBits(Thread->Viewport->RenderTarget->IsBgra() ? FRACBITS : fracbits); CameraLight *cameraLight = CameraLight::Instance(); bool fixed = (cameraLight->FixedColormap() != NULL || cameraLight->FixedLightLevel() >= 0); @@ -357,7 +355,7 @@ namespace swrenderer if (x + 1 < x2) xmagnitude = fabs(FIXED2DBL(lwal[x + 1]) - FIXED2DBL(lwal[x])); - WallSampler sampler(y1, texturemid, swal[x], yrepeat, lwal[x] + xoffset, xmagnitude, rw_pic); + WallSampler sampler(Thread->Viewport.get(), y1, texturemid, swal[x], yrepeat, lwal[x] + xoffset, xmagnitude, rw_pic); Draw1Column(x, y1, y2, sampler); } @@ -387,7 +385,7 @@ namespace swrenderer // kg3D - fake floors instead of zdoom light list for (unsigned int i = 0; i < frontsector->e->XFloor.lightlist.Size(); i++) { - ProjectedWallCull j = most3.Project(frontsector->e->XFloor.lightlist[i].plane, &WallC, curline, renderportal->MirrorFlags & RF_XFLIP); + ProjectedWallCull j = most3.Project(Thread->Viewport.get(), frontsector->e->XFloor.lightlist[i].plane, &WallC, curline, renderportal->MirrorFlags & RF_XFLIP); if (j != ProjectedWallCull::OutsideAbove) { for (int j = x1; j < x2; ++j) @@ -401,7 +399,7 @@ namespace swrenderer lightlist_t *lit = &frontsector->e->XFloor.lightlist[i]; basecolormap = lit->extra_colormap; - wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(foggy, *lit->p_lightlevel, lit->lightsource != NULL) + LightVisibility::ActualExtraLight(foggy), foggy); + wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(foggy, *lit->p_lightlevel, lit->lightsource != NULL) + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy); } ProcessNormalWall(up, dwal, texturemid, swal, lwal); @@ -446,17 +444,17 @@ namespace swrenderer if (yrepeat >= 0) { // normal orientation: draw strips from top to bottom - partition = top - fmod(top - texturemid / yrepeat - r_viewpoint.Pos.Z, scaledtexheight); + partition = top - fmod(top - texturemid / yrepeat - Thread->Viewport->viewpoint.Pos.Z, scaledtexheight); if (partition == top) { partition -= scaledtexheight; } const short *up = uwal; short *down = most1.ScreenY; - texturemid = (partition - r_viewpoint.Pos.Z) * yrepeat + texheight; + texturemid = (partition - Thread->Viewport->viewpoint.Pos.Z) * yrepeat + texheight; while (partition > bot) { - ProjectedWallCull j = most3.Project(partition - r_viewpoint.Pos.Z, &WallC); + ProjectedWallCull j = most3.Project(Thread->Viewport.get(), partition - Thread->Viewport->viewpoint.Pos.Z, &WallC); if (j != ProjectedWallCull::OutsideAbove) { for (int j = x1; j < x2; ++j) @@ -474,13 +472,13 @@ namespace swrenderer } else { // upside down: draw strips from bottom to top - partition = bot - fmod(bot - texturemid / yrepeat - r_viewpoint.Pos.Z, scaledtexheight); + partition = bot - fmod(bot - texturemid / yrepeat - Thread->Viewport->viewpoint.Pos.Z, scaledtexheight); short *up = most1.ScreenY; const short *down = dwal; - texturemid = (partition - r_viewpoint.Pos.Z) * yrepeat + texheight; + texturemid = (partition - Thread->Viewport->viewpoint.Pos.Z) * yrepeat + texheight; while (partition < top) { - ProjectedWallCull j = most3.Project(partition - r_viewpoint.Pos.Z, &WallC); + ProjectedWallCull j = most3.Project(Thread->Viewport.get(), partition - Thread->Viewport->viewpoint.Pos.Z, &WallC); if (j != ProjectedWallCull::OutsideBelow) { for (int j = x1; j < x2; ++j) diff --git a/src/swrenderer/line/r_walldraw.h b/src/swrenderer/line/r_walldraw.h index 97be825d2..d662092d2 100644 --- a/src/swrenderer/line/r_walldraw.h +++ b/src/swrenderer/line/r_walldraw.h @@ -94,7 +94,7 @@ namespace swrenderer struct WallSampler { WallSampler() { } - WallSampler(int y1, double texturemid, float swal, double yrepeat, fixed_t xoffset, double xmagnitude, FTexture *texture); + WallSampler(RenderViewport *viewport, int y1, double texturemid, float swal, double yrepeat, fixed_t xoffset, double xmagnitude, FTexture *texture); uint32_t uv_pos; uint32_t uv_step; diff --git a/src/swrenderer/line/r_wallsetup.cpp b/src/swrenderer/line/r_wallsetup.cpp index 38420586b..dbae303d5 100644 --- a/src/swrenderer/line/r_wallsetup.cpp +++ b/src/swrenderer/line/r_wallsetup.cpp @@ -27,15 +27,13 @@ namespace swrenderer { - ProjectedWallCull ProjectedWallLine::Project(double z, const FWallCoords *wallc) + ProjectedWallCull ProjectedWallLine::Project(RenderViewport *viewport, double z, const FWallCoords *wallc) { - return Project(z, z, wallc); + return Project(viewport, z, z, wallc); } - ProjectedWallCull ProjectedWallLine::Project(double z1, double z2, const FWallCoords *wallc) + ProjectedWallCull ProjectedWallLine::Project(RenderViewport *viewport, double z1, double z2, const FWallCoords *wallc) { - auto viewport = RenderViewport::Instance(); - float y1 = (float)(viewport->CenterY - z1 * viewport->InvZtoScale / wallc->sz1); float y2 = (float)(viewport->CenterY - z2 * viewport->InvZtoScale / wallc->sz2); @@ -76,11 +74,11 @@ namespace swrenderer return ProjectedWallCull::Visible; } - ProjectedWallCull ProjectedWallLine::Project(const secplane_t &plane, const FWallCoords *wallc, seg_t *curline, bool xflip) + ProjectedWallCull ProjectedWallLine::Project(RenderViewport *viewport, const secplane_t &plane, const FWallCoords *wallc, seg_t *curline, bool xflip) { if (!plane.isSlope()) { - return Project(plane.Zat0() - r_viewpoint.Pos.Z, wallc); + return Project(viewport, plane.Zat0() - viewport->viewpoint.Pos.Z, wallc); } else { @@ -96,7 +94,7 @@ namespace swrenderer x -= frac * (x - curline->v1->fX()); y -= frac * (y - curline->v1->fY()); } - z1 = plane.ZatPoint(x, y) - r_viewpoint.Pos.Z; + z1 = plane.ZatPoint(x, y) - viewport->viewpoint.Pos.Z; if (wallc->sx2 > wallc->sx1 + 1) { @@ -108,7 +106,7 @@ namespace swrenderer x += frac * (curline->v2->fX() - x); y += frac * (curline->v2->fY() - y); } - z2 = plane.ZatPoint(x, y) - r_viewpoint.Pos.Z; + z2 = plane.ZatPoint(x, y) - viewport->viewpoint.Pos.Z; } else { @@ -125,7 +123,7 @@ namespace swrenderer x += frac * (curline->v2->fX() - x); y += frac * (curline->v2->fY() - y); } - z1 = plane.ZatPoint(x, y) - r_viewpoint.Pos.Z; + z1 = plane.ZatPoint(x, y) - viewport->viewpoint.Pos.Z; if (wallc->sx2 > wallc->sx1 + 1) { @@ -137,7 +135,7 @@ namespace swrenderer x -= frac * (x - curline->v1->fX()); y -= frac * (y - curline->v1->fY()); } - z2 = plane.ZatPoint(x, y) - r_viewpoint.Pos.Z; + z2 = plane.ZatPoint(x, y) - viewport->viewpoint.Pos.Z; } else { @@ -145,16 +143,14 @@ namespace swrenderer } } - return Project(z1, z2, wallc); + return Project(viewport, z1, z2, wallc); } } ///////////////////////////////////////////////////////////////////////// - void ProjectedWallTexcoords::Project(double walxrepeat, int x1, int x2, const FWallTmapVals &WallT) + void ProjectedWallTexcoords::Project(RenderViewport *viewport, double walxrepeat, int x1, int x2, const FWallTmapVals &WallT) { - auto viewport = RenderViewport::Instance(); - float uOverZ = WallT.UoverZorg + WallT.UoverZstep * (float)(x1 + 0.5 - viewport->CenterX); float invZ = WallT.InvZorg + WallT.InvZstep * (float)(x1 + 0.5 - viewport->CenterX); float uGradient = WallT.UoverZstep; @@ -191,10 +187,8 @@ namespace swrenderer } } - void ProjectedWallTexcoords::ProjectPos(double walxrepeat, int x1, int x2, const FWallTmapVals &WallT) + void ProjectedWallTexcoords::ProjectPos(RenderViewport *viewport, double walxrepeat, int x1, int x2, const FWallTmapVals &WallT) { - auto viewport = RenderViewport::Instance(); - float uOverZ = WallT.UoverZorg + WallT.UoverZstep * (float)(x1 + 0.5 - viewport->CenterX); float invZ = WallT.InvZorg + WallT.InvZstep * (float)(x1 + 0.5 - viewport->CenterX); float uGradient = WallT.UoverZstep; diff --git a/src/swrenderer/line/r_wallsetup.h b/src/swrenderer/line/r_wallsetup.h index 1234a33dc..d7d32dd5b 100644 --- a/src/swrenderer/line/r_wallsetup.h +++ b/src/swrenderer/line/r_wallsetup.h @@ -20,9 +20,9 @@ namespace swrenderer public: short ScreenY[MAXWIDTH]; - ProjectedWallCull Project(double z1, double z2, const FWallCoords *wallc); - ProjectedWallCull Project(const secplane_t &plane, const FWallCoords *wallc, seg_t *line, bool xflip); - ProjectedWallCull Project(double z, const FWallCoords *wallc); + ProjectedWallCull Project(RenderViewport *viewport, double z1, double z2, const FWallCoords *wallc); + ProjectedWallCull Project(RenderViewport *viewport, const secplane_t &plane, const FWallCoords *wallc, seg_t *line, bool xflip); + ProjectedWallCull Project(RenderViewport *viewport, double z, const FWallCoords *wallc); }; class ProjectedWallTexcoords @@ -31,7 +31,7 @@ namespace swrenderer float VStep[MAXWIDTH]; // swall fixed_t UPos[MAXWIDTH]; // lwall - void Project(double walxrepeat, int x1, int x2, const FWallTmapVals &WallT); - void ProjectPos(double walxrepeat, int x1, int x2, const FWallTmapVals &WallT); + void Project(RenderViewport *viewport, double walxrepeat, int x1, int x2, const FWallTmapVals &WallT); + void ProjectPos(RenderViewport *viewport, double walxrepeat, int x1, int x2, const FWallTmapVals &WallT); }; } diff --git a/src/swrenderer/plane/r_flatplane.cpp b/src/swrenderer/plane/r_flatplane.cpp index 5ac1f8a31..25d6a5ff6 100644 --- a/src/swrenderer/plane/r_flatplane.cpp +++ b/src/swrenderer/plane/r_flatplane.cpp @@ -59,7 +59,7 @@ namespace swrenderer } drawerargs.SetSolidColor(3); - drawerargs.SetTexture(texture); + drawerargs.SetTexture(Thread->Viewport.get(), texture); double planeang = (pl->xform.Angle + pl->xform.baseAngle).Radians(); double xstep, ystep, leftxfrac, leftyfrac, rightxfrac, rightyfrac; @@ -68,22 +68,22 @@ namespace swrenderer if (planeang != 0) { double cosine = cos(planeang), sine = sin(planeang); - pviewx = pl->xform.xOffs + r_viewpoint.Pos.X * cosine - r_viewpoint.Pos.Y * sine; - pviewy = pl->xform.yOffs + pl->xform.baseyOffs - r_viewpoint.Pos.X * sine - r_viewpoint.Pos.Y * cosine; + pviewx = pl->xform.xOffs + Thread->Viewport->viewpoint.Pos.X * cosine - Thread->Viewport->viewpoint.Pos.Y * sine; + pviewy = pl->xform.yOffs + pl->xform.baseyOffs - Thread->Viewport->viewpoint.Pos.X * sine - Thread->Viewport->viewpoint.Pos.Y * cosine; } else { - pviewx = pl->xform.xOffs + r_viewpoint.Pos.X; - pviewy = pl->xform.yOffs - r_viewpoint.Pos.Y; + pviewx = pl->xform.xOffs + Thread->Viewport->viewpoint.Pos.X; + pviewy = pl->xform.yOffs - Thread->Viewport->viewpoint.Pos.Y; } pviewx = _xscale * pviewx; pviewy = _yscale * pviewy; // left to right mapping - planeang += (r_viewpoint.Angles.Yaw - 90).Radians(); + planeang += (Thread->Viewport->viewpoint.Angles.Yaw - 90).Radians(); - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); // Scale will be unit scale at FocalLengthX (normally SCREENWIDTH/2) distance xstep = cos(planeang) / viewport->FocalLengthX; @@ -113,7 +113,7 @@ namespace swrenderer minx = pl->left; - planeheight = fabs(pl->height.Zat0() - r_viewpoint.Pos.Z); + planeheight = fabs(pl->height.Zat0() - Thread->Viewport->viewpoint.Pos.Z); basecolormap = colormap; @@ -155,7 +155,7 @@ namespace swrenderer } #endif - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); double curxfrac = basexfrac + xstepscale * (x1 + 0.5 - minx); double curyfrac = baseyfrac + ystepscale * (x1 + 0.5 - minx); @@ -231,12 +231,12 @@ namespace swrenderer cur_node = light_list; while (cur_node) { - double lightX = cur_node->lightsource->X() - r_viewpoint.Pos.X; - double lightY = cur_node->lightsource->Y() - r_viewpoint.Pos.Y; - double lightZ = cur_node->lightsource->Z() - r_viewpoint.Pos.Z; + double lightX = cur_node->lightsource->X() - Thread->Viewport->viewpoint.Pos.X; + double lightY = cur_node->lightsource->Y() - Thread->Viewport->viewpoint.Pos.Y; + double lightZ = cur_node->lightsource->Z() - Thread->Viewport->viewpoint.Pos.Z; - float lx = (float)(lightX * r_viewpoint.Sin - lightY * r_viewpoint.Cos); - float ly = (float)(lightX * r_viewpoint.TanCos + lightY * r_viewpoint.TanSin) - drawerargs.dc_viewpos.Y; + float lx = (float)(lightX * Thread->Viewport->viewpoint.Sin - lightY * Thread->Viewport->viewpoint.Cos); + float ly = (float)(lightX * Thread->Viewport->viewpoint.TanCos + lightY * Thread->Viewport->viewpoint.TanSin) - drawerargs.dc_viewpos.Y; float lz = (float)lightZ - drawerargs.dc_viewpos.Z; // Precalculate the constant part of the dot here so the drawer doesn't have to. @@ -268,7 +268,7 @@ namespace swrenderer drawerargs.dc_num_lights = 0; } - drawerargs.SetDestY(y); + drawerargs.SetDestY(viewport, y); drawerargs.SetDestX1(x1); drawerargs.SetDestX2(x2); diff --git a/src/swrenderer/plane/r_skyplane.cpp b/src/swrenderer/plane/r_skyplane.cpp index 433d32ee7..534a46890 100644 --- a/src/swrenderer/plane/r_skyplane.cpp +++ b/src/swrenderer/plane/r_skyplane.cpp @@ -70,7 +70,7 @@ namespace swrenderer } sky2tex = sky2texture; skymid = skytexturemid; - skyangle = r_viewpoint.Angles.Yaw.BAMs(); + skyangle = Thread->Viewport->viewpoint.Angles.Yaw.BAMs(); if (pl->picnum == skyflatnum) { @@ -169,7 +169,7 @@ namespace swrenderer void RenderSkyPlane::DrawSkyColumnStripe(int start_x, int y1, int y2, double scale, double texturemid, double yrepeat) { RenderPortal *renderportal = Thread->Portal.get(); - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); uint32_t height = frontskytex->GetHeight(); @@ -188,7 +188,7 @@ namespace swrenderer if (r_linearsky) { - angle_t xangle = (angle_t)((0.5 - x / (double)viewwidth) * r_viewwindow.FocalTangent * ANGLE_90); + angle_t xangle = (angle_t)((0.5 - x / (double)viewwidth) * viewport->viewwindow.FocalTangent * ANGLE_90); ang = (skyangle + xangle) ^ skyflip; } else @@ -198,11 +198,11 @@ namespace swrenderer angle1 = (uint32_t)((UMulScale16(ang, frontcyl) + frontpos) >> FRACBITS); angle2 = (uint32_t)((UMulScale16(ang, backcyl) + backpos) >> FRACBITS); - drawerargs.SetFrontTexture(frontskytex, angle1); - drawerargs.SetBackTexture(backskytex, angle2); + drawerargs.SetFrontTexture(viewport, frontskytex, angle1); + drawerargs.SetBackTexture(viewport, backskytex, angle2); drawerargs.SetTextureVStep(uv_step); drawerargs.SetTextureVPos(uv_pos); - drawerargs.SetDest(start_x, y1); + drawerargs.SetDest(viewport, start_x, y1); drawerargs.SetCount(y2 - y1); drawerargs.SetFadeSky(r_skymode == 2 && !(level.flags & LEVEL_FORCETILEDSKY)); drawerargs.SetSolidTop(frontskytex->GetSkyCapColor(false)); @@ -223,7 +223,7 @@ namespace swrenderer } else { - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); double yrepeat = frontskytex->Scale.Y; double scale = frontskytex->Scale.Y * skyscale; double iscale = 1 / scale; diff --git a/src/swrenderer/plane/r_slopeplane.cpp b/src/swrenderer/plane/r_slopeplane.cpp index 3f396b0f3..16e73f0b8 100644 --- a/src/swrenderer/plane/r_slopeplane.cpp +++ b/src/swrenderer/plane/r_slopeplane.cpp @@ -77,16 +77,16 @@ namespace swrenderer return; } - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); drawerargs.SetSolidColor(3); - drawerargs.SetTexture(texture); + drawerargs.SetTexture(Thread->Viewport.get(), texture); lxscale = _xscale * ifloatpow2[drawerargs.TextureWidthBits()]; lyscale = _yscale * ifloatpow2[drawerargs.TextureHeightBits()]; xscale = 64.f / lxscale; yscale = 64.f / lyscale; - zeroheight = pl->height.ZatPoint(r_viewpoint.Pos); + zeroheight = pl->height.ZatPoint(Thread->Viewport->viewpoint.Pos); pviewx = xs_ToFixed(32 - drawerargs.TextureWidthBits(), pl->xform.xOffs * pl->xform.xScale); pviewy = xs_ToFixed(32 - drawerargs.TextureHeightBits(), pl->xform.yOffs * pl->xform.yScale); @@ -95,11 +95,11 @@ namespace swrenderer // p is the texture origin in view space // Don't add in the offsets at this stage, because doing so can result in // errors if the flat is rotated. - ang = M_PI * 3 / 2 - r_viewpoint.Angles.Yaw.Radians(); + ang = M_PI * 3 / 2 - Thread->Viewport->viewpoint.Angles.Yaw.Radians(); cosine = cos(ang), sine = sin(ang); - p[0] = r_viewpoint.Pos.X * cosine - r_viewpoint.Pos.Y * sine; - p[2] = r_viewpoint.Pos.X * sine + r_viewpoint.Pos.Y * cosine; - p[1] = pl->height.ZatPoint(0.0, 0.0) - r_viewpoint.Pos.Z; + p[0] = Thread->Viewport->viewpoint.Pos.X * cosine - Thread->Viewport->viewpoint.Pos.Y * sine; + p[2] = Thread->Viewport->viewpoint.Pos.X * sine + Thread->Viewport->viewpoint.Pos.Y * cosine; + p[1] = pl->height.ZatPoint(0.0, 0.0) - Thread->Viewport->viewpoint.Pos.Z; // m is the v direction vector in view space ang = ang - M_PI / 2 - planeang; @@ -126,8 +126,8 @@ namespace swrenderer // how much you slope the surface. Use the commented-out code above instead to keep // the textures a constant size across the surface's plane instead. cosine = cos(planeang), sine = sin(planeang); - m[1] = pl->height.ZatPoint(r_viewpoint.Pos.X + yscale * sine, r_viewpoint.Pos.Y + yscale * cosine) - zeroheight; - n[1] = -(pl->height.ZatPoint(r_viewpoint.Pos.X - xscale * cosine, r_viewpoint.Pos.Y + xscale * sine) - zeroheight); + m[1] = pl->height.ZatPoint(Thread->Viewport->viewpoint.Pos.X + yscale * sine, Thread->Viewport->viewpoint.Pos.Y + yscale * cosine) - zeroheight; + n[1] = -(pl->height.ZatPoint(Thread->Viewport->viewpoint.Pos.X - xscale * cosine, Thread->Viewport->viewpoint.Pos.Y + xscale * sine) - zeroheight); plane_su = p ^ m; plane_sv = p ^ n; @@ -157,7 +157,7 @@ namespace swrenderer basecolormap = colormap; bool foggy = level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE);; - planelightfloat = (LightVisibility::Instance()->SlopePlaneGlobVis(foggy) * lxscale * lyscale) / (fabs(pl->height.ZatPoint(r_viewpoint.Pos) - r_viewpoint.Pos.Z)) / 65536.f; + planelightfloat = (LightVisibility::Instance()->SlopePlaneGlobVis(foggy) * lxscale * lyscale) / (fabs(pl->height.ZatPoint(Thread->Viewport->viewpoint.Pos) - Thread->Viewport->viewpoint.Pos.Z)) / 65536.f; if (pl->height.fC() > 0) planelightfloat = -planelightfloat; diff --git a/src/swrenderer/plane/r_visibleplanelist.cpp b/src/swrenderer/plane/r_visibleplanelist.cpp index e62462950..dcb3756f8 100644 --- a/src/swrenderer/plane/r_visibleplanelist.cpp +++ b/src/swrenderer/plane/r_visibleplanelist.cpp @@ -191,7 +191,7 @@ namespace swrenderer renderportal->CurrentPortalUniq == check->CurrentPortalUniq && renderportal->MirrorFlags == check->MirrorFlags && Thread->Clip3D->CurrentSkybox == check->CurrentSkybox && - r_viewpoint.Pos == check->viewpos + Thread->Viewport->viewpoint.Pos == check->viewpos ) { return check; @@ -350,8 +350,8 @@ namespace swrenderer VisiblePlane *pl; int i; - DVector3 oViewPos = r_viewpoint.Pos; - DAngle oViewAngle = r_viewpoint.Angles.Yaw; + DVector3 oViewPos = Thread->Viewport->viewpoint.Pos; + DAngle oViewAngle = Thread->Viewport->viewpoint.Angles.Yaw; RenderPortal *renderportal = Thread->Portal.get(); @@ -364,15 +364,15 @@ namespace swrenderer if (pl->sky < 0 && pl->height.Zat0() == height) { - r_viewpoint.Pos = pl->viewpos; - r_viewpoint.Angles.Yaw = pl->viewangle; + Thread->Viewport->viewpoint.Pos = pl->viewpos; + Thread->Viewport->viewpoint.Angles.Yaw = pl->viewangle; renderportal->MirrorFlags = pl->MirrorFlags; pl->Render(Thread, pl->sky & 0x7FFFFFFF, pl->Additive, true); } } } - r_viewpoint.Pos = oViewPos; - r_viewpoint.Angles.Yaw = oViewAngle; + Thread->Viewport->viewpoint.Pos = oViewPos; + Thread->Viewport->viewpoint.Angles.Yaw = oViewAngle; } } diff --git a/src/swrenderer/r_renderthread.cpp b/src/swrenderer/r_renderthread.cpp index 41bb2fc5a..559d57ec1 100644 --- a/src/swrenderer/r_renderthread.cpp +++ b/src/swrenderer/r_renderthread.cpp @@ -61,6 +61,7 @@ namespace swrenderer Scene = scene; MainThread = mainThread; FrameMemory = std::make_unique(); + Viewport = std::make_unique(); DrawQueue = std::make_shared(this); OpaquePass = std::make_unique(this); TranslucentPass = std::make_unique(this); @@ -79,9 +80,9 @@ namespace swrenderer { } - SWPixelFormatDrawers *RenderThread::Drawers() + SWPixelFormatDrawers *RenderThread::Drawers(RenderViewport *viewport) { - if (RenderViewport::Instance()->RenderTarget->IsBgra()) + if (viewport->RenderTarget->IsBgra()) return tc_drawers.get(); else return pal_drawers.get(); diff --git a/src/swrenderer/r_renderthread.h b/src/swrenderer/r_renderthread.h index e874dbe4e..70dfec342 100644 --- a/src/swrenderer/r_renderthread.h +++ b/src/swrenderer/r_renderthread.h @@ -36,11 +36,13 @@ namespace swrenderer class RenderTranslucentPass; class RenderPlayerSprites; class RenderScene; + class RenderViewport; class Clip3DFloors; class VisiblePlaneList; class DrawSegmentList; class RenderClipSegment; class RenderMemory; + class RenderViewport; class SWPixelFormatDrawers; class SWTruecolorDrawers; class SWPalDrawers; @@ -66,6 +68,7 @@ namespace swrenderer std::unique_ptr PlaneList; std::unique_ptr DrawSegments; std::unique_ptr ClipSegments; + std::unique_ptr Viewport; DrawerCommandQueuePtr DrawQueue; std::thread thread; @@ -74,7 +77,7 @@ namespace swrenderer short clipbot[MAXWIDTH]; short cliptop[MAXWIDTH]; - SWPixelFormatDrawers *Drawers(); + SWPixelFormatDrawers *Drawers(RenderViewport *viewport); private: std::unique_ptr tc_drawers; diff --git a/src/swrenderer/r_swcanvas.cpp b/src/swrenderer/r_swcanvas.cpp index fc0095013..df17ba5ab 100644 --- a/src/swrenderer/r_swcanvas.cpp +++ b/src/swrenderer/r_swcanvas.cpp @@ -52,7 +52,10 @@ void SWCanvas::DrawTexture(DCanvas *canvas, FTexture *img, DrawParms &parms) { static short bottomclipper[MAXWIDTH], topclipper[MAXWIDTH]; - auto viewport = RenderViewport::Instance(); + static RenderThread thread(nullptr); + thread.DrawQueue->ThreadedRender = false; + + auto viewport = thread.Viewport.get(); viewport->RenderTarget = canvas; viewport->RenderTarget->Lock(true); @@ -100,7 +103,7 @@ void SWCanvas::DrawTexture(DCanvas *canvas, FTexture *img, DrawParms &parms) drawerargs.SetTranslationMap(translation); drawerargs.SetLight(basecolormap, 0.0f, shade); - bool visible = drawerargs.SetStyle(parms.style, parms.Alpha, -1, parms.fillcolor, basecolormap); + bool visible = drawerargs.SetStyle(viewport, parms.style, parms.Alpha, -1, parms.fillcolor, basecolormap); double x0 = parms.x - parms.left * parms.destwidth / parms.texwidth; double y0 = parms.y - parms.top * parms.destheight / parms.texheight; @@ -184,8 +187,6 @@ void SWCanvas::DrawTexture(DCanvas *canvas, FTexture *img, DrawParms &parms) int x2_i = int(x2); fixed_t xiscale_i = FLOAT2FIXED(xiscale); - static RenderThread thread(nullptr); - thread.DrawQueue->ThreadedRender = false; while (x < x2_i) { drawerargs.DrawMaskedColumn(&thread, x, iscale, img, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, !parms.masked); @@ -256,7 +257,10 @@ void SWCanvas::FillSimplePoly(DCanvas *canvas, FTexture *tex, FVector2 *points, return; } - auto viewport = RenderViewport::Instance(); + static RenderThread thread(nullptr); + thread.DrawQueue->ThreadedRender = false; + + auto viewport = thread.Viewport.get(); viewport->RenderTarget = canvas; viewport->RenderTarget->Lock(true); @@ -270,7 +274,7 @@ void SWCanvas::FillSimplePoly(DCanvas *canvas, FTexture *tex, FVector2 *points, // Setup constant texture mapping parameters. SpanDrawerArgs drawerargs; - drawerargs.SetTexture(tex); + drawerargs.SetTexture(viewport, tex); if (colormap) drawerargs.SetLight(colormap, 0, clamp(shade >> FRACBITS, 0, NUMCOLORMAPS - 1)); else @@ -330,9 +334,6 @@ void SWCanvas::FillSimplePoly(DCanvas *canvas, FTexture *tex, FVector2 *points, pt2++; if (pt2 > npoints) pt2 = 0; } while (pt1 != botpt); - static RenderThread thread(nullptr); - thread.DrawQueue->ThreadedRender = false; - // Travel down the left edge and fill it in. pt1 = toppt; pt2 = toppt - 1; if (pt2 < 0) pt2 = npoints; @@ -364,7 +365,7 @@ void SWCanvas::FillSimplePoly(DCanvas *canvas, FTexture *tex, FVector2 *points, #if 0 memset(this->Buffer + y * this->Pitch + x1, (int)tex, x2 - x1); #else - drawerargs.SetDestY(y); + drawerargs.SetDestY(viewport, y); drawerargs.SetDestX1(x1); drawerargs.SetDestX2(x2 - 1); diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index 367e498f7..c1110b79e 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -175,9 +175,21 @@ void FSoftwareRenderer::Precache(uint8_t *texhitlist, TMap & void FSoftwareRenderer::RenderView(player_t *player) { if (r_polyrenderer) + { + PolyRenderer::Instance()->Thread.Viewport->viewpoint = r_viewpoint; + PolyRenderer::Instance()->Thread.Viewport->viewwindow = r_viewwindow; PolyRenderer::Instance()->RenderView(player); + r_viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + r_viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow; + } else + { + mScene.MainThread()->Viewport->viewpoint = r_viewpoint; + mScene.MainThread()->Viewport->viewwindow = r_viewwindow; mScene.RenderView(player); + r_viewpoint = mScene.MainThread()->Viewport->viewpoint; + r_viewwindow = mScene.MainThread()->Viewport->viewwindow; + } FCanvasTextureInfo::UpdateAll(); } @@ -200,9 +212,21 @@ void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int wi pic->ObjectFlags |= OF_Fixed; pic->Lock (); if (r_polyrenderer) + { + PolyRenderer::Instance()->Thread.Viewport->viewpoint = r_viewpoint; + PolyRenderer::Instance()->Thread.Viewport->viewwindow = r_viewwindow; PolyRenderer::Instance()->RenderViewToCanvas(player->mo, pic, 0, 0, width, height, true); + r_viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + r_viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow; + } else - mScene.RenderViewToCanvas (player->mo, pic, 0, 0, width, height); + { + mScene.MainThread()->Viewport->viewpoint = r_viewpoint; + mScene.MainThread()->Viewport->viewwindow = r_viewwindow; + mScene.RenderViewToCanvas(player->mo, pic, 0, 0, width, height); + r_viewpoint = mScene.MainThread()->Viewport->viewpoint; + r_viewwindow = mScene.MainThread()->Viewport->viewwindow; + } screen->GetFlashedPalette (palette); M_CreatePNG (file, pic->GetBuffer(), palette, SS_PAL, width, height, pic->GetPitch()); pic->Unlock (); @@ -215,11 +239,19 @@ void FSoftwareRenderer::DrawRemainingPlayerSprites() { if (!r_polyrenderer) { + mScene.MainThread()->Viewport->viewpoint = r_viewpoint; + mScene.MainThread()->Viewport->viewwindow = r_viewwindow; mScene.MainThread()->PlayerSprites->RenderRemaining(); + r_viewpoint = mScene.MainThread()->Viewport->viewpoint; + r_viewwindow = mScene.MainThread()->Viewport->viewwindow; } else { + PolyRenderer::Instance()->Thread.Viewport->viewpoint = r_viewpoint; + PolyRenderer::Instance()->Thread.Viewport->viewwindow = r_viewwindow; PolyRenderer::Instance()->RenderRemainingPlayerSprites(); + r_viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; + r_viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow; } } @@ -247,7 +279,11 @@ void FSoftwareRenderer::SetClearColor(int color) void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) { - auto viewport = RenderViewport::Instance(); + auto viewport = r_polyrenderer ? PolyRenderer::Instance()->Thread.Viewport.get() : mScene.MainThread()->Viewport.get(); + + // Grab global state shared with rest of zdoom + viewport->viewpoint = r_viewpoint; + viewport->viewwindow = r_viewwindow; uint8_t *Pixels = viewport->RenderTarget->IsBgra() ? (uint8_t*)tex->GetPixelsBgra() : (uint8_t*)tex->GetPixels(); DSimpleCanvas *Canvas = viewport->RenderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas(); @@ -256,15 +292,15 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin // These get clobbered by rendering to a camera texture but they need to be preserved so the final rendering can be done with the correct palette. CameraLight savedCameraLight = *CameraLight::Instance(); - DAngle savedfov = r_viewpoint.FieldOfView; - R_SetFOV (r_viewpoint, (double)fov); + DAngle savedfov = viewport->viewpoint.FieldOfView; + R_SetFOV (viewport->viewpoint, (double)fov); if (r_polyrenderer) PolyRenderer::Instance()->RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); else mScene.RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); - R_SetFOV (r_viewpoint, savedfov); + R_SetFOV (viewport->viewpoint, savedfov); if (Canvas->IsBgra()) { @@ -315,6 +351,10 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin tex->SetUpdated(); *CameraLight::Instance() = savedCameraLight; + + // Sync state back to zdoom + r_viewpoint = viewport->viewpoint; + r_viewwindow = viewport->viewwindow; } sector_t *FSoftwareRenderer::FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel) @@ -336,3 +376,13 @@ void FSoftwareRenderer::CleanLevelData() { gl_CleanLevelData(); } + +double FSoftwareRenderer::GetVisibility() +{ + return LightVisibility::Instance()->GetVisibility(); +} + +void FSoftwareRenderer::SetVisibility(double vis) +{ + LightVisibility::Instance()->SetVisibility(mScene.MainThread()->Viewport.get(), vis); +} diff --git a/src/swrenderer/r_swrenderer.h b/src/swrenderer/r_swrenderer.h index e37bb0b87..48a4e16fb 100644 --- a/src/swrenderer/r_swrenderer.h +++ b/src/swrenderer/r_swrenderer.h @@ -40,6 +40,9 @@ struct FSoftwareRenderer : public FRenderer void PreprocessLevel() override; void CleanLevelData() override; + double GetVisibility() override; + void SetVisibility(double vis) override; + private: void PrecacheTexture(FTexture *tex, int cache); diff --git a/src/swrenderer/scene/r_3dfloors.cpp b/src/swrenderer/scene/r_3dfloors.cpp index b9bf28c12..f1496cd9e 100644 --- a/src/swrenderer/scene/r_3dfloors.cpp +++ b/src/swrenderer/scene/r_3dfloors.cpp @@ -68,7 +68,7 @@ namespace swrenderer HeightLevel *near; HeightLevel *curr; - double height = add->ZatPoint(r_viewpoint.Pos); + double height = add->ZatPoint(Thread->Viewport->viewpoint.Pos); if (height >= sec->CenterCeiling()) return; if (height <= sec->CenterFloor()) return; diff --git a/src/swrenderer/scene/r_light.cpp b/src/swrenderer/scene/r_light.cpp index 877ba095b..d0f76ee9f 100644 --- a/src/swrenderer/scene/r_light.cpp +++ b/src/swrenderer/scene/r_light.cpp @@ -45,9 +45,9 @@ namespace swrenderer return &instance; } - void CameraLight::SetCamera(AActor *actor) + void CameraLight::SetCamera(RenderViewport *viewport, AActor *actor) { - AActor *camera = r_viewpoint.camera; + AActor *camera = viewport->viewpoint.camera; player_t *player = actor->player; if (camera && camera->player != nullptr) player = camera->player; @@ -61,7 +61,6 @@ namespace swrenderer if (player->fixedcolormap >= 0 && player->fixedcolormap < (int)SpecialColormaps.Size()) { realfixedcolormap = &SpecialColormaps[player->fixedcolormap]; - auto viewport = RenderViewport::Instance(); if (viewport->RenderTarget == screen && (viewport->RenderTarget->IsBgra() || ((DFrameBuffer *)screen->Accel2D && r_shadercolormaps))) { // Render everything fullbright. The copy to video memory will @@ -85,10 +84,10 @@ namespace swrenderer } } // [RH] Inverse light for shooting the Sigil - if (fixedcolormap == nullptr && r_viewpoint.extralight == INT_MIN) + if (fixedcolormap == nullptr && viewport->viewpoint.extralight == INT_MIN) { fixedcolormap = &SpecialColormaps[INVERSECOLORMAP]; - r_viewpoint.extralight = 0; + viewport->viewpoint.extralight = 0; } } @@ -101,15 +100,14 @@ namespace swrenderer } // Changes how rapidly things get dark with distance - void LightVisibility::SetVisibility(double vis) + void LightVisibility::SetVisibility(RenderViewport *viewport, double vis) { // Allow negative visibilities, just for novelty's sake vis = clamp(vis, -204.7, 204.7); // (205 and larger do not work in 5:4 aspect ratio) CurrentVisibility = vis; - auto viewport = RenderViewport::Instance(); - if (r_viewwindow.FocalTangent == 0 || viewport->FocalLengthY == 0) + if (viewport->viewwindow.FocalTangent == 0 || viewport->FocalLengthY == 0) { // If r_visibility is called before the renderer is all set up, don't // divide by zero. This will be called again later, and the proper // values can be initialized then. @@ -118,7 +116,7 @@ namespace swrenderer BaseVisibility = vis; - MaxVisForWall = (viewport->InvZtoScale * (SCREENWIDTH*r_Yaspect) / (viewwidth*SCREENHEIGHT * r_viewwindow.FocalTangent)); + MaxVisForWall = (viewport->InvZtoScale * (SCREENWIDTH*r_Yaspect) / (viewwidth*SCREENHEIGHT * viewport->viewwindow.FocalTangent)); MaxVisForWall = 32767.0 / MaxVisForWall; MaxVisForFloor = 32767.0 / (viewheight >> 2) * viewport->FocalLengthY / 160; @@ -130,8 +128,8 @@ namespace swrenderer else WallVisibility = BaseVisibility; - WallVisibility = (viewport->InvZtoScale * SCREENWIDTH*AspectBaseHeight(r_viewwindow.WidescreenRatio) / - (viewwidth*SCREENHEIGHT * 3)) * (WallVisibility * r_viewwindow.FocalTangent); + WallVisibility = (viewport->InvZtoScale * SCREENWIDTH*AspectBaseHeight(viewport->viewwindow.WidescreenRatio) / + (viewwidth*SCREENHEIGHT * 3)) * (WallVisibility * viewport->viewwindow.FocalTangent); // Prevent overflow on floors/ceilings. Note that the calculation of // MaxVisForFloor means that planes less than two units from the player's @@ -146,7 +144,7 @@ namespace swrenderer FloorVisibility = 160.0 * FloorVisibility / viewport->FocalLengthY; - TiltVisibility = float(vis * r_viewwindow.FocalTangent * (16.f * 320.f) / viewwidth); + TiltVisibility = float(vis * viewport->viewwindow.FocalTangent * (16.f * 320.f) / viewwidth); NoLightFade = glset.nolightfade; } @@ -174,11 +172,11 @@ namespace swrenderer { if (argv.argc() < 2) { - Printf("Visibility is %g\n", LightVisibility::Instance()->GetVisibility()); + Printf("Visibility is %g\n", Renderer->GetVisibility()); } else if (!netgame) { - LightVisibility::Instance()->SetVisibility(atof(argv[1])); + Renderer->SetVisibility(atof(argv[1])); } else { diff --git a/src/swrenderer/scene/r_light.h b/src/swrenderer/scene/r_light.h index 22b2c03e5..be697cc95 100644 --- a/src/swrenderer/scene/r_light.h +++ b/src/swrenderer/scene/r_light.h @@ -57,7 +57,7 @@ namespace swrenderer fixed_t FixedLightLevelShade() const { return (FixedLightLevel() >> COLORMAPSHIFT) << FRACBITS; } - void SetCamera(AActor *actor); + void SetCamera(RenderViewport *viewport, AActor *actor); void ClearShaderColormap() { realfixedcolormap = nullptr; } private: @@ -71,7 +71,7 @@ namespace swrenderer public: static LightVisibility *Instance(); - void SetVisibility(double visibility); + void SetVisibility(RenderViewport *viewport, double visibility); double GetVisibility() const { return CurrentVisibility; } double WallGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : WallVisibility; } @@ -84,10 +84,10 @@ namespace swrenderer double WallVis(double screenZ, bool foggy) const { return WallGlobVis(foggy) / screenZ; } double SpriteVis(double screenZ, bool foggy) const { return SpriteGlobVis(foggy) / screenZ; } double ParticleVis(double screenZ, bool foggy) const { return ParticleGlobVis(foggy) / screenZ; } - double FlatPlaneVis(int screenY, double planeZ, bool foggy) const { return FlatPlaneGlobVis(foggy) / fabs(planeZ - r_viewpoint.Pos.Z) * fabs(RenderViewport::Instance()->CenterY - screenY); } + double FlatPlaneVis(int screenY, double planeZ, bool foggy, RenderViewport *viewport) const { return FlatPlaneGlobVis(foggy) / fabs(planeZ - viewport->viewpoint.Pos.Z) * fabs(viewport->CenterY - screenY); } static fixed_t LightLevelToShade(int lightlevel, bool foggy); - static int ActualExtraLight(bool fog) { return fog ? 0 : r_viewpoint.extralight << 4; } + static int ActualExtraLight(bool fog, RenderViewport *viewport) { return fog ? 0 : viewport->viewpoint.extralight << 4; } private: double BaseVisibility = 0.0; diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index b7540ff80..0fefb42a1 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -98,9 +98,9 @@ namespace swrenderer const sector_t *s = sec->GetHeightSec(); if (s != nullptr) { - sector_t *heightsec = r_viewpoint.sector->heightsec; + sector_t *heightsec = Thread->Viewport->viewpoint.sector->heightsec; bool underwater = r_fakingunderwater || - (heightsec && heightsec->floorplane.PointOnSide(r_viewpoint.Pos) <= 0); + (heightsec && heightsec->floorplane.PointOnSide(Thread->Viewport->viewpoint.Pos) <= 0); bool doorunderwater = false; int diffTex = (s->MoreFlags & SECF_CLIPFAKEPLANES); @@ -159,8 +159,8 @@ namespace swrenderer } } - double refceilz = s->ceilingplane.ZatPoint(r_viewpoint.Pos); - double orgceilz = sec->ceilingplane.ZatPoint(r_viewpoint.Pos); + double refceilz = s->ceilingplane.ZatPoint(Thread->Viewport->viewpoint.Pos); + double orgceilz = sec->ceilingplane.ZatPoint(Thread->Viewport->viewpoint.Pos); #if 1 // [RH] Allow viewing underwater areas through doors/windows that @@ -234,7 +234,7 @@ namespace swrenderer } FakeSide = WaterFakeSide::BelowFloor; } - else if (heightsec && heightsec->ceilingplane.PointOnSide(r_viewpoint.Pos) <= 0 && + else if (heightsec && heightsec->ceilingplane.PointOnSide(Thread->Viewport->viewpoint.Pos) <= 0 && orgceilz > refceilz && !(s->MoreFlags & SECF_FAKEFLOORONLY)) { // Above-ceiling hack tempsec->ceilingplane = s->ceilingplane; @@ -307,16 +307,16 @@ namespace swrenderer // Find the corners of the box // that define the edges from current viewpoint. - if (r_viewpoint.Pos.X <= bspcoord[BOXLEFT]) + if (Thread->Viewport->viewpoint.Pos.X <= bspcoord[BOXLEFT]) boxx = 0; - else if (r_viewpoint.Pos.X < bspcoord[BOXRIGHT]) + else if (Thread->Viewport->viewpoint.Pos.X < bspcoord[BOXRIGHT]) boxx = 1; else boxx = 2; - if (r_viewpoint.Pos.Y >= bspcoord[BOXTOP]) + if (Thread->Viewport->viewpoint.Pos.Y >= bspcoord[BOXTOP]) boxy = 0; - else if (r_viewpoint.Pos.Y > bspcoord[BOXBOTTOM]) + else if (Thread->Viewport->viewpoint.Pos.Y > bspcoord[BOXBOTTOM]) boxy = 1; else boxy = 2; @@ -325,10 +325,10 @@ namespace swrenderer if (boxpos == 5) return true; - x1 = bspcoord[checkcoord[boxpos][0]] - r_viewpoint.Pos.X; - y1 = bspcoord[checkcoord[boxpos][1]] - r_viewpoint.Pos.Y; - x2 = bspcoord[checkcoord[boxpos][2]] - r_viewpoint.Pos.X; - y2 = bspcoord[checkcoord[boxpos][3]] - r_viewpoint.Pos.Y; + x1 = bspcoord[checkcoord[boxpos][0]] - Thread->Viewport->viewpoint.Pos.X; + y1 = bspcoord[checkcoord[boxpos][1]] - Thread->Viewport->viewpoint.Pos.Y; + x2 = bspcoord[checkcoord[boxpos][2]] - Thread->Viewport->viewpoint.Pos.X; + y2 = bspcoord[checkcoord[boxpos][3]] - Thread->Viewport->viewpoint.Pos.Y; // check clip list for an open space @@ -336,10 +336,10 @@ namespace swrenderer if (y1 * (x1 - x2) + x1 * (y2 - y1) >= -EQUAL_EPSILON) return true; - rx1 = x1 * r_viewpoint.Sin - y1 * r_viewpoint.Cos; - rx2 = x2 * r_viewpoint.Sin - y2 * r_viewpoint.Cos; - ry1 = x1 * r_viewpoint.TanCos + y1 * r_viewpoint.TanSin; - ry2 = x2 * r_viewpoint.TanCos + y2 * r_viewpoint.TanSin; + rx1 = x1 * Thread->Viewport->viewpoint.Sin - y1 * Thread->Viewport->viewpoint.Cos; + rx2 = x2 * Thread->Viewport->viewpoint.Sin - y2 * Thread->Viewport->viewpoint.Cos; + ry1 = x1 * Thread->Viewport->viewpoint.TanCos + y1 * Thread->Viewport->viewpoint.TanSin; + ry2 = x2 * Thread->Viewport->viewpoint.TanCos + y2 * Thread->Viewport->viewpoint.TanSin; if (Thread->Portal->MirrorFlags & RF_XFLIP) { @@ -349,7 +349,7 @@ namespace swrenderer swapvalues(ry1, ry2); } - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); if (rx1 >= -ry1) { @@ -501,7 +501,7 @@ namespace swrenderer portal = frontsector->ValidatePortal(sector_t::ceiling); - VisiblePlane *ceilingplane = frontsector->ceilingplane.PointOnSide(r_viewpoint.Pos) > 0 || + VisiblePlane *ceilingplane = frontsector->ceilingplane.PointOnSide(Thread->Viewport->viewpoint.Pos) > 0 || frontsector->GetTexture(sector_t::ceiling) == skyflatnum || portal != nullptr || (frontsector->heightsec && @@ -509,7 +509,7 @@ namespace swrenderer frontsector->heightsec->GetTexture(sector_t::floor) == skyflatnum) ? Thread->PlaneList->FindPlane(frontsector->ceilingplane, // killough 3/8/98 frontsector->GetTexture(sector_t::ceiling), - ceilinglightlevel + LightVisibility::ActualExtraLight(foggy), // killough 4/11/98 + ceilinglightlevel + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), // killough 4/11/98 frontsector->GetAlpha(sector_t::ceiling), !!(frontsector->GetFlags(sector_t::ceiling) & PLANEF_ADDITIVE), frontsector->planes[sector_t::ceiling].xform, @@ -542,7 +542,7 @@ namespace swrenderer // killough 10/98: add support for skies transferred from sidedefs portal = frontsector->ValidatePortal(sector_t::floor); - VisiblePlane *floorplane = frontsector->floorplane.PointOnSide(r_viewpoint.Pos) > 0 || // killough 3/7/98 + VisiblePlane *floorplane = frontsector->floorplane.PointOnSide(Thread->Viewport->viewpoint.Pos) > 0 || // killough 3/7/98 frontsector->GetTexture(sector_t::floor) == skyflatnum || portal != nullptr || (frontsector->heightsec && @@ -550,7 +550,7 @@ namespace swrenderer frontsector->heightsec->GetTexture(sector_t::ceiling) == skyflatnum) ? Thread->PlaneList->FindPlane(frontsector->floorplane, frontsector->GetTexture(sector_t::floor), - floorlightlevel + LightVisibility::ActualExtraLight(foggy), // killough 3/16/98 + floorlightlevel + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), // killough 3/16/98 frontsector->GetAlpha(sector_t::floor), !!(frontsector->GetFlags(sector_t::floor) & PLANEF_ADDITIVE), frontsector->planes[sector_t::floor].xform, @@ -591,7 +591,7 @@ namespace swrenderer clip3d->NewClip(); } double fakeHeight = clip3d->fakeFloor->fakeFloor->top.plane->ZatPoint(frontsector->centerspot); - if (fakeHeight < r_viewpoint.Pos.Z && + if (fakeHeight < Thread->Viewport->viewpoint.Pos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot)) { clip3d->fake3D = FAKE3D_FAKEFLOOR; @@ -616,7 +616,7 @@ namespace swrenderer ceilingplane = nullptr; floorplane = Thread->PlaneList->FindPlane(frontsector->floorplane, frontsector->GetTexture(sector_t::floor), - floorlightlevel + LightVisibility::ActualExtraLight(foggy), // killough 3/16/98 + floorlightlevel + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), // killough 3/16/98 frontsector->GetAlpha(sector_t::floor), !!(clip3d->fakeFloor->fakeFloor->flags & FF_ADDITIVETRANS), frontsector->planes[position].xform, @@ -654,7 +654,7 @@ namespace swrenderer clip3d->NewClip(); } double fakeHeight = clip3d->fakeFloor->fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot); - if (fakeHeight > r_viewpoint.Pos.Z && + if (fakeHeight > Thread->Viewport->viewpoint.Pos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot)) { clip3d->fake3D = FAKE3D_FAKECEILING; @@ -682,7 +682,7 @@ namespace swrenderer floorplane = nullptr; ceilingplane = Thread->PlaneList->FindPlane(frontsector->ceilingplane, // killough 3/8/98 frontsector->GetTexture(sector_t::ceiling), - ceilinglightlevel + LightVisibility::ActualExtraLight(foggy), // killough 4/11/98 + ceilinglightlevel + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), // killough 4/11/98 frontsector->GetAlpha(sector_t::ceiling), !!(clip3d->fakeFloor->fakeFloor->flags & FF_ADDITIVETRANS), frontsector->planes[position].xform, @@ -717,7 +717,7 @@ namespace swrenderer // [RH] Add particles if ((unsigned int)(sub - subsectors) < (unsigned int)numsubsectors) { // Only do it for the main BSP. - int shade = LightVisibility::LightLevelToShade((floorlightlevel + ceilinglightlevel) / 2 + LightVisibility::ActualExtraLight(foggy), foggy); + int shade = LightVisibility::LightLevelToShade((floorlightlevel + ceilinglightlevel) / 2 + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy); for (int i = ParticlesInSubsec[(unsigned int)(sub - subsectors)]; i != NO_PARTICLE; i = Particles[i].snext) { RenderParticle::Project(Thread, Particles + i, subsectors[sub - subsectors].sector, shade, FakeSide, foggy); @@ -798,7 +798,7 @@ namespace swrenderer node_t *bsp = (node_t *)node; // Decide which side the view point is on. - int side = R_PointOnSide(r_viewpoint.Pos, bsp); + int side = R_PointOnSide(Thread->Viewport->viewpoint.Pos, bsp); // Recursively divide front space (toward the viewer). RenderBSPNode(bsp->children[side]); @@ -815,10 +815,9 @@ namespace swrenderer void RenderOpaquePass::ClearClip() { - auto viewport = RenderViewport::Instance(); // clip ceiling to console bottom fillshort(floorclip, viewwidth, viewheight); - fillshort(ceilingclip, viewwidth, !screen->Accel2D && ConBottom > viewwindowy && !viewport->RenderingToCanvas() ? (ConBottom - viewwindowy) : 0); + fillshort(ceilingclip, viewwidth, !screen->Accel2D && ConBottom > viewwindowy && !Thread->Viewport->RenderingToCanvas() ? (ConBottom - viewwindowy) : 0); } void RenderOpaquePass::AddSprites(sector_t *sec, int lightlevel, WaterFakeSide fakeside, bool foggy, FDynamicColormap *basecolormap) @@ -834,7 +833,7 @@ namespace swrenderer //sec->validcount = validcount; SeenSpriteSectors.insert(sec); - int spriteshade = LightVisibility::LightLevelToShade(lightlevel + LightVisibility::ActualExtraLight(foggy), foggy); + int spriteshade = LightVisibility::LightLevelToShade(lightlevel + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy); // Handle all things in sector. for (auto p = sec->touching_renderthings; p != nullptr; p = p->m_snext) @@ -848,7 +847,7 @@ namespace swrenderer FIntCVar *cvar = thing->GetClass()->distancecheck; if (cvar != nullptr && *cvar >= 0) { - double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); + double dist = (thing->Pos() - Thread->Viewport->viewpoint.Pos).LengthSquared(); double check = (double)**cvar; if (dist >= check * check) { @@ -886,7 +885,7 @@ namespace swrenderer if (sec->sectornum != thing->Sector->sectornum) // compare sectornums to account for R_FakeFlat copies. { int lightlevel = thing->Sector->GetTexture(sector_t::ceiling) == skyflatnum ? thing->Sector->GetCeilingLight() : thing->Sector->GetFloorLight(); - thingShade = LightVisibility::LightLevelToShade(lightlevel + LightVisibility::ActualExtraLight(foggy), foggy); + thingShade = LightVisibility::LightLevelToShade(lightlevel + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy); thingColormap = thing->Sector->ColorMap; } @@ -930,8 +929,8 @@ namespace swrenderer bool RenderOpaquePass::GetThingSprite(AActor *thing, ThingSprite &sprite) { - sprite.pos = thing->InterpolatedPosition(r_viewpoint.TicFrac); - sprite.pos.Z += thing->GetBobOffset(r_viewpoint.TicFrac); + sprite.pos = thing->InterpolatedPosition(Thread->Viewport->viewpoint.TicFrac); + sprite.pos.Z += thing->GetBobOffset(Thread->Viewport->viewpoint.TicFrac); sprite.spritenum = thing->sprite; sprite.tex = nullptr; @@ -958,7 +957,7 @@ namespace swrenderer { // choose a different rotation based on player view spriteframe_t *sprframe = &SpriteFrames[sprite.tex->Rotations]; - DAngle ang = (sprite.pos - r_viewpoint.Pos).Angle(); + DAngle ang = (sprite.pos - Thread->Viewport->viewpoint.Pos).Angle(); angle_t rot; if (sprframe->Texture[0] == sprframe->Texture[1]) { @@ -1001,7 +1000,7 @@ namespace swrenderer //picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0]; // choose a different rotation based on player view spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame]; - DAngle ang = (sprite.pos - r_viewpoint.Pos).Angle(); + DAngle ang = (sprite.pos - Thread->Viewport->viewpoint.Pos).Angle(); angle_t rot; if (sprframe->Texture[0] == sprframe->Texture[1]) { diff --git a/src/swrenderer/scene/r_opaque_pass.h b/src/swrenderer/scene/r_opaque_pass.h index 6a14703c5..123e08e0a 100644 --- a/src/swrenderer/scene/r_opaque_pass.h +++ b/src/swrenderer/scene/r_opaque_pass.h @@ -79,7 +79,7 @@ namespace swrenderer void AddSprites(sector_t *sec, int lightlevel, WaterFakeSide fakeside, bool foggy, FDynamicColormap *basecolormap); bool IsPotentiallyVisible(AActor *thing); - static bool GetThingSprite(AActor *thing, ThingSprite &sprite); + bool GetThingSprite(AActor *thing, ThingSprite &sprite); subsector_t *InSubsector = nullptr; sector_t *frontsector = nullptr; diff --git a/src/swrenderer/scene/r_portal.cpp b/src/swrenderer/scene/r_portal.cpp index 9c7e65835..0844e7779 100644 --- a/src/swrenderer/scene/r_portal.cpp +++ b/src/swrenderer/scene/r_portal.cpp @@ -101,12 +101,12 @@ namespace swrenderer Thread->Clip3D->EnterSkybox(); CurrentPortalInSkybox = true; - int savedextralight = r_viewpoint.extralight; - DVector3 savedpos = r_viewpoint.Pos; - DRotator savedangles = r_viewpoint.Angles; + int savedextralight = Thread->Viewport->viewpoint.extralight; + DVector3 savedpos = Thread->Viewport->viewpoint.Pos; + DRotator savedangles = Thread->Viewport->viewpoint.Angles; double savedvisibility = LightVisibility::Instance()->GetVisibility(); - AActor *savedcamera = r_viewpoint.camera; - sector_t *savedsector = r_viewpoint.sector; + AActor *savedcamera = Thread->Viewport->viewpoint.camera; + sector_t *savedsector = Thread->Viewport->viewpoint.sector; for (VisiblePlane *pl = planes->PopFirstPortalPlane(); pl != nullptr; pl = planes->PopFirstPortalPlane()) { @@ -125,11 +125,11 @@ namespace swrenderer { // Don't let gun flashes brighten the sky box AActor *sky = port->mSkybox; - r_viewpoint.extralight = 0; - LightVisibility::Instance()->SetVisibility(sky->args[0] * 0.25f); + Thread->Viewport->viewpoint.extralight = 0; + LightVisibility::Instance()->SetVisibility(Thread->Viewport.get(), sky->args[0] * 0.25f); - r_viewpoint.Pos = sky->InterpolatedPosition(r_viewpoint.TicFrac); - r_viewpoint.Angles.Yaw = savedangles.Yaw + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_viewpoint.TicFrac); + Thread->Viewport->viewpoint.Pos = sky->InterpolatedPosition(Thread->Viewport->viewpoint.TicFrac); + Thread->Viewport->viewpoint.Angles.Yaw = savedangles.Yaw + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * Thread->Viewport->viewpoint.TicFrac); CopyStackedViewParameters(); break; @@ -138,12 +138,12 @@ namespace swrenderer case PORTS_STACKEDSECTORTHING: case PORTS_PORTAL: case PORTS_LINKEDPORTAL: - r_viewpoint.extralight = pl->extralight; - LightVisibility::Instance()->SetVisibility(pl->visibility); - r_viewpoint.Pos.X = pl->viewpos.X + port->mDisplacement.X; - r_viewpoint.Pos.Y = pl->viewpos.Y + port->mDisplacement.Y; - r_viewpoint.Pos.Z = pl->viewpos.Z; - r_viewpoint.Angles.Yaw = pl->viewangle; + Thread->Viewport->viewpoint.extralight = pl->extralight; + LightVisibility::Instance()->SetVisibility(Thread->Viewport.get(), pl->visibility); + Thread->Viewport->viewpoint.Pos.X = pl->viewpos.X + port->mDisplacement.X; + Thread->Viewport->viewpoint.Pos.Y = pl->viewpos.Y + port->mDisplacement.Y; + Thread->Viewport->viewpoint.Pos.Z = pl->viewpos.Z; + Thread->Viewport->viewpoint.Angles.Yaw = pl->viewangle; break; case PORTS_HORIZON: @@ -158,10 +158,10 @@ namespace swrenderer port->mFlags |= PORTSF_INSKYBOX; if (port->mPartner > 0) level.sectorPortals[port->mPartner].mFlags |= PORTSF_INSKYBOX; - r_viewpoint.camera = nullptr; - r_viewpoint.sector = port->mDestination; - assert(r_viewpoint.sector != nullptr); - R_SetViewAngle(r_viewpoint, r_viewwindow); + Thread->Viewport->viewpoint.camera = nullptr; + Thread->Viewport->viewpoint.sector = port->mDestination; + assert(viewsector != nullptr); + R_SetViewAngle(Thread->Viewport->viewpoint, Thread->Viewport->viewwindow); Thread->OpaquePass->ClearSeenSprites(); Thread->Clip3D->ClearFakeFloors(); @@ -188,7 +188,7 @@ namespace swrenderer drawseglist->PushPortal(); Thread->SpriteList->PushPortal(); - viewposStack.Push(r_viewpoint.Pos); + viewposStack.Push(Thread->Viewport->viewpoint.Pos); visplaneStack.Push(pl); // Create a drawseg to clip sprites to the sky plane @@ -227,7 +227,7 @@ namespace swrenderer while (viewposStack.Size() > 0) { // Masked textures and planes need the view coordinates restored for proper positioning. - viewposStack.Pop(r_viewpoint.Pos); + viewposStack.Pop(Thread->Viewport->viewpoint.Pos); Thread->TranslucentPass->Render(); @@ -242,13 +242,13 @@ namespace swrenderer drawseglist->PopPortal(); } - r_viewpoint.camera = savedcamera; - r_viewpoint.sector = savedsector; - r_viewpoint.Pos = savedpos; - LightVisibility::Instance()->SetVisibility(savedvisibility); - r_viewpoint.extralight = savedextralight; - r_viewpoint.Angles = savedangles; - R_SetViewAngle(r_viewpoint, r_viewwindow); + Thread->Viewport->viewpoint.camera = savedcamera; + Thread->Viewport->viewpoint.sector = savedsector; + Thread->Viewport->viewpoint.Pos = savedpos; + LightVisibility::Instance()->SetVisibility(Thread->Viewport.get(), savedvisibility); + Thread->Viewport->viewpoint.extralight = savedextralight; + Thread->Viewport->viewpoint.Angles = savedangles; + R_SetViewAngle(Thread->Viewport->viewpoint, Thread->Viewport->viewwindow); CurrentPortalInSkybox = false; Thread->Clip3D->LeaveSkybox(); @@ -274,7 +274,8 @@ namespace swrenderer void RenderPortal::RenderLinePortal(PortalDrawseg* pds, int depth) { - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); + auto &viewpoint = viewport->viewpoint; // [ZZ] check depth. fill portal with black if it's exceeding the visual recursion limit, and continue like nothing happened. if (depth >= r_portal_recursions) @@ -318,12 +319,12 @@ namespace swrenderer return; } - DAngle startang = r_viewpoint.Angles.Yaw; - DVector3 startpos = r_viewpoint.Pos; - DVector3 savedpath[2] = { r_viewpoint.Path[0], r_viewpoint.Path[1] }; - ActorRenderFlags savedvisibility = r_viewpoint.camera ? r_viewpoint.camera->renderflags & RF_INVISIBLE : ActorRenderFlags::FromInt(0); + DAngle startang = viewpoint.Angles.Yaw; + DVector3 startpos = viewpoint.Pos; + DVector3 savedpath[2] = { viewpoint.Path[0], viewpoint.Path[1] }; + ActorRenderFlags savedvisibility = viewpoint.camera ? viewpoint.camera->renderflags & RF_INVISIBLE : ActorRenderFlags::FromInt(0); - r_viewpoint.camera->renderflags &= ~RF_INVISIBLE; + viewpoint.camera->renderflags &= ~RF_INVISIBLE; CurrentPortalUniq++; @@ -337,11 +338,11 @@ namespace swrenderer // Reflect the current view behind the mirror. if (pds->src->Delta().X == 0) { // vertical mirror - r_viewpoint.Pos.X = v1->fX() - startpos.X + v1->fX(); + viewpoint.Pos.X = v1->fX() - startpos.X + v1->fX(); } else if (pds->src->Delta().Y == 0) { // horizontal mirror - r_viewpoint.Pos.Y = v1->fY() - startpos.Y + v1->fY(); + viewpoint.Pos.Y = v1->fY() - startpos.Y + v1->fY(); } else { // any mirror @@ -357,40 +358,40 @@ namespace swrenderer // the above two cases catch len == 0 double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy); - r_viewpoint.Pos.X = (x1 + r * dx) * 2 - x; - r_viewpoint.Pos.Y = (y1 + r * dy) * 2 - y; + viewpoint.Pos.X = (x1 + r * dx) * 2 - x; + viewpoint.Pos.Y = (y1 + r * dy) * 2 - y; } - r_viewpoint.Angles.Yaw = pds->src->Delta().Angle() * 2 - startang; + viewpoint.Angles.Yaw = pds->src->Delta().Angle() * 2 - startang; } else { - P_TranslatePortalXY(pds->src, r_viewpoint.Pos.X, r_viewpoint.Pos.Y); - P_TranslatePortalZ(pds->src, r_viewpoint.Pos.Z); - P_TranslatePortalAngle(pds->src, r_viewpoint.Angles.Yaw); - P_TranslatePortalXY(pds->src, r_viewpoint.Path[0].X, r_viewpoint.Path[0].Y); - P_TranslatePortalXY(pds->src, r_viewpoint.Path[1].X, r_viewpoint.Path[1].Y); + P_TranslatePortalXY(pds->src, viewpoint.Pos.X, viewpoint.Pos.Y); + P_TranslatePortalZ(pds->src, viewpoint.Pos.Z); + P_TranslatePortalAngle(pds->src, viewpoint.Angles.Yaw); + P_TranslatePortalXY(pds->src, viewpoint.Path[0].X, viewpoint.Path[0].Y); + P_TranslatePortalXY(pds->src, viewpoint.Path[1].X, viewpoint.Path[1].Y); - if (!r_viewpoint.showviewer && r_viewpoint.camera && P_PointOnLineSidePrecise(r_viewpoint.Path[0], pds->dst) != P_PointOnLineSidePrecise(r_viewpoint.Path[1], pds->dst)) + if (!viewpoint.showviewer && viewpoint.camera && P_PointOnLineSidePrecise(viewpoint.Path[0], pds->dst) != P_PointOnLineSidePrecise(viewpoint.Path[1], pds->dst)) { - double distp = (r_viewpoint.Path[0] - r_viewpoint.Path[1]).Length(); + double distp = (viewpoint.Path[0] - viewpoint.Path[1]).Length(); if (distp > EQUAL_EPSILON) { - double dist1 = (r_viewpoint.Pos - r_viewpoint.Path[0]).Length(); - double dist2 = (r_viewpoint.Pos - r_viewpoint.Path[1]).Length(); + double dist1 = (viewpoint.Pos - viewpoint.Path[0]).Length(); + double dist2 = (viewpoint.Pos - viewpoint.Path[1]).Length(); if (dist1 + dist2 < distp + 1) { - r_viewpoint.camera->renderflags |= RF_INVISIBLE; + viewpoint.camera->renderflags |= RF_INVISIBLE; } } } } - r_viewpoint.Sin = r_viewpoint.Angles.Yaw.Sin(); - r_viewpoint.Cos = r_viewpoint.Angles.Yaw.Cos(); + viewpoint.Sin = viewpoint.Angles.Yaw.Sin(); + viewpoint.Cos = viewpoint.Angles.Yaw.Cos(); - r_viewpoint.TanSin = r_viewwindow.FocalTangent * r_viewpoint.Sin; - r_viewpoint.TanCos = r_viewwindow.FocalTangent * r_viewpoint.Cos; + viewpoint.TanSin = Thread->Viewport->viewwindow.FocalTangent * viewpoint.Sin; + viewpoint.TanCos = Thread->Viewport->viewwindow.FocalTangent * viewpoint.Cos; CopyStackedViewParameters(); @@ -425,14 +426,14 @@ namespace swrenderer Thread->OpaquePass->RenderScene(); Thread->Clip3D->ResetClip(); // reset clips (floor/ceiling) - if (!savedvisibility && r_viewpoint.camera) r_viewpoint.camera->renderflags &= ~RF_INVISIBLE; + if (!savedvisibility && viewpoint.camera) viewpoint.camera->renderflags &= ~RF_INVISIBLE; PlaneCycles.Clock(); Thread->PlaneList->Render(); RenderPlanePortals(); PlaneCycles.Unclock(); - double vzp = r_viewpoint.Pos.Z; + double vzp = viewpoint.Pos.Z; int prevuniq = CurrentPortalUniq; // depth check is in another place right now @@ -463,10 +464,10 @@ namespace swrenderer CurrentPortal = prevpds; MirrorFlags = prevmf; - r_viewpoint.Angles.Yaw = startang; - r_viewpoint.Pos = startpos; - r_viewpoint.Path[0] = savedpath[0]; - r_viewpoint.Path[1] = savedpath[1]; + viewpoint.Angles.Yaw = startang; + viewpoint.Pos = startpos; + viewpoint.Path[0] = savedpath[0]; + viewpoint.Path[1] = savedpath[1]; } void RenderPortal::RenderLinePortalHighlight(PortalDrawseg* pds) @@ -474,7 +475,7 @@ namespace swrenderer // [ZZ] NO OVERFLOW CHECKS HERE // I believe it won't break. if it does, blame me. :( - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); if (viewport->RenderTarget->IsBgra()) // Assuming this is just a debug function return; @@ -513,9 +514,9 @@ namespace swrenderer void RenderPortal::CopyStackedViewParameters() { - stacked_viewpos = r_viewpoint.Pos; - stacked_angle = r_viewpoint.Angles; - stacked_extralight = r_viewpoint.extralight; + stacked_viewpos = Thread->Viewport->viewpoint.Pos; + stacked_angle = Thread->Viewport->viewpoint.Angles; + stacked_extralight = Thread->Viewport->viewpoint.extralight; stacked_visibility = LightVisibility::Instance()->GetVisibility(); } diff --git a/src/swrenderer/scene/r_scene.cpp b/src/swrenderer/scene/r_scene.cpp index 98756e1d0..5f0c41bd6 100644 --- a/src/swrenderer/scene/r_scene.cpp +++ b/src/swrenderer/scene/r_scene.cpp @@ -76,7 +76,7 @@ namespace swrenderer void RenderScene::RenderView(player_t *player) { - auto viewport = RenderViewport::Instance(); + auto viewport = MainThread()->Viewport.get(); viewport->RenderTarget = screen; int width = SCREENWIDTH; @@ -132,9 +132,9 @@ namespace swrenderer MaskedCycles.Reset(); WallScanCycles.Reset(); - R_SetupFrame(r_viewpoint, r_viewwindow, actor); - CameraLight::Instance()->SetCamera(actor); - RenderViewport::Instance()->SetupFreelook(); + R_SetupFrame(MainThread()->Viewport->viewpoint, MainThread()->Viewport->viewwindow, actor); + CameraLight::Instance()->SetCamera(MainThread()->Viewport.get(), actor); + MainThread()->Viewport->SetupFreelook(); NetUpdate(); @@ -143,23 +143,23 @@ namespace swrenderer // [RH] Setup particles for this frame P_FindParticleSubsectors(); - ActorRenderFlags savedflags = r_viewpoint.camera->renderflags; + ActorRenderFlags savedflags = MainThread()->Viewport->viewpoint.camera->renderflags; // Never draw the player unless in chasecam mode - if (!r_viewpoint.showviewer) + if (!MainThread()->Viewport->viewpoint.showviewer) { - r_viewpoint.camera->renderflags |= RF_INVISIBLE; + MainThread()->Viewport->viewpoint.camera->renderflags |= RF_INVISIBLE; } RenderThreadSlices(); MainThread()->PlayerSprites->Render(); RenderDrawQueues(); - r_viewpoint.camera->renderflags = savedflags; + MainThread()->Viewport->viewpoint.camera->renderflags = savedflags; interpolator.RestoreInterpolations(); // If we don't want shadered colormaps, NULL it now so that the // copy to the screen does not use a special colormap shader. - if (!r_shadercolormaps && !RenderViewport::Instance()->RenderTarget->IsBgra()) + if (!r_shadercolormaps && !MainThread()->Viewport->RenderTarget->IsBgra()) { CameraLight::Instance()->ClearShaderColormap(); } @@ -184,6 +184,7 @@ namespace swrenderer std::unique_lock start_lock(start_mutex); for (int i = 0; i < numThreads; i++) { + *Threads[i]->Viewport = *MainThread()->Viewport; Threads[i]->X1 = viewwidth * i / numThreads; Threads[i]->X2 = viewwidth * (i + 1) / numThreads; } @@ -321,24 +322,24 @@ namespace swrenderer void RenderScene::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines) { - auto viewport = RenderViewport::Instance(); + auto viewport = MainThread()->Viewport.get(); const bool savedviewactive = viewactive; viewwidth = width; viewport->RenderTarget = canvas; - R_SetWindow(r_viewpoint, r_viewwindow, 12, width, height, height, true); + R_SetWindow(MainThread()->Viewport->viewpoint, MainThread()->Viewport->viewwindow, 12, width, height, height, true); viewwindowx = x; viewwindowy = y; viewactive = true; - viewport->SetViewport(width, height, r_viewwindow.WidescreenRatio); + viewport->SetViewport(width, height, MainThread()->Viewport->viewwindow.WidescreenRatio); RenderActorView(actor, dontmaplines); viewport->RenderTarget = screen; - R_ExecuteSetViewSize(r_viewpoint, r_viewwindow); + R_ExecuteSetViewSize(MainThread()->Viewport->viewpoint, MainThread()->Viewport->viewwindow); float trueratio; ActiveRatio(width, height, &trueratio); screen->Lock(true); @@ -350,7 +351,7 @@ namespace swrenderer void RenderScene::ScreenResized() { - auto viewport = RenderViewport::Instance(); + auto viewport = MainThread()->Viewport.get(); viewport->RenderTarget = screen; int width = SCREENWIDTH; int height = SCREENHEIGHT; diff --git a/src/swrenderer/scene/r_translucent_pass.cpp b/src/swrenderer/scene/r_translucent_pass.cpp index d7e096bbd..442643332 100644 --- a/src/swrenderer/scene/r_translucent_pass.cpp +++ b/src/swrenderer/scene/r_translucent_pass.cpp @@ -175,7 +175,7 @@ namespace swrenderer else { // kg3D - correct sorting // ceilings - for (HeightLevel *hl = clip3d->height_cur; hl != nullptr && hl->height >= r_viewpoint.Pos.Z; hl = hl->prev) + for (HeightLevel *hl = clip3d->height_cur; hl != nullptr && hl->height >= Thread->Viewport->viewpoint.Pos.Z; hl = hl->prev) { if (hl->next) { @@ -195,7 +195,7 @@ namespace swrenderer clip3d->fake3D = FAKE3D_DOWN2UP | FAKE3D_CLIPTOP; clip3d->sclipTop = clip3d->height_top->height; DrawMaskedSingle(true); - for (HeightLevel *hl = clip3d->height_top; hl != nullptr && hl->height < r_viewpoint.Pos.Z; hl = hl->next) + for (HeightLevel *hl = clip3d->height_top; hl != nullptr && hl->height < Thread->Viewport->viewpoint.Pos.Z; hl = hl->next) { Thread->PlaneList->RenderHeight(hl->height); if (hl->next) diff --git a/src/swrenderer/things/r_decal.cpp b/src/swrenderer/things/r_decal.cpp index d12117b3a..1dd37c55c 100644 --- a/src/swrenderer/things/r_decal.cpp +++ b/src/swrenderer/things/r_decal.cpp @@ -144,8 +144,8 @@ namespace swrenderer DVector2 angvec = (curline->v2->fPos() - curline->v1->fPos()).Unit(); float maskedScaleY; - decal_left = decal_pos - edge_left * angvec - r_viewpoint.Pos; - decal_right = decal_pos + edge_right * angvec - r_viewpoint.Pos; + decal_left = decal_pos - edge_left * angvec - thread->Viewport->viewpoint.Pos; + decal_right = decal_pos + edge_right * angvec - thread->Viewport->viewpoint.Pos; CameraLight *cameraLight; double texturemid; @@ -222,7 +222,7 @@ namespace swrenderer } yscale = decal->ScaleY; - texturemid = WallSpriteTile->TopOffset + (zpos - r_viewpoint.Pos.Z) / yscale; + texturemid = WallSpriteTile->TopOffset + (zpos - thread->Viewport->viewpoint.Pos.Z) / yscale; // Clip sprite to drawseg x1 = MAX(clipper->x1, x1); @@ -233,7 +233,7 @@ namespace swrenderer } ProjectedWallTexcoords walltexcoords; - walltexcoords.Project(WallSpriteTile->GetWidth(), x1, x2, WallT); + walltexcoords.Project(thread->Viewport.get(), WallSpriteTile->GetWidth(), x1, x2, WallT); if (flipx) { @@ -291,7 +291,7 @@ namespace swrenderer else calclighting = true; - bool visible = drawerargs.SetStyle(decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor, basecolormap); + bool visible = drawerargs.SetStyle(thread->Viewport.get(), decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor, basecolormap); // R_SetPatchStyle can modify basecolormap. if (rereadcolormap) @@ -323,7 +323,7 @@ namespace swrenderer void RenderDecal::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip) { - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); float iscale = walltexcoords.VStep[x] * maskedScaleY; double spryscale = 1 / iscale; diff --git a/src/swrenderer/things/r_particle.cpp b/src/swrenderer/things/r_particle.cpp index b415fa670..d3c048653 100644 --- a/src/swrenderer/things/r_particle.cpp +++ b/src/swrenderer/things/r_particle.cpp @@ -77,16 +77,16 @@ namespace swrenderer return; // transform the origin point - tr_x = particle->Pos.X - r_viewpoint.Pos.X; - tr_y = particle->Pos.Y - r_viewpoint.Pos.Y; + tr_x = particle->Pos.X - thread->Viewport->viewpoint.Pos.X; + tr_y = particle->Pos.Y - thread->Viewport->viewpoint.Pos.Y; - tz = tr_x * r_viewpoint.TanCos + tr_y * r_viewpoint.TanSin; + tz = tr_x * thread->Viewport->viewpoint.TanCos + tr_y * thread->Viewport->viewpoint.TanSin; // particle is behind view plane? if (tz < MINZ) return; - tx = tr_x * r_viewpoint.Sin - tr_y * r_viewpoint.Cos; + tx = tr_x * thread->Viewport->viewpoint.Sin - tr_y * thread->Viewport->viewpoint.Cos; // Flip for mirrors if (renderportal->MirrorFlags & RF_XFLIP) @@ -99,21 +99,21 @@ namespace swrenderer return; tiz = 1 / tz; - xscale = r_viewwindow.centerx * tiz; + xscale = thread->Viewport->viewwindow.centerx * tiz; // calculate edges of the shape double psize = particle->size / 8.0; - x1 = MAX(renderportal->WindowLeft, r_viewwindow.centerx + xs_RoundToInt((tx - psize) * xscale)); - x2 = MIN(renderportal->WindowRight, r_viewwindow.centerx + xs_RoundToInt((tx + psize) * xscale)); + x1 = MAX(renderportal->WindowLeft, thread->Viewport->viewwindow.centerx + xs_RoundToInt((tx - psize) * xscale)); + x2 = MIN(renderportal->WindowRight, thread->Viewport->viewwindow.centerx + xs_RoundToInt((tx + psize) * xscale)); if (x1 >= x2) return; - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); yscale = xscale; // YaspectMul is not needed for particles as they should always be square - ty = particle->Pos.Z - r_viewpoint.Pos.Z; + ty = particle->Pos.Z - viewport->viewpoint.Pos.Z; y1 = xs_RoundToInt(viewport->CenterY - (ty + psize) * yscale); y2 = xs_RoundToInt(viewport->CenterY - (ty - psize) * yscale); @@ -231,7 +231,7 @@ namespace swrenderer fixed_t fglevel = ((vis->renderflags + 1) << 8) & ~0x3ff; uint32_t alpha = fglevel * 256 / FRACUNIT; - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); spacing = viewport->RenderTarget->GetPitch(); diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index b68523d89..daa8e7ea4 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -82,37 +82,37 @@ namespace swrenderer F3DFloor *rover; if (!r_drawplayersprites || - !r_viewpoint.camera || - !r_viewpoint.camera->player || + !Thread->Viewport->viewpoint.camera || + !Thread->Viewport->viewpoint.camera->player || (players[consoleplayer].cheats & CF_CHASECAM) || - (r_deathcamera && r_viewpoint.camera->health <= 0)) + (r_deathcamera && Thread->Viewport->viewpoint.camera->health <= 0)) return; FDynamicColormap *basecolormap; CameraLight *cameraLight = CameraLight::Instance(); - if (cameraLight->FixedLightLevel() < 0 && r_viewpoint.sector->e && r_viewpoint.sector->e->XFloor.lightlist.Size()) + if (cameraLight->FixedLightLevel() < 0 && Thread->Viewport->viewpoint.sector->e && Thread->Viewport->viewpoint.sector->e->XFloor.lightlist.Size()) { - for (i = r_viewpoint.sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) + for (i = Thread->Viewport->viewpoint.sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { - if (r_viewpoint.Pos.Z <= r_viewpoint.sector->e->XFloor.lightlist[i].plane.Zat0()) + if (Thread->Viewport->viewpoint.Pos.Z <= Thread->Viewport->viewpoint.sector->e->XFloor.lightlist[i].plane.Zat0()) { - rover = r_viewpoint.sector->e->XFloor.lightlist[i].caster; + rover = Thread->Viewport->viewpoint.sector->e->XFloor.lightlist[i].caster; if (rover) { - if (rover->flags & FF_DOUBLESHADOW && r_viewpoint.Pos.Z <= rover->bottom.plane->Zat0()) + if (rover->flags & FF_DOUBLESHADOW && Thread->Viewport->viewpoint.Pos.Z <= rover->bottom.plane->Zat0()) break; sec = rover->model; if (rover->flags & FF_FADEWALLS) basecolormap = sec->ColorMap; else - basecolormap = r_viewpoint.sector->e->XFloor.lightlist[i].extra_colormap; + basecolormap = Thread->Viewport->viewpoint.sector->e->XFloor.lightlist[i].extra_colormap; } break; } } if (!sec) { - sec = r_viewpoint.sector; + sec = Thread->Viewport->viewpoint.sector; basecolormap = sec->ColorMap; } floorlight = ceilinglight = sec->lightlevel; @@ -120,7 +120,7 @@ namespace swrenderer else { // This used to use camera->Sector but due to interpolation that can be incorrect // when the interpolated viewpoint is in a different sector than the camera. - sec = Thread->OpaquePass->FakeFlat(r_viewpoint.sector, &tempsec, &floorlight, &ceilinglight, nullptr, 0, 0, 0, 0); + sec = Thread->OpaquePass->FakeFlat(Thread->Viewport->viewpoint.sector, &tempsec, &floorlight, &ceilinglight, nullptr, 0, 0, 0, 0); // [RH] set basecolormap basecolormap = sec->ColorMap; @@ -130,12 +130,12 @@ namespace swrenderer bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // get light level - lightnum = ((floorlight + ceilinglight) >> 1) + LightVisibility::ActualExtraLight(foggy); + lightnum = ((floorlight + ceilinglight) >> 1) + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()); int spriteshade = LightVisibility::LightLevelToShade(lightnum, foggy) - 24 * FRACUNIT; - if (r_viewpoint.camera->player != NULL) + if (Thread->Viewport->viewpoint.camera->player != NULL) { - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); double centerhack = viewport->CenterY; double wx, wy; @@ -143,10 +143,10 @@ namespace swrenderer viewport->CenterY = viewheight / 2; - P_BobWeapon(r_viewpoint.camera->player, &bobx, &boby, r_viewpoint.TicFrac); + P_BobWeapon(viewport->viewpoint.camera->player, &bobx, &boby, viewport->viewpoint.TicFrac); // Interpolate the main weapon layer once so as to be able to add it to other layers. - if ((weapon = r_viewpoint.camera->player->FindPSprite(PSP_WEAPON)) != nullptr) + if ((weapon = viewport->viewpoint.camera->player->FindPSprite(PSP_WEAPON)) != nullptr) { if (weapon->firstTic) { @@ -155,8 +155,8 @@ namespace swrenderer } else { - wx = weapon->oldx + (weapon->x - weapon->oldx) * r_viewpoint.TicFrac; - wy = weapon->oldy + (weapon->y - weapon->oldy) * r_viewpoint.TicFrac; + wx = weapon->oldx + (weapon->x - weapon->oldx) * viewport->viewpoint.TicFrac; + wy = weapon->oldy + (weapon->y - weapon->oldy) * viewport->viewpoint.TicFrac; } } else @@ -166,7 +166,7 @@ namespace swrenderer } // add all active psprites - psp = r_viewpoint.camera->player->psprites; + psp = viewport->viewpoint.camera->player->psprites; while (psp) { // [RH] Don't draw the targeter's crosshair if the player already has a crosshair set. @@ -176,7 +176,7 @@ namespace swrenderer if ((psp->GetID() != PSP_TARGETCENTER || CrosshairImage == nullptr) && psp->GetCaller() != nullptr) { - RenderSprite(psp, r_viewpoint.camera, bobx, boby, wx, wy, r_viewpoint.TicFrac, spriteshade, basecolormap, foggy); + RenderSprite(psp, viewport->viewpoint.camera, bobx, boby, wx, wy, viewport->viewpoint.TicFrac, spriteshade, basecolormap, foggy); } psp = psp->GetNext(); @@ -243,9 +243,9 @@ namespace swrenderer sy += wy; } - auto viewport = RenderViewport::Instance(); + auto viewport = Thread->Viewport.get(); - double pspritexscale = r_viewwindow.centerxwide / 160.0; + double pspritexscale = viewport->viewwindow.centerxwide / 160.0; double pspriteyscale = pspritexscale * viewport->YaspectMul; double pspritexiscale = 1 / pspritexscale; @@ -273,7 +273,7 @@ namespace swrenderer vis.texturemid = (BASEYCENTER - sy) * tex->Scale.Y + tex->TopOffset; - if (r_viewpoint.camera->player && (viewport->RenderTarget != screen || + if (Thread->Viewport->viewpoint.camera->player && (viewport->RenderTarget != screen || viewheight == viewport->RenderTarget->GetHeight() || (viewport->RenderTarget->GetWidth() > (BASEXCENTER * 2) && !st_scale))) { // Adjust PSprite for fullscreen views @@ -292,7 +292,7 @@ namespace swrenderer } if (pspr->GetID() < PSP_TARGETCENTER) { // Move the weapon down for 1280x1024. - vis.texturemid -= AspectPspriteOffset(r_viewwindow.WidescreenRatio); + vis.texturemid -= AspectPspriteOffset(viewport->viewwindow.WidescreenRatio); } vis.x1 = x1 < 0 ? 0 : x1; vis.x2 = x2 >= viewwidth ? viewwidth : x2; @@ -447,14 +447,14 @@ namespace swrenderer colormap_to_use = (FDynamicColormap*)vis.Light.BaseColormap; - if (r_viewpoint.camera->Inventory != nullptr) + if (Thread->Viewport->viewpoint.camera->Inventory != nullptr) { visstyle_t visstyle; visstyle.Alpha = vis.Alpha; visstyle.RenderStyle = STYLE_Count; visstyle.Invert = false; - r_viewpoint.camera->Inventory->AlterWeaponSprite(&visstyle); + Thread->Viewport->viewpoint.camera->Inventory->AlterWeaponSprite(&visstyle); vis.Alpha = visstyle.Alpha; @@ -599,7 +599,7 @@ namespace swrenderer FDynamicColormap *basecolormap = static_cast(Light.BaseColormap); - bool visible = drawerargs.SetStyle(RenderStyle, Alpha, Translation, FillColor, basecolormap, Light.ColormapNum << FRACBITS); + bool visible = drawerargs.SetStyle(thread->Viewport.get(), RenderStyle, Alpha, Translation, FillColor, basecolormap, Light.ColormapNum << FRACBITS); if (!visible) return; @@ -607,7 +607,7 @@ namespace swrenderer bool sprflipvert = false; fixed_t iscale = FLOAT2FIXED(1 / yscale); - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); double sprtopscreen; if (renderflags & RF_YFLIP) diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index 06b6ec9bb..88bec93ce 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -66,16 +66,16 @@ namespace swrenderer void RenderSprite::Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap) { // transform the origin point - double tr_x = pos.X - r_viewpoint.Pos.X; - double tr_y = pos.Y - r_viewpoint.Pos.Y; + double tr_x = pos.X - thread->Viewport->viewpoint.Pos.X; + double tr_y = pos.Y - thread->Viewport->viewpoint.Pos.Y; - double tz = tr_x * r_viewpoint.TanCos + tr_y * r_viewpoint.TanSin; + double tz = tr_x * thread->Viewport->viewpoint.TanCos + tr_y * thread->Viewport->viewpoint.TanSin; // thing is behind view plane? if (tz < MINZ) return; - double tx = tr_x * r_viewpoint.Sin - tr_y * r_viewpoint.Cos; + double tx = tr_x * thread->Viewport->viewpoint.Sin - tr_y * thread->Viewport->viewpoint.Cos; // [RH] Flip for mirrors RenderPortal *renderportal = thread->Portal.get(); @@ -124,12 +124,12 @@ namespace swrenderer } } - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); double xscale = viewport->CenterX / tz; // [RH] Reject sprites that are off the top or bottom of the screen - if (viewport->globaluclip * tz > r_viewpoint.Pos.Z - gzb || viewport->globaldclip * tz < r_viewpoint.Pos.Z - gzt) + if (viewport->globaluclip * tz > viewport->viewpoint.Pos.Z - gzb || viewport->globaldclip * tz < viewport->viewpoint.Pos.Z - gzt) { return; } @@ -142,14 +142,14 @@ namespace swrenderer tx -= ((renderflags & RF_XFLIP) ? (tex->GetWidth() - tex->LeftOffset - 1) : tex->LeftOffset) * thingxscalemul; double dtx1 = tx * xscale; - int x1 = r_viewwindow.centerx + xs_RoundToInt(dtx1); + int x1 = viewport->viewwindow.centerx + xs_RoundToInt(dtx1); // off the right side? if (x1 >= renderportal->WindowRight) return; tx += tex->GetWidth() * thingxscalemul; - int x2 = r_viewwindow.centerx + xs_RoundToInt(tx * xscale); + int x2 = viewport->viewwindow.centerx + xs_RoundToInt(tx * xscale); // off the left side or too small? if ((x2 < renderportal->WindowLeft || x2 <= x1)) @@ -168,7 +168,7 @@ namespace swrenderer vis->yscale = float(viewport->InvZtoScale * yscale / tz); vis->idepth = float(1 / tz); vis->floorclip = thing->Floorclip / yscale; - vis->texturemid = tex->TopOffset - (r_viewpoint.Pos.Z - pos.Z + thing->Floorclip) / yscale; + vis->texturemid = tex->TopOffset - (viewport->viewpoint.Pos.Z - pos.Z + thing->Floorclip) / yscale; vis->x1 = x1 < renderportal->WindowLeft ? renderportal->WindowLeft : x1; vis->x2 = x2 > renderportal->WindowRight ? renderportal->WindowRight : x2; //vis->Angle = thing->Angles.Yaw; @@ -184,7 +184,7 @@ namespace swrenderer vis->xiscale = iscale; } - vis->startfrac += (fixed_t)(vis->xiscale * (vis->x1 - r_viewwindow.centerx + 0.5 - dtx1)); + vis->startfrac += (fixed_t)(vis->xiscale * (vis->x1 - viewport->viewwindow.centerx + 0.5 - dtx1)); // killough 3/27/98: save sector for special clipping later vis->heightsec = heightsec; @@ -194,8 +194,8 @@ namespace swrenderer vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z }; vis->gzb = (float)gzb; // [RH] use gzb, not thing->z vis->gzt = (float)gzt; // killough 3/27/98 - vis->deltax = float(pos.X - r_viewpoint.Pos.X); - vis->deltay = float(pos.Y - r_viewpoint.Pos.Y); + vis->deltax = float(pos.X - viewport->viewpoint.Pos.X); + vis->deltay = float(pos.Y - viewport->viewpoint.Pos.Y); vis->renderflags = renderflags; if (thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D @@ -308,7 +308,7 @@ namespace swrenderer FDynamicColormap *basecolormap = static_cast(vis->Light.BaseColormap); - bool visible = drawerargs.SetStyle(vis->RenderStyle, vis->Alpha, vis->Translation, vis->FillColor, basecolormap, vis->Light.ColormapNum << FRACBITS); + bool visible = drawerargs.SetStyle(thread->Viewport.get(), vis->RenderStyle, vis->Alpha, vis->Translation, vis->FillColor, basecolormap, vis->Light.ColormapNum << FRACBITS); if (visible) { @@ -320,7 +320,7 @@ namespace swrenderer xiscale = vis->xiscale; double texturemid = vis->texturemid; - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); if (vis->renderflags & RF_YFLIP) { diff --git a/src/swrenderer/things/r_visiblesprite.cpp b/src/swrenderer/things/r_visiblesprite.cpp index a535ae565..ea895321a 100644 --- a/src/swrenderer/things/r_visiblesprite.cpp +++ b/src/swrenderer/things/r_visiblesprite.cpp @@ -95,7 +95,7 @@ namespace swrenderer { if (!(clip3d->fake3D & FAKE3D_CLIPTOP)) { - clip3d->sclipTop = spr->sector->ceilingplane.ZatPoint(r_viewpoint.Pos); + clip3d->sclipTop = spr->sector->ceilingplane.ZatPoint(thread->Viewport->viewpoint.Pos); } sector_t *sec = nullptr; FDynamicColormap *mybasecolormap = nullptr; @@ -138,7 +138,7 @@ namespace swrenderer bool isFullBright = !foggy && (renderflags & RF_FULLBRIGHT); bool fadeToBlack = spr->RenderStyle == LegacyRenderStyles[STYLE_Add] && mybasecolormap->Fade != 0; - int spriteshade = LightVisibility::LightLevelToShade(sec->lightlevel + LightVisibility::ActualExtraLight(spr->foggy), foggy); + int spriteshade = LightVisibility::LightLevelToShade(sec->lightlevel + LightVisibility::ActualExtraLight(spr->foggy, thread->Viewport.get()), foggy); Light.SetColormap(LightVisibility::Instance()->SpriteGlobVis(foggy) / MAX(MINZ, (double)spr->depth), spriteshade, mybasecolormap, isFullBright, invertcolormap, fadeToBlack); } @@ -154,7 +154,7 @@ namespace swrenderer // Clip the sprite against deep water and/or fake ceilings. // [RH] rewrote this to be based on which part of the sector is really visible - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); double scale = viewport->InvZtoScale * spr->idepth; double hzb = -DBL_MAX, hzt = DBL_MAX; @@ -169,7 +169,7 @@ namespace swrenderer if (spr->FakeFlatStat != WaterFakeSide::AboveCeiling) { double hz = spr->heightsec->floorplane.ZatPoint(spr->gpos); - int h = xs_RoundToInt(viewport->CenterY - (hz - r_viewpoint.Pos.Z) * scale); + int h = xs_RoundToInt(viewport->CenterY - (hz - viewport->viewpoint.Pos.Z) * scale); if (spr->FakeFlatStat == WaterFakeSide::BelowFloor) { // seen below floor: clip top @@ -191,7 +191,7 @@ namespace swrenderer if (spr->FakeFlatStat != WaterFakeSide::BelowFloor && !(spr->heightsec->MoreFlags & SECF_FAKEFLOORONLY)) { double hz = spr->heightsec->ceilingplane.ZatPoint(spr->gpos); - int h = xs_RoundToInt(viewport->CenterY - (hz - r_viewpoint.Pos.Z) * scale); + int h = xs_RoundToInt(viewport->CenterY - (hz - viewport->viewpoint.Pos.Z) * scale); if (spr->FakeFlatStat == WaterFakeSide::AboveCeiling) { // seen above ceiling: clip bottom @@ -230,12 +230,12 @@ namespace swrenderer if (spr->fakefloor) { double floorz = spr->fakefloor->top.plane->Zat0(); - if (r_viewpoint.Pos.Z > floorz && floorz == clip3d->sclipBottom) + if (viewport->viewpoint.Pos.Z > floorz && floorz == clip3d->sclipBottom) { hz = spr->fakefloor->bottom.plane->Zat0(); } } - int h = xs_RoundToInt(viewport->CenterY - (hz - r_viewpoint.Pos.Z) * scale); + int h = xs_RoundToInt(viewport->CenterY - (hz - viewport->viewpoint.Pos.Z) * scale); if (h < botclip) { botclip = MAX(0, h); @@ -251,12 +251,12 @@ namespace swrenderer if (spr->fakeceiling != nullptr) { double ceilingZ = spr->fakeceiling->bottom.plane->Zat0(); - if (r_viewpoint.Pos.Z < ceilingZ && ceilingZ == clip3d->sclipTop) + if (viewport->viewpoint.Pos.Z < ceilingZ && ceilingZ == clip3d->sclipTop) { hz = spr->fakeceiling->top.plane->Zat0(); } } - int h = xs_RoundToInt(viewport->CenterY - (hz - r_viewpoint.Pos.Z) * scale); + int h = xs_RoundToInt(viewport->CenterY - (hz - viewport->viewpoint.Pos.Z) * scale); if (h > topclip) { topclip = short(MIN(h, viewheight)); diff --git a/src/swrenderer/things/r_voxel.cpp b/src/swrenderer/things/r_voxel.cpp index 1a2037922..46220d9dd 100644 --- a/src/swrenderer/things/r_voxel.cpp +++ b/src/swrenderer/things/r_voxel.cpp @@ -45,11 +45,11 @@ namespace swrenderer void RenderVoxel::Project(RenderThread *thread, AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap) { // transform the origin point - double tr_x = pos.X - r_viewpoint.Pos.X; - double tr_y = pos.Y - r_viewpoint.Pos.Y; + double tr_x = pos.X - thread->Viewport->viewpoint.Pos.X; + double tr_y = pos.Y - thread->Viewport->viewpoint.Pos.Y; - double tz = tr_x * r_viewpoint.TanCos + tr_y * r_viewpoint.TanSin; - double tx = tr_x * r_viewpoint.Sin - tr_y * r_viewpoint.Cos; + double tz = tr_x * thread->Viewport->viewpoint.TanCos + tr_y * thread->Viewport->viewpoint.TanSin; + double tx = tr_x * thread->Viewport->viewpoint.Sin - tr_y * thread->Viewport->viewpoint.Cos; // [RH] Flip for mirrors RenderPortal *renderportal = thread->Portal.get(); @@ -121,8 +121,8 @@ namespace swrenderer vis->Angle -= ang; } - vis->pa.vpos = { (float)r_viewpoint.Pos.X, (float)r_viewpoint.Pos.Y, (float)r_viewpoint.Pos.Z }; - vis->pa.vang = FAngle((float)r_viewpoint.Angles.Yaw.Degrees); + vis->pa.vpos = { (float)thread->Viewport->viewpoint.Pos.X, (float)thread->Viewport->viewpoint.Pos.Y, (float)thread->Viewport->viewpoint.Pos.Z }; + vis->pa.vang = FAngle((float)thread->Viewport->viewpoint.Angles.Yaw.Degrees); // killough 3/27/98: save sector for special clipping later vis->heightsec = heightsec; @@ -132,8 +132,8 @@ namespace swrenderer vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z }; vis->gzb = (float)gzb; // [RH] use gzb, not thing->z vis->gzt = (float)gzt; // killough 3/27/98 - vis->deltax = float(pos.X - r_viewpoint.Pos.X); - vis->deltay = float(pos.Y - r_viewpoint.Pos.Y); + vis->deltax = float(pos.X - thread->Viewport->viewpoint.Pos.X); + vis->deltay = float(pos.Y - thread->Viewport->viewpoint.Pos.Y); vis->renderflags = renderflags; if (thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D @@ -178,13 +178,13 @@ namespace swrenderer void RenderVoxel::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) { auto spr = this; - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); SpriteDrawerArgs drawerargs; drawerargs.SetLight(spr->Light.BaseColormap, 0, spr->Light.ColormapNum << FRACBITS); FDynamicColormap *basecolormap = (FDynamicColormap*)spr->Light.BaseColormap; - bool visible = drawerargs.SetStyle(spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, basecolormap); + bool visible = drawerargs.SetStyle(viewport, spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, basecolormap); if (!visible) return; @@ -265,11 +265,11 @@ namespace swrenderer FVoxelMipLevel *mip; int z1a[64], z2a[64], yplc[64]; - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); - const int nytooclose = r_viewwindow.centerxwide * 2100, nytoofar = 32768*32768 - 1048576; - const int xdimenscale = FLOAT2FIXED(r_viewwindow.centerxwide * viewport->YaspectMul / 160); - const double centerxwide_f = r_viewwindow.centerxwide; + const int nytooclose = viewport->viewwindow.centerxwide * 2100, nytoofar = 32768*32768 - 1048576; + const int xdimenscale = FLOAT2FIXED(viewport->viewwindow.centerxwide * viewport->YaspectMul / 160); + const double centerxwide_f = viewport->viewwindow.centerxwide; const double centerxwidebig_f = centerxwide_f * 65536*65536*8; // Convert to Build's coordinate system. @@ -315,8 +315,8 @@ namespace swrenderer daxscale <<= (k+8); dayscale <<= (k+8); dazscale = FixedDiv(dayscale, FLOAT2FIXED(viewport->BaseYaspectMul)); daxscale = fixed_t(daxscale / viewport->YaspectMul); - daxscale = Scale(daxscale, xdimenscale, r_viewwindow.centerxwide << 9); - dayscale = Scale(dayscale, FixedMul(xdimenscale, viewport->viewingrangerecip), r_viewwindow.centerxwide << 9); + daxscale = Scale(daxscale, xdimenscale, viewport->viewwindow.centerxwide << 9); + dayscale = Scale(dayscale, FixedMul(xdimenscale, viewport->viewingrangerecip), viewport->viewwindow.centerxwide << 9); daxscalerecip = (1<<30) / daxscale; dayscalerecip = (1<<30) / dayscale; @@ -432,9 +432,9 @@ namespace swrenderer voxend = (kvxslab_t *)(slabxoffs + xyoffs[y+1]); if (voxptr >= voxend) continue; - lx = xs_RoundToInt(nx * centerxwide_f / (ny + y1)) + r_viewwindow.centerx; + lx = xs_RoundToInt(nx * centerxwide_f / (ny + y1)) + viewport->viewwindow.centerx; if (lx < 0) lx = 0; - rx = xs_RoundToInt((nx + nxoff) * centerxwide_f / (ny + y2)) + r_viewwindow.centerx; + rx = xs_RoundToInt((nx + nxoff) * centerxwide_f / (ny + y2)) + viewport->viewwindow.centerx; if (rx > viewwidth) rx = viewwidth; if (rx <= lx) continue; @@ -475,20 +475,20 @@ namespace swrenderer if (k < 0) { if ((voxptr->backfacecull & oand32) == 0) continue; - z2 = MulScale32(l2, k) + r_viewwindow.centery; /* Below slab */ + z2 = MulScale32(l2, k) + viewport->viewwindow.centery; /* Below slab */ } else { if ((voxptr->backfacecull & oand) == 0) continue; /* Middle of slab */ - z2 = MulScale32(l1, k) + r_viewwindow.centery; + z2 = MulScale32(l1, k) + viewport->viewwindow.centery; } - z1 = MulScale32(l1, j) + r_viewwindow.centery; + z1 = MulScale32(l1, j) + viewport->viewwindow.centery; } else { if ((voxptr->backfacecull & oand16) == 0) continue; - z1 = MulScale32(l2, j) + r_viewwindow.centery; /* Above slab */ - z2 = MulScale32(l1, j + (zleng << 15)) + r_viewwindow.centery; + z1 = MulScale32(l2, j) + viewport->viewwindow.centery; /* Above slab */ + z2 = MulScale32(l1, j + (zleng << 15)) + viewport->viewwindow.centery; } if (z2 <= z1) continue; @@ -560,7 +560,7 @@ namespace swrenderer for (int x = xxl; x < xxr; ++x) { - drawerargs.SetDest(lxt + x, z1); + drawerargs.SetDest(viewport, lxt + x, z1); drawerargs.SetCount(z2 - z1); drawerargs.DrawVoxelColumn(thread, yplc[xxl], yinc, columnColors, zleng); } diff --git a/src/swrenderer/things/r_wallsprite.cpp b/src/swrenderer/things/r_wallsprite.cpp index c152880c9..1c6cdfa59 100644 --- a/src/swrenderer/things/r_wallsprite.cpp +++ b/src/swrenderer/things/r_wallsprite.cpp @@ -82,8 +82,8 @@ namespace swrenderer x1 *= scale.X; x2 *= scale.X; - left.X = pos.X - x1 * angcos - r_viewpoint.Pos.X; - left.Y = pos.Y - x1 * angsin - r_viewpoint.Pos.Y; + left.X = pos.X - x1 * angcos - thread->Viewport->viewpoint.Pos.X; + left.Y = pos.Y - x1 * angsin - thread->Viewport->viewpoint.Pos.Y; right.X = left.X + x2 * angcos; right.Y = right.Y + x2 * angsin; @@ -98,7 +98,7 @@ namespace swrenderer // Sprite sorting should probably treat these as walls, not sprites, // but right now, I just want to get them drawing. - tz = (pos.X - r_viewpoint.Pos.X) * r_viewpoint.TanCos + (pos.Y - r_viewpoint.Pos.Y) * r_viewpoint.TanSin; + tz = (pos.X - thread->Viewport->viewpoint.Pos.X) * thread->Viewport->viewpoint.TanCos + (pos.Y - thread->Viewport->viewpoint.Pos.Y) * thread->Viewport->viewpoint.TanSin; int scaled_to = pic->GetScaledTopOffset(); int scaled_bo = scaled_to - pic->GetScaledHeight(); @@ -117,8 +117,8 @@ namespace swrenderer vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z }; vis->gzb = (float)gzb; vis->gzt = (float)gzt; - vis->deltax = float(pos.X - r_viewpoint.Pos.X); - vis->deltay = float(pos.Y - r_viewpoint.Pos.Y); + vis->deltax = float(pos.X - thread->Viewport->viewpoint.Pos.X); + vis->deltay = float(pos.Y - thread->Viewport->viewpoint.Pos.Y); vis->renderflags = renderflags; if (thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D vis->RenderStyle = thing->RenderStyle; @@ -155,10 +155,10 @@ namespace swrenderer WallT.InitFromWallCoords(thread, &spr->wallc); ProjectedWallTexcoords walltexcoords; - walltexcoords.Project(spr->pic->GetWidth() << FRACBITS, x1, x2, WallT); + walltexcoords.Project(thread->Viewport.get(), spr->pic->GetWidth() << FRACBITS, x1, x2, WallT); iyscale = 1 / spr->yscale; - double texturemid = (spr->gzt - r_viewpoint.Pos.Z) * iyscale; + double texturemid = (spr->gzt - thread->Viewport->viewpoint.Pos.Z) * iyscale; if (spr->renderflags & RF_XFLIP) { int right = (spr->pic->GetWidth() << FRACBITS) - 1; @@ -182,7 +182,7 @@ namespace swrenderer SpriteDrawerArgs drawerargs; - int shade = LightVisibility::LightLevelToShade(spr->sector->lightlevel + LightVisibility::ActualExtraLight(spr->foggy), spr->foggy); + int shade = LightVisibility::LightLevelToShade(spr->sector->lightlevel + LightVisibility::ActualExtraLight(spr->foggy, thread->Viewport.get()), spr->foggy); double GlobVis = LightVisibility::Instance()->WallGlobVis(foggy); float lightleft = float(GlobVis / spr->wallc.sz1); float lightstep = float((GlobVis / spr->wallc.sz2 - lightleft) / (spr->wallc.sx2 - spr->wallc.sx1)); @@ -216,7 +216,7 @@ namespace swrenderer FDynamicColormap *basecolormap = static_cast(spr->Light.BaseColormap); - bool visible = drawerargs.SetStyle(spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, basecolormap); + bool visible = drawerargs.SetStyle(thread->Viewport.get(), spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, basecolormap); // R_SetPatchStyle can modify basecolormap. if (rereadcolormap) @@ -248,7 +248,7 @@ namespace swrenderer void RenderWallSprite::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip) { - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); float iscale = walltexcoords.VStep[x] * maskedScaleY; double spryscale = 1 / iscale; diff --git a/src/swrenderer/viewport/r_drawerargs.cpp b/src/swrenderer/viewport/r_drawerargs.cpp index 60a0edf61..78cc3ea8f 100644 --- a/src/swrenderer/viewport/r_drawerargs.cpp +++ b/src/swrenderer/viewport/r_drawerargs.cpp @@ -28,11 +28,11 @@ namespace swrenderer mTranslation = translation; } - uint8_t *DrawerArgs::Colormap() const + uint8_t *DrawerArgs::Colormap(RenderViewport *viewport) const { if (mBaseColormap) { - if (RenderViewport::Instance()->RenderTarget->IsBgra()) + if (viewport->RenderTarget->IsBgra()) return mBaseColormap->Maps; else return mBaseColormap->Maps + (GETPALOOKUP(mLight, mShade) << COLORMAPSHIFT); diff --git a/src/swrenderer/viewport/r_drawerargs.h b/src/swrenderer/viewport/r_drawerargs.h index ad77dadd2..f1c5fc556 100644 --- a/src/swrenderer/viewport/r_drawerargs.h +++ b/src/swrenderer/viewport/r_drawerargs.h @@ -33,7 +33,7 @@ namespace swrenderer void SetLight(FSWColormap *base_colormap, float light, int shade); void SetTranslationMap(lighttable_t *translation); - uint8_t *Colormap() const; + uint8_t *Colormap(RenderViewport *viewport) const; uint8_t *TranslationMap() const { return mTranslation; } ShadeConstants ColormapConstants() const; diff --git a/src/swrenderer/viewport/r_skydrawer.cpp b/src/swrenderer/viewport/r_skydrawer.cpp index 74462b2fa..df93c6eed 100644 --- a/src/swrenderer/viewport/r_skydrawer.cpp +++ b/src/swrenderer/viewport/r_skydrawer.cpp @@ -19,24 +19,24 @@ namespace swrenderer { void SkyDrawerArgs::DrawSingleSkyColumn(RenderThread *thread) { - thread->Drawers()->DrawSingleSkyColumn(*this); + thread->Drawers(dc_viewport)->DrawSingleSkyColumn(*this); } void SkyDrawerArgs::DrawDoubleSkyColumn(RenderThread *thread) { - thread->Drawers()->DrawDoubleSkyColumn(*this); + thread->Drawers(dc_viewport)->DrawDoubleSkyColumn(*this); } - void SkyDrawerArgs::SetDest(int x, int y) + void SkyDrawerArgs::SetDest(RenderViewport *viewport, int x, int y) { - auto viewport = RenderViewport::Instance(); dc_dest = viewport->GetDest(x, y); dc_dest_y = y; + dc_viewport = viewport; } - void SkyDrawerArgs::SetFrontTexture(FTexture *texture, uint32_t column) + void SkyDrawerArgs::SetFrontTexture(RenderViewport *viewport, FTexture *texture, uint32_t column) { - if (RenderViewport::Instance()->RenderTarget->IsBgra()) + if (viewport->RenderTarget->IsBgra()) { dc_source = (const uint8_t *)texture->GetColumnBgra(column, nullptr); dc_sourceheight = texture->GetHeight(); @@ -48,14 +48,14 @@ namespace swrenderer } } - void SkyDrawerArgs::SetBackTexture(FTexture *texture, uint32_t column) + void SkyDrawerArgs::SetBackTexture(RenderViewport *viewport, FTexture *texture, uint32_t column) { if (texture == nullptr) { dc_source2 = nullptr; dc_sourceheight2 = 1; } - else if (RenderViewport::Instance()->RenderTarget->IsBgra()) + else if (viewport->RenderTarget->IsBgra()) { dc_source2 = (const uint8_t *)texture->GetColumnBgra(column, nullptr); dc_sourceheight2 = texture->GetHeight(); diff --git a/src/swrenderer/viewport/r_skydrawer.h b/src/swrenderer/viewport/r_skydrawer.h index b4d23a7ee..2f352e939 100644 --- a/src/swrenderer/viewport/r_skydrawer.h +++ b/src/swrenderer/viewport/r_skydrawer.h @@ -13,10 +13,10 @@ namespace swrenderer class SkyDrawerArgs : public DrawerArgs { public: - void SetDest(int x, int y); + void SetDest(RenderViewport *viewport, int x, int y); void SetCount(int count) { dc_count = count; } - void SetFrontTexture(FTexture *texture, uint32_t column); - void SetBackTexture(FTexture *texture, uint32_t column); + void SetFrontTexture(RenderViewport *viewport, FTexture *texture, uint32_t column); + void SetBackTexture(RenderViewport *viewport, FTexture *texture, uint32_t column); void SetTextureVPos(uint32_t texturefrac) { dc_texturefrac = texturefrac; } void SetTextureVStep(uint32_t iscale) { dc_iscale = iscale; } void SetSolidTop(uint32_t color) { solid_top = color; } @@ -39,6 +39,8 @@ namespace swrenderer int FrontTextureHeight() const { return dc_sourceheight; } int BackTextureHeight() const { return dc_sourceheight2; } + RenderViewport *Viewport() const { return dc_viewport; } + void DrawSingleSkyColumn(RenderThread *thread); void DrawDoubleSkyColumn(RenderThread *thread); @@ -55,5 +57,6 @@ namespace swrenderer uint32_t solid_top; uint32_t solid_bottom; bool fadeSky; + RenderViewport *dc_viewport = nullptr; }; } diff --git a/src/swrenderer/viewport/r_spandrawer.cpp b/src/swrenderer/viewport/r_spandrawer.cpp index ac28c5242..afe1cbc66 100644 --- a/src/swrenderer/viewport/r_spandrawer.cpp +++ b/src/swrenderer/viewport/r_spandrawer.cpp @@ -22,7 +22,7 @@ namespace swrenderer spanfunc = &SWPixelFormatDrawers::DrawSpan; } - void SpanDrawerArgs::SetTexture(FTexture *tex) + void SpanDrawerArgs::SetTexture(RenderViewport *viewport, FTexture *tex) { tex->GetWidth(); ds_xbits = tex->WidthBits; @@ -36,7 +36,6 @@ namespace swrenderer ds_ybits--; } - auto viewport = RenderViewport::Instance(); ds_source = viewport->RenderTarget->IsBgra() ? (const uint8_t*)tex->GetPixelsBgra() : tex->GetPixels(); ds_source_mipmapped = tex->Mipmapped() && tex->GetWidth() > 1 && tex->GetHeight() > 1; } @@ -99,21 +98,30 @@ namespace swrenderer void SpanDrawerArgs::DrawSpan(RenderThread *thread) { - (thread->Drawers()->*spanfunc)(*this); + (thread->Drawers(ds_viewport)->*spanfunc)(*this); } void SpanDrawerArgs::DrawTiltedSpan(RenderThread *thread, int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) { - thread->Drawers()->DrawTiltedSpan(*this, y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap); + SetDestY(thread->Viewport.get(), y); + SetDestX1(x1); + SetDestX2(x2); + thread->Drawers(ds_viewport)->DrawTiltedSpan(*this, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap); } void SpanDrawerArgs::DrawFogBoundaryLine(RenderThread *thread, int y, int x1, int x2) { - thread->Drawers()->DrawFogBoundaryLine(*this, y, x1, x2); + SetDestY(thread->Viewport.get(), y); + SetDestX1(x1); + SetDestX2(x2); + thread->Drawers(ds_viewport)->DrawFogBoundaryLine(*this); } void SpanDrawerArgs::DrawColoredSpan(RenderThread *thread, int y, int x1, int x2) { - thread->Drawers()->DrawColoredSpan(*this, y, x1, x2); + SetDestY(thread->Viewport.get(), y); + SetDestX1(x1); + SetDestX2(x2); + thread->Drawers(ds_viewport)->DrawColoredSpan(*this); } } diff --git a/src/swrenderer/viewport/r_spandrawer.h b/src/swrenderer/viewport/r_spandrawer.h index 368ae8a32..cba3ab0d7 100644 --- a/src/swrenderer/viewport/r_spandrawer.h +++ b/src/swrenderer/viewport/r_spandrawer.h @@ -16,10 +16,10 @@ namespace swrenderer SpanDrawerArgs(); void SetStyle(bool masked, bool additive, fixed_t alpha); - void SetDestY(int y) { ds_y = y; } + void SetDestY(RenderViewport *viewport, int y) { ds_viewport = viewport; ds_y = y; } void SetDestX1(int x) { ds_x1 = x; } void SetDestX2(int x) { ds_x2 = x; } - void SetTexture(FTexture *tex); + void SetTexture(RenderViewport *viewport, FTexture *tex); void SetTextureLOD(double lod) { ds_lod = lod; } void SetTextureUPos(dsfixed_t xfrac) { ds_xfrac = xfrac; } void SetTextureVPos(dsfixed_t yfrac) { ds_yfrac = yfrac; } @@ -49,6 +49,7 @@ namespace swrenderer const uint8_t *TexturePixels() const { return ds_source; } bool MipmappedTexture() const { return ds_source_mipmapped; } double TextureLOD() const { return ds_lod; } + RenderViewport *Viewport() const { return ds_viewport; } FVector3 dc_normal; FVector3 dc_viewpos; @@ -77,5 +78,6 @@ namespace swrenderer fixed_t dc_destalpha; int ds_color = 0; double ds_lod; + RenderViewport *ds_viewport = nullptr; }; } diff --git a/src/swrenderer/viewport/r_spritedrawer.cpp b/src/swrenderer/viewport/r_spritedrawer.cpp index f4cc0a17e..cd5bc44d7 100644 --- a/src/swrenderer/viewport/r_spritedrawer.cpp +++ b/src/swrenderer/viewport/r_spritedrawer.cpp @@ -48,7 +48,7 @@ namespace swrenderer if (x < thread->X1 || x >= thread->X2) return; - auto viewport = RenderViewport::Instance(); + auto viewport = thread->Viewport.get(); // Handle the linear filtered version in a different function to reduce chances of merge conflicts from zdoom. if (viewport->RenderTarget->IsBgra() && !drawer_needs_pal_input) // To do: add support to R_DrawColumnHoriz_rgba @@ -57,6 +57,7 @@ namespace swrenderer return; } + dc_viewport = viewport; dc_x = x; dc_iscale = iscale; dc_textureheight = tex->GetHeight(); @@ -108,7 +109,7 @@ namespace swrenderer dc_texturefrac = FLOAT2FIXED((dc_yl + 0.5 - sprtopscreen) / spryscale); dc_source = column; dc_source2 = nullptr; - SetDest(dc_x, dc_yl); + SetDest(viewport, dc_x, dc_yl); dc_count = dc_yh - dc_yl + 1; fixed_t maxfrac = ((top + length) << FRACBITS) - 1; @@ -119,7 +120,7 @@ namespace swrenderer else if (dc_iscale < 0) dc_count = MIN(dc_count, (dc_texturefrac - dc_iscale) / (-dc_iscale)); - (thread->Drawers()->*colfunc)(*this); + (thread->Drawers(dc_viewport)->*colfunc)(*this); } span++; } @@ -127,6 +128,7 @@ namespace swrenderer void SpriteDrawerArgs::DrawMaskedColumnBgra(RenderThread *thread, int x, fixed_t iscale, FTexture *tex, fixed_t col, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked) { + dc_viewport = thread->Viewport.get(); dc_x = x; dc_iscale = iscale; @@ -228,13 +230,13 @@ namespace swrenderer if (dc_yl <= dc_yh) { - SetDest(dc_x, dc_yl); + SetDest(dc_viewport, dc_x, dc_yl); dc_count = dc_yh - dc_yl + 1; double v = ((dc_yl + 0.5 - sprtopscreen) / spryscale) / tex->GetHeight(); dc_texturefrac = (uint32_t)(v * (1 << 30)); - (thread->Drawers()->*colfunc)(*this); + (thread->Drawers(dc_viewport)->*colfunc)(*this); } span++; } @@ -376,7 +378,7 @@ namespace swrenderer } } - bool SpriteDrawerArgs::SetStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade) + bool SpriteDrawerArgs::SetStyle(RenderViewport *viewport, FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade) { fixed_t fglevel, bglevel; @@ -408,8 +410,6 @@ namespace swrenderer alpha = clamp(alpha, 0, OPAQUE); } - auto viewport = RenderViewport::Instance(); - if (translation != -1) { SetTranslationMap(nullptr); @@ -483,19 +483,19 @@ namespace swrenderer return SpriteDrawerArgs::SetBlendFunc(style.BlendOp, fglevel, bglevel, style.Flags); } - bool SpriteDrawerArgs::SetStyle(FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade) + bool SpriteDrawerArgs::SetStyle(RenderViewport *viewport, FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade) { - return SetStyle(style, FLOAT2FIXED(alpha), translation, color, basecolormap, shadedlightshade); + return SetStyle(viewport, style, FLOAT2FIXED(alpha), translation, color, basecolormap, shadedlightshade); } void SpriteDrawerArgs::FillColumn(RenderThread *thread) { - thread->Drawers()->FillColumn(*this); + thread->Drawers(dc_viewport)->FillColumn(*this); } void SpriteDrawerArgs::DrawVoxelColumn(RenderThread *thread, fixed_t vPos, fixed_t vStep, const uint8_t *voxels, int voxelsCount) { - if (RenderViewport::Instance()->RenderTarget->IsBgra()) + if (dc_viewport->RenderTarget->IsBgra()) { double v = vPos / (double)voxelsCount / FRACUNIT; double vstep = vStep / (double)voxelsCount / FRACUNIT; @@ -512,13 +512,13 @@ namespace swrenderer dc_source = voxels; dc_source2 = 0; dc_textureheight = voxelsCount; - (thread->Drawers()->*colfunc)(*this); + (thread->Drawers(dc_viewport)->*colfunc)(*this); } - void SpriteDrawerArgs::SetDest(int x, int y) + void SpriteDrawerArgs::SetDest(RenderViewport *viewport, int x, int y) { - auto viewport = RenderViewport::Instance(); dc_dest = viewport->GetDest(x, y); dc_dest_y = y; + dc_viewport = viewport; } } diff --git a/src/swrenderer/viewport/r_spritedrawer.h b/src/swrenderer/viewport/r_spritedrawer.h index eaee87805..34e80cf60 100644 --- a/src/swrenderer/viewport/r_spritedrawer.h +++ b/src/swrenderer/viewport/r_spritedrawer.h @@ -15,9 +15,9 @@ namespace swrenderer public: SpriteDrawerArgs(); - bool SetStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade = 0); - bool SetStyle(FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade = 0); - void SetDest(int x, int y); + bool SetStyle(RenderViewport *viewport, FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade = 0); + bool SetStyle(RenderViewport *viewport, FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade = 0); + void SetDest(RenderViewport *viewport, int x, int y); void SetCount(int count) { dc_count = count; } void SetSolidColor(int color) { dc_color = color; } void SetDynamicLight(uint32_t color) { dynlightcolor = color; } @@ -54,6 +54,7 @@ namespace swrenderer uint32_t DynamicLight() const { return dynlightcolor; } bool DrawerNeedsPalInput() const { return drawer_needs_pal_input; } + RenderViewport *Viewport() const { return dc_viewport; } private: bool SetBlendFunc(int op, fixed_t fglevel, fixed_t bglevel, int flags); @@ -90,5 +91,7 @@ namespace swrenderer typedef void(SWPixelFormatDrawers::*SpriteDrawerFunc)(const SpriteDrawerArgs &args); SpriteDrawerFunc colfunc; + + RenderViewport *dc_viewport = nullptr; }; } diff --git a/src/swrenderer/viewport/r_viewport.cpp b/src/swrenderer/viewport/r_viewport.cpp index 384c37c6a..47599d1f4 100644 --- a/src/swrenderer/viewport/r_viewport.cpp +++ b/src/swrenderer/viewport/r_viewport.cpp @@ -40,12 +40,6 @@ CVAR(String, r_viewsize, "", CVAR_NOSET) namespace swrenderer { - RenderViewport *RenderViewport::Instance() - { - static RenderViewport instance; - return &instance; - } - RenderViewport::RenderViewport() { } @@ -70,8 +64,8 @@ namespace swrenderer fuzzviewheight = viewheight - 2; // Maximum row the fuzzer can draw to - CenterX = r_viewwindow.centerx; - CenterY = r_viewwindow.centery; + CenterX = viewwindow.centerx; + CenterY = viewwindow.centery; virtwidth = virtwidth2 = fullWidth; virtheight = virtheight2 = fullHeight; @@ -85,13 +79,13 @@ namespace swrenderer virtwidth2 = virtwidth2 * AspectMultiplier(trueratio) / 48; } - if (AspectTallerThanWide(r_viewwindow.WidescreenRatio)) + if (AspectTallerThanWide(viewwindow.WidescreenRatio)) { - virtheight = virtheight * AspectMultiplier(r_viewwindow.WidescreenRatio) / 48; + virtheight = virtheight * AspectMultiplier(viewwindow.WidescreenRatio) / 48; } else { - virtwidth = virtwidth * AspectMultiplier(r_viewwindow.WidescreenRatio) / 48; + virtwidth = virtwidth * AspectMultiplier(viewwindow.WidescreenRatio) / 48; } BaseYaspectMul = 320.0 * virtheight2 / (r_Yaspect * virtwidth2); @@ -108,7 +102,7 @@ namespace swrenderer // Reset r_*Visibility vars LightVisibility *visibility = LightVisibility::Instance(); - visibility->SetVisibility(visibility->GetVisibility()); + visibility->SetVisibility(this, visibility->GetVisibility()); SetupBuffer(); } @@ -117,9 +111,9 @@ namespace swrenderer { double dy; - if (r_viewpoint.camera != NULL) + if (viewpoint.camera != NULL) { - dy = FocalLengthY * (-r_viewpoint.Angles.Pitch).Tan(); + dy = FocalLengthY * (-viewpoint.Angles.Pitch).Tan(); } else { @@ -127,7 +121,7 @@ namespace swrenderer } CenterY = (viewheight / 2.0) + dy; - r_viewwindow.centery = xs_ToInt(CenterY); + viewwindow.centery = xs_ToInt(CenterY); globaluclip = -CenterY / InvZtoScale; globaldclip = (viewheight - CenterY) / InvZtoScale; } @@ -153,23 +147,23 @@ namespace swrenderer int i; // Calc focallength so FieldOfView angles cover viewwidth. - FocalLengthX = CenterX / r_viewwindow.FocalTangent; + FocalLengthX = CenterX / viewwindow.FocalTangent; FocalLengthY = FocalLengthX * YaspectMul; // This is 1/FocalTangent before the widescreen extension of FOV. - viewingrangerecip = FLOAT2FIXED(1. / tan(r_viewpoint.FieldOfView.Radians() / 2)); + viewingrangerecip = FLOAT2FIXED(1. / tan(viewpoint.FieldOfView.Radians() / 2)); // Now generate xtoviewangle for sky texture mapping. // [RH] Do not generate viewangletox, because texture mapping is no // longer done with trig, so it's not needed. - const double slopestep = r_viewwindow.FocalTangent / r_viewwindow.centerx; + const double slopestep = viewwindow.FocalTangent / viewwindow.centerx; double slope; - for (i = r_viewwindow.centerx, slope = 0; i <= viewwidth; i++, slope += slopestep) + for (i = viewwindow.centerx, slope = 0; i <= viewwidth; i++, slope += slopestep) { xtoviewangle[i] = angle_t((2 * M_PI - atan(slope)) * (ANGLE_180 / M_PI)); } - for (i = 0; i < r_viewwindow.centerx; i++) + for (i = 0; i < viewwindow.centerx; i++) { xtoviewangle[i] = 0 - xtoviewangle[viewwidth - i - 1]; } @@ -177,23 +171,23 @@ namespace swrenderer DVector2 RenderViewport::PointWorldToView(const DVector2 &worldPos) const { - double translatedX = worldPos.X - r_viewpoint.Pos.X; - double translatedY = worldPos.Y - r_viewpoint.Pos.Y; + double translatedX = worldPos.X - viewpoint.Pos.X; + double translatedY = worldPos.Y - viewpoint.Pos.Y; return { - translatedX * r_viewpoint.Sin - translatedY * r_viewpoint.Cos, - translatedX * r_viewpoint.TanCos + translatedY * r_viewpoint.TanSin + translatedX * viewpoint.Sin - translatedY * viewpoint.Cos, + translatedX * viewpoint.TanCos + translatedY * viewpoint.TanSin }; } DVector3 RenderViewport::PointWorldToView(const DVector3 &worldPos) const { - double translatedX = worldPos.X - r_viewpoint.Pos.X; - double translatedY = worldPos.Y - r_viewpoint.Pos.Y; - double translatedZ = worldPos.Z - r_viewpoint.Pos.Z; + double translatedX = worldPos.X - viewpoint.Pos.X; + double translatedY = worldPos.Y - viewpoint.Pos.Y; + double translatedZ = worldPos.Z - viewpoint.Pos.Z; return { - translatedX * r_viewpoint.Sin - translatedY * r_viewpoint.Cos, + translatedX * viewpoint.Sin - translatedY * viewpoint.Cos, translatedZ, - translatedX * r_viewpoint.TanCos + translatedY * r_viewpoint.TanSin + translatedX * viewpoint.TanCos + translatedY * viewpoint.TanSin }; } diff --git a/src/swrenderer/viewport/r_viewport.h b/src/swrenderer/viewport/r_viewport.h index a16c8fde2..9898458a5 100644 --- a/src/swrenderer/viewport/r_viewport.h +++ b/src/swrenderer/viewport/r_viewport.h @@ -22,8 +22,6 @@ namespace swrenderer class RenderViewport { public: - static RenderViewport *Instance(); - RenderViewport(); ~RenderViewport(); @@ -32,6 +30,9 @@ namespace swrenderer DCanvas *RenderTarget = nullptr; + FViewWindow viewwindow; + FRenderViewpoint viewpoint; + double FocalLengthX = 0.0; double FocalLengthY = 0.0; double InvZtoScale = 0.0; diff --git a/src/swrenderer/viewport/r_walldrawer.cpp b/src/swrenderer/viewport/r_walldrawer.cpp index aaada0604..2ec85e675 100644 --- a/src/swrenderer/viewport/r_walldrawer.cpp +++ b/src/swrenderer/viewport/r_walldrawer.cpp @@ -17,16 +17,16 @@ namespace swrenderer { - void WallDrawerArgs::SetDest(int x, int y) + void WallDrawerArgs::SetDest(RenderViewport *viewport, int x, int y) { - auto viewport = RenderViewport::Instance(); + dc_viewport = viewport; dc_dest = viewport->GetDest(x, y); dc_dest_y = y; } void WallDrawerArgs::DrawColumn(RenderThread *thread) { - (thread->Drawers()->*wallfunc)(*this); + (thread->Drawers(dc_viewport)->*wallfunc)(*this); } void WallDrawerArgs::SetStyle(bool masked, bool additive, fixed_t alpha) diff --git a/src/swrenderer/viewport/r_walldrawer.h b/src/swrenderer/viewport/r_walldrawer.h index b7afddc21..5dde5cc5c 100644 --- a/src/swrenderer/viewport/r_walldrawer.h +++ b/src/swrenderer/viewport/r_walldrawer.h @@ -9,12 +9,13 @@ struct FLightNode; namespace swrenderer { class RenderThread; + class RenderViewport; class WallDrawerArgs : public DrawerArgs { public: void SetStyle(bool masked, bool additive, fixed_t alpha); - void SetDest(int x, int y); + void SetDest(RenderViewport *viewport, int x, int y); void SetCount(int count) { dc_count = count; } void SetTexture(const uint8_t *pixels, const uint8_t *pixels2, int height) { @@ -56,6 +57,8 @@ namespace swrenderer DrawerLight *dc_lights = nullptr; int dc_num_lights = 0; + RenderViewport *Viewport() const { return dc_viewport; } + private: uint8_t *dc_dest = nullptr; int dc_dest_y = 0; @@ -76,5 +79,7 @@ namespace swrenderer typedef void(SWPixelFormatDrawers::*WallDrawerFunc)(const WallDrawerArgs &args); WallDrawerFunc wallfunc = nullptr; + + RenderViewport *dc_viewport = nullptr; }; }