diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 1915b3177..413b97ef6 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -90,8 +90,6 @@ void PolyFrameBuffer::InitializeState() mViewpoints = new HWViewpointBuffer; mLights = new FLightBuffer(); - PolyTriangleDrawer::SetLightBuffer(GetDrawCommands(), mLightBuffer->Memory()); - CheckCanvas(); } @@ -110,18 +108,22 @@ void PolyFrameBuffer::CheckCanvas() } } -const DrawerCommandQueuePtr &PolyFrameBuffer::GetDrawCommands() +PolyCommandBuffer *PolyFrameBuffer::GetDrawCommands() { if (!mDrawCommands) - mDrawCommands = std::make_shared(&mFrameMemory); - return mDrawCommands; + { + mDrawCommands.reset(new PolyCommandBuffer(&mFrameMemory)); + mDrawCommands->SetLightBuffer(mLightBuffer->Memory()); + } + return mDrawCommands.get(); } void PolyFrameBuffer::FlushDrawCommands() { + mRenderState->EndRenderPass(); if (mDrawCommands) { - DrawerThreads::Execute(mDrawCommands); + mDrawCommands->Submit(); mDrawCommands.reset(); } } diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index ba35b5a16..cd89f531b 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -19,7 +19,7 @@ public: PolyRenderState *GetRenderState() { return mRenderState.get(); } DCanvas *GetCanvas() override { return mCanvas.get(); } PolyDepthStencil *GetDepthStencil() { return mDepthStencil.get(); } - const DrawerCommandQueuePtr &GetDrawCommands(); + PolyCommandBuffer *GetDrawCommands(); void FlushDrawCommands(); unsigned int GetLightBufferBlockSize() const; @@ -81,7 +81,7 @@ private: std::unique_ptr mRenderState; std::unique_ptr mCanvas; std::unique_ptr mDepthStencil; - std::shared_ptr mDrawCommands; + std::unique_ptr mDrawCommands; RenderMemory mFrameMemory; bool cur_vsync = false; diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 7c879d82c..f63933b8d 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -39,51 +39,61 @@ void PolyRenderState::ClearScreen() void PolyRenderState::Draw(int dt, int index, int count, bool apply) { - if (apply) + if (apply || mNeedApply) Apply(); - PolyTriangleDrawer::Draw(GetPolyFrameBuffer()->GetDrawCommands(), index, count, dtToDrawMode[dt]); + mDrawCommands->Draw(index, count, dtToDrawMode[dt]); } void PolyRenderState::DrawIndexed(int dt, int index, int count, bool apply) { - if (apply) + if (apply || mNeedApply) Apply(); - PolyTriangleDrawer::DrawIndexed(GetPolyFrameBuffer()->GetDrawCommands(), index, count, dtToDrawMode[dt]); + mDrawCommands->DrawIndexed(index, count, dtToDrawMode[dt]); } bool PolyRenderState::SetDepthClamp(bool on) { bool lastValue = mDepthClamp; mDepthClamp = on; - PolyTriangleDrawer::SetDepthClamp(GetPolyFrameBuffer()->GetDrawCommands(), on); + mNeedApply = true; return lastValue; } void PolyRenderState::SetDepthMask(bool on) { - PolyTriangleDrawer::SetDepthMask(GetPolyFrameBuffer()->GetDrawCommands(), on); + mDepthMask = on; + mNeedApply = true; } void PolyRenderState::SetDepthFunc(int func) { - PolyTriangleDrawer::SetDepthFunc(GetPolyFrameBuffer()->GetDrawCommands(), func); + mDepthFunc = func; + mNeedApply = true; } void PolyRenderState::SetDepthRange(float min, float max) { - PolyTriangleDrawer::SetDepthRange(GetPolyFrameBuffer()->GetDrawCommands(), min, max); + mDepthRangeMin = min; + mDepthRangeMax = max; + mNeedApply = true; } void PolyRenderState::SetColorMask(bool r, bool g, bool b, bool a) { - PolyTriangleDrawer::SetColorMask(GetPolyFrameBuffer()->GetDrawCommands(), r, g, b, a); + mColorMask[0] = r; + mColorMask[1] = g; + mColorMask[2] = b; + mColorMask[3] = a; + mNeedApply = true; } void PolyRenderState::SetStencil(int offs, int op, int flags) { - PolyTriangleDrawer::SetStencil(GetPolyFrameBuffer()->GetDrawCommands(), screen->stencilValue + offs, op); + mStencilValue = screen->stencilValue + offs; + mStencilOp = op; + mNeedApply = true; if (flags != -1) { @@ -95,32 +105,35 @@ void PolyRenderState::SetStencil(int offs, int op, int flags) void PolyRenderState::SetCulling(int mode) { - PolyTriangleDrawer::SetCulling(GetPolyFrameBuffer()->GetDrawCommands(), mode); + mCulling = mode; + mNeedApply = true; } void PolyRenderState::EnableClipDistance(int num, bool state) { - PolyTriangleDrawer::EnableClipDistance(GetPolyFrameBuffer()->GetDrawCommands(), num, state); } void PolyRenderState::Clear(int targets) { + if (mNeedApply) + Apply(); + //if (targets & CT_Color) - // PolyTriangleDrawer::ClearColor(GetPolyFrameBuffer()->GetDrawCommands()); + // mDrawCommands->ClearColor(); if (targets & CT_Depth) - PolyTriangleDrawer::ClearDepth(GetPolyFrameBuffer()->GetDrawCommands(), 65535.0f); + mDrawCommands->ClearDepth(65535.0f); if (targets & CT_Stencil) - PolyTriangleDrawer::ClearStencil(GetPolyFrameBuffer()->GetDrawCommands(), 0); + mDrawCommands->ClearStencil(0); } void PolyRenderState::EnableStencil(bool on) { - PolyTriangleDrawer::EnableStencil(GetPolyFrameBuffer()->GetDrawCommands(), on); + mStencilEnabled = on; + mNeedApply = true; } void PolyRenderState::SetScissor(int x, int y, int w, int h) { - auto fb = GetPolyFrameBuffer(); if (w < 0) { x = 0; @@ -128,7 +141,11 @@ void PolyRenderState::SetScissor(int x, int y, int w, int h) w = mRenderTarget.Canvas->GetWidth(); h = mRenderTarget.Canvas->GetHeight(); } - PolyTriangleDrawer::SetScissor(fb->GetDrawCommands(), x, mRenderTarget.Canvas->GetHeight() - y - h, w, h); + mScissor.x = x; + mScissor.y = mRenderTarget.Canvas->GetHeight() - y - h; + mScissor.width = w; + mScissor.height = h; + mNeedApply = true; } void PolyRenderState::SetViewport(int x, int y, int w, int h) @@ -141,12 +158,17 @@ void PolyRenderState::SetViewport(int x, int y, int w, int h) w = mRenderTarget.Canvas->GetWidth(); h = mRenderTarget.Canvas->GetHeight(); } - PolyTriangleDrawer::SetViewport(fb->GetDrawCommands(), x, mRenderTarget.Canvas->GetHeight() - y - h, w, h, mRenderTarget.Canvas, mRenderTarget.DepthStencil); + mViewport.x = x; + mViewport.y = mRenderTarget.Canvas->GetHeight() - y - h; + mViewport.width = w; + mViewport.height = h; + mNeedApply = true; } void PolyRenderState::EnableDepthTest(bool on) { - PolyTriangleDrawer::EnableDepthTest(GetPolyFrameBuffer()->GetDrawCommands(), on); + mDepthTest = on; + mNeedApply = true; } void PolyRenderState::EnableMultisampling(bool on) @@ -161,10 +183,38 @@ void PolyRenderState::EnableDrawBuffers(int count) { } +void PolyRenderState::EndRenderPass() +{ + mDrawCommands = nullptr; + mNeedApply = true; + mFirstMatrixApply = true; +} + void PolyRenderState::Apply() { drawcalls.Clock(); - auto fb = GetPolyFrameBuffer(); + + if (!mDrawCommands) + { + mDrawCommands = GetPolyFrameBuffer()->GetDrawCommands(); + } + + if (mNeedApply) + { + mDrawCommands->SetViewport(mViewport.x, mViewport.y, mViewport.width, mViewport.height, mRenderTarget.Canvas, mRenderTarget.DepthStencil); + mDrawCommands->SetScissor(mScissor.x, mScissor.y, mScissor.width, mScissor.height); + mDrawCommands->SetViewpointUniforms(mViewpointUniforms); + mDrawCommands->EnableDepthTest(mDepthTest); + mDrawCommands->SetDepthClamp(mDepthClamp); + mDrawCommands->SetDepthMask(mDepthMask); + mDrawCommands->SetDepthFunc(mDepthFunc); + mDrawCommands->SetDepthRange(mDepthRangeMin, mDepthRangeMax); + mDrawCommands->EnableStencil(mStencilEnabled); + mDrawCommands->SetStencil(mStencilValue, mStencilOp); + mDrawCommands->SetCulling(mCulling); + mDrawCommands->SetColorMask(mColorMask[0], mColorMask[1], mColorMask[2], mColorMask[3]); + mNeedApply = false; + } int fogset = 0; if (mFogEnabled) @@ -185,19 +235,19 @@ void PolyRenderState::Apply() ApplyMaterial(); - if (mVertexBuffer) PolyTriangleDrawer::SetVertexBuffer(fb->GetDrawCommands(), mVertexBuffer->Memory()); - if (mIndexBuffer) PolyTriangleDrawer::SetIndexBuffer(fb->GetDrawCommands(), mIndexBuffer->Memory()); - PolyTriangleDrawer::SetInputAssembly(fb->GetDrawCommands(), static_cast(mVertexBuffer)->VertexFormat); - PolyTriangleDrawer::SetRenderStyle(fb->GetDrawCommands(), mRenderStyle); + if (mVertexBuffer) mDrawCommands->SetVertexBuffer(mVertexBuffer->Memory()); + if (mIndexBuffer) mDrawCommands->SetIndexBuffer(mIndexBuffer->Memory()); + mDrawCommands->SetInputAssembly(static_cast(mVertexBuffer)->VertexFormat); + mDrawCommands->SetRenderStyle(mRenderStyle); if (mSpecialEffect > EFF_NONE) { - PolyTriangleDrawer::SetShader(fb->GetDrawCommands(), mSpecialEffect, 0, false); + mDrawCommands->SetShader(mSpecialEffect, 0, false); } else { int effectState = mMaterial.mOverrideShader >= 0 ? mMaterial.mOverrideShader : (mMaterial.mMaterial ? mMaterial.mMaterial->GetShaderIndex() : 0); - PolyTriangleDrawer::SetShader(fb->GetDrawCommands(), EFF_NONE, mTextureEnabled ? effectState : SHADER_NoTexture, mAlphaThreshold >= 0.f); + mDrawCommands->SetShader(EFF_NONE, mTextureEnabled ? effectState : SHADER_NoTexture, mAlphaThreshold >= 0.f); } PolyPushConstants constants; @@ -211,12 +261,12 @@ void PolyRenderState::Apply() constants.uClipSplit = { mClipSplit[0], mClipSplit[1] }; constants.uLightIndex = mLightIndex; - PolyTriangleDrawer::PushStreamData(fb->GetDrawCommands(), mStreamData, constants); + mDrawCommands->PushStreamData(mStreamData, constants); ApplyMatrices(); if (mBias.mChanged) { - PolyTriangleDrawer::SetDepthBias(fb->GetDrawCommands(), mBias.mUnits, mBias.mFactor); + mDrawCommands->SetDepthBias(mBias.mUnits, mBias.mFactor); mBias.mChanged = false; } @@ -233,7 +283,7 @@ void PolyRenderState::ApplyMaterial() if (base) { DCanvas *texcanvas = base->GetImage(mMaterial); - PolyTriangleDrawer::SetTexture(GetPolyFrameBuffer()->GetDrawCommands(), 0, texcanvas->GetPixels(), texcanvas->GetHeight(), texcanvas->GetWidth(), texcanvas->IsBgra()); + mDrawCommands->SetTexture(0, texcanvas->GetPixels(), texcanvas->GetHeight(), texcanvas->GetWidth(), texcanvas->IsBgra()); int numLayers = mMaterial.mMaterial->GetLayers(); for (int i = 1; i < numLayers; i++) @@ -242,7 +292,7 @@ void PolyRenderState::ApplyMaterial() auto systex = static_cast(mMaterial.mMaterial->GetLayer(i, 0, &layer)); texcanvas = systex->GetImage(layer, 0, mMaterial.mMaterial->isExpanded() ? CTF_Expand : 0); - PolyTriangleDrawer::SetTexture(GetPolyFrameBuffer()->GetDrawCommands(), i, texcanvas->GetPixels(), texcanvas->GetHeight(), texcanvas->GetWidth(), texcanvas->IsBgra()); + mDrawCommands->SetTexture(i, texcanvas->GetPixels(), texcanvas->GetHeight(), texcanvas->GetWidth(), texcanvas->IsBgra()); } } @@ -294,7 +344,7 @@ void PolyRenderState::ApplyMatrices() if (modified) { mFirstMatrixApply = false; - PolyTriangleDrawer::PushMatrices(GetPolyFrameBuffer()->GetDrawCommands(), mMatrices.ModelMatrix, mMatrices.NormalModelMatrix, mMatrices.TextureMatrix); + mDrawCommands->PushMatrices(mMatrices.ModelMatrix, mMatrices.NormalModelMatrix, mMatrices.TextureMatrix); } } @@ -302,7 +352,6 @@ void PolyRenderState::SetRenderTarget(DCanvas *canvas, PolyDepthStencil *depthSt { mRenderTarget.Canvas = canvas; mRenderTarget.DepthStencil = depthStencil; - PolyTriangleDrawer::SetViewport(GetPolyFrameBuffer()->GetDrawCommands(), 0, 0, canvas->GetWidth(), canvas->GetHeight(), canvas, depthStencil); } void PolyRenderState::Bind(PolyDataBuffer *buffer, uint32_t offset, uint32_t length) @@ -310,7 +359,7 @@ void PolyRenderState::Bind(PolyDataBuffer *buffer, uint32_t offset, uint32_t len if (buffer->bindingpoint == VIEWPOINT_BINDINGPOINT) { mViewpointUniforms = reinterpret_cast(static_cast(buffer->Memory()) + offset); - PolyTriangleDrawer::SetViewpointUniforms(GetPolyFrameBuffer()->GetDrawCommands(), mViewpointUniforms); + mNeedApply = true; } } diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.h b/src/rendering/polyrenderer/backend/poly_renderstate.h index 4afa1218e..e677dd714 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.h +++ b/src/rendering/polyrenderer/backend/poly_renderstate.h @@ -43,6 +43,7 @@ public: void SetRenderTarget(DCanvas *canvas, PolyDepthStencil *depthStencil); void Bind(PolyDataBuffer *buffer, uint32_t offset, uint32_t length); PolyVertexInputAssembly *GetVertexFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs); + void EndRenderPass(); private: void Apply(); @@ -69,4 +70,27 @@ private: DCanvas *Canvas = nullptr; PolyDepthStencil *DepthStencil = nullptr; } mRenderTarget; + + struct Rect + { + int x = 0; + int y = 0; + int width = 0; + int height = 0; + } mScissor, mViewport; + + bool mNeedApply = true; + + bool mDepthTest = false; + bool mDepthMask = false; + int mDepthFunc = DF_Always; + float mDepthRangeMin = 0.0f; + float mDepthRangeMax = 1.0f; + bool mStencilEnabled = false; + int mStencilValue = 0; + int mStencilOp = SOP_Keep; + int mCulling = Cull_None; + bool mColorMask[4] = { true, true, true, true }; + + PolyCommandBuffer* mDrawCommands = nullptr; }; diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.cpp b/src/rendering/polyrenderer/drawers/poly_triangle.cpp index 19db47fab..4da0938fd 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/poly_triangle.cpp @@ -39,17 +39,12 @@ #include "screen_triangle.h" #include "x86.h" -void PolyTriangleDrawer::ClearDepth(const DrawerCommandQueuePtr &queue, float value) +PolyCommandBuffer::PolyCommandBuffer(RenderMemory* frameMemory) { - queue->Push(value); + mQueue = std::make_shared(frameMemory); } -void PolyTriangleDrawer::ClearStencil(const DrawerCommandQueuePtr &queue, uint8_t value) -{ - queue->Push(value); -} - -void PolyTriangleDrawer::SetViewport(const DrawerCommandQueuePtr &queue, int x, int y, int width, int height, DCanvas *canvas, PolyDepthStencil *depthstencil) +void PolyCommandBuffer::SetViewport(int x, int y, int width, int height, DCanvas *canvas, PolyDepthStencil *depthstencil) { uint8_t *dest = (uint8_t*)canvas->GetPixels(); int dest_width = canvas->GetWidth(); @@ -57,127 +52,137 @@ void PolyTriangleDrawer::SetViewport(const DrawerCommandQueuePtr &queue, int x, int dest_pitch = canvas->GetPitch(); bool dest_bgra = canvas->IsBgra(); - queue->Push(x, y, width, height, dest, dest_width, dest_height, dest_pitch, dest_bgra, depthstencil); + mQueue->Push(x, y, width, height, dest, dest_width, dest_height, dest_pitch, dest_bgra, depthstencil); } -void PolyTriangleDrawer::SetInputAssembly(const DrawerCommandQueuePtr &queue, PolyInputAssembly *input) +void PolyCommandBuffer::SetInputAssembly(PolyInputAssembly *input) { - queue->Push(input); + mQueue->Push(input); } -void PolyTriangleDrawer::SetVertexBuffer(const DrawerCommandQueuePtr &queue, const void *vertices) +void PolyCommandBuffer::SetVertexBuffer(const void *vertices) { - queue->Push(vertices); + mQueue->Push(vertices); } -void PolyTriangleDrawer::SetIndexBuffer(const DrawerCommandQueuePtr &queue, const void *elements) +void PolyCommandBuffer::SetIndexBuffer(const void *elements) { - queue->Push(elements); + mQueue->Push(elements); } -void PolyTriangleDrawer::SetLightBuffer(const DrawerCommandQueuePtr& queue, const void *lights) +void PolyCommandBuffer::SetLightBuffer(const void *lights) { - queue->Push(lights); + mQueue->Push(lights); } -void PolyTriangleDrawer::SetDepthClamp(const DrawerCommandQueuePtr &queue, bool on) +void PolyCommandBuffer::SetDepthClamp(bool on) { - queue->Push(on); + mQueue->Push(on); } -void PolyTriangleDrawer::SetDepthMask(const DrawerCommandQueuePtr &queue, bool on) +void PolyCommandBuffer::SetDepthMask(bool on) { - queue->Push(on); + mQueue->Push(on); } -void PolyTriangleDrawer::SetDepthFunc(const DrawerCommandQueuePtr &queue, int func) +void PolyCommandBuffer::SetDepthFunc(int func) { - queue->Push(func); + mQueue->Push(func); } -void PolyTriangleDrawer::SetDepthRange(const DrawerCommandQueuePtr &queue, float min, float max) +void PolyCommandBuffer::SetDepthRange(float min, float max) { - queue->Push(min, max); + mQueue->Push(min, max); } -void PolyTriangleDrawer::SetDepthBias(const DrawerCommandQueuePtr &queue, float depthBiasConstantFactor, float depthBiasSlopeFactor) +void PolyCommandBuffer::SetDepthBias(float depthBiasConstantFactor, float depthBiasSlopeFactor) { - queue->Push(depthBiasConstantFactor, depthBiasSlopeFactor); + mQueue->Push(depthBiasConstantFactor, depthBiasSlopeFactor); } -void PolyTriangleDrawer::SetColorMask(const DrawerCommandQueuePtr &queue, bool r, bool g, bool b, bool a) +void PolyCommandBuffer::SetColorMask(bool r, bool g, bool b, bool a) { - queue->Push(r, g, b, a); + mQueue->Push(r, g, b, a); } -void PolyTriangleDrawer::SetStencil(const DrawerCommandQueuePtr &queue, int stencilRef, int op) +void PolyCommandBuffer::SetStencil(int stencilRef, int op) { - queue->Push(stencilRef, op); + mQueue->Push(stencilRef, op); } -void PolyTriangleDrawer::SetCulling(const DrawerCommandQueuePtr &queue, int mode) +void PolyCommandBuffer::SetCulling(int mode) { - queue->Push(mode); + mQueue->Push(mode); } -void PolyTriangleDrawer::EnableClipDistance(const DrawerCommandQueuePtr &queue, int num, bool state) +void PolyCommandBuffer::EnableStencil(bool on) { - queue->Push(num, state); + mQueue->Push(on); } -void PolyTriangleDrawer::EnableStencil(const DrawerCommandQueuePtr &queue, bool on) +void PolyCommandBuffer::SetScissor(int x, int y, int w, int h) { - queue->Push(on); + mQueue->Push(x, y, w, h); } -void PolyTriangleDrawer::SetScissor(const DrawerCommandQueuePtr &queue, int x, int y, int w, int h) +void PolyCommandBuffer::EnableDepthTest(bool on) { - queue->Push(x, y, w, h); + mQueue->Push(on); } -void PolyTriangleDrawer::EnableDepthTest(const DrawerCommandQueuePtr &queue, bool on) +void PolyCommandBuffer::SetRenderStyle(FRenderStyle style) { - queue->Push(on); + mQueue->Push(style); } -void PolyTriangleDrawer::SetRenderStyle(const DrawerCommandQueuePtr &queue, FRenderStyle style) +void PolyCommandBuffer::SetTexture(int unit, void *pixels, int width, int height, bool bgra) { - queue->Push(style); + mQueue->Push(unit, pixels, width, height, bgra); } -void PolyTriangleDrawer::SetTexture(const DrawerCommandQueuePtr &queue, int unit, void *pixels, int width, int height, bool bgra) +void PolyCommandBuffer::SetShader(int specialEffect, int effectState, bool alphaTest) { - queue->Push(unit, pixels, width, height, bgra); + mQueue->Push(specialEffect, effectState, alphaTest); } -void PolyTriangleDrawer::SetShader(const DrawerCommandQueuePtr &queue, int specialEffect, int effectState, bool alphaTest) +void PolyCommandBuffer::PushStreamData(const StreamData &data, const PolyPushConstants &constants) { - queue->Push(specialEffect, effectState, alphaTest); + mQueue->Push(data, constants); } -void PolyTriangleDrawer::PushStreamData(const DrawerCommandQueuePtr &queue, const StreamData &data, const PolyPushConstants &constants) +void PolyCommandBuffer::PushMatrices(const VSMatrix &modelMatrix, const VSMatrix &normalModelMatrix, const VSMatrix &textureMatrix) { - queue->Push(data, constants); + mQueue->Push(modelMatrix, normalModelMatrix, textureMatrix); } -void PolyTriangleDrawer::PushMatrices(const DrawerCommandQueuePtr &queue, const VSMatrix &modelMatrix, const VSMatrix &normalModelMatrix, const VSMatrix &textureMatrix) +void PolyCommandBuffer::SetViewpointUniforms(const HWViewpointUniforms *uniforms) { - queue->Push(modelMatrix, normalModelMatrix, textureMatrix); + mQueue->Push(uniforms); } -void PolyTriangleDrawer::SetViewpointUniforms(const DrawerCommandQueuePtr &queue, const HWViewpointUniforms *uniforms) +void PolyCommandBuffer::ClearDepth(float value) { - queue->Push(uniforms); + mQueue->Push(value); } -void PolyTriangleDrawer::Draw(const DrawerCommandQueuePtr &queue, int index, int vcount, PolyDrawMode mode) +void PolyCommandBuffer::ClearStencil(uint8_t value) { - queue->Push(index, vcount, mode); + mQueue->Push(value); } -void PolyTriangleDrawer::DrawIndexed(const DrawerCommandQueuePtr &queue, int index, int count, PolyDrawMode mode) +void PolyCommandBuffer::Draw(int index, int vcount, PolyDrawMode mode) { - queue->Push(index, count, mode); + mQueue->Push(index, vcount, mode); +} + +void PolyCommandBuffer::DrawIndexed(int index, int count, PolyDrawMode mode) +{ + mQueue->Push(index, count, mode); +} + +void PolyCommandBuffer::Submit() +{ + DrawerThreads::Execute(mQueue); } ///////////////////////////////////////////////////////////////////////////// @@ -372,10 +377,6 @@ void PolyTriangleThreadData::SetCulling(int mode) SetCullCCW(mode == Cull_CCW); } -void PolyTriangleThreadData::EnableClipDistance(int num, bool state) -{ -} - void PolyTriangleThreadData::EnableStencil(bool on) { StencilTest = on; diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.h b/src/rendering/polyrenderer/drawers/poly_triangle.h index 8b7402943..446edd600 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.h +++ b/src/rendering/polyrenderer/drawers/poly_triangle.h @@ -29,6 +29,7 @@ #include "polyrenderer/drawers/poly_vertex_shader.h" class DCanvas; +class RenderMemory; class PolyDrawerCommand; class PolyInputAssembly; class PolyDepthStencil; @@ -43,36 +44,41 @@ enum class PolyDrawMode TriangleStrip }; -class PolyTriangleDrawer +class PolyCommandBuffer { public: - static void SetViewport(const DrawerCommandQueuePtr &queue, int x, int y, int width, int height, DCanvas *canvas, PolyDepthStencil *depthStencil); - static void SetInputAssembly(const DrawerCommandQueuePtr &queue, PolyInputAssembly *input); - static void SetVertexBuffer(const DrawerCommandQueuePtr &queue, const void *vertices); - static void SetIndexBuffer(const DrawerCommandQueuePtr &queue, const void *elements); - static void SetLightBuffer(const DrawerCommandQueuePtr& queue, const void *lights); - static void SetViewpointUniforms(const DrawerCommandQueuePtr &queue, const HWViewpointUniforms *uniforms); - static void SetDepthClamp(const DrawerCommandQueuePtr &queue, bool on); - static void SetDepthMask(const DrawerCommandQueuePtr &queue, bool on); - static void SetDepthFunc(const DrawerCommandQueuePtr &queue, int func); - static void SetDepthRange(const DrawerCommandQueuePtr &queue, float min, float max); - static void SetDepthBias(const DrawerCommandQueuePtr &queue, float depthBiasConstantFactor, float depthBiasSlopeFactor); - static void SetColorMask(const DrawerCommandQueuePtr &queue, bool r, bool g, bool b, bool a); - static void SetStencil(const DrawerCommandQueuePtr &queue, int stencilRef, int op); - static void SetCulling(const DrawerCommandQueuePtr &queue, int mode); - static void EnableClipDistance(const DrawerCommandQueuePtr &queue, int num, bool state); - static void EnableStencil(const DrawerCommandQueuePtr &queue, bool on); - static void SetScissor(const DrawerCommandQueuePtr &queue, int x, int y, int w, int h); - static void EnableDepthTest(const DrawerCommandQueuePtr &queue, bool on); - static void SetRenderStyle(const DrawerCommandQueuePtr &queue, FRenderStyle style); - static void SetTexture(const DrawerCommandQueuePtr &queue, int unit, void *pixels, int width, int height, bool bgra); - static void SetShader(const DrawerCommandQueuePtr &queue, int specialEffect, int effectState, bool alphaTest); - static void PushStreamData(const DrawerCommandQueuePtr &queue, const StreamData &data, const PolyPushConstants &constants); - static void PushMatrices(const DrawerCommandQueuePtr &queue, const VSMatrix &modelMatrix, const VSMatrix &normalModelMatrix, const VSMatrix &textureMatrix); - static void ClearDepth(const DrawerCommandQueuePtr &queue, float value); - static void ClearStencil(const DrawerCommandQueuePtr &queue, uint8_t value); - static void Draw(const DrawerCommandQueuePtr &queue, int index, int vcount, PolyDrawMode mode = PolyDrawMode::Triangles); - static void DrawIndexed(const DrawerCommandQueuePtr &queue, int index, int count, PolyDrawMode mode = PolyDrawMode::Triangles); + PolyCommandBuffer(RenderMemory* frameMemory); + + void SetViewport(int x, int y, int width, int height, DCanvas *canvas, PolyDepthStencil *depthStencil); + void SetInputAssembly(PolyInputAssembly *input); + void SetVertexBuffer(const void *vertices); + void SetIndexBuffer(const void *elements); + void SetLightBuffer(const void *lights); + void SetViewpointUniforms(const HWViewpointUniforms *uniforms); + void SetDepthClamp(bool on); + void SetDepthMask(bool on); + void SetDepthFunc(int func); + void SetDepthRange(float min, float max); + void SetDepthBias(float depthBiasConstantFactor, float depthBiasSlopeFactor); + void SetColorMask(bool r, bool g, bool b, bool a); + void SetStencil(int stencilRef, int op); + void SetCulling(int mode); + void EnableStencil(bool on); + void SetScissor(int x, int y, int w, int h); + void EnableDepthTest(bool on); + void SetRenderStyle(FRenderStyle style); + void SetTexture(int unit, void *pixels, int width, int height, bool bgra); + void SetShader(int specialEffect, int effectState, bool alphaTest); + void PushStreamData(const StreamData &data, const PolyPushConstants &constants); + void PushMatrices(const VSMatrix &modelMatrix, const VSMatrix &normalModelMatrix, const VSMatrix &textureMatrix); + void ClearDepth(float value); + void ClearStencil(uint8_t value); + void Draw(int index, int vcount, PolyDrawMode mode = PolyDrawMode::Triangles); + void DrawIndexed(int index, int count, PolyDrawMode mode = PolyDrawMode::Triangles); + void Submit(); + +private: + std::shared_ptr mQueue; }; class PolyDepthStencil @@ -150,7 +156,6 @@ public: void SetColorMask(bool r, bool g, bool b, bool a); void SetStencil(int stencilRef, int op); void SetCulling(int mode); - void EnableClipDistance(int num, bool state); void EnableStencil(bool on); void SetScissor(int x, int y, int w, int h); void EnableDepthTest(bool on); @@ -379,17 +384,6 @@ private: int mode; }; -class PolyEnableClipDistanceCommand : public PolyDrawerCommand -{ -public: - PolyEnableClipDistanceCommand(int num, bool state) : num(num), state(state) { } - void Execute(DrawerThread *thread) override { PolyTriangleThreadData::Get(thread)->EnableClipDistance(num, state); } - -private: - int num; - bool state; -}; - class PolyEnableStencilCommand : public PolyDrawerCommand { public: diff --git a/src/rendering/swrenderer/scene/r_scene.cpp b/src/rendering/swrenderer/scene/r_scene.cpp index a434bf6b6..a5d3a29f2 100644 --- a/src/rendering/swrenderer/scene/r_scene.cpp +++ b/src/rendering/swrenderer/scene/r_scene.cpp @@ -104,7 +104,7 @@ namespace swrenderer ActiveRatio(width, height, &trueratio); viewport->SetViewport(player->camera->Level, MainThread(), width, height, trueratio); - r_modelscene = r_models && Models.Size() > 0; + /*r_modelscene = r_models && Models.Size() > 0; if (r_modelscene) { if (!DepthStencil || DepthStencil->Width() != viewport->RenderTarget->GetWidth() || DepthStencil->Height() != viewport->RenderTarget->GetHeight()) @@ -114,7 +114,7 @@ namespace swrenderer } PolyTriangleDrawer::SetViewport(MainThread()->DrawQueue, 0, 0, viewport->RenderTarget->GetWidth(), viewport->RenderTarget->GetHeight(), viewport->RenderTarget, DepthStencil.get()); PolyTriangleDrawer::ClearStencil(MainThread()->DrawQueue, 0); - } + }*/ if (r_clearbuffer != 0 || r_debug_draw != 0) { @@ -280,11 +280,11 @@ namespace swrenderer thread->OpaquePass->ResetFakingUnderwater(); // [RH] Hack to make windows into underwater areas possible thread->Portal->SetMainPortal(); - if (r_modelscene && thread->MainThread) + /*if (r_modelscene && thread->MainThread) PolyTriangleDrawer::ClearStencil(MainThread()->DrawQueue, 0); PolyTriangleDrawer::SetViewport(thread->DrawQueue, viewwindowx, viewwindowy, viewwidth, viewheight, thread->Viewport->RenderTarget, DepthStencil.get()); - PolyTriangleDrawer::SetScissor(thread->DrawQueue, viewwindowx, viewwindowy, viewwidth, viewheight); + PolyTriangleDrawer::SetScissor(thread->DrawQueue, viewwindowx, viewwindowy, viewwidth, viewheight);*/ // Cull things outside the range seen by this thread VisibleSegmentRenderer visitor;