1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDERER_ATTACHMENT_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDERER_ATTACHMENT_H
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include <dali/internal/event/common/event-thread-services.h>
21 #include <dali/internal/update/common/double-buffered.h>
22 #include <dali/internal/update/common/property-owner.h>
23 #include <dali/internal/update/common/animatable-property.h>
24 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
25 #include <dali/internal/update/controllers/render-message-dispatcher.h>
26 #include <dali/internal/update/controllers/scene-controller.h>
27 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
28 #include <dali/internal/render/data-providers/render-data-provider.h>
39 struct RendererWithSortAttributes;
42 * The renderer attachment is the SceneGraph equivalent of Dali::Renderer. It is used to create an instance of a geometry and material for rendering, and is attached to an actor.
44 * It observes it's children (Material and Geometry) for connection change and for uniform map change, and observer's it's actor parent for uniform map change - this allows it to re-generate the uniform maps used by its RenderThread equivalent class.
46 * Lifetime and ownership
47 * It is created when a Dali::Renderer is created, and sent to UpdateManager. At this point
48 * Initialize is called on the object, but ownership is NOT taken by UpdateManager.
50 * When a Dali::Renderer is added to an actor, then this object becomes the node attachment
51 * for that actor, and the node takes ownership. It will create the Render::NewRenderer object
52 * in the Update thread on reciept of the connection message.
54 * When it's not attached to an actor, it is still possible to send messages to this
55 * object, to, e.g., set the material, or a property.
57 * @todo MESH_REWORK On merge with RenderableAttachment, change owner of all attachments to UpdateManager.
59 class RendererAttachment : public RenderableAttachment,
61 public UniformMapDataProvider,
62 public UniformMap::Observer,
63 public ConnectionChangePropagator::Observer
67 * Create a new renderer attachment.
68 * @return The newly allocated RendererAttachment
70 static RendererAttachment* New();
80 virtual ~RendererAttachment();
83 * @copydoc RenderableAttachment::Initialize2().
85 virtual void Initialize2( BufferIndex updateBufferIndex );
88 * @copydoc RenderableAttachment::OnDestroy2().
90 virtual void OnDestroy2();
93 * @copydoc NodeAttachment::ConnectedToSceneGraph()
95 virtual void ConnectedToSceneGraph();
98 * @copydoc NodeAttachment::DisconnectedFromSceneGraph()
100 virtual void DisconnectedFromSceneGraph();
103 * Set the material for the renderer
104 * @param[in] bufferIndex The current frame's buffer index
105 * @param[in] material The material this renderer will use
107 void SetMaterial( BufferIndex bufferIndex, Material* material);
110 * Get the material of this renderer
111 * @return the material this renderer uses
113 Material& GetMaterial();
116 * Set the geometry for the renderer
117 * @param[in] bufferIndex The current frame's buffer index
118 * @param[in] geometry The geometry this renderer will use
120 void SetGeometry( BufferIndex bufferIndex, Geometry* geometry);
123 * Get the geometry of this renderer
124 * @return the geometry this renderer uses
126 Geometry& GetGeometry();
129 * Set the depth index
130 * @param[in] depthIndex the new depth index to use
132 void SetDepthIndex( int depthIndex );
134 protected: // From NodeAttachment
136 * @brief Get the depth index
137 * @return The depth index
139 virtual int GetDepthIndex()
145 * Write the attachment's sort attributes to the passed in reference.
146 * @param[in] bufferIndex The buffer index
147 * @param[out] sortAttributes
149 virtual void SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes );
151 protected: // From RenderableAttachment
153 * @copydoc RenderableAttachment::GetRenderer().
155 virtual Renderer& GetRenderer();
158 * @copydoc RenderableAttachment::GetRenderer().
160 virtual const Renderer& GetRenderer() const;
163 * @copydoc RenderableAttachment::DoPrepareResources()
165 virtual bool DoPrepareResources( BufferIndex updateBufferIndex,
166 ResourceManager& resourceManager );
169 * @copydoc RenderableAttachment::DoPrepareRender()
171 virtual void DoPrepareRender( BufferIndex updateBufferIndex );
174 * @copydoc RenderableAttachment::IsFullyOpaque()
176 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex );
179 * @copydoc RenderableAttachment::SizeChanged()
181 virtual void SizeChanged( BufferIndex updateBufferIndex );
183 protected: // From ConnectionObserver
185 * @copydoc ConnectionObservers::Observer::ConnectionsChanged
187 virtual void ConnectionsChanged(PropertyOwner& object);
190 * @copydoc ConnectionObservers::Observer::ConnectedUniformMapChanged
192 virtual void ConnectedUniformMapChanged();
194 protected: // From UniformMap::Observer
196 * @copydoc UniformMap::Observer::UniformMappingsChanged
198 virtual void UniformMappingsChanged( const UniformMap& mappings );
200 protected: // From UniformMapDataProvider
202 * @copydoc UniformMapDataProvider::GetUniformMapChanged
204 virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const;
207 * @copydoc UniformMapDataProvider::GetUniformMap
209 virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const;
213 * Add any new mappings from map into the current map.
214 * This doesn't override any existing mappings.
215 * @param[in] localMap The map of collected uniforms.
216 * @param[in] map The map to import into the local map
218 void AddMappings( CollectedUniformMap& localMap, const UniformMap& map );
221 * Create a new render data provider
222 * @return the new (initialized) data provider
224 RenderDataProvider* NewRenderDataProvider();
227 NewRenderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
229 Material* mMaterial; ///< The material this renderer uses. (Not owned)
230 Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
232 CollectedUniformMap mCollectedUniformMap[2];
233 int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
234 bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
235 bool mResendDataProviders : 1; ///< True if the data providers should be resent to the renderer
236 bool mResendGeometry : 1; ///< True if geometry should be resent to the renderer
237 bool mUseBlend : 1; ///< True if the attachment & renderer should be considered opaque for sorting and blending.
238 public: // Properties
240 int mDepthIndex; ///< Used only in PrepareRenderInstructions
243 // Messages for RendererAttachment
245 inline void SetMaterialMessage( EventThreadServices& eventThreadServices, const RendererAttachment& attachment, const Material& material )
247 typedef MessageDoubleBuffered1< RendererAttachment, Material* > LocalType;
249 // Reserve some memory inside the message queue
250 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
252 // Construct message in the message queue memory; note that delete should not be called on the return value
253 new (slot) LocalType( &attachment, &RendererAttachment::SetMaterial, const_cast<Material*>(&material) );
256 inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const RendererAttachment& attachment, const Geometry& geometry )
258 typedef MessageDoubleBuffered1< RendererAttachment, Geometry* > LocalType;
260 // Reserve some memory inside the message queue
261 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
263 // Construct message in the message queue memory; note that delete should not be called on the return value
264 new (slot) LocalType( &attachment, &RendererAttachment::SetGeometry, const_cast<Geometry*>(&geometry) );
267 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const RendererAttachment& attachment, int depthIndex )
269 typedef MessageValue1< RendererAttachment, int > LocalType;
271 // Reserve some memory inside the message queue
272 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
274 // Construct message in the message queue memory; note that delete should not be called on the return value
275 new (slot) LocalType( &attachment, &RendererAttachment::SetDepthIndex, depthIndex );
278 } // namespace SceneGraph
279 } // namespace Internal
283 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_ATTACHMENT_H