mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-23 12:32:34 +00:00
- detached the poly renderer from the software renderer
This commit is contained in:
parent
f45371e231
commit
11e5759913
33 changed files with 328 additions and 316 deletions
|
@ -862,6 +862,7 @@ set( POLYRENDER_SOURCES
|
|||
polyrenderer/scene/poly_wallsprite.cpp
|
||||
polyrenderer/scene/poly_sprite.cpp
|
||||
polyrenderer/scene/poly_sky.cpp
|
||||
polyrenderer/scene/poly_light.cpp
|
||||
polyrenderer/drawers/poly_buffer.cpp
|
||||
polyrenderer/drawers/poly_triangle.cpp
|
||||
polyrenderer/drawers/poly_draw_args.cpp
|
||||
|
|
|
@ -49,8 +49,7 @@ void PolyDrawArgs::SetTexture(FTexture *texture)
|
|||
{
|
||||
textureWidth = texture->GetWidth();
|
||||
textureHeight = texture->GetHeight();
|
||||
auto viewport = PolyRenderer::Instance()->Thread.Viewport.get();
|
||||
if (viewport->RenderTarget->IsBgra())
|
||||
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
|
||||
texturePixels = (const uint8_t *)texture->GetPixelsBgra();
|
||||
else
|
||||
texturePixels = texture->GetPixels();
|
||||
|
@ -64,7 +63,7 @@ void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool fo
|
|||
FRemapTable *table = TranslationToTable(translationID);
|
||||
if (table != nullptr && !table->Inactive)
|
||||
{
|
||||
if (PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra())
|
||||
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
|
||||
translation = (uint8_t*)table->Palette;
|
||||
else
|
||||
translation = table->Remap;
|
||||
|
|
|
@ -82,7 +82,7 @@ void PolyTriangleDrawer::toggle_mirror()
|
|||
|
||||
void PolyTriangleDrawer::draw(const PolyDrawArgs &args)
|
||||
{
|
||||
PolyRenderer::Instance()->Thread.DrawQueue->Push<DrawPolyTrianglesCommand>(args, mirror);
|
||||
PolyRenderer::Instance()->DrawQueue->Push<DrawPolyTrianglesCommand>(args, mirror);
|
||||
}
|
||||
|
||||
void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, WorkerThreadData *thread)
|
||||
|
|
|
@ -132,6 +132,7 @@ TriMatrix TriMatrix::frustum(float left, float right, float bottom, float top, f
|
|||
return m;
|
||||
}
|
||||
|
||||
#if 0
|
||||
TriMatrix TriMatrix::worldToView(const FRenderViewpoint &viewpoint)
|
||||
{
|
||||
TriMatrix m = null();
|
||||
|
@ -144,15 +145,16 @@ TriMatrix TriMatrix::worldToView(const FRenderViewpoint &viewpoint)
|
|||
return m * translate((float)-viewpoint.Pos.X, (float)-viewpoint.Pos.Y, (float)-viewpoint.Pos.Z);
|
||||
}
|
||||
|
||||
TriMatrix TriMatrix::viewToClip(swrenderer::RenderViewport *viewport)
|
||||
TriMatrix TriMatrix::viewToClip(double focalTangent, double centerY, double invZtoScale)
|
||||
{
|
||||
float near = 5.0f;
|
||||
float far = 65536.0f;
|
||||
float width = (float)(viewport->viewwindow.FocalTangent * near);
|
||||
float top = (float)(viewport->CenterY / viewport->InvZtoScale * near);
|
||||
float bottom = (float)(top - viewheight / viewport->InvZtoScale * near);
|
||||
float width = (float)(focalTangent * near);
|
||||
float top = (float)(centerY / invZtoScale * near);
|
||||
float bottom = (float)(top - viewheight / invZtoScale * near);
|
||||
return frustum(-width, width, bottom, top, near, far);
|
||||
}
|
||||
#endif
|
||||
|
||||
TriMatrix TriMatrix::operator*(const TriMatrix &mult) const
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
struct TriVertex;
|
||||
struct ShadedTriVertex;
|
||||
namespace swrenderer { class RenderViewport; }
|
||||
struct FRenderViewpoint;
|
||||
|
||||
struct TriMatrix
|
||||
{
|
||||
|
@ -37,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(const FRenderViewpoint &viewpoint); // Software renderer world to view space transform
|
||||
static TriMatrix viewToClip(swrenderer::RenderViewport *viewport); // Software renderer shearing projection
|
||||
//static TriMatrix worldToView(const FRenderViewpoint &viewpoint); // Software renderer world to view space transform
|
||||
//static TriMatrix viewToClip(double focalTangent, double centerY, double invZtoScale); // Software renderer shearing projection
|
||||
|
||||
ShadedTriVertex operator*(TriVertex v) const;
|
||||
TriMatrix operator*(const TriMatrix &m) const;
|
||||
|
|
|
@ -16,3 +16,4 @@
|
|||
#include "scene/poly_sprite.cpp"
|
||||
#include "scene/poly_wall.cpp"
|
||||
#include "scene/poly_wallsprite.cpp"
|
||||
#include "scene/poly_light.cpp"
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
#include "po_man.h"
|
||||
#include "st_stuff.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
#include "swrenderer/scene/r_scene.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "swrenderer/drawers/r_draw_rgba.h"
|
||||
#include "swrenderer/viewport/r_viewport.h"
|
||||
#include "swrenderer/r_swcolormaps.h"
|
||||
|
@ -50,49 +50,46 @@ PolyRenderer *PolyRenderer::Instance()
|
|||
return &scene;
|
||||
}
|
||||
|
||||
PolyRenderer::PolyRenderer() : Thread(nullptr)
|
||||
PolyRenderer::PolyRenderer()
|
||||
{
|
||||
DrawQueue = std::make_shared<DrawerCommandQueue>(&FrameMemory);
|
||||
}
|
||||
|
||||
void PolyRenderer::RenderView(player_t *player)
|
||||
{
|
||||
using namespace swrenderer;
|
||||
|
||||
auto viewport = Thread.Viewport.get();
|
||||
|
||||
viewport->RenderTarget = screen;
|
||||
RenderTarget = screen;
|
||||
|
||||
int width = SCREENWIDTH;
|
||||
int height = SCREENHEIGHT;
|
||||
int stHeight = gST_Y;
|
||||
float trueratio;
|
||||
ActiveRatio(width, height, &trueratio);
|
||||
viewport->SetViewport(&Thread, width, height, trueratio);
|
||||
//viewport->SetViewport(&Thread, width, height, trueratio);
|
||||
|
||||
RenderActorView(player->mo, false);
|
||||
|
||||
// Apply special colormap if the target cannot do it
|
||||
CameraLight *cameraLight = CameraLight::Instance();
|
||||
if (cameraLight->ShaderColormap() && viewport->RenderTarget->IsBgra() && !(r_shadercolormaps && screen->Accel2D))
|
||||
if (cameraLight->ShaderColormap() && RenderTarget->IsBgra() && !(r_shadercolormaps && screen->Accel2D))
|
||||
{
|
||||
Thread.DrawQueue->Push<ApplySpecialColormapRGBACommand>(cameraLight->ShaderColormap(), screen);
|
||||
DrawQueue->Push<ApplySpecialColormapRGBACommand>(cameraLight->ShaderColormap(), screen);
|
||||
}
|
||||
|
||||
DrawerThreads::Execute(Thread.DrawQueue);
|
||||
DrawerThreads::Execute(DrawQueue);
|
||||
DrawerThreads::WaitForWorkers();
|
||||
Thread.DrawQueue->Clear();
|
||||
DrawQueue->Clear();
|
||||
}
|
||||
|
||||
void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines)
|
||||
{
|
||||
auto viewport = Thread.Viewport.get();
|
||||
|
||||
const bool savedviewactive = viewactive;
|
||||
|
||||
viewwidth = width;
|
||||
viewport->RenderTarget = canvas;
|
||||
R_SetWindow(viewport->viewpoint, viewport->viewwindow, 12, width, height, height, true);
|
||||
viewport->SetViewport(&Thread, width, height, viewport->viewwindow.WidescreenRatio);
|
||||
RenderTarget = canvas;
|
||||
R_SetWindow(Viewpoint, Viewwindow, 12, width, height, height, true);
|
||||
//viewport->SetViewport(&Thread, width, height, Viewwindow.WidescreenRatio);
|
||||
viewwindowx = x;
|
||||
viewwindowy = y;
|
||||
viewactive = true;
|
||||
|
@ -100,16 +97,16 @@ void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int
|
|||
canvas->Lock(true);
|
||||
|
||||
RenderActorView(actor, dontmaplines);
|
||||
DrawerThreads::Execute(Thread.DrawQueue);
|
||||
DrawerThreads::Execute(DrawQueue);
|
||||
DrawerThreads::WaitForWorkers();
|
||||
|
||||
canvas->Unlock();
|
||||
|
||||
viewport->RenderTarget = screen;
|
||||
R_ExecuteSetViewSize(viewport->viewpoint, viewport->viewwindow);
|
||||
RenderTarget = screen;
|
||||
R_ExecuteSetViewSize(Viewpoint, Viewwindow);
|
||||
float trueratio;
|
||||
ActiveRatio(width, height, &trueratio);
|
||||
viewport->SetViewport(&Thread, width, height, viewport->viewwindow.WidescreenRatio);
|
||||
//viewport->SetViewport(&Thread, width, height, viewport->viewwindow.WidescreenRatio);
|
||||
viewactive = savedviewactive;
|
||||
}
|
||||
|
||||
|
@ -121,19 +118,19 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines)
|
|||
|
||||
P_FindParticleSubsectors();
|
||||
PO_LinkToSubsectors();
|
||||
R_SetupFrame(Thread.Viewport->viewpoint, Thread.Viewport->viewwindow, actor);
|
||||
R_SetupFrame(Viewpoint, Viewwindow, actor);
|
||||
|
||||
if (APART(R_OldBlend)) NormalLight.Maps = realcolormaps.Maps;
|
||||
else NormalLight.Maps = realcolormaps.Maps + NUMCOLORMAPS * 256 * R_OldBlend;
|
||||
|
||||
|
||||
swrenderer::CameraLight::Instance()->SetCamera(Thread.Viewport.get(), actor);
|
||||
Thread.Viewport->SetupFreelook();
|
||||
PolyCameraLight::Instance()->SetCamera(Viewpoint, RenderTarget, actor);
|
||||
//Viewport->SetupFreelook();
|
||||
|
||||
ActorRenderFlags savedflags = Thread.Viewport->viewpoint.camera->renderflags;
|
||||
ActorRenderFlags savedflags = Viewpoint.camera->renderflags;
|
||||
// Never draw the player unless in chasecam mode
|
||||
if (!Thread.Viewport->viewpoint.showviewer)
|
||||
Thread.Viewport->viewpoint.camera->renderflags |= RF_INVISIBLE;
|
||||
if (!Viewpoint.showviewer)
|
||||
Viewpoint.camera->renderflags |= RF_INVISIBLE;
|
||||
|
||||
ClearBuffers();
|
||||
SetSceneViewport();
|
||||
|
@ -144,7 +141,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines)
|
|||
MainPortal.RenderTranslucent(0);
|
||||
PlayerSprites.Render();
|
||||
|
||||
Thread.Viewport->viewpoint.camera->renderflags = savedflags;
|
||||
Viewpoint.camera->renderflags = savedflags;
|
||||
interpolator.RestoreInterpolations ();
|
||||
|
||||
NetUpdate();
|
||||
|
@ -158,9 +155,8 @@ void PolyRenderer::RenderRemainingPlayerSprites()
|
|||
void PolyRenderer::ClearBuffers()
|
||||
{
|
||||
PolyVertexBuffer::Clear();
|
||||
auto viewport = Thread.Viewport.get();
|
||||
PolyStencilBuffer::Instance()->Clear(viewport->RenderTarget->GetWidth(), viewport->RenderTarget->GetHeight(), 0);
|
||||
PolySubsectorGBuffer::Instance()->Resize(viewport->RenderTarget->GetPitch(), viewport->RenderTarget->GetHeight());
|
||||
PolyStencilBuffer::Instance()->Clear(RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0);
|
||||
PolySubsectorGBuffer::Instance()->Resize(RenderTarget->GetPitch(), RenderTarget->GetHeight());
|
||||
NextStencilValue = 0;
|
||||
SeenLinePortals.clear();
|
||||
SeenMirrors.clear();
|
||||
|
@ -170,9 +166,7 @@ void PolyRenderer::SetSceneViewport()
|
|||
{
|
||||
using namespace swrenderer;
|
||||
|
||||
auto viewport = Thread.Viewport.get();
|
||||
|
||||
if (viewport->RenderTarget == screen) // Rendering to screen
|
||||
if (RenderTarget == screen) // Rendering to screen
|
||||
{
|
||||
int height;
|
||||
if (screenblocks >= 10)
|
||||
|
@ -181,11 +175,11 @@ void PolyRenderer::SetSceneViewport()
|
|||
height = (screenblocks*SCREENHEIGHT / 10) & ~7;
|
||||
|
||||
int bottom = SCREENHEIGHT - (height + viewwindowy - ((height - viewheight) / 2));
|
||||
PolyTriangleDrawer::set_viewport(viewwindowx, SCREENHEIGHT - bottom - height, viewwidth, height, viewport->RenderTarget);
|
||||
PolyTriangleDrawer::set_viewport(viewwindowx, SCREENHEIGHT - bottom - height, viewwidth, height, RenderTarget);
|
||||
}
|
||||
else // Rendering to camera texture
|
||||
{
|
||||
PolyTriangleDrawer::set_viewport(0, 0, viewport->RenderTarget->GetWidth(), viewport->RenderTarget->GetHeight(), viewport->RenderTarget);
|
||||
PolyTriangleDrawer::set_viewport(0, 0, RenderTarget->GetWidth(), RenderTarget->GetHeight(), RenderTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,25 +195,23 @@ 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.
|
||||
const auto &viewpoint = Thread.Viewport->viewpoint;
|
||||
const auto &viewwindow = Thread.Viewport->viewwindow;
|
||||
double radPitch = viewpoint.Angles.Pitch.Normalized180().Radians();
|
||||
double radPitch = Viewpoint.Angles.Pitch.Normalized180().Radians();
|
||||
double angx = cos(radPitch);
|
||||
double angy = sin(radPitch) * level.info->pixelstretch;
|
||||
double alen = sqrt(angx*angx + angy*angy);
|
||||
float adjustedPitch = (float)asin(angy / alen);
|
||||
float adjustedViewAngle = (float)(viewpoint.Angles.Yaw - 90).Radians();
|
||||
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);
|
||||
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, level.info->pixelstretch, 1.0f) *
|
||||
TriMatrix::swapYZ() *
|
||||
TriMatrix::translate((float)-viewpoint.Pos.X, (float)-viewpoint.Pos.Y, (float)-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;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
#include "scene/poly_portal.h"
|
||||
#include "scene/poly_playersprite.h"
|
||||
#include "scene/poly_sky.h"
|
||||
#include "swrenderer/r_renderthread.h"
|
||||
#include "scene/poly_light.h"
|
||||
#include "swrenderer/r_memory.h"
|
||||
|
||||
class AActor;
|
||||
class DCanvas;
|
||||
|
@ -56,7 +57,12 @@ public:
|
|||
|
||||
bool DontMapLines = false;
|
||||
|
||||
swrenderer::RenderThread Thread;
|
||||
RenderMemory FrameMemory;
|
||||
DrawerCommandQueuePtr DrawQueue;
|
||||
DCanvas *RenderTarget = nullptr;
|
||||
FViewWindow Viewwindow;
|
||||
FRenderViewpoint Viewpoint;
|
||||
PolyLightVisibility Light;
|
||||
|
||||
private:
|
||||
void RenderActorView(AActor *actor, bool dontmaplines);
|
||||
|
|
|
@ -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(PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos, bsp);
|
||||
int side = PointOnSide(PolyRenderer::Instance()->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() - PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos;
|
||||
DVector2 pt2 = line->v2->fPos() - PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos;
|
||||
DVector2 pt1 = line->v1->fPos() - PolyRenderer::Instance()->Viewpoint.Pos;
|
||||
DVector2 pt2 = line->v2->fPos() - PolyRenderer::Instance()->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)PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos.Z - 1000.0f), Vec3f(bspcoord[BOXRIGHT], bspcoord[BOXTOP], (float)PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos.Z + 1000.0f));
|
||||
AxisAlignedBoundingBox aabb(Vec3f(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM], (float)PolyRenderer::Instance()->Viewpoint.Pos.Z - 1000.0f), Vec3f(bspcoord[BOXRIGHT], bspcoord[BOXTOP], (float)PolyRenderer::Instance()->Viewpoint.Pos.Z + 1000.0f));
|
||||
auto result = IntersectionTest::frustum_aabb(frustumPlanes, aabb);
|
||||
if (result == IntersectionTest::outside)
|
||||
return false;
|
||||
|
@ -266,7 +266,7 @@ LineSegmentRange PolyCull::GetSegmentRangeForLine(double x1, double y1, double x
|
|||
}
|
||||
|
||||
// Transform to 2D view space:
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
x1 = x1 - viewpoint.Pos.X;
|
||||
y1 = y1 - viewpoint.Pos.Y;
|
||||
x2 = x2 - viewpoint.Pos.X;
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
#include "r_data/r_translate.h"
|
||||
#include "poly_decal.h"
|
||||
#include "polyrenderer/poly_renderer.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
#include "a_sharedglobal.h"
|
||||
#include "swrenderer/scene/r_scene.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
|
||||
void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const Vec4f &clipPlane, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue)
|
||||
{
|
||||
|
@ -107,7 +107,7 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
|
|||
return;
|
||||
|
||||
bool foggy = false;
|
||||
int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Thread.Viewport->viewpoint.extralight << 4;
|
||||
int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4;
|
||||
|
||||
std::pair<float, float> offsets[4] =
|
||||
{
|
||||
|
@ -133,13 +133,13 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
|
|||
|
||||
bool fullbrightSprite = (decal->RenderFlags & RF_FULLBRIGHT) == RF_FULLBRIGHT;
|
||||
|
||||
swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance();
|
||||
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
|
||||
|
||||
PolyDrawArgs args;
|
||||
args.uniforms.flags = 0;
|
||||
args.SetColormap(GetColorTable(front->Colormap));
|
||||
args.SetTexture(tex, decal->Translation, true);
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->WallGlobVis(foggy);
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);
|
||||
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
|
||||
{
|
||||
args.uniforms.light = 256;
|
||||
|
@ -151,7 +151,7 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
|
|||
}
|
||||
args.uniforms.subsectorDepth = subsectorDepth;
|
||||
|
||||
if (PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra())
|
||||
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
|
||||
{
|
||||
args.uniforms.color = 0xff000000 | decal->AlphaColor;
|
||||
}
|
||||
|
|
43
src/polyrenderer/scene/poly_light.cpp
Normal file
43
src/polyrenderer/scene/poly_light.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
** Light calculations
|
||||
** Copyright (c) 2016 Magnus Norddahl
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any damages
|
||||
** arising from the use of this software.
|
||||
**
|
||||
** Permission is granted to anyone to use this software for any purpose,
|
||||
** including commercial applications, and to alter it and redistribute it
|
||||
** freely, subject to the following restrictions:
|
||||
**
|
||||
** 1. The origin of this software must not be misrepresented; you must not
|
||||
** claim that you wrote the original software. If you use this software
|
||||
** in a product, an acknowledgment in the product documentation would be
|
||||
** appreciated but is not required.
|
||||
** 2. Altered source versions must be plainly marked as such, and must not be
|
||||
** misrepresented as being the original software.
|
||||
** 3. This notice may not be removed or altered from any source distribution.
|
||||
**
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "templates.h"
|
||||
#include "doomdef.h"
|
||||
#include "sbar.h"
|
||||
#include "poly_light.h"
|
||||
|
||||
fixed_t PolyLightVisibility::LightLevelToShade(int lightlevel, bool foggy)
|
||||
{
|
||||
bool nolightfade = !foggy && ((level.flags3 & LEVEL3_NOLIGHTFADE));
|
||||
if (nolightfade)
|
||||
{
|
||||
return (MAX(255 - lightlevel, 0) * NUMCOLORMAPS) << (FRACBITS - 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert a light level into an unbounded colormap index (shade). Result is
|
||||
// fixed point. Why the +12? I wish I knew, but experimentation indicates it
|
||||
// is necessary in order to best reproduce Doom's original lighting.
|
||||
return (NUMCOLORMAPS * 2 * FRACUNIT) - ((lightlevel + 12) * (FRACUNIT*NUMCOLORMAPS / 128));
|
||||
}
|
||||
}
|
49
src/polyrenderer/scene/poly_light.h
Normal file
49
src/polyrenderer/scene/poly_light.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
** Light calculations
|
||||
** Copyright (c) 2016 Magnus Norddahl
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any damages
|
||||
** arising from the use of this software.
|
||||
**
|
||||
** Permission is granted to anyone to use this software for any purpose,
|
||||
** including commercial applications, and to alter it and redistribute it
|
||||
** freely, subject to the following restrictions:
|
||||
**
|
||||
** 1. The origin of this software must not be misrepresented; you must not
|
||||
** claim that you wrote the original software. If you use this software
|
||||
** in a product, an acknowledgment in the product documentation would be
|
||||
** appreciated but is not required.
|
||||
** 2. Altered source versions must be plainly marked as such, and must not be
|
||||
** misrepresented as being the original software.
|
||||
** 3. This notice may not be removed or altered from any source distribution.
|
||||
**
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
|
||||
// Keep using the software renderer's camera light class, for now.
|
||||
// The DFrameBuffer abstraction relies on this being globally shared
|
||||
typedef swrenderer::CameraLight PolyCameraLight;
|
||||
|
||||
class PolyLightVisibility
|
||||
{
|
||||
public:
|
||||
double WallGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : WallVisibility; }
|
||||
double SpriteGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : WallVisibility; }
|
||||
double ParticleGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : (WallVisibility * 0.5); }
|
||||
|
||||
// The vis value to pass into the GETPALOOKUP or LIGHTSCALE macros
|
||||
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; }
|
||||
|
||||
static fixed_t LightLevelToShade(int lightlevel, bool foggy);
|
||||
|
||||
private:
|
||||
// 1706 is the value for walls on 1080p 16:9 displays.
|
||||
double WallVisibility = 1706.0;
|
||||
bool NoLightFade = false;
|
||||
};
|
|
@ -27,7 +27,7 @@
|
|||
#include "r_data/r_translate.h"
|
||||
#include "poly_particle.h"
|
||||
#include "polyrenderer/poly_renderer.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
|
||||
void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue)
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ 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;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
|
||||
DVector2 points[2] =
|
||||
{
|
||||
|
@ -72,11 +72,11 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP
|
|||
|
||||
// int color = (particle->color >> 24) & 0xff; // pal index, I think
|
||||
bool fullbrightSprite = particle->bright != 0;
|
||||
swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance();
|
||||
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
|
||||
|
||||
PolyDrawArgs args;
|
||||
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->ParticleGlobVis(foggy);
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.ParticleGlobVis(foggy);
|
||||
|
||||
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
|
||||
{
|
||||
|
@ -92,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 (PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra())
|
||||
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
|
||||
{
|
||||
args.uniforms.color = (alpha << 24) | (particle->color & 0xffffff);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "poly_portal.h"
|
||||
#include "polyrenderer/poly_renderer.h"
|
||||
#include "r_sky.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
|
||||
EXTERN_CVAR(Int, r_3dfloors)
|
||||
|
||||
|
@ -39,7 +39,7 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const Vec4f &cl
|
|||
|
||||
if (r_3dfloors)
|
||||
{
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
|
||||
auto frontsector = sub->sector;
|
||||
auto &ffloors = frontsector->e->XFloor.ffloors;
|
||||
|
@ -98,7 +98,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c
|
|||
if (tex->UseType == FTexture::TEX_Null)
|
||||
return;
|
||||
|
||||
swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance();
|
||||
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
|
||||
|
||||
int lightlevel = 255;
|
||||
bool foggy = false;
|
||||
|
@ -112,7 +112,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c
|
|||
UVTransform xform(ceiling ? fakeFloor->top.model->planes[sector_t::ceiling].xform : fakeFloor->top.model->planes[sector_t::floor].xform, tex);
|
||||
|
||||
PolyDrawArgs args;
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->SlopePlaneGlobVis(foggy) * 48.0f;
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); // .SlopePlaneGlobVis(foggy) * 48.0f;
|
||||
args.uniforms.light = (uint32_t)(lightlevel / 255.0f * 256.0f);
|
||||
if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
|
||||
args.uniforms.light = 256;
|
||||
|
@ -156,7 +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<std::unique_ptr<PolyDrawSectorPortal>> §orPortals)
|
||||
{
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
std::vector<PolyPortalSegment> portalSegments;
|
||||
FSectorPortal *portal = nullptr;// sub->sector->ValidatePortal(ceiling ? sector_t::ceiling : sector_t::floor);
|
||||
bool foggy = false;
|
||||
|
@ -307,10 +307,10 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
|
|||
|
||||
UVTransform transform(ceiling ? frontsector->planes[sector_t::ceiling].xform : frontsector->planes[sector_t::floor].xform, tex);
|
||||
|
||||
swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance();
|
||||
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
|
||||
|
||||
PolyDrawArgs args;
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->SlopePlaneGlobVis(foggy) * 48.0f;
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);// ->SlopePlaneGlobVis(foggy) * 48.0f;
|
||||
args.uniforms.light = (uint32_t)(frontsector->lightlevel / 255.0f * 256.0f);
|
||||
if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
|
||||
args.uniforms.light = 256;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "polyrenderer/poly_renderer.h"
|
||||
#include "d_player.h"
|
||||
#include "swrenderer/viewport/r_viewport.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
|
||||
EXTERN_CVAR(Bool, r_drawplayersprites)
|
||||
EXTERN_CVAR(Bool, r_deathcamera)
|
||||
|
@ -42,7 +42,7 @@ 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;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
|
||||
if (!r_drawplayersprites ||
|
||||
!viewpoint.camera ||
|
||||
|
@ -143,25 +143,26 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa
|
|||
sy += wy;
|
||||
}
|
||||
|
||||
auto viewport = PolyRenderer::Instance()->Thread.Viewport.get();
|
||||
const auto &viewpoint = viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
auto renderTarget = PolyRenderer::Instance()->RenderTarget;
|
||||
double YaspectMul = 1.2f;
|
||||
|
||||
double pspritexscale = PolyRenderer::Instance()->Thread.Viewport->viewwindow.centerxwide / 160.0;
|
||||
double pspriteyscale = pspritexscale * viewport->YaspectMul;
|
||||
double pspritexscale = PolyRenderer::Instance()->Viewwindow.centerxwide / 160.0;
|
||||
double pspriteyscale = pspritexscale * YaspectMul;
|
||||
double pspritexiscale = 1 / pspritexscale;
|
||||
|
||||
// calculate edges of the shape
|
||||
double tx = sx - BaseXCenter;
|
||||
|
||||
tx -= tex->GetScaledLeftOffset();
|
||||
int x1 = xs_RoundToInt(viewport->CenterX + tx * pspritexscale);
|
||||
int x1 = xs_RoundToInt(renderTarget->GetWidth() * 0.5 + tx * pspritexscale);
|
||||
|
||||
// off the right side
|
||||
if (x1 > viewwidth)
|
||||
return;
|
||||
|
||||
tx += tex->GetScaledWidth();
|
||||
int x2 = xs_RoundToInt(viewport->CenterX + tx * pspritexscale);
|
||||
int x2 = xs_RoundToInt(renderTarget->GetWidth() * 0.5 + tx * pspritexscale);
|
||||
|
||||
// off the left side
|
||||
if (x2 <= 0)
|
||||
|
@ -170,12 +171,12 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa
|
|||
double texturemid = (BaseYCenter - sy) * tex->Scale.Y + tex->TopOffset;
|
||||
|
||||
// Adjust PSprite for fullscreen views
|
||||
if (viewpoint.camera->player && (viewport->RenderTarget != screen || viewheight == viewport->RenderTarget->GetHeight() || (viewport->RenderTarget->GetWidth() > (BaseXCenter * 2) && !st_scale)))
|
||||
if (viewpoint.camera->player && (renderTarget != screen || viewheight == renderTarget->GetHeight() || (renderTarget->GetWidth() > (BaseXCenter * 2) && !st_scale)))
|
||||
{
|
||||
AWeapon *weapon = dyn_cast<AWeapon>(sprite->GetCaller());
|
||||
if (weapon != nullptr && weapon->YAdjust != 0)
|
||||
{
|
||||
if (viewport->RenderTarget != screen || viewheight == viewport->RenderTarget->GetHeight())
|
||||
if (renderTarget != screen || viewheight == renderTarget->GetHeight())
|
||||
{
|
||||
texturemid -= weapon->YAdjust;
|
||||
}
|
||||
|
@ -189,7 +190,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa
|
|||
// Move the weapon down for 1280x1024.
|
||||
if (sprite->GetID() < PSP_TARGETCENTER)
|
||||
{
|
||||
texturemid -= AspectPspriteOffset(PolyRenderer::Instance()->Thread.Viewport->viewwindow.WidescreenRatio);
|
||||
texturemid -= AspectPspriteOffset(PolyRenderer::Instance()->Viewwindow.WidescreenRatio);
|
||||
}
|
||||
|
||||
int clipped_x1 = MAX(x1, 0);
|
||||
|
@ -226,9 +227,9 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa
|
|||
|
||||
bool foggy = false;
|
||||
int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
|
||||
int spriteshade = swrenderer::LightVisibility::LightLevelToShade(owner->Sector->lightlevel + actualextralight, foggy);
|
||||
int spriteshade = PolyLightVisibility::LightLevelToShade(owner->Sector->lightlevel + actualextralight, foggy);
|
||||
double minz = double((2048 * 4) / double(1 << 20));
|
||||
ColormapNum = GETPALOOKUP(PolyRenderer::Instance()->Thread.Light->SpriteGlobVis(foggy) / minz, spriteshade);
|
||||
ColormapNum = GETPALOOKUP(PolyRenderer::Instance()->Light.SpriteGlobVis(foggy) / minz, spriteshade);
|
||||
|
||||
if (sprite->GetID() < PSP_TARGETCENTER)
|
||||
{
|
||||
|
@ -261,9 +262,9 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa
|
|||
}
|
||||
|
||||
/*
|
||||
if (swrenderer::realfixedcolormap != nullptr && (!swrenderer::r_swtruecolor || (r_shadercolormaps && screen->Accel2D)))
|
||||
if (realfixedcolormap != nullptr && (!r_swtruecolor || (r_shadercolormaps && screen->Accel2D)))
|
||||
{ // fixed color
|
||||
BaseColormap = swrenderer::realfixedcolormap;
|
||||
BaseColormap = realfixedcolormap;
|
||||
ColormapNum = 0;
|
||||
}
|
||||
else
|
||||
|
@ -272,10 +273,10 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa
|
|||
{
|
||||
mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate);
|
||||
}
|
||||
if (swrenderer::fixedlightlev >= 0)
|
||||
if (fixedlightlev >= 0)
|
||||
{
|
||||
BaseColormap = (r_fullbrightignoresectorcolor) ? &FullNormalLight : mybasecolormap;
|
||||
ColormapNum = swrenderer::fixedlightlev >> COLORMAPSHIFT;
|
||||
ColormapNum = fixedlightlev >> COLORMAPSHIFT;
|
||||
}
|
||||
else if (!foggy && sprite->GetState()->GetFullbright())
|
||||
{ // full bright
|
||||
|
@ -331,7 +332,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa
|
|||
}
|
||||
// If the main colormap has fixed lights, and this sprite is being drawn with that
|
||||
// colormap, disable acceleration so that the lights can remain fixed.
|
||||
swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance();
|
||||
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
|
||||
if (!noaccel && cameraLight->ShaderColormap() == nullptr &&
|
||||
NormalLightHasFixedLights && mybasecolormap == &NormalLight &&
|
||||
tex->UseBasePalette())
|
||||
|
@ -348,7 +349,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 && PolyRenderer::Instance()->Thread.Viewport->RenderTarget == screen && (DFrameBuffer *)screen->Accel2D)
|
||||
if (!noaccel && renderTarget == screen && (DFrameBuffer *)screen->Accel2D)
|
||||
{
|
||||
FRenderStyle style = RenderStyle;
|
||||
style.CheckFuzz();
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "r_data/r_translate.h"
|
||||
#include "poly_portal.h"
|
||||
#include "polyrenderer/poly_renderer.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -46,8 +46,8 @@ void PolyDrawSectorPortal::Render(int portalDepth)
|
|||
SaveGlobals();
|
||||
|
||||
// To do: get this information from PolyRenderer instead of duplicating the code..
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Viewwindow;
|
||||
double radPitch = viewpoint.Angles.Pitch.Normalized180().Radians();
|
||||
double angx = cos(radPitch);
|
||||
double angy = sin(radPitch) * level.info->pixelstretch;
|
||||
|
@ -86,13 +86,13 @@ void PolyDrawSectorPortal::RenderTranslucent(int portalDepth)
|
|||
|
||||
void PolyDrawSectorPortal::SaveGlobals()
|
||||
{
|
||||
auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow;
|
||||
auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Viewwindow;
|
||||
|
||||
savedextralight = viewpoint.extralight;
|
||||
savedpos = viewpoint.Pos;
|
||||
savedangles = viewpoint.Angles;
|
||||
savedvisibility = PolyRenderer::Instance()->Thread.Light->GetVisibility();
|
||||
//savedvisibility = PolyRenderer::Instance()->Light.GetVisibility();
|
||||
savedcamera = viewpoint.camera;
|
||||
savedsector = viewpoint.sector;
|
||||
|
||||
|
@ -101,14 +101,14 @@ void PolyDrawSectorPortal::SaveGlobals()
|
|||
// Don't let gun flashes brighten the sky box
|
||||
AActor *sky = Portal->mSkybox;
|
||||
viewpoint.extralight = 0;
|
||||
PolyRenderer::Instance()->Thread.Light->SetVisibility(PolyRenderer::Instance()->Thread.Viewport.get(), sky->args[0] * 0.25f);
|
||||
//PolyRenderer::Instance()->Light.SetVisibility(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);
|
||||
//SetVisibility(pl->visibility);
|
||||
viewpoint.Pos.X += Portal->mDisplacement.X;
|
||||
viewpoint.Pos.Y += Portal->mDisplacement.Y;
|
||||
}
|
||||
|
@ -126,13 +126,13 @@ void PolyDrawSectorPortal::RestoreGlobals()
|
|||
Portal->mFlags &= ~PORTSF_INSKYBOX;
|
||||
if (Portal->mPartner > 0) level.sectorPortals[Portal->mPartner].mFlags &= ~PORTSF_INSKYBOX;
|
||||
|
||||
auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow;
|
||||
auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Viewwindow;
|
||||
|
||||
viewpoint.camera = savedcamera;
|
||||
viewpoint.sector = savedsector;
|
||||
viewpoint.Pos = savedpos;
|
||||
PolyRenderer::Instance()->Thread.Light->SetVisibility(PolyRenderer::Instance()->Thread.Viewport.get(), savedvisibility);
|
||||
//PolyRenderer::Instance()->Light.SetVisibility(savedvisibility);
|
||||
viewpoint.extralight = savedextralight;
|
||||
viewpoint.Angles = savedangles;
|
||||
R_SetViewAngle(viewpoint, viewwindow);
|
||||
|
@ -155,8 +155,8 @@ void PolyDrawLinePortal::Render(int portalDepth)
|
|||
SaveGlobals();
|
||||
|
||||
// To do: get this information from PolyRenderer instead of duplicating the code..
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Viewwindow;
|
||||
double radPitch = viewpoint.Angles.Pitch.Normalized180().Radians();
|
||||
double angx = cos(radPitch);
|
||||
double angy = sin(radPitch) * level.info->pixelstretch;
|
||||
|
@ -200,8 +200,8 @@ void PolyDrawLinePortal::RenderTranslucent(int portalDepth)
|
|||
|
||||
void PolyDrawLinePortal::SaveGlobals()
|
||||
{
|
||||
auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow;
|
||||
auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Viewwindow;
|
||||
|
||||
savedextralight = viewpoint.extralight;
|
||||
savedpos = viewpoint.Pos;
|
||||
|
@ -287,8 +287,8 @@ void PolyDrawLinePortal::SaveGlobals()
|
|||
|
||||
void PolyDrawLinePortal::RestoreGlobals()
|
||||
{
|
||||
auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow;
|
||||
auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
const auto &viewwindow = PolyRenderer::Instance()->Viewwindow;
|
||||
if (viewpoint.camera)
|
||||
{
|
||||
if (savedinvisibility)
|
||||
|
|
|
@ -64,7 +64,7 @@ private:
|
|||
int savedextralight;
|
||||
DVector3 savedpos;
|
||||
DRotator savedangles;
|
||||
double savedvisibility;
|
||||
//double savedvisibility;
|
||||
AActor *savedcamera;
|
||||
sector_t *savedsector;
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "r_data/r_translate.h"
|
||||
#include "polyrenderer/scene/poly_scene.h"
|
||||
#include "polyrenderer/poly_renderer.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
|
||||
CVAR(Bool, r_debug_cull, 0, 0)
|
||||
EXTERN_CVAR(Int, r_portal_recursions)
|
||||
|
@ -185,7 +185,7 @@ 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;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
|
||||
// Reject lines not facing viewer
|
||||
DVector2 pt1 = line->v1->fPos() - viewpoint.Pos;
|
||||
|
@ -243,7 +243,7 @@ void RenderPolyScene::RenderPortals(int portalDepth)
|
|||
PolyDrawArgs args;
|
||||
args.objectToClip = &WorldToClip;
|
||||
args.mode = TriangleDrawMode::Fan;
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->WallGlobVis(foggy);
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);
|
||||
args.uniforms.color = 0;
|
||||
args.uniforms.light = 256;
|
||||
args.uniforms.flags = TriUniforms::fixed_light;
|
||||
|
@ -329,7 +329,7 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
|
|||
}
|
||||
}
|
||||
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
for (sector_t *sector : SeenSectors)
|
||||
{
|
||||
for (AActor *thing = sector->thinglist; thing != nullptr; thing = thing->snext)
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "poly_portal.h"
|
||||
#include "r_sky.h" // for skyflatnum
|
||||
#include "g_levellocals.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
|
||||
PolySkyDome::PolySkyDome()
|
||||
{
|
||||
|
@ -50,14 +50,14 @@ void PolySkyDome::Render(const TriMatrix &worldToClip)
|
|||
if (level.flags & LEVEL_DOUBLESKY)
|
||||
backskytex = TexMan(sky2tex, true);
|
||||
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
TriMatrix objectToWorld = TriMatrix::translate((float)viewpoint.Pos.X, (float)viewpoint.Pos.Y, (float)viewpoint.Pos.Z);
|
||||
objectToClip = worldToClip * objectToWorld;
|
||||
|
||||
int rc = mRows + 1;
|
||||
|
||||
PolyDrawArgs args;
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->WallGlobVis(foggy);
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);
|
||||
args.uniforms.light = 256;
|
||||
args.uniforms.flags = 0;
|
||||
args.uniforms.subsectorDepth = RenderPolyScene::SkySubsectorDepth;
|
||||
|
@ -96,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 (!PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra())
|
||||
if (!PolyRenderer::Instance()->RenderTarget->IsBgra())
|
||||
solid = RGB32k.RGB[(RPART(solid) >> 3)][(GPART(solid) >> 3)][(BPART(solid) >> 3)];
|
||||
|
||||
args.vinput = &mVertices[mPrimStart[row]];
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "poly_sprite.h"
|
||||
#include "polyrenderer/poly_renderer.h"
|
||||
#include "polyrenderer/math/poly_intersection.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
|
||||
EXTERN_CVAR(Float, transsouls)
|
||||
EXTERN_CVAR(Int, r_drawfuzz)
|
||||
|
@ -38,7 +38,7 @@ bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right)
|
|||
if (IsThingCulled(thing))
|
||||
return false;
|
||||
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
|
||||
|
||||
bool flipTextureX = false;
|
||||
|
@ -71,7 +71,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla
|
|||
if (!GetLine(thing, line[0], line[1]))
|
||||
return;
|
||||
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
|
||||
pos.Z += thing->GetBobOffset(viewpoint.TicFrac);
|
||||
|
||||
|
@ -138,10 +138,10 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla
|
|||
}
|
||||
|
||||
bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));
|
||||
swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance();
|
||||
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
|
||||
|
||||
PolyDrawArgs args;
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->SpriteGlobVis(foggy);
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.SpriteGlobVis(foggy);
|
||||
args.uniforms.flags = 0;
|
||||
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
|
||||
{
|
||||
|
@ -252,7 +252,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla
|
|||
args.SetTexture(tex, thing->Translation, true);
|
||||
}
|
||||
|
||||
if (!PolyRenderer::Instance()->Thread.Viewport->RenderTarget->IsBgra())
|
||||
if (!PolyRenderer::Instance()->RenderTarget->IsBgra())
|
||||
{
|
||||
uint32_t r = (args.uniforms.color >> 16) & 0xff;
|
||||
uint32_t g = (args.uniforms.color >> 8) & 0xff;
|
||||
|
@ -275,7 +275,7 @@ bool RenderPolySprite::IsThingCulled(AActor *thing)
|
|||
FIntCVar *cvar = thing->GetClass()->distancecheck;
|
||||
if (cvar != nullptr && *cvar >= 0)
|
||||
{
|
||||
double dist = (thing->Pos() - PolyRenderer::Instance()->Thread.Viewport->viewpoint.Pos).LengthSquared();
|
||||
double dist = (thing->Pos() - PolyRenderer::Instance()->Viewpoint.Pos).LengthSquared();
|
||||
double check = (double)**cvar;
|
||||
if (dist >= check * check)
|
||||
return true;
|
||||
|
@ -293,88 +293,9 @@ bool RenderPolySprite::IsThingCulled(AActor *thing)
|
|||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
visstyle_t RenderPolySprite::GetSpriteVisStyle(AActor *thing, double z)
|
||||
{
|
||||
visstyle_t visstyle;
|
||||
|
||||
bool foggy = false;
|
||||
int actualextralight = foggy ? 0 : extralight << 4;
|
||||
int spriteshade = LIGHT2SHADE(thing->Sector->lightlevel + actualextralight);
|
||||
|
||||
FRenderStyle RenderStyle;
|
||||
RenderStyle = thing->RenderStyle;
|
||||
float Alpha = float(thing->Alpha);
|
||||
int ColormapNum = 0;
|
||||
|
||||
// The software renderer cannot invert the source without inverting the overlay
|
||||
// too. That means if the source is inverted, we need to do the reverse of what
|
||||
// the invert overlay flag says to do.
|
||||
bool invertcolormap = (RenderStyle.Flags & STYLEF_InvertOverlay) != 0;
|
||||
|
||||
if (RenderStyle.Flags & STYLEF_InvertSource)
|
||||
{
|
||||
invertcolormap = !invertcolormap;
|
||||
}
|
||||
|
||||
FDynamicColormap *mybasecolormap = thing->Sector->ColorMap;
|
||||
|
||||
// Sprites that are added to the scene must fade to black.
|
||||
if (RenderStyle == LegacyRenderStyles[STYLE_Add] && mybasecolormap->Fade != 0)
|
||||
{
|
||||
mybasecolormap = GetSpecialLights(mybasecolormap->Color, 0, mybasecolormap->Desaturate);
|
||||
}
|
||||
|
||||
if (RenderStyle.Flags & STYLEF_FadeToBlack)
|
||||
{
|
||||
if (invertcolormap)
|
||||
{ // Fade to white
|
||||
mybasecolormap = GetSpecialLights(mybasecolormap->Color, MAKERGB(255, 255, 255), mybasecolormap->Desaturate);
|
||||
invertcolormap = false;
|
||||
}
|
||||
else
|
||||
{ // Fade to black
|
||||
mybasecolormap = GetSpecialLights(mybasecolormap->Color, MAKERGB(0, 0, 0), mybasecolormap->Desaturate);
|
||||
}
|
||||
}
|
||||
|
||||
// get light level
|
||||
if (swrenderer::fixedcolormap != nullptr)
|
||||
{ // fixed map
|
||||
BaseColormap = swrenderer::fixedcolormap;
|
||||
ColormapNum = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (invertcolormap)
|
||||
{
|
||||
mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate);
|
||||
}
|
||||
if (swrenderer::fixedlightlev >= 0)
|
||||
{
|
||||
BaseColormap = mybasecolormap;
|
||||
ColormapNum = swrenderer::fixedlightlev >> COLORMAPSHIFT;
|
||||
}
|
||||
else if (!foggy && ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)))
|
||||
{ // full bright
|
||||
BaseColormap = mybasecolormap;
|
||||
ColormapNum = 0;
|
||||
}
|
||||
else
|
||||
{ // diminished light
|
||||
double minz = double((2048 * 4) / double(1 << 20));
|
||||
ColormapNum = GETPALOOKUP(swrenderer::r_SpriteVisibility / MAX(z, minz), spriteshade);
|
||||
BaseColormap = mybasecolormap;
|
||||
}
|
||||
}
|
||||
|
||||
return visstyle;
|
||||
}
|
||||
#endif
|
||||
|
||||
FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX)
|
||||
{
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
flipX = false;
|
||||
|
||||
if (thing->renderflags & RF_FLATSPRITE)
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "poly_decal.h"
|
||||
#include "polyrenderer/poly_renderer.h"
|
||||
#include "r_sky.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
#include "g_levellocals.h"
|
||||
|
||||
EXTERN_CVAR(Bool, r_drawmirrors)
|
||||
|
@ -249,7 +249,7 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane
|
|||
}
|
||||
|
||||
PolyDrawArgs args;
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->WallGlobVis(foggy);
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);
|
||||
args.uniforms.light = (uint32_t)(GetLightLevel() / 255.0f * 256.0f);
|
||||
args.uniforms.flags = 0;
|
||||
args.uniforms.subsectorDepth = SubsectorDepth;
|
||||
|
@ -354,7 +354,7 @@ FTexture *RenderPolyWall::GetTexture()
|
|||
|
||||
int RenderPolyWall::GetLightLevel()
|
||||
{
|
||||
swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance();
|
||||
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
|
||||
if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
|
||||
{
|
||||
return 255;
|
||||
|
@ -362,7 +362,7 @@ int RenderPolyWall::GetLightLevel()
|
|||
else
|
||||
{
|
||||
bool foggy = false;
|
||||
int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Thread.Viewport->viewpoint.extralight << 4;
|
||||
int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4;
|
||||
return clamp(Side->GetLightLevel(foggy, LineSeg->frontsector->lightlevel) + actualextralight, 0, 255);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,14 +27,14 @@
|
|||
#include "r_data/r_translate.h"
|
||||
#include "poly_wallsprite.h"
|
||||
#include "polyrenderer/poly_renderer.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
#include "polyrenderer/scene/poly_light.h"
|
||||
|
||||
void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue)
|
||||
{
|
||||
if (RenderPolySprite::IsThingCulled(thing))
|
||||
return;
|
||||
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
|
||||
pos.Z += thing->GetBobOffset(viewpoint.TicFrac);
|
||||
|
||||
|
@ -99,10 +99,10 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli
|
|||
}
|
||||
|
||||
bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));
|
||||
swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance();
|
||||
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
|
||||
|
||||
PolyDrawArgs args;
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->WallGlobVis(foggy);
|
||||
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);
|
||||
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
|
||||
{
|
||||
args.uniforms.light = 256;
|
||||
|
|
|
@ -167,11 +167,11 @@ void VectoredTryCatch(void *data, void(*tryBlock)(void *data), void(*catchBlock)
|
|||
|
||||
#endif
|
||||
|
||||
DrawerCommandQueue::DrawerCommandQueue(swrenderer::RenderThread *renderthread) : renderthread(renderthread)
|
||||
DrawerCommandQueue::DrawerCommandQueue(RenderMemory *frameMemory) : FrameMemory(frameMemory)
|
||||
{
|
||||
}
|
||||
|
||||
void *DrawerCommandQueue::AllocMemory(size_t size)
|
||||
{
|
||||
return renderthread->FrameMemory->AllocMemory<uint8_t>((int)size);
|
||||
return FrameMemory->AllocMemory<uint8_t>((int)size);
|
||||
}
|
||||
|
|
|
@ -144,12 +144,12 @@ private:
|
|||
friend class DrawerCommandQueue;
|
||||
};
|
||||
|
||||
namespace swrenderer { class RenderThread; }
|
||||
class RenderMemory;
|
||||
|
||||
class DrawerCommandQueue
|
||||
{
|
||||
public:
|
||||
DrawerCommandQueue(swrenderer::RenderThread *renderthread);
|
||||
DrawerCommandQueue(RenderMemory *memoryAllocator);
|
||||
|
||||
void Clear() { commands.clear(); }
|
||||
|
||||
|
@ -178,7 +178,7 @@ private:
|
|||
void *AllocMemory(size_t size);
|
||||
|
||||
std::vector<DrawerCommand *> commands;
|
||||
swrenderer::RenderThread *renderthread;
|
||||
RenderMemory *FrameMemory;
|
||||
|
||||
friend class DrawerThreads;
|
||||
};
|
||||
|
|
|
@ -31,41 +31,38 @@
|
|||
#include "r_data/colormaps.h"
|
||||
#include "r_memory.h"
|
||||
|
||||
namespace swrenderer
|
||||
void *RenderMemory::AllocBytes(int size)
|
||||
{
|
||||
void *RenderMemory::AllocBytes(int size)
|
||||
size = (size + 15) / 16 * 16; // 16-byte align
|
||||
|
||||
if (UsedBlocks.empty() || UsedBlocks.back()->Position + size > BlockSize)
|
||||
{
|
||||
size = (size + 15) / 16 * 16; // 16-byte align
|
||||
|
||||
if (UsedBlocks.empty() || UsedBlocks.back()->Position + size > BlockSize)
|
||||
if (!FreeBlocks.empty())
|
||||
{
|
||||
if (!FreeBlocks.empty())
|
||||
{
|
||||
auto block = std::move(FreeBlocks.back());
|
||||
block->Position = 0;
|
||||
FreeBlocks.pop_back();
|
||||
UsedBlocks.push_back(std::move(block));
|
||||
}
|
||||
else
|
||||
{
|
||||
UsedBlocks.push_back(std::make_unique<MemoryBlock>());
|
||||
}
|
||||
auto block = std::move(FreeBlocks.back());
|
||||
block->Position = 0;
|
||||
FreeBlocks.pop_back();
|
||||
UsedBlocks.push_back(std::move(block));
|
||||
}
|
||||
else
|
||||
{
|
||||
UsedBlocks.push_back(std::make_unique<MemoryBlock>());
|
||||
}
|
||||
|
||||
auto &block = UsedBlocks.back();
|
||||
void *data = block->Data + block->Position;
|
||||
block->Position += size;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
auto &block = UsedBlocks.back();
|
||||
void *data = block->Data + block->Position;
|
||||
block->Position += size;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void RenderMemory::Clear()
|
||||
void RenderMemory::Clear()
|
||||
{
|
||||
while (!UsedBlocks.empty())
|
||||
{
|
||||
while (!UsedBlocks.empty())
|
||||
{
|
||||
auto block = std::move(UsedBlocks.back());
|
||||
UsedBlocks.pop_back();
|
||||
FreeBlocks.push_back(std::move(block));
|
||||
}
|
||||
auto block = std::move(UsedBlocks.back());
|
||||
UsedBlocks.pop_back();
|
||||
FreeBlocks.push_back(std::move(block));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,44 +16,41 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace swrenderer
|
||||
// Memory needed for the duration of a frame rendering
|
||||
class RenderMemory
|
||||
{
|
||||
// Memory needed for the duration of a frame rendering
|
||||
class RenderMemory
|
||||
public:
|
||||
void Clear();
|
||||
|
||||
template<typename T>
|
||||
T *AllocMemory(int size = 1)
|
||||
{
|
||||
public:
|
||||
void Clear();
|
||||
return (T*)AllocBytes(sizeof(T) * size);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *AllocMemory(int size = 1)
|
||||
{
|
||||
return (T*)AllocBytes(sizeof(T) * size);
|
||||
}
|
||||
template<typename T, typename... Types>
|
||||
T *NewObject(Types &&... args)
|
||||
{
|
||||
void *ptr = AllocBytes(sizeof(T));
|
||||
return new (ptr)T(std::forward<Types>(args)...);
|
||||
}
|
||||
|
||||
template<typename T, typename... Types>
|
||||
T *NewObject(Types &&... args)
|
||||
{
|
||||
void *ptr = AllocBytes(sizeof(T));
|
||||
return new (ptr)T(std::forward<Types>(args)...);
|
||||
}
|
||||
private:
|
||||
void *AllocBytes(int size);
|
||||
|
||||
private:
|
||||
void *AllocBytes(int size);
|
||||
enum { BlockSize = 1024 * 1024 };
|
||||
|
||||
enum { BlockSize = 1024 * 1024 };
|
||||
|
||||
struct MemoryBlock
|
||||
{
|
||||
MemoryBlock() : Data(new uint8_t[BlockSize]), Position(0) { }
|
||||
~MemoryBlock() { delete[] Data; }
|
||||
struct MemoryBlock
|
||||
{
|
||||
MemoryBlock() : Data(new uint8_t[BlockSize]), Position(0) { }
|
||||
~MemoryBlock() { delete[] Data; }
|
||||
|
||||
MemoryBlock(const MemoryBlock &) = delete;
|
||||
MemoryBlock &operator=(const MemoryBlock &) = delete;
|
||||
MemoryBlock(const MemoryBlock &) = delete;
|
||||
MemoryBlock &operator=(const MemoryBlock &) = delete;
|
||||
|
||||
uint8_t *Data;
|
||||
uint32_t Position;
|
||||
};
|
||||
std::vector<std::unique_ptr<MemoryBlock>> UsedBlocks;
|
||||
std::vector<std::unique_ptr<MemoryBlock>> FreeBlocks;
|
||||
uint8_t *Data;
|
||||
uint32_t Position;
|
||||
};
|
||||
}
|
||||
std::vector<std::unique_ptr<MemoryBlock>> UsedBlocks;
|
||||
std::vector<std::unique_ptr<MemoryBlock>> FreeBlocks;
|
||||
};
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace swrenderer
|
|||
FrameMemory = std::make_unique<RenderMemory>();
|
||||
Viewport = std::make_unique<RenderViewport>();
|
||||
Light = std::make_unique<LightVisibility>();
|
||||
DrawQueue = std::make_shared<DrawerCommandQueue>(this);
|
||||
DrawQueue = std::make_shared<DrawerCommandQueue>(FrameMemory.get());
|
||||
OpaquePass = std::make_unique<RenderOpaquePass>(this);
|
||||
TranslucentPass = std::make_unique<RenderTranslucentPass>(this);
|
||||
SpriteList = std::make_unique<VisibleSpriteList>();
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
class DrawerCommandQueue;
|
||||
typedef std::shared_ptr<DrawerCommandQueue> DrawerCommandQueuePtr;
|
||||
class RenderMemory;
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
|
@ -41,7 +42,6 @@ namespace swrenderer
|
|||
class VisiblePlaneList;
|
||||
class DrawSegmentList;
|
||||
class RenderClipSegment;
|
||||
class RenderMemory;
|
||||
class RenderViewport;
|
||||
class LightVisibility;
|
||||
class SWPixelFormatDrawers;
|
||||
|
|
|
@ -173,11 +173,11 @@ 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()->Viewpoint = r_viewpoint;
|
||||
PolyRenderer::Instance()->Viewwindow = r_viewwindow;
|
||||
PolyRenderer::Instance()->RenderView(player);
|
||||
r_viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
r_viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow;
|
||||
r_viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
r_viewwindow = PolyRenderer::Instance()->Viewwindow;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -210,11 +210,11 @@ void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int wi
|
|||
pic->Lock ();
|
||||
if (r_polyrenderer)
|
||||
{
|
||||
PolyRenderer::Instance()->Thread.Viewport->viewpoint = r_viewpoint;
|
||||
PolyRenderer::Instance()->Thread.Viewport->viewwindow = r_viewwindow;
|
||||
PolyRenderer::Instance()->Viewpoint = r_viewpoint;
|
||||
PolyRenderer::Instance()->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;
|
||||
r_viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
r_viewwindow = PolyRenderer::Instance()->Viewwindow;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -244,11 +244,11 @@ void FSoftwareRenderer::DrawRemainingPlayerSprites()
|
|||
}
|
||||
else
|
||||
{
|
||||
PolyRenderer::Instance()->Thread.Viewport->viewpoint = r_viewpoint;
|
||||
PolyRenderer::Instance()->Thread.Viewport->viewwindow = r_viewwindow;
|
||||
PolyRenderer::Instance()->Viewpoint = r_viewpoint;
|
||||
PolyRenderer::Instance()->Viewwindow = r_viewwindow;
|
||||
PolyRenderer::Instance()->RenderRemainingPlayerSprites();
|
||||
r_viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
|
||||
r_viewwindow = PolyRenderer::Instance()->Thread.Viewport->viewwindow;
|
||||
r_viewpoint = PolyRenderer::Instance()->Viewpoint;
|
||||
r_viewwindow = PolyRenderer::Instance()->Viewwindow;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,28 +276,30 @@ void FSoftwareRenderer::SetClearColor(int color)
|
|||
|
||||
void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov)
|
||||
{
|
||||
auto viewport = r_polyrenderer ? PolyRenderer::Instance()->Thread.Viewport.get() : mScene.MainThread()->Viewport.get();
|
||||
auto renderTarget = r_polyrenderer ? PolyRenderer::Instance()->RenderTarget : mScene.MainThread()->Viewport->RenderTarget;
|
||||
auto &cameraViewpoint = r_polyrenderer ? PolyRenderer::Instance()->Viewpoint : mScene.MainThread()->Viewport->viewpoint;
|
||||
auto &cameraViewwindow = r_polyrenderer ? PolyRenderer::Instance()->Viewwindow : mScene.MainThread()->Viewport->viewwindow;
|
||||
|
||||
// Grab global state shared with rest of zdoom
|
||||
viewport->viewpoint = r_viewpoint;
|
||||
viewport->viewwindow = r_viewwindow;
|
||||
cameraViewpoint = r_viewpoint;
|
||||
cameraViewwindow = 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();
|
||||
uint8_t *Pixels = renderTarget->IsBgra() ? (uint8_t*)tex->GetPixelsBgra() : (uint8_t*)tex->GetPixels();
|
||||
DSimpleCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas();
|
||||
|
||||
// curse Doom's overuse of global variables in the renderer.
|
||||
// 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 = viewport->viewpoint.FieldOfView;
|
||||
R_SetFOV (viewport->viewpoint, (double)fov);
|
||||
DAngle savedfov = cameraViewpoint.FieldOfView;
|
||||
R_SetFOV (cameraViewpoint, (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 (viewport->viewpoint, savedfov);
|
||||
R_SetFOV (cameraViewpoint, savedfov);
|
||||
|
||||
if (Canvas->IsBgra())
|
||||
{
|
||||
|
@ -322,7 +324,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin
|
|||
}
|
||||
}
|
||||
|
||||
if (viewport->RenderTarget->IsBgra())
|
||||
if (renderTarget->IsBgra())
|
||||
{
|
||||
// True color render still sometimes uses palette textures (for sprites, mostly).
|
||||
// We need to make sure that both pixel buffers contain data:
|
||||
|
@ -350,8 +352,8 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin
|
|||
*CameraLight::Instance() = savedCameraLight;
|
||||
|
||||
// Sync state back to zdoom
|
||||
r_viewpoint = viewport->viewpoint;
|
||||
r_viewwindow = viewport->viewwindow;
|
||||
r_viewpoint = cameraViewpoint;
|
||||
r_viewwindow = cameraViewwindow;
|
||||
}
|
||||
|
||||
void FSoftwareRenderer::PreprocessLevel()
|
||||
|
|
|
@ -44,9 +44,9 @@ namespace swrenderer
|
|||
return &instance;
|
||||
}
|
||||
|
||||
void CameraLight::SetCamera(RenderViewport *viewport, AActor *actor)
|
||||
void CameraLight::SetCamera(FRenderViewpoint &viewpoint, DCanvas *renderTarget, AActor *actor)
|
||||
{
|
||||
AActor *camera = viewport->viewpoint.camera;
|
||||
AActor *camera = viewpoint.camera;
|
||||
player_t *player = actor->player;
|
||||
if (camera && camera->player != nullptr)
|
||||
player = camera->player;
|
||||
|
@ -60,7 +60,7 @@ namespace swrenderer
|
|||
if (player->fixedcolormap >= 0 && player->fixedcolormap < (int)SpecialColormaps.Size())
|
||||
{
|
||||
realfixedcolormap = &SpecialColormaps[player->fixedcolormap];
|
||||
if (viewport->RenderTarget == screen && (viewport->RenderTarget->IsBgra() || ((DFrameBuffer *)screen->Accel2D && r_shadercolormaps)))
|
||||
if (renderTarget == screen && (renderTarget->IsBgra() || ((DFrameBuffer *)screen->Accel2D && r_shadercolormaps)))
|
||||
{
|
||||
// Render everything fullbright. The copy to video memory will
|
||||
// apply the special colormap, so it won't be restricted to the
|
||||
|
@ -83,10 +83,10 @@ namespace swrenderer
|
|||
}
|
||||
}
|
||||
// [RH] Inverse light for shooting the Sigil
|
||||
if (fixedcolormap == nullptr && viewport->viewpoint.extralight == INT_MIN)
|
||||
if (fixedcolormap == nullptr && viewpoint.extralight == INT_MIN)
|
||||
{
|
||||
fixedcolormap = &SpecialSWColormaps[INVERSECOLORMAP];
|
||||
viewport->viewpoint.extralight = 0;
|
||||
viewpoint.extralight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace swrenderer
|
|||
|
||||
fixed_t FixedLightLevelShade() const { return (FixedLightLevel() >> COLORMAPSHIFT) << FRACBITS; }
|
||||
|
||||
void SetCamera(RenderViewport *viewport, AActor *actor);
|
||||
void SetCamera(FRenderViewpoint &viewpoint, DCanvas *renderTarget, AActor *actor);
|
||||
void ClearShaderColormap() { realfixedcolormap = nullptr; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace swrenderer
|
|||
// Apply special colormap if the target cannot do it
|
||||
if (CameraLight::Instance()->ShaderColormap() && viewport->RenderTarget->IsBgra() && !(r_shadercolormaps && screen->Accel2D))
|
||||
{
|
||||
auto queue = std::make_shared<DrawerCommandQueue>(MainThread());
|
||||
auto queue = std::make_shared<DrawerCommandQueue>(MainThread()->FrameMemory.get());
|
||||
queue->Push<ApplySpecialColormapRGBACommand>(CameraLight::Instance()->ShaderColormap(), screen);
|
||||
DrawerThreads::Execute(queue);
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ namespace swrenderer
|
|||
if (APART(R_OldBlend)) NormalLight.Maps = realcolormaps.Maps;
|
||||
else NormalLight.Maps = realcolormaps.Maps + NUMCOLORMAPS * 256 * R_OldBlend;
|
||||
|
||||
CameraLight::Instance()->SetCamera(MainThread()->Viewport.get(), actor);
|
||||
CameraLight::Instance()->SetCamera(MainThread()->Viewport->viewpoint, MainThread()->Viewport->RenderTarget, actor);
|
||||
MainThread()->Viewport->SetupFreelook();
|
||||
|
||||
NetUpdate();
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include <stddef.h>
|
||||
#include <memory>
|
||||
#include "v_video.h"
|
||||
#include "r_defs.h"
|
||||
|
||||
namespace swrenderer
|
||||
|
|
Loading…
Reference in a new issue