diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index 3e05d01a2..11cff6a2c 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -17,6 +17,7 @@ class PolyFrameBuffer : public SystemBaseFrameBuffer public: RenderMemory *GetFrameMemory() { return &mFrameMemory; } PolyRenderState *GetRenderState() { return mRenderState.get(); } + DCanvas *GetCanvas() { return mCanvas.get(); } const DrawerCommandQueuePtr &GetDrawCommands(); void FlushDrawCommands(); diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 60e7a74f9..bbe19b047 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -13,6 +13,7 @@ #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/shaderuniforms.h" +#include "swrenderer/r_swcolormaps.h" static PolyDrawMode dtToDrawMode[] = { @@ -79,6 +80,7 @@ void PolyRenderState::SetDepthRange(float min, float max) void PolyRenderState::SetColorMask(bool r, bool g, bool b, bool a) { + args.SetWriteColor(r || g || b || a); } void PolyRenderState::SetStencil(int offs, int op, int flags) @@ -113,6 +115,8 @@ void PolyRenderState::SetScissor(int x, int y, int w, int h) void PolyRenderState::SetViewport(int x, int y, int w, int h) { + auto fb = GetPolyFrameBuffer(); + PolyTriangleDrawer::SetViewport(fb->GetDrawCommands(), x, y, w, h, fb->GetCanvas()); } void PolyRenderState::EnableDepthTest(bool on) @@ -138,7 +142,10 @@ void PolyRenderState::Apply() args.SetStencilTest(false); args.SetWriteStencil(false); - args.SetNoColormap(); + + FColormap cm; + cm.Clear(); + args.SetLight(GetColorTable(cm), (int)(mLightParms[3] * 255.0f), mViewpointUniforms->mGlobVis, true); args.SetColor(MAKEARGB( static_cast(mStreamData.uVertexColor.W * 255.0f + 0.5f), @@ -153,7 +160,15 @@ void PolyRenderState::Apply() { DCanvas *texcanvas = base->GetImage(mMaterial); args.SetTexture(texcanvas->GetPixels(), texcanvas->GetHeight(), texcanvas->GetWidth()); - args.SetStyle(TriBlendMode::Opaque); + + if (mRenderStyle == LegacyRenderStyles[STYLE_Normal]) + args.SetStyle(TriBlendMode::Normal); + else if (mRenderStyle == LegacyRenderStyles[STYLE_Add]) + args.SetStyle(TriBlendMode::Add); + else if (mRenderStyle == LegacyRenderStyles[STYLE_Translucent]) + args.SetStyle(TriBlendMode::Translucent); + else + args.SetStyle(TriBlendMode::Opaque); } else { @@ -173,10 +188,10 @@ void PolyRenderState::Bind(PolyDataBuffer *buffer, uint32_t offset, uint32_t len { if (buffer->bindingpoint == VIEWPOINT_BINDINGPOINT) { - HWViewpointUniforms *uniforms = reinterpret_cast(static_cast(buffer->Memory()) + offset); + mViewpointUniforms = reinterpret_cast(static_cast(buffer->Memory()) + offset); - Mat4f viewToProj = Mat4f::FromValues(uniforms->mProjectionMatrix.get()); - Mat4f worldToView = Mat4f::FromValues(uniforms->mViewMatrix.get()); + Mat4f viewToProj = Mat4f::FromValues(mViewpointUniforms->mProjectionMatrix.get()); + Mat4f worldToView = Mat4f::FromValues(mViewpointUniforms->mViewMatrix.get()); auto fb = GetPolyFrameBuffer(); PolyTriangleDrawer::SetTransform(fb->GetDrawCommands(), fb->GetFrameMemory()->NewObject(viewToProj * worldToView), nullptr); diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.h b/src/rendering/polyrenderer/backend/poly_renderstate.h index 84c9c190a..7e3676615 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.h +++ b/src/rendering/polyrenderer/backend/poly_renderstate.h @@ -10,7 +10,7 @@ #include "hwrenderer/scene/hw_renderstate.h" #include "hwrenderer/textures/hw_material.h" -class PolyRenderPassSetup; +struct HWViewpointUniforms; class PolyRenderState : public FRenderState { @@ -45,6 +45,8 @@ public: private: void Apply(); + HWViewpointUniforms *mViewpointUniforms = nullptr; + bool mDepthClamp = true; PolyDrawArgs args; }; diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.cpp b/src/rendering/polyrenderer/drawers/screen_triangle.cpp index 45656e35e..82b652532 100644 --- a/src/rendering/polyrenderer/drawers/screen_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/screen_triangle.cpp @@ -2250,10 +2250,10 @@ void(*ScreenTriangle::RectDrawers32[])(const void *, int, int, int, const RectDr void(*ScreenTriangle::TriangleDrawers[])(const TriDrawTriangleArgs *args, PolyTriangleThreadData *thread, int16_t *edges, int topY, int bottomY) = { - nullptr, - nullptr, - nullptr, - nullptr, + &DrawTriangle, + &DrawTriangle, + &DrawTriangle, + &DrawTriangle, &DrawTriangle, &DrawTriangle, &DrawTriangle, diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.h b/src/rendering/polyrenderer/drawers/screen_triangle.h index cee3975a3..613466593 100644 --- a/src/rendering/polyrenderer/drawers/screen_triangle.h +++ b/src/rendering/polyrenderer/drawers/screen_triangle.h @@ -223,6 +223,10 @@ namespace TriScreenDrawerModes SWTRI_WriteStencil = 16 }; + struct TriangleOpt0 { static const int Flags = 0; }; + struct TriangleOpt1 { static const int Flags = 1; }; + struct TriangleOpt2 { static const int Flags = 2; }; + struct TriangleOpt3 { static const int Flags = 3; }; struct TriangleOpt4 { static const int Flags = 4; }; struct TriangleOpt5 { static const int Flags = 5; }; struct TriangleOpt6 { static const int Flags = 6; };