From 5ce0ea65793e1ac68c63b4fbf74023869e890b5c Mon Sep 17 00:00:00 2001 From: Nicolas Capens Date: Thu, 2 Jul 2015 16:55:29 -0400 Subject: [PATCH] Use the projection matrix to scale z. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Bug 22123818 Change-Id: I2c72e221d9d9410c32875188a5edea6ce7310f20 Reviewed-on: https://swiftshader-review.googlesource.com/3625 Tested-by: Nicolas Capens Reviewed-by: Alexis Hétu Reviewed-by: Nicolas Capens --- src/OpenGL/libGL/Context.cpp | 15 +++++++++++++-- src/OpenGL/libGLES_CM/Context.cpp | 7 ++++++- src/Shader/VertexRoutine.cpp | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/OpenGL/libGL/Context.cpp b/src/OpenGL/libGL/Context.cpp index 69217d973..8a2b5cfa0 100644 --- a/src/OpenGL/libGL/Context.cpp +++ b/src/OpenGL/libGL/Context.cpp @@ -2479,7 +2479,13 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count) if(!mState.currentProgram) { //return;// error(GL_INVALID_OPERATION); - device->setProjectionMatrix(projection.current()); + + const sw::Matrix Z(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 0.5, 0.5, + 0, 0, 0, 1); // Map depth range from [-1, 1] to [0, 1] + + device->setProjectionMatrix(Z * projection.current()); device->setViewMatrix(modelView.current()); device->setTextureMatrix(0, texture[0].current()); device->setTextureMatrix(1, texture[1].current()); @@ -3509,7 +3515,12 @@ void Context::end() return error(GL_INVALID_OPERATION); } - device->setProjectionMatrix(projection.current()); + const sw::Matrix Z(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 0.5, 0.5, + 0, 0, 0, 1); // Map depth range from [-1, 1] to [0, 1] + + device->setProjectionMatrix(Z * projection.current()); device->setViewMatrix(modelView.current()); device->setTextureMatrix(0, texture[0].current()); device->setTextureMatrix(1, texture[1].current()); diff --git a/src/OpenGL/libGLES_CM/Context.cpp b/src/OpenGL/libGLES_CM/Context.cpp index 68be54695..774455daf 100644 --- a/src/OpenGL/libGLES_CM/Context.cpp +++ b/src/OpenGL/libGLES_CM/Context.cpp @@ -1805,7 +1805,12 @@ void Context::applyState(GLenum drawMode) device->setAmbientMaterialSource(sw::MATERIAL_MATERIAL); device->setEmissiveMaterialSource(sw::MATERIAL_MATERIAL); - device->setProjectionMatrix(projectionStack.current()); + const sw::Matrix Z(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 0.5, 0.5, + 0, 0, 0, 1); // Map depth range from [-1, 1] to [0, 1] + + device->setProjectionMatrix(Z * projectionStack.current()); device->setModelMatrix(modelViewStack.current()); device->setTextureMatrix(0, textureStack0.current()); device->setTextureMatrix(1, textureStack1.current()); diff --git a/src/Shader/VertexRoutine.cpp b/src/Shader/VertexRoutine.cpp index c14b633e3..e6c6fb9da 100644 --- a/src/Shader/VertexRoutine.cpp +++ b/src/Shader/VertexRoutine.cpp @@ -488,7 +488,7 @@ namespace sw r.o[pos].y = r.o[pos].y + *Pointer(r.data + OFFSET(DrawData,halfPixelY)) * r.o[pos].w; } - if(symmetricNormalizedDepth) + if(symmetricNormalizedDepth && !state.fixedFunction) { r.o[pos].z = (r.o[pos].z + r.o[pos].w) * Float4(0.5f); } -- 2.11.0