2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
22 #include <dali/integration-api/resource-declarations.h>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/internal/update/manager/prepare-render-instructions.h>
25 #include <dali/internal/update/nodes/node.h>
26 #include <dali/internal/update/resources/resource-manager.h>
27 #include <dali/internal/update/resources/complete-status-manager.h>
28 #include <dali/internal/update/resources/resource-tracker.h>
29 #include <dali/internal/render/queue/render-queue.h>
30 #include <dali/internal/render/renderers/scene-graph-renderer.h>
31 #include <dali/internal/render/shaders/scene-graph-shader.h>
32 #include <dali/internal/common/image-sampler.h>
43 RenderableAttachment::RenderableAttachment( bool usesGeometryScaling )
44 : mSceneController(NULL), //@todo MESH_REWORK Pass in where required rather than store
47 mSortModifier( 0.0f ),
48 mBlendingMode( Dali::ImageActor::DEFAULT_BLENDING_MODE ),
49 mUsesGeometryScaling( usesGeometryScaling ),
50 mScaleForSizeDirty( true ),
51 mHasSizeAndColorFlag( false ),
52 mResourcesReady( false ),
53 mFinishedResourceAcquisition( false ),
54 mHasUntrackedResources( false )
58 RenderableAttachment::~RenderableAttachment()
62 void RenderableAttachment::Initialize( SceneController& sceneController, BufferIndex updateBufferIndex )
64 mSceneController = &sceneController;
66 // Chain to derived attachments
67 Initialize2( updateBufferIndex );
70 void RenderableAttachment::OnDestroy()
72 // Chain to derived attachments
75 // SceneController is no longer valid
76 mSceneController = NULL;
79 void RenderableAttachment::SetRecalculateScaleForSize()
81 mScaleForSizeDirty = true;
84 void RenderableAttachment::GetScaleForSize( const Vector3& nodeSize, Vector3& scaling )
86 DoGetScaleForSize( nodeSize, scaling );
87 mScaleForSizeDirty = false;
90 bool RenderableAttachment::ResolveVisibility( BufferIndex updateBufferIndex )
92 mHasSizeAndColorFlag = false;
93 const Vector4& color = mParent->GetWorldColor( updateBufferIndex );
94 if( color.a > FULLY_TRANSPARENT ) // not fully transparent
96 const float MAX_NODE_SIZE = float(1u<<30);
97 const Vector3& size = mParent->GetSize( updateBufferIndex );
98 if( ( size.width > Math::MACHINE_EPSILON_1000 ) && // width is greater than a very small number
99 ( size.height > Math::MACHINE_EPSILON_1000 ) ) // height is greater than a very small number
101 if( ( size.width < MAX_NODE_SIZE ) && // width is smaller than the maximum allowed size
102 ( size.height < MAX_NODE_SIZE ) ) // height is smaller than the maximum allowed size
104 mHasSizeAndColorFlag = true;
108 DALI_LOG_ERROR("Actor size should not be bigger than %f.\n", MAX_NODE_SIZE );
109 DALI_LOG_ACTOR_TREE( mParent );
113 return mHasSizeAndColorFlag;
116 void RenderableAttachment::DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling )
118 scaling = Vector3::ONE;
121 void RenderableAttachment::PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager )
123 mHasUntrackedResources = false; // Only need to know this if the resources are not yet complete
124 mTrackedResources.Clear(); // Resource trackers are only needed if not yet completea
128 Integration::ResourceId id = mShader->GetEffectTextureResourceId();
132 CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
134 if(CompleteStatusManager::COMPLETE != completeStatusManager.GetStatus( id ))
137 mFinishedResourceAcquisition = false;
138 mResourcesReady = false;
140 // If shader has effect texture and it's not complete and tracked, ensure
141 // we call DoPrepareResources, as the effect texture may become ready in
142 // the ProcessRenderTasks step. Otherwise, may early out.
143 if( mHasUntrackedResources )
151 mResourcesReady = DoPrepareResources( updateBufferIndex, resourceManager );
154 void RenderableAttachment::FollowTracker( Integration::ResourceId id )
156 CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
158 if( completeStatusManager.FindResourceTracker(id) != NULL )
161 std::size_t numTrackedResources = mTrackedResources.Count();
162 for( size_t i=0; i < numTrackedResources; ++i )
164 if(mTrackedResources[i] == id)
172 mTrackedResources.PushBack( id );
177 mHasUntrackedResources = true;
182 void RenderableAttachment::GetReadyAndComplete(bool& ready, bool& complete) const
184 ready = mResourcesReady;
187 CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
189 std::size_t numTrackedResources = mTrackedResources.Count();
190 if( mHasUntrackedResources || numTrackedResources == 0 )
192 complete = mFinishedResourceAcquisition;
196 // If there are tracked resources and no untracked resources, test the trackers
197 bool trackersComplete = true;
198 for( size_t i=0; i < numTrackedResources; ++i )
200 ResourceId id = mTrackedResources[i];
201 ResourceTracker* tracker = completeStatusManager.FindResourceTracker(id);
202 if( tracker && ! tracker->IsComplete() )
204 trackersComplete = false;
209 complete = mFinishedResourceAcquisition || trackersComplete;
213 RenderableAttachment* RenderableAttachment::GetRenderable()
218 void RenderableAttachment::SetSortModifier(float modifier)
220 // Setting sort modifier makes the node dirty, i.e. we cannot reuse previous frames render items
223 // only do this if we are on-stage
224 mParent->SetDirtyFlag( SortModifierFlag );
226 mSortModifier = modifier;
229 void RenderableAttachment::SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes )
231 sortAttributes.shader = mShader;
232 sortAttributes.material = NULL;
233 sortAttributes.geometry = NULL;
236 } // namespace SceneGraph
238 } // namespace Internal