summaryrefslogtreecommitdiffstats
path: root/tools/gfx/render-vk.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-08-06 15:52:38 -0700
committerGitHub <noreply@github.com>2018-08-06 15:52:38 -0700
commit73ff6907d723003d30e400f661876e7960de574f (patch)
tree76fb87e0d7cdf6310c4a62753556dbf061842d7b /tools/gfx/render-vk.cpp
parent68d705f6c805c9b4d31b386e065762e6db13ad18 (diff)
Add basic support for "Dear IMGUI" (#625)
This isn't being made visible just yet, but it will allow us to have a simple UI for loading models into the model-viewer example. In order to support rendering with IMGUI I had to add the following to the `Renderer` layer: * viewports * scissor rects * blend support These are really only fully implemented for D3D11, but adding them to the other back-ends should be a reasonably small task.
Diffstat (limited to 'tools/gfx/render-vk.cpp')
-rw-r--r--tools/gfx/render-vk.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/gfx/render-vk.cpp b/tools/gfx/render-vk.cpp
index 27926e0e6..aee45a86e 100644
--- a/tools/gfx/render-vk.cpp
+++ b/tools/gfx/render-vk.cpp
@@ -75,6 +75,8 @@ public:
virtual void setVertexBuffers(UInt startSlot, UInt slotCount, BufferResource*const* buffers, const UInt* strides, const UInt* offsets) override;
virtual void setIndexBuffer(BufferResource* buffer, Format indexFormat, UInt offset) override;
virtual void setDepthStencilTarget(ResourceView* depthStencilView) override;
+ void setViewports(UInt count, Viewport const* viewports) override;
+ void setScissorRects(UInt count, ScissorRect const* rects) override;
virtual void setPipelineState(PipelineType pipelineType, PipelineState* state) override;
virtual void draw(UInt vertexCount, UInt startVertex) override;
virtual void drawIndexed(UInt indexCount, UInt startIndex, UInt baseVertex) override;
@@ -1877,6 +1879,50 @@ void VKRenderer::setDepthStencilTarget(ResourceView* depthStencilView)
{
}
+void VKRenderer::setViewports(UInt count, Viewport const* viewports)
+{
+ static const int kMaxViewports = 8; // TODO: base on device caps
+ assert(count <= kMaxViewports);
+
+ VkViewport vkViewports[kMaxViewports];
+ for(UInt ii = 0; ii < count; ++ii)
+ {
+ auto& inViewport = viewports[ii];
+ auto& vkViewport = vkViewports[ii];
+
+ vkViewport.x = inViewport.originX;
+ vkViewport.y = inViewport.originY;
+ vkViewport.width = inViewport.extentX;
+ vkViewport.height = inViewport.extentY;
+ vkViewport.minDepth = inViewport.minZ;
+ vkViewport.maxDepth = inViewport.maxZ;
+ }
+
+ VkCommandBuffer commandBuffer = m_deviceQueue.getCommandBuffer();
+ m_api.vkCmdSetViewport(commandBuffer, 0, count, vkViewports);
+}
+
+void VKRenderer::setScissorRects(UInt count, ScissorRect const* rects)
+{
+ static const int kMaxScissorRects = 8; // TODO: base on device caps
+ assert(count <= kMaxScissorRects);
+
+ VkRect2D vkRects[kMaxScissorRects];
+ for(UInt ii = 0; ii < count; ++ii)
+ {
+ auto& inRect = rects[ii];
+ auto& vkRect = vkRects[ii];
+
+ vkRect.offset.x = inRect.minX;
+ vkRect.offset.y = inRect.minY;
+ vkRect.extent.width = inRect.maxX - inRect.minX;
+ vkRect.extent.height = inRect.maxY - inRect.minY;
+ }
+
+ VkCommandBuffer commandBuffer = m_deviceQueue.getCommandBuffer();
+ m_api.vkCmdSetScissor(commandBuffer, 0, count, vkRects);
+}
+
void VKRenderer::setPipelineState(PipelineType pipelineType, PipelineState* state)
{
m_currentPipeline = (PipelineStateImpl*)state;