Simplify the depth transformation in the scene graph.
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>
Wed, 11 Apr 2012 15:39:46 +0000 (17:39 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 25 May 2012 08:01:11 +0000 (10:01 +0200)
Use default depth function GL_LESS and depth clear value 1, and
set the near and far clipping planes to -1 and 1. This change
will make the transformations a bit easier for people who
implement custom 3D geometry since [-1, 1] is the typical z-range
after a projection transformation. The change has no visual impact
on 2D geometry.

Change-Id: I75d4a8acc15131ffaa5d13a749e42dffbc1d09db
Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
src/quick/scenegraph/coreapi/qsgdefaultrenderer.cpp
src/quick/scenegraph/coreapi/qsgdefaultrenderer_p.h
src/quick/scenegraph/coreapi/qsgrenderer.cpp

index 56d549e..c04afd7 100644 (file)
@@ -231,11 +231,11 @@ void QSGDefaultRenderer::render()
 
     glEnable(GL_DEPTH_TEST);
     glDepthMask(true);
-    glDepthFunc(GL_GREATER);
+    glDepthFunc(GL_LESS);
 #if defined(QT_OPENGL_ES)
-    glClearDepthf(0);
+    glClearDepthf(1);
 #else
-    glClearDepth(0);
+    glClearDepth(1);
 #endif
 
     glDisable(GL_SCISSOR_TEST);
@@ -298,9 +298,6 @@ void QSGDefaultRenderer::render()
     int debugtimeSorting = debugTimer.elapsed();
 #endif
 
-    m_renderOrderMatrix.setToIdentity();
-    m_renderOrderMatrix.scale(1, 1, qreal(1) / m_currentRenderOrder);
-
     int opaqueStart = 0;
     int transparentStart = 0;
     for (int i = 0; i < m_renderGroups.size(); ++i) {
@@ -523,16 +520,16 @@ void QSGDefaultRenderer::renderNodes(QSGNode *const *nodes, int count)
             }
             if (changes & QSGRenderNode::DepthState) {
 #if defined(QT_OPENGL_ES)
-                glClearDepthf(0);
+                glClearDepthf(1);
 #else
-                glClearDepth(0);
+                glClearDepth(1);
 #endif
                 if (m_clear_mode & QSGRenderer::ClearDepthBuffer) {
                     glDepthMask(true);
                     glClear(GL_DEPTH_BUFFER_BIT);
                 }
                 glDepthMask(false);
-                glDepthFunc(GL_GREATER);
+                glDepthFunc(GL_LESS);
             }
             if (changes & QSGRenderNode::ColorState)
                 bindable()->reactivate();
@@ -617,7 +614,7 @@ void QSGDefaultRenderer::renderNodes(QSGNode *const *nodes, int count)
             if (changeRenderOrder) {
                 currentRenderOrder = geomNode->renderOrder();
                 m_current_projection_matrix.setColumn(3, projection.column(3)
-                                                      + currentRenderOrder
+                                                      + (m_currentRenderOrder - 1 - 2 * currentRenderOrder)
                                                       * m_current_projection_matrix.column(2));
                 updates |= QSGMaterialShader::RenderState::DirtyMatrix;
             }
index 5c12c32..53384bf 100644 (file)
@@ -96,7 +96,6 @@ private:
     QSGMaterial *m_currentMaterial;
     QSGMaterialShader *m_currentProgram;
     const QMatrix4x4 *m_currentMatrix;
-    QMatrix4x4 m_renderOrderMatrix;
     QDataBuffer<QSGNode *> m_opaqueNodes;
     QDataBuffer<QSGNode *> m_transparentNodes;
     QDataBuffer<QSGNode *> m_tempNodes;
index 92b99b8..0049ae7 100644 (file)
@@ -313,7 +313,7 @@ void QSGRenderer::setProjectionMatrixToRect(const QRectF &rect)
                  rect.x() + rect.width(),
                  rect.y() + rect.height(),
                  rect.y(),
-                 qreal(0.01),
+                 1,
                  -1);
     setProjectionMatrix(matrix);
 }