1 #ifndef DALI_INTERNAL_SCENE_GRAPH_SAMPLER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_SAMPLER_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/shader-effects/sampler.h>
21 #include <dali/integration-api/resource-declarations.h>
22 #include <dali/internal/event/common/event-thread-services.h>
23 #include <dali/internal/update/common/double-buffered.h>
24 #include <dali/internal/update/common/double-buffered-property.h>
25 #include <dali/internal/update/common/property-owner.h>
26 #include <dali/internal/update/common/scene-graph-connection-observers.h>
27 #include <dali/internal/update/resources/bitmap-metadata.h>
28 #include <dali/internal/render/data-providers/sampler-data-provider.h>
38 class SceneController;
40 class Sampler : public PropertyOwner, public SamplerDataProvider
43 typedef Dali::Sampler::FilterMode FilterMode;
44 typedef Dali::Sampler::WrapMode WrapMode;
49 Sampler( const std::string& samplerName );
57 * Set the uniform name of this sampler. This allows the shader to find the
58 * GL index of this sampler.
60 void SetTextureUnitUniformName( const std::string& textureUnitUniformName );
63 * Set the texture identity of this sampler (needs to double buffer this value because
64 * it can be read through the data provider interface in the render thread )
65 * @param[in] bufferIndex The buffer index to use
66 * @param[in] textureId The identity of the texture
68 void SetTexture( BufferIndex bufferIndex, Integration::ResourceId textureId );
71 * Set the filter modes for minify and magnify filters
72 * @param[in] bufferIndex The buffer index to use
73 * @param[in] minFilter The minify filter
74 * @param[in] magFilter The magnify filter
76 void SetFilterMode( BufferIndex bufferIndex, FilterMode minFilter, FilterMode magFilter );
79 * @param[in] bufferIndex The buffer index to use
81 void SetWrapMode( BufferIndex bufferIndex, WrapMode uWrap, WrapMode vWrap );
84 * @param[in] bufferIndex The buffer index to use
85 * @return true if this sampler affects transparency of the material
86 * @note this should only be called from Update thread
88 bool AffectsTransparency( BufferIndex bufferIndex ) const;
91 * Sets whether the associated texture is fully opaque or not.
92 * @param[in] fullyOpaque true if it's fully opaque
94 void SetFullyOpaque( bool fullyOpaque );
97 * @param[in] bufferIndex The buffer index to use
98 * @return true if the texture is fully opaque
99 * @note this should only be called from Update thread
101 bool IsFullyOpaque( BufferIndex bufferIndex ) const;
104 public: // SamplerDataProvider interface - called from RenderThread
106 * Get the texture unit uniform name
107 * @return the name of the texture unit uniform
109 virtual const std::string& GetTextureUnitUniformName() const;
113 * @param[in] bufferIndex The buffer index to use
114 * @return the identity of the associated texture
116 virtual Integration::ResourceId GetTextureId(BufferIndex buffer) const;
119 * Get the filter mode
120 * @param[in] bufferIndex The buffer index to use
121 * @return The minify filter mode
123 virtual FilterMode GetMinifyFilterMode( BufferIndex bufferIndex ) const;
126 * Get the filter mode
127 * @param[in] bufferIndex The buffer index to use
128 * @return The magnify filter mode
130 virtual FilterMode GetMagnifyFilterMode( BufferIndex bufferIndex ) const;
133 * Get the horizontal wrap mode
134 * @param[in] bufferIndex The buffer index to use
135 * @return The horizontal wrap mode
137 virtual WrapMode GetUWrapMode( BufferIndex bufferIndex ) const;
140 * Get the vertical wrap mode
141 * @param[in] bufferIndex The buffer index to use
142 * @return The vertical wrap mode
144 virtual WrapMode GetVWrapMode( BufferIndex bufferIndex ) const;
147 * Connect the object to the scene graph
149 * @param[in] sceneController The scene controller - used for sending messages to render thread
150 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
152 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
155 * Disconnect the object from the scene graph
156 * @param[in] sceneController The scene controller - used for sending messages to render thread
157 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
159 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
161 * @copydoc ConnectionObservers::AddObserver
163 void AddConnectionObserver(ConnectionObservers::Observer& observer);
166 * @copydoc ConnectionObservers::RemoveObserver
168 void RemoveConnectionObserver(ConnectionObservers::Observer& observer);
170 public: // PropertyOwner implementation
172 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
174 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
176 public: // Properties
177 DoubleBufferedProperty<int> mMinFilter; ///< The minify filter
178 DoubleBufferedProperty<int> mMagFilter; ///< The magnify filter
179 DoubleBufferedProperty<int> mUWrapMode; ///< The horizontal wrap mode
180 DoubleBufferedProperty<int> mVWrapMode; ///< The vertical wrap mode
181 DoubleBufferedProperty<bool> mAffectsTransparency; ///< If this sampler affects renderer transparency
184 std::string mTextureUnitUniformName; ///< The name of the uniform of the texture unit
185 DoubleBufferedProperty<unsigned int> mTextureId;
186 ConnectionObservers mConnectionObservers; ///< Connection observers that will be informed when textures change.
187 bool mFullyOpaque; // Update only flag - no need for double buffering
190 } // namespace SceneGraph
192 inline void SetTextureUnitUniformNameMessage( EventThreadServices& eventThreadServices, const SceneGraph::Sampler& sampler, const std::string& name )
194 typedef MessageValue1< SceneGraph::Sampler, std::string > LocalType;
196 // Reserve some memory inside the message queue
197 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
199 // Construct message in the message queue memory; note that delete should not be called on the return value
200 new (slot) LocalType( &sampler, &SceneGraph::Sampler::SetTextureUnitUniformName, name );
204 inline void SetTextureMessage( EventThreadServices& eventThreadServices, const SceneGraph::Sampler& sampler, unsigned int resourceId )
206 typedef MessageDoubleBuffered1< SceneGraph::Sampler, unsigned int > LocalType;
208 // Reserve some memory inside the message queue
209 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
211 // Construct message in the message queue memory; note that delete should not be called on the return value
212 new (slot) LocalType( &sampler, &SceneGraph::Sampler::SetTexture, resourceId );
215 // Declare enum as a message parameter type outside the SceneGraph namespace
216 template <> struct ParameterType< SceneGraph::Sampler::FilterMode > : public BasicType< SceneGraph::Sampler::FilterMode > {};
219 inline void SetFilterModeMessage( EventThreadServices& eventThreadServices, const SceneGraph::Sampler& sampler, SceneGraph::Sampler::FilterMode minFilter, SceneGraph::Sampler::FilterMode magFilter )
221 typedef MessageDoubleBuffered2< SceneGraph::Sampler, SceneGraph::Sampler::FilterMode, SceneGraph::Sampler::FilterMode > LocalType;
223 // Reserve some memory inside the message queue
224 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
226 // Construct message in the message queue memory; note that delete should not be called on the return value
227 new (slot) LocalType( &sampler, &SceneGraph::Sampler::SetFilterMode, minFilter, magFilter );
230 // Declare enum as a message parameter type
231 template <> struct ParameterType< SceneGraph::Sampler::WrapMode > : public BasicType< SceneGraph::Sampler::WrapMode > {};
234 inline void SetWrapModeMessage( EventThreadServices& eventThreadServices, const SceneGraph::Sampler& sampler, SceneGraph::Sampler::WrapMode horizontalWrap, SceneGraph::Sampler::WrapMode verticalWrap )
236 typedef MessageDoubleBuffered2< SceneGraph::Sampler, SceneGraph::Sampler::WrapMode, SceneGraph::Sampler::WrapMode > LocalType;
238 // Reserve some memory inside the message queue
239 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
241 // Construct message in the message queue memory; note that delete should not be called on the return value
242 new (slot) LocalType( &sampler, &SceneGraph::Sampler::SetWrapMode, horizontalWrap, verticalWrap );
245 } // namespace Internal
249 #endif // DALI_INTERNAL_SCENE_GRAPH_SAMPLER_H