From 9ea345e6372433217915a45b73acb81a81627bde Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Mon, 26 Aug 2019 13:39:45 +0200 Subject: Add property to Camera to enable frustum culling when needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default frustum culling is disabled because for most scenes all items are always visible. There is a not insignificant cost to doing frustum culling, so it shouldn't be the default behavior. Change-Id: Ibc0c0a4bd1cf65a215256de9ec22ca1d97eb6de5 Reviewed-by: Antti Määttä Reviewed-by: Miikka Heikkinen --- ...Qt3DSRendererImplLayerRenderPreparationData.cpp | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/runtimerender/rendererimpl/Qt3DSRendererImplLayerRenderPreparationData.cpp') diff --git a/src/runtimerender/rendererimpl/Qt3DSRendererImplLayerRenderPreparationData.cpp b/src/runtimerender/rendererimpl/Qt3DSRendererImplLayerRenderPreparationData.cpp index a53a40a..bfd52d6 100644 --- a/src/runtimerender/rendererimpl/Qt3DSRendererImplLayerRenderPreparationData.cpp +++ b/src/runtimerender/rendererimpl/Qt3DSRendererImplLayerRenderPreparationData.cpp @@ -1409,17 +1409,21 @@ namespace render { theTextScaleFactor = m_Camera->GetTextScaleFactor( thePrepResult.GetLayerToPresentationViewport(), thePrepResult.GetPresentationDesignDimensions()); - SClipPlane nearPlane; - QT3DSMat33 theUpper33(m_Camera->m_GlobalTransform.getUpper3x3InverseTranspose()); - - QT3DSVec3 dir(theUpper33.transform(QT3DSVec3(0, 0, -1))); - dir.normalize(); - nearPlane.normal = dir; - QT3DSVec3 theGlobalPos = m_Camera->GetGlobalPos() + m_Camera->m_ClipNear * dir; - nearPlane.d = -(dir.dot(theGlobalPos)); - // the near plane's bbox edges are calculated in the clipping frustum's - // constructor. - m_ClippingFrustum = SClippingFrustum(m_ViewProjection, nearPlane); + if (m_Camera->m_EnableFrustumCulling) { + SClipPlane nearPlane; + QT3DSMat33 theUpper33(m_Camera->m_GlobalTransform.getUpper3x3InverseTranspose()); + + QT3DSVec3 dir(theUpper33.transform(QT3DSVec3(0, 0, -1))); + dir.normalize(); + nearPlane.normal = dir; + QT3DSVec3 theGlobalPos = m_Camera->GetGlobalPos() + m_Camera->m_ClipNear * dir; + nearPlane.d = -(dir.dot(theGlobalPos)); + // the near plane's bbox edges are calculated in the clipping frustum's + // constructor. + m_ClippingFrustum = SClippingFrustum(m_ViewProjection, nearPlane); + } else if (m_ClippingFrustum.hasValue()) { + m_ClippingFrustum.setEmpty(); + } } else { m_ViewProjection = QT3DSMat44::createIdentity(); } -- cgit v1.2.3