From dff598ebd16c9806493c7a521b9f102a5585788d Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 8 Oct 2015 12:06:09 -0700 Subject: [PATCH] clening and getting ready for pr --- libraries/gpu/src/gpu/Batch.cpp | 7 +++++++ libraries/gpu/src/gpu/Batch.h | 2 ++ libraries/gpu/src/gpu/GLBackend.h | 2 ++ libraries/gpu/src/gpu/GLBackendTransform.cpp | 15 ++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index 966182c7d3..c3e186a630 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -205,6 +205,13 @@ void Batch::setViewportTransform(const Vec4i& viewport) { _params.push_back(cacheData(sizeof(Vec4i), &viewport)); } +void Batch::setDepthRangeTransform(float nearDepth, float farDepth) { + ADD_COMMAND(setDepthRangeTransform); + + _params.push_back(farDepth); + _params.push_back(nearDepth); +} + void Batch::setPipeline(const PipelinePointer& pipeline) { ADD_COMMAND(setPipeline); diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index e1b76e2e81..deb70f7a68 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -187,6 +187,7 @@ public: void setProjectionTransform(const Mat4& proj); // Viewport is xy = low left corner in framebuffer, zw = width height of the viewport, expressed in pixels void setViewportTransform(const Vec4i& viewport); + void setDepthRangeTransform(float nearDepth, float farDepth); // Pipeline Stage void setPipeline(const PipelinePointer& pipeline); @@ -285,6 +286,7 @@ public: COMMAND_setViewTransform, COMMAND_setProjectionTransform, COMMAND_setViewportTransform, + COMMAND_setDepthRangeTransform, COMMAND_setPipeline, COMMAND_setStateBlendFactor, diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index e01dbcd0dc..9cb988a431 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -314,6 +314,7 @@ protected: void do_setViewTransform(Batch& batch, uint32 paramOffset); void do_setProjectionTransform(Batch& batch, uint32 paramOffset); void do_setViewportTransform(Batch& batch, uint32 paramOffset); + void do_setDepthRangeTransform(Batch& batch, uint32 paramOffset); void initTransform(); void killTransform(); @@ -339,6 +340,7 @@ protected: Transform _view; Mat4 _projection; Vec4i _viewport{ 0, 0, 1, 1 }; + Vec2 _depthRange{ 0.0f, 1.0f }; bool _invalidModel{true}; bool _invalidView{false}; bool _invalidProj{false}; diff --git a/libraries/gpu/src/gpu/GLBackendTransform.cpp b/libraries/gpu/src/gpu/GLBackendTransform.cpp index 5e16421c6a..963cab778f 100755 --- a/libraries/gpu/src/gpu/GLBackendTransform.cpp +++ b/libraries/gpu/src/gpu/GLBackendTransform.cpp @@ -45,10 +45,21 @@ void GLBackend::do_setViewportTransform(Batch& batch, uint32 paramOffset) { glViewport(vp.x, vp.y, vp.z, vp.w); - // The Viewport is tagged invalid because the CameraTransformUBO is not up to date and willl need update on next drawcall + // The Viewport is tagged invalid because the CameraTransformUBO is not up to date and will need update on next drawcall _transform._invalidViewport = true; } +void GLBackend::do_setDepthRangeTransform(Batch& batch, uint32 paramOffset) { + + Vec2 depthRange(batch._params[paramOffset + 0]._float, batch._params[paramOffset + 1]._float); + + if ((depthRange.x != _transform._depthRange.x) || (depthRange.y != _transform._depthRange.y)) { + _transform._depthRange = depthRange; + + glDepthRangef(depthRange.x, depthRange.y); + } +} + void GLBackend::initTransform() { glGenBuffers(1, &_transform._objectBuffer); glGenBuffers(1, &_transform._cameraBuffer); @@ -75,6 +86,8 @@ void GLBackend::syncTransformStateCache() { glGetIntegerv(GL_VIEWPORT, (GLint*) &_transform._viewport); + glGetFloatv(GL_DEPTH_RANGE, (GLfloat*)&_transform._depthRange); + Mat4 modelView; auto modelViewInv = glm::inverse(modelView); _transform._view.evalFromRawMatrix(modelViewInv);