1 #ifndef DALI_INTERNAL_SCENE_GRAPH_MATERIAL_H
2 #define DALI_INTERNAL_SCENE_GRAPH_MATERIAL_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/public-api/actors/renderable-actor.h> // For CullFaceMode
21 #include <dali/internal/common/buffer-index.h>
22 #include <dali/internal/common/blending-options.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/update/common/animatable-property.h>
25 #include <dali/internal/update/common/double-buffered-property.h>
26 #include <dali/internal/update/common/property-owner.h>
27 #include <dali/internal/update/common/scene-graph-connection-observers.h>
28 #include <dali/internal/update/common/uniform-map.h>
29 #include <dali/internal/render/data-providers/render-data-provider.h>
39 class ConnectionObserver;
40 class SceneController;
42 class Material : public PropertyOwner, public MaterialDataProvider, public UniformMap::Observer, public ConnectionObservers::Observer
56 * Set the shader effect for this material
57 * @param[in] shader The shader effect to use
59 void SetShader( const Shader* shader );
62 * Add a sampler (image + sampler modes) to the material
63 * @param[in] sampler A sampler to add
65 void AddSampler( const Sampler* sampler );
68 * Remove a sampler (image + sampler modes) from the material
69 * @param[in] sampler A sampler to remove
71 void RemoveSampler( const Sampler* sampler );
74 * Connect the object to the scene graph
76 * @param[in] sceneController The scene controller - used for sending messages to render thread
77 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
79 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
82 * Disconnect the object from the scene graph
83 * @param[in] sceneController The scene controller - used for sending messages to render thread
84 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
86 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
89 * @copydoc ConnectionObservers::AddObserver
91 void AddConnectionObserver(ConnectionObservers::Observer& observer);
94 * @copydoc ConnectionObservers::RemoveObserver
96 void RemoveConnectionObserver(ConnectionObservers::Observer& observer);
98 public: // MaterialDataProvider implementation
100 * Get the shader effect of this material
101 * @return the shader effect;
103 virtual Shader* GetShader() const;
106 * Get the samplers this material uses.
107 * @return the samplers
109 virtual const RenderDataProvider::Samplers& GetSamplers() const;
111 public: // UniformMap::Observer
113 * @copydoc UniformMap::Observer::UniformMappingsChanged
115 virtual void UniformMappingsChanged( const UniformMap& mappings );
117 public: // ConnectionObserver::Observer
120 * @copydoc ConnectionObservers::ConnectionsChanged
122 virtual void ConnectionsChanged( PropertyOwner& owner );
125 * @copydoc ConnectionObservers::ConnectedUniformMapChanged
127 virtual void ConnectedUniformMapChanged( );
129 public: // PropertyOwner implementation
131 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
133 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
135 public: // Property data
136 AnimatableProperty<Vector4> mColor;
137 AnimatableProperty<Vector4> mBlendColor;
138 DoubleBufferedProperty<int> mFaceCullingMode;
141 const Shader* mShader;
142 RenderDataProvider::Samplers mSamplers; // Not owned
143 ConnectionObservers mConnectionObservers;
145 // @todo MESH_REWORK add property values for cull face mode, blending options, blend color
146 // Add getters/setters?
149 inline void SetShaderMessage( EventThreadServices& eventThreadServices, const Material& material, const Shader& shader )
151 typedef MessageValue1< Material, const Shader* > LocalType;
153 // Reserve some memory inside the message queue
154 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
156 // Construct message in the message queue memory; note that delete should not be called on the return value
157 new (slot) LocalType( &material, &Material::SetShader, &shader );
160 inline void AddSamplerMessage( EventThreadServices& eventThreadServices, const Material& material, const Sampler& sampler )
162 typedef MessageValue1< Material, const Sampler* > LocalType;
164 // Reserve some memory inside the message queue
165 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
167 // Construct message in the message queue memory; note that delete should not be called on the return value
168 new (slot) LocalType( &material, &Material::AddSampler, &sampler );
171 inline void RemoveSamplerMessage( EventThreadServices& eventThreadServices, const Material& material, const Sampler& sampler )
173 typedef MessageValue1< Material, const Sampler* > LocalType;
175 // Reserve some memory inside the message queue
176 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
178 // Construct message in the message queue memory; note that delete should not be called on the return value
179 new (slot) LocalType( &material, &Material::RemoveSampler, &sampler );
182 } // namespace SceneGraph
183 } // namespace Internal
186 #endif // DALI_INTERNAL_SCENE_GRAPH_MATERIAL_H