From 73ff6907d723003d30e400f661876e7960de574f Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 6 Aug 2018 15:52:38 -0700 Subject: 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. --- tools/gfx/render-d3d12.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tools/gfx/render-d3d12.cpp') diff --git a/tools/gfx/render-d3d12.cpp b/tools/gfx/render-d3d12.cpp index 2d3b8f521..38ecaa5ef 100644 --- a/tools/gfx/render-d3d12.cpp +++ b/tools/gfx/render-d3d12.cpp @@ -88,6 +88,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; @@ -2545,6 +2547,48 @@ void D3D12Renderer::setDepthStencilTarget(ResourceView* depthStencilView) { } +void D3D12Renderer::setViewports(UInt count, Viewport const* viewports) +{ + static const int kMaxViewports = D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; + assert(count <= kMaxViewports); + + D3D12_VIEWPORT dxViewports[kMaxViewports]; + for(UInt ii = 0; ii < count; ++ii) + { + auto& inViewport = viewports[ii]; + auto& dxViewport = dxViewports[ii]; + + dxViewport.TopLeftX = inViewport.originX; + dxViewport.TopLeftY = inViewport.originY; + dxViewport.Width = inViewport.extentX; + dxViewport.Height = inViewport.extentY; + dxViewport.MinDepth = inViewport.minZ; + dxViewport.MaxDepth = inViewport.maxZ; + } + + m_commandList->RSSetViewports(count, dxViewports); +} + +void D3D12Renderer::setScissorRects(UInt count, ScissorRect const* rects) +{ + static const int kMaxScissorRects = D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; + assert(count <= kMaxScissorRects); + + D3D12_RECT dxRects[kMaxScissorRects]; + for(UInt ii = 0; ii < count; ++ii) + { + auto& inRect = rects[ii]; + auto& dxRect = dxRects[ii]; + + dxRect.left = inRect.minX; + dxRect.top = inRect.minY; + dxRect.right = inRect.maxX; + dxRect.bottom = inRect.maxY; + } + + m_commandList->RSSetScissorRects(count, dxRects); +} + void D3D12Renderer::setPipelineState(PipelineType pipelineType, PipelineState* state) { m_currentPipelineState = (PipelineStateImpl*)state; -- cgit v1.2.3