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/render-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 = mParent->ResolveVisibility(updateBufferIndex);
93 return mHasSizeAndColorFlag;
96 void RenderableAttachment::DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling )
98 scaling = Vector3::ONE;
101 void RenderableAttachment::PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager )
103 mHasUntrackedResources = false; // Only need to know this if the resources are not yet complete
104 mTrackedResources.Clear(); // Resource trackers are only needed if not yet completea
108 Integration::ResourceId id = mShader->GetEffectTextureResourceId();
112 CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
114 if(CompleteStatusManager::COMPLETE != completeStatusManager.GetStatus( id ))
117 mFinishedResourceAcquisition = false;
118 mResourcesReady = false;
120 // If shader has effect texture and it's not complete and tracked, ensure
121 // we call DoPrepareResources, as the effect texture may become ready in
122 // the ProcessRenderTasks step. Otherwise, may early out.
123 if( mHasUntrackedResources )
131 mResourcesReady = DoPrepareResources( updateBufferIndex, resourceManager );
134 void RenderableAttachment::FollowTracker( Integration::ResourceId id )
136 CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
138 if( completeStatusManager.FindResourceTracker(id) != NULL )
141 std::size_t numTrackedResources = mTrackedResources.Count();
142 for( size_t i=0; i < numTrackedResources; ++i )
144 if(mTrackedResources[i] == id)
152 mTrackedResources.PushBack( id );
157 mHasUntrackedResources = true;
162 void RenderableAttachment::GetReadyAndComplete(bool& ready, bool& complete) const
164 ready = mResourcesReady;
167 CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
169 std::size_t numTrackedResources = mTrackedResources.Count();
170 if( mHasUntrackedResources || numTrackedResources == 0 )
172 complete = mFinishedResourceAcquisition;
176 // If there are tracked resources and no untracked resources, test the trackers
177 bool trackersComplete = true;
178 for( size_t i=0; i < numTrackedResources; ++i )
180 ResourceId id = mTrackedResources[i];
181 ResourceTracker* tracker = completeStatusManager.FindResourceTracker(id);
182 if( tracker && ! tracker->IsComplete() )
184 trackersComplete = false;
189 complete = mFinishedResourceAcquisition || trackersComplete;
193 RenderableAttachment* RenderableAttachment::GetRenderable()
198 void RenderableAttachment::SetSortModifier(float modifier)
200 // Setting sort modifier makes the node dirty, i.e. we cannot reuse previous frames render items
203 // only do this if we are on-stage
204 mParent->SetDirtyFlag( SortModifierFlag );
206 mSortModifier = modifier;
209 void RenderableAttachment::SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes )
211 sortAttributes.shader = mShader;
212 sortAttributes.textureResourceId = Integration::InvalidResourceId;
213 sortAttributes.geometry = NULL;
216 } // namespace SceneGraph
218 } // namespace Internal