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/common/discard-queue.h>
22 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/update/nodes/node.h>
25 #include <dali/internal/render/queue/render-queue.h>
26 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
27 #include <dali/internal/render/renderers/scene-graph-renderer.h>
28 #include <dali/internal/render/shaders/scene-graph-shader.h>
39 DiscardQueue::DiscardQueue( RenderQueue& renderQueue )
40 : mRenderQueue( renderQueue )
44 DiscardQueue::~DiscardQueue()
48 void DiscardQueue::Add( BufferIndex updateBufferIndex, Node* node )
50 DALI_ASSERT_DEBUG( NULL != node );
52 // The GL resources will now be freed in frame N
53 // The Update for frame N+1 may occur in parallel with the rendering of frame N
54 // Queue the node for destruction in frame N+2
55 if ( 0u == updateBufferIndex )
57 mNodeQueue0.PushBack( node );
61 mNodeQueue1.PushBack( node );
65 void DiscardQueue::Add( BufferIndex updateBufferIndex, NodeAttachment* attachment )
67 DALI_ASSERT_DEBUG( NULL != attachment );
69 // The GL resources will now be freed in Render frame N
70 // The Update for frame N+1 may occur in parallel with the rendering of frame N
71 // Queue the attachment for destruction in Update frame N+2
72 if ( 0u == updateBufferIndex )
74 mAttachmentQueue0.PushBack( attachment );
78 mAttachmentQueue1.PushBack( attachment );
82 void DiscardQueue::Add( BufferIndex updateBufferIndex, Geometry* geometry )
84 DALI_ASSERT_DEBUG( NULL != geometry );
86 // The GL resources will now be freed in frame N
87 // The Update for frame N+1 may occur in parallel with the rendering of frame N
88 // Queue the node for destruction in frame N+2
89 if ( 0u == updateBufferIndex )
91 mGeometryQueue0.PushBack( geometry );
95 mGeometryQueue1.PushBack( geometry );
99 void DiscardQueue::Add( BufferIndex updateBufferIndex, Material* material )
101 DALI_ASSERT_DEBUG( NULL != material );
103 // The GL resources will now be freed in frame N
104 // The Update for frame N+1 may occur in parallel with the rendering of frame N
105 // Queue the node for destruction in frame N+2
106 if ( 0u == updateBufferIndex )
108 mMaterialQueue0.PushBack( material );
112 mMaterialQueue1.PushBack( material );
117 void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader )
119 DALI_ASSERT_DEBUG( NULL != shader );
121 // Programs are cached for the lifetime of DALi so no need for GL cleanup for shader for now.
123 // The GL resources will now be freed in frame N
124 // The Update for frame N+1 may occur in parallel with the rendering of frame N
125 // Queue the node for destruction in frame N+2
126 if ( 0u == updateBufferIndex )
128 mShaderQueue0.PushBack( shader );
132 mShaderQueue1.PushBack( shader );
136 void DiscardQueue::Add( BufferIndex updateBufferIndex, Sampler* sampler )
138 DALI_ASSERT_DEBUG( NULL != sampler );
140 if ( 0u == updateBufferIndex )
142 mSamplerQueue0.PushBack( sampler );
146 mSamplerQueue1.PushBack( sampler );
150 void DiscardQueue::Add( BufferIndex updateBufferIndex, PropertyBuffer* propertyBuffer )
152 DALI_ASSERT_DEBUG( NULL != propertyBuffer );
154 if ( 0u == updateBufferIndex )
156 mPropertyBufferQueue0.PushBack( propertyBuffer );
160 mPropertyBufferQueue1.PushBack( propertyBuffer );
164 void DiscardQueue::Clear( BufferIndex updateBufferIndex )
166 // Destroy some discarded objects; these should no longer own any GL resources
168 if ( 0u == updateBufferIndex )
171 mAttachmentQueue0.Clear();
172 mShaderQueue0.Clear();
173 mGeometryQueue0.Clear();
174 mMaterialQueue0.Clear();
175 mSamplerQueue0.Clear();
176 mPropertyBufferQueue0.Clear();
181 mAttachmentQueue1.Clear();
182 mShaderQueue1.Clear();
183 mGeometryQueue1.Clear();
184 mMaterialQueue1.Clear();
185 mSamplerQueue1.Clear();
186 mPropertyBufferQueue1.Clear();
190 } // namespace SceneGraph
192 } // namespace Internal