diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 382bd9e993..83a6e277d2 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -614,3 +614,34 @@ void VkRenderState::EndFrame() mStreamDataOffset = 0; mDataIndex = -1; } + +///////////////////////////////////////////////////////////////////////////// + +void VkRenderStateMolten::Draw(int dt, int index, int count, bool apply) +{ + if (dt == DT_TriangleFan) + { + IIndexBuffer *oldIndexBuffer = mIndexBuffer; + mIndexBuffer = GetVulkanFrameBuffer()->FanToTrisIndexBuffer.get(); + + if (apply || mNeedApply) + Apply(DT_Triangles); + else + ApplyVertexBuffers(); + + drawcalls.Clock(); + mCommandBuffer->drawIndexed((count - 2) * 3, 1, 0, index, 0); + drawcalls.Unclock(); + + mIndexBuffer = oldIndexBuffer; + } + else + { + if (apply || mNeedApply) + Apply(dt); + + drawcalls.Clock(); + mCommandBuffer->draw(count, 1, index, 0); + drawcalls.Unclock(); + } +} diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/rendering/vulkan/renderer/vk_renderstate.h index 0e9be9a8cf..4b098b6916 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/rendering/vulkan/renderer/vk_renderstate.h @@ -17,6 +17,7 @@ class VkRenderState : public FRenderState { public: VkRenderState(); + virtual ~VkRenderState() = default; // Draw commands void ClearScreen() override; @@ -45,7 +46,7 @@ public: void EndRenderPass(); void EndFrame(); -private: +protected: void Apply(int dt); void ApplyRenderPass(int dt); void ApplyStencilRef(); @@ -106,3 +107,11 @@ private: bool mLastModelMatrixEnabled = true; bool mLastTextureMatrixEnabled = true; }; + +class VkRenderStateMolten : public VkRenderState +{ +public: + using VkRenderState::VkRenderState; + + void Draw(int dt, int index, int count, bool apply = true) override; +}; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index d67ccc62a0..199ede7f5e 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -120,6 +120,8 @@ void VulkanFrameBuffer::InitializeState() mViewpoints = new GLViewpointBuffer; mLights = new FLightBuffer(); + CreateFanToTrisIndexBuffer(); + // To do: move this to HW renderer interface maybe? MatricesUBO = (VKDataBuffer*)CreateDataBuffer(-1, false); StreamUBO = (VKDataBuffer*)CreateDataBuffer(-1, false); @@ -129,7 +131,11 @@ void VulkanFrameBuffer::InitializeState() mShaderManager.reset(new VkShaderManager(device)); mSamplerManager.reset(new VkSamplerManager(device)); mRenderPassManager->Init(); +#ifdef __APPLE__ + mRenderState.reset(new VkRenderStateMolten()); +#else mRenderState.reset(new VkRenderState()); +#endif } void VulkanFrameBuffer::Update() @@ -621,3 +627,17 @@ void VulkanFrameBuffer::PrintStartupLog() Printf("Max. uniform buffer range: %d\n", limits.maxUniformBufferRange); Printf("Min. uniform buffer offset alignment: %d\n", limits.minUniformBufferOffsetAlignment); } + +void VulkanFrameBuffer::CreateFanToTrisIndexBuffer() +{ + TArray data; + for (int i = 2; i < 1000; i++) + { + data.Push(0); + data.Push(i - 1); + data.Push(i); + } + + FanToTrisIndexBuffer.reset(CreateIndexBuffer()); + FanToTrisIndexBuffer->SetData(sizeof(uint32_t) * data.Size(), data.Data()); +} diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index bf9bb1d898..fe9a7c5cb1 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -42,6 +42,8 @@ public: VKDataBuffer *MatricesUBO = nullptr; VKDataBuffer *StreamUBO = nullptr; + std::unique_ptr FanToTrisIndexBuffer; + std::vector> mFrameDeleteList; std::unique_ptr swdrawer; @@ -86,6 +88,7 @@ private: sector_t *RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void DrawScene(HWDrawInfo *di, int drawmode); void PrintStartupLog(); + void CreateFanToTrisIndexBuffer(); std::unique_ptr mShaderManager; std::unique_ptr mSamplerManager;