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/render-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, Renderer* renderer )
67 DALI_ASSERT_DEBUG( NULL != renderer );
69 // The GL resources will now be freed in frame N
70 // The Update for frame N+1 may occur in parallel with the rendering of frame N
71 // Queue the node for destruction in frame N+2
72 if ( 0u == updateBufferIndex )
74 mRendererQueue0.PushBack( renderer );
78 mRendererQueue1.PushBack( renderer );
82 void DiscardQueue::Add( BufferIndex updateBufferIndex, NodeAttachment* attachment )
84 DALI_ASSERT_DEBUG( NULL != attachment );
86 // The GL resources will now be freed in Render frame N
87 // The Update for frame N+1 may occur in parallel with the rendering of frame N
88 // Queue the attachment for destruction in Update frame N+2
89 if ( 0u == updateBufferIndex )
91 mAttachmentQueue0.PushBack( attachment );
95 mAttachmentQueue1.PushBack( attachment );
99 void DiscardQueue::Add( BufferIndex updateBufferIndex, Geometry* geometry )
101 DALI_ASSERT_DEBUG( NULL != geometry );
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 mGeometryQueue0.PushBack( geometry );
112 mGeometryQueue1.PushBack( geometry );
116 void DiscardQueue::Add( BufferIndex updateBufferIndex, Material* material )
118 DALI_ASSERT_DEBUG( NULL != material );
120 // The GL resources will now be freed in frame N
121 // The Update for frame N+1 may occur in parallel with the rendering of frame N
122 // Queue the node for destruction in frame N+2
123 if ( 0u == updateBufferIndex )
125 mMaterialQueue0.PushBack( material );
129 mMaterialQueue1.PushBack( material );
134 void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader )
136 DALI_ASSERT_DEBUG( NULL != shader );
138 // Programs are cached for the lifetime of DALi so no need for GL cleanup for shader for now.
140 // The GL resources will now be freed in frame N
141 // The Update for frame N+1 may occur in parallel with the rendering of frame N
142 // Queue the node for destruction in frame N+2
143 if ( 0u == updateBufferIndex )
145 mShaderQueue0.PushBack( shader );
149 mShaderQueue1.PushBack( shader );
153 void DiscardQueue::Clear( BufferIndex updateBufferIndex )
155 // Destroy some discarded objects; these should no longer own any GL resources
157 if ( 0u == updateBufferIndex )
160 mAttachmentQueue0.Clear();
161 mShaderQueue0.Clear();
162 mGeometryQueue0.Clear();
163 mMaterialQueue0.Clear();
164 mRendererQueue0.Clear();
169 mAttachmentQueue1.Clear();
170 mShaderQueue1.Clear();
171 mGeometryQueue1.Clear();
172 mMaterialQueue1.Clear();
173 mRendererQueue1.Clear();
177 } // namespace SceneGraph
179 } // namespace Internal