From 5dd7b370c8880971e798d656b5c2d4e0e5a1538f Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Mon, 16 Jun 2014 14:27:24 +0200 Subject: Project quads to z=0 instead of compressing them between 0 and 1 Since all quads are already separated in non-intersecting geometries and ordered according to their depth by Chromium, there is no need to keep any z value once the perspective projection has been applied. Avoid the useless computation and project the quads to z=0 the same way that QMatrix4x4::toTransform() does when used to flatten QQuickItem::transform(). Change-Id: I3ec5dc2da23cf431e2d8d0bb8b1ed48f2f2d2d8e Reviewed-by: Andras Becsi --- src/core/delegated_frame_node.cpp | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'src/core/delegated_frame_node.cpp') diff --git a/src/core/delegated_frame_node.cpp b/src/core/delegated_frame_node.cpp index 09cc540b7..c390b07b8 100644 --- a/src/core/delegated_frame_node.cpp +++ b/src/core/delegated_frame_node.cpp @@ -162,42 +162,18 @@ static inline QSharedPointer &findMailboxTexture(unsigned resour return texture; } -static QSGNode *buildRenderPassChain(QSGNode *chainParent, const cc::RenderPass *renderPass) +static QSGNode *buildRenderPassChain(QSGNode *chainParent) { // Chromium already ordered the quads from back to front for us, however the // Qt scene graph layers individual geometries in their own z-range and uses // the depth buffer to visually stack nodes according to their item tree order. - // This finds the z-span of all layers so that we can z-compress them to fit - // them between 0.0 and 1.0 on the z axis. - double minZ = 0; - double maxZ = 1; - double src2[8]; - double dst4[16]; - // topleft.x, topleft.y, topRight.y and bottomLeft.x - src2[0] = src2[1] = src2[3] = src2[4] = 0; - - // Go through each layer in this pass and find out their transformed rect. - cc::SharedQuadStateList::const_iterator it = renderPass->shared_quad_state_list.begin(); - cc::SharedQuadStateList::const_iterator sharedStateEnd = renderPass->shared_quad_state_list.end(); - for (; it != sharedStateEnd; ++it) { - gfx::Size &layerSize = (*it)->content_bounds; - // topRight.x - src2[2] = layerSize.width(); - // bottomLeft.y - src2[5] = layerSize.height(); - // bottomRight - src2[6] = layerSize.width(); - src2[7] = layerSize.height(); - (*it)->content_to_target_transform.matrix().map2(src2, 4, dst4); - // Check the mapped corner's z value and track the boundaries. - minZ = std::min(std::min(std::min(std::min(minZ, dst4[2]), dst4[6]), dst4[10]), dst4[14]); - maxZ = std::max(std::max(std::max(std::max(maxZ, dst4[2]), dst4[6]), dst4[10]), dst4[14]); - } + // This gets rid of the z component of all quads, once any x and y perspective + // transformation has been applied to vertices not on the z=0 plane. Qt will + // use an orthographic projection to render them. QSGTransformNode *zCompressNode = new QSGTransformNode; QMatrix4x4 zCompressMatrix; - zCompressMatrix.scale(1, 1, 1 / (maxZ - minZ)); - zCompressMatrix.translate(0, 0, -minZ); + zCompressMatrix.scale(1, 1, 0); zCompressNode->setMatrix(zCompressMatrix); chainParent->appendChildNode(zCompressNode); return zCompressNode; @@ -504,7 +480,7 @@ void DelegatedFrameNode::commit(DelegatedFrameNodeData* data, cc::ReturnedResour while (QSGNode *oldChain = renderPassParent->firstChild()) delete oldChain; - QSGNode *renderPassChain = buildRenderPassChain(renderPassParent, pass); + QSGNode *renderPassChain = buildRenderPassChain(renderPassParent); const cc::SharedQuadState *currentLayerState = 0; QSGNode *currentLayerChain = 0; -- cgit v1.2.3