// INTERNAL INCLUDES
#include <dali/integration-api/debug.h>
+#include <dali/internal/common/matrix-utils.h>
#include <dali/internal/event/actors/layer-impl.h> // for the default sorting function
#include <dali/internal/render/common/render-instruction-container.h>
#include <dali/internal/render/common/render-instruction.h>
}
/**
- * Set the update size of the node
+ * Set the update area of the node
* @param[in] node The node of the renderer
* @param[in] isLayer3d Whether we are processing a 3D layer or not
* @param[in,out] nodeWorldMatrix The world matrix of the node
* @param[in,out] nodeSize The size of the node
- * @param[in,out] nodeUpdateSize The update size of the node
+ * @param[in,out] nodeUpdateArea The update area of the node
*
- * @return True if node use it's own UpdateSizeHint, or z transform occured. False if we use nodeUpdateSize equal with nodeSize.
+ * @return True if node use it's own UpdateAreaHint, or z transform occured. False if we use nodeUpdateArea equal with Vector4(0, 0, nodeSize.width, nodeSize.height).
*/
-inline bool SetNodeUpdateSize(Node* node, bool isLayer3d, Matrix& nodeWorldMatrix, Vector3& nodeSize, Vector3& nodeUpdateSize)
+inline bool SetNodeUpdateArea(Node* node, bool isLayer3d, Matrix& nodeWorldMatrix, Vector3& nodeSize, Vector4& nodeUpdateArea)
{
node->GetWorldMatrixAndSize(nodeWorldMatrix, nodeSize);
- if(node->GetUpdateSizeHint() == Vector3::ZERO)
+ if(node->GetUpdateAreaHint() == Vector4::ZERO)
{
// RenderItem::CalculateViewportSpaceAABB cannot cope with z transform
// I don't use item.mModelMatrix.GetTransformComponents() for z transform, would be too slow
if(!isLayer3d && nodeWorldMatrix.GetZAxis() == Vector3(0.0f, 0.0f, 1.0f))
{
- nodeUpdateSize = nodeSize;
+ nodeUpdateArea = Vector4(0.0f, 0.0f, nodeSize.width, nodeSize.height);
return false;
}
- // Keep nodeUpdateSize as Vector3::ZERO, and return true.
+ // Keep nodeUpdateArea as Vector4::ZERO, and return true.
return true;
}
else
{
- nodeUpdateSize = node->GetUpdateSizeHint();
+ nodeUpdateArea = node->GetUpdateAreaHint();
return true;
}
}
* @param viewport The viewport
* @param cull Whether frustum culling is enabled or not
*/
-inline void AddRendererToRenderList(BufferIndex updateBufferIndex,
- RenderList& renderList,
- Renderable& renderable,
- const Matrix& viewMatrix,
- SceneGraph::Camera& camera,
- bool isLayer3d,
- bool viewportSet,
- const Viewport& viewport,
- bool cull)
+inline void AddRendererToRenderList(BufferIndex updateBufferIndex,
+ RenderList& renderList,
+ Renderable& renderable,
+ const Matrix& viewMatrix,
+ const SceneGraph::Camera& camera,
+ bool isLayer3d,
+ bool viewportSet,
+ const Viewport& viewport,
+ bool cull)
{
bool inside(true);
Node* node = renderable.mNode;
Matrix nodeWorldMatrix(false);
Vector3 nodeSize;
- Vector3 nodeUpdateSize;
- bool nodeUpdateSizeSet(false);
- bool nodeUpdateSizeUseHint(false);
+ Vector4 nodeUpdateArea;
+ bool nodeUpdateAreaSet(false);
+ bool nodeUpdateAreaUseHint(false);
Matrix nodeModelViewMatrix(false);
bool nodeModelViewMatrixSet(false);
if(inside && !isLayer3d && viewportSet)
{
- nodeUpdateSizeUseHint = SetNodeUpdateSize(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateSize);
- nodeUpdateSizeSet = true;
+ nodeUpdateAreaUseHint = SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea);
+ nodeUpdateAreaSet = true;
const Vector3& scale = node->GetWorldScale(updateBufferIndex);
- const Vector3& size = nodeUpdateSize * scale;
+ const Vector3& size = Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 1.0f) * scale;
if(size.LengthSquared() > Math::MACHINE_EPSILON_1000)
{
- Matrix::Multiply(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix);
+ MatrixUtils::Multiply(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix);
nodeModelViewMatrixSet = true;
// Assume actors are at z=0, compute AABB in view space & test rect intersection
// against z=0 plane boundaries for frustum. (NOT viewport). This should take into account
// magnification due to FOV etc.
- ClippingBox boundingBox = RenderItem::CalculateTransformSpaceAABB(nodeModelViewMatrix, nodeUpdateSize);
+ ClippingBox boundingBox = RenderItem::CalculateTransformSpaceAABB(nodeModelViewMatrix, Vector3(nodeUpdateArea.x, nodeUpdateArea.y, 0.0f), Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 0.0f));
ClippingBox clippingBox(camera.mLeftClippingPlane, camera.mBottomClippingPlane, camera.mRightClippingPlane - camera.mLeftClippingPlane, fabsf(camera.mBottomClippingPlane - camera.mTopClippingPlane));
inside = clippingBox.Intersects(boundingBox);
}
if(DALI_LIKELY(renderable.mRenderer))
{
+ partialRenderingCacheInfo.color.a *= renderable.mRenderer->GetOpacity(updateBufferIndex);
partialRenderingCacheInfo.textureSet = renderable.mRenderer->GetTextureSet();
}
item.mTextureSet = renderable.mRenderer->GetTextureSet();
item.mDepthIndex += renderable.mRenderer->GetDepthIndex();
- // Ensure collected map is up to date
- item.mIsUpdated |= renderable.mRenderer->UpdateUniformMap();
+ // Get whether collected map is up to date
+ item.mIsUpdated |= renderable.mRenderer->UniformMapUpdated();
}
else
{
item.mIsUpdated |= isLayer3d;
- if(!nodeUpdateSizeSet)
+ if(!nodeUpdateAreaSet)
{
- nodeUpdateSizeUseHint = SetNodeUpdateSize(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateSize);
+ nodeUpdateAreaUseHint = SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea);
}
item.mSize = nodeSize;
- item.mUpdateSize = nodeUpdateSize;
+ item.mUpdateArea = nodeUpdateArea;
item.mModelMatrix = nodeWorldMatrix;
// Apply transform informations if node doesn't have update size hint and use VisualRenderer.
- if(!nodeUpdateSizeUseHint && renderable.mRenderer && renderable.mRenderer->GetVisualProperties())
+ if(!nodeUpdateAreaUseHint && renderable.mRenderer && renderable.mRenderer->GetVisualProperties())
{
- item.mUpdateSize = renderable.mRenderer->CalculateVisualTransformedUpdateSize(updateBufferIndex, item.mUpdateSize);
+ Vector3 updateSize = renderable.mRenderer->CalculateVisualTransformedUpdateSize(updateBufferIndex, Vector3(item.mUpdateArea.z, item.mUpdateArea.w, 0.0f));
+ item.mUpdateArea.z = updateSize.x;
+ item.mUpdateArea.w = updateSize.y;
}
if(!nodeModelViewMatrixSet)
{
- Matrix::Multiply(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix);
+ MatrixUtils::Multiply(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix);
}
item.mModelViewMatrix = nodeModelViewMatrix;
- partialRenderingCacheInfo.matrix = item.mModelViewMatrix;
- partialRenderingCacheInfo.size = item.mSize;
- partialRenderingCacheInfo.updatedSize = item.mUpdateSize;
+ partialRenderingCacheInfo.matrix = item.mModelViewMatrix;
+ partialRenderingCacheInfo.size = item.mSize;
+ partialRenderingCacheInfo.updatedPositionSize = item.mUpdateArea;
item.mIsUpdated = partialRenderingData.IsUpdated() || item.mIsUpdated;
* @param isLayer3d Whether we are processing a 3D layer or not
* @param cull Whether frustum culling is enabled or not
*/
-inline void AddRenderersToRenderList(BufferIndex updateBufferIndex,
- RenderList& renderList,
- RenderableContainer& renderers,
- const Matrix& viewMatrix,
- SceneGraph::Camera& camera,
- bool isLayer3d,
- bool viewportSet,
- const Viewport& viewport,
- bool cull)
+inline void AddRenderersToRenderList(BufferIndex updateBufferIndex,
+ RenderList& renderList,
+ RenderableContainer& renderers,
+ const Matrix& viewMatrix,
+ const SceneGraph::Camera& camera,
+ bool isLayer3d,
+ bool viewportSet,
+ const Viewport& viewport,
+ bool cull)
{
DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "AddRenderersToRenderList()\n");
RenderInstructionProcessor::~RenderInstructionProcessor() = default;
-inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, RenderList& renderList, Layer& layer, bool respectClippingOrder)
+inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, RenderList& renderList, Layer& layer, bool respectClippingOrder, bool isOrthographicCamera)
{
const uint32_t renderableCount = static_cast<uint32_t>(renderList.Count());
// Reserve space if needed.
// Calculate the sorting value, once per item by calling the layers sort function.
// Using an if and two for-loops rather than if inside for as its better for branch prediction.
- if(layer.UsesDefaultSortFunction())
- {
- for(uint32_t index = 0; index < renderableCount; ++index)
- {
- RenderItem& item = renderList.GetItem(index);
- if(DALI_LIKELY(item.mRenderer))
- {
- item.mRenderer->SetSortAttributes(mSortingHelper[index]);
- }
+ // List of zValue calculating functions.
+ const Dali::Layer::SortFunctionType zValueFunctionFromVector3[] = {
+ [](const Vector3& position) { return position.z; },
+ [](const Vector3& position) { return position.LengthSquared(); },
+ layer.GetSortFunction(),
+ };
- // texture set
- mSortingHelper[index].textureSet = item.mTextureSet;
+ // Determine whether we need to use zValue as Euclidean distance or translatoin's z value.
+ // If layer is LAYER_UI or camera is OrthographicProjection mode, we don't need to calculate
+ // renderItem's distance from camera.
- // The default sorting function should get inlined here.
- mSortingHelper[index].zValue = Internal::Layer::ZValue(item.mModelViewMatrix.GetTranslation3()) - static_cast<float>(item.mDepthIndex);
+ // Here we determine which zValue SortFunctionType (of the 3) to use.
+ // 0 is position z value : Default LAYER_UI or Orthographic camera
+ // 1 is distance square value : Default LAYER_3D and Perspective camera
+ // 2 is user defined function.
+ const int zValueFunctionIndex = layer.UsesDefaultSortFunction() ? ((layer.GetBehavior() == Dali::Layer::LAYER_UI || isOrthographicCamera) ? 0 : 1) : 2;
- // Keep the renderitem pointer in the helper so we can quickly reorder items after sort.
- mSortingHelper[index].renderItem = &item;
- }
- }
- else
+ for(uint32_t index = 0; index < renderableCount; ++index)
{
- const Dali::Layer::SortFunctionType sortFunction = layer.GetSortFunction();
- for(uint32_t index = 0; index < renderableCount; ++index)
- {
- RenderItem& item = renderList.GetItem(index);
+ RenderItem& item = renderList.GetItem(index);
- if(DALI_LIKELY(item.mRenderer))
- {
- item.mRenderer->SetSortAttributes(mSortingHelper[index]);
- }
+ if(DALI_LIKELY(item.mRenderer))
+ {
+ item.mRenderer->SetSortAttributes(mSortingHelper[index]);
+ }
- // texture set
- mSortingHelper[index].textureSet = item.mTextureSet;
+ // texture set
+ mSortingHelper[index].textureSet = item.mTextureSet;
- mSortingHelper[index].zValue = (*sortFunction)(item.mModelViewMatrix.GetTranslation3()) - static_cast<float>(item.mDepthIndex);
+ mSortingHelper[index].zValue = zValueFunctionFromVector3[zValueFunctionIndex](item.mModelViewMatrix.GetTranslation3()) - static_cast<float>(item.mDepthIndex);
- // Keep the RenderItem pointer in the helper so we can quickly reorder items after sort.
- mSortingHelper[index].renderItem = &item;
- }
+ // Keep the renderitem pointer in the helper so we can quickly reorder items after sort.
+ mSortingHelper[index].renderItem = &item;
}
// Here we determine which comparitor (of the 3) to use.
bool isRenderListAdded = false;
bool isRootLayerDirty = false;
- const Matrix& viewMatrix = renderTask.GetViewMatrix(updateBufferIndex);
- SceneGraph::Camera& camera = renderTask.GetCamera();
+ const Matrix& viewMatrix = renderTask.GetViewMatrix(updateBufferIndex);
+ const SceneGraph::Camera& camera = renderTask.GetCamera();
+ const bool isOrthographicCamera = camera.mProjectionMode == Dali::Camera::ProjectionMode::ORTHOGRAPHIC_PROJECTION;
Viewport viewport;
bool viewportSet = renderTask.QueryViewport(updateBufferIndex, viewport);
for(SortedLayersIter iter = sortedLayers.begin(); iter != endIter; ++iter)
{
Layer& layer = **iter;
- const bool tryReuseRenderList(viewMatrixHasNotChanged && layer.CanReuseRenderers(&renderTask.GetCamera()));
+ const bool tryReuseRenderList(viewMatrixHasNotChanged && layer.CanReuseRenderers(&camera));
const bool isLayer3D = layer.GetBehavior() == Dali::Layer::LAYER_3D;
RenderList* renderList = nullptr;
cull);
// We only use the clipping version of the sort comparitor if any clipping nodes exist within the RenderList.
- SortRenderItems(updateBufferIndex, *renderList, layer, hasClippingNodes);
+ SortRenderItems(updateBufferIndex, *renderList, layer, hasClippingNodes, isOrthographicCamera);
}
isRenderListAdded = true;
cull);
// Clipping hierarchy is irrelevant when sorting overlay items, so we specify using the non-clipping version of the sort comparitor.
- SortRenderItems(updateBufferIndex, *renderList, layer, false);
+ SortRenderItems(updateBufferIndex, *renderList, layer, false, isOrthographicCamera);
}
isRenderListAdded = true;