summaryrefslogtreecommitdiffstats
path: root/tools/gfx/render-gl.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-gl.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-gl.cpp')
-rw-r--r--tools/gfx/render-gl.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/gfx/render-gl.cpp b/tools/gfx/render-gl.cpp
index 3ab818fdd..d77271702 100644
--- a/tools/gfx/render-gl.cpp
+++ b/tools/gfx/render-gl.cpp
@@ -114,6 +114,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;
@@ -1030,6 +1032,46 @@ void GLRenderer::setDepthStencilTarget(ResourceView* depthStencilView)
{
}
+void GLRenderer::setViewports(UInt count, Viewport const* viewports)
+{
+ assert(count == 1);
+ auto viewport = viewports[0];
+ glViewport(
+ (GLint) viewport.originX,
+ (GLint) viewport.originY,
+ (GLsizei) viewport.extentX,
+ (GLsizei) viewport.extentY);
+ glDepthRange(viewport.minZ, viewport.maxZ);
+}
+
+void GLRenderer::setScissorRects(UInt count, ScissorRect const* rects)
+{
+ assert(count <= 1);
+ if( count )
+ {
+ // TODO: this isn't goign to be quite right because of the
+ // flipped coordinate system in GL.
+ //
+ // The best way around this is probably to *always* render
+ // things internally into textures with "flipped" conventions,
+ // and then only deal with the flipping as part of a final
+ // "present" step that copies to the primary back-buffer.
+ //
+ auto rect = rects[0];
+ glScissor(
+ rect.minX,
+ rect.minY,
+ rect.maxX - rect.minX,
+ rect.maxY - rect.minY);
+
+ glEnable(GL_SCISSOR_TEST);
+ }
+ else
+ {
+ glDisable(GL_SCISSOR_TEST);
+ }
+}
+
void GLRenderer::setPipelineState(PipelineType pipelineType, PipelineState* state)
{
auto pipelineStateImpl = (PipelineStateImpl*) state;