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/internal/common/event-to-update.h>
22 #include <dali/internal/update/common/double-buffered.h>
23 #include <dali/internal/update/common/property-owner.h>
24 #include <dali/internal/render/renderers/sampler-data-provider.h>
35 class Sampler : public PropertyOwner, public SamplerDataProvider
38 typedef Dali::Sampler::FilterMode FilterMode;
39 typedef Dali::Sampler::WrapMode WrapMode;
44 Sampler( const std::string& samplerName );
52 * Set the uniform name of this sampler. This allows the shader to find the
53 * GL index of this sampler.
55 void SetUniformName( const std::string& samplerName );
58 * Set the texture identity of this sampler
59 * @param[in] textureId The identity of the texture
61 void SetTextureId( ResourceId textureId );
64 * Set the filter modes for minify and magnify filters
65 * @param[in] bufferIndex The buffer index to use
66 * @param[in] minFilter The minify filter
67 * @param[in] magFilter The magnify filter
69 void SetFilterMode( BufferIndex bufferIndex, FilterMode minFilter, FilterMode magFilter );
72 * @param[in] bufferIndex The buffer index to use
74 void SetWrapMode( BufferIndex bufferIndex, WrapMode uWrap, WrapMode vWrap );
76 public: // SamplerDataProvider interface
80 const std::string& GetUniformName();
84 * @return the identity of the associated texture
86 virtual ResourceId GetTextureId();
90 * @param[in] bufferIndex The buffer index to use
91 * @return The minify filter mode
93 virtual FilterMode GetMinifyFilterMode( BufferIndex bufferIndex );
97 * @param[in] bufferIndex The buffer index to use
98 * @return The magnify filter mode
100 virtual FilterMode GetMagnifyFilterMode( BufferIndex bufferIndex );
103 * Get the horizontal wrap mode
104 * @param[in] bufferIndex The buffer index to use
105 * @return The horizontal wrap mode
107 virtual WrapMode GetUWrapMode( BufferIndex bufferIndex );
110 * Get the vertical wrap mode
111 * @param[in] bufferIndex The buffer index to use
112 * @return The vertical wrap mode
114 virtual WrapMode GetVWrapMode( BufferIndex bufferIndex );
117 * @return true if the texture is fully opaque.
118 * @todo MESH_REWORK Requires access to ResourceManager::GetBitmapMetadata()
120 bool IsFullyOpaque();
123 std::string mUniformName; ///< The name of the uniform referencing this sampler
124 ResourceId mTextureId; ///< The identity of the associated texture
126 DoubleBuffered<FilterMode> mMinFilter; ///< The minify filter
127 DoubleBuffered<FilterMode> mMagFilter; ///< The magnify filter
128 DoubleBuffered<WrapMode> mUWrapMode; ///< The horizontal wrap mode
129 DoubleBuffered<WrapMode> mVWrapMode; ///< The vertical wrap mode
132 inline void SetUniformNameMessage( EventToUpdate& eventToUpdate, const Sampler& sampler, const std::string& name )
134 typedef MessageValue1< Sampler, std::string > LocalType;
136 // Reserve some memory inside the message queue
137 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
139 // Construct message in the message queue memory; note that delete should not be called on the return value
140 new (slot) LocalType( &sampler, &Sampler::SetUniformName, name );
143 } // namespace SceneGraph
145 // Declare enum as a message parameter type outside the SceneGraph namespace
146 template <> struct ParameterType< SceneGraph::Sampler::FilterMode > : public BasicType< SceneGraph::Sampler::FilterMode > {};
151 inline void SetFilterModeMessage( EventToUpdate& eventToUpdate, const Sampler& sampler, Sampler::FilterMode minFilter, Sampler::FilterMode magFilter )
153 typedef MessageDoubleBuffered2< Sampler, Sampler::FilterMode, Sampler::FilterMode > LocalType;
155 // Reserve some memory inside the message queue
156 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
158 // Construct message in the message queue memory; note that delete should not be called on the return value
159 new (slot) LocalType( &sampler, &Sampler::SetFilterMode, minFilter, magFilter );
162 } // namespace SceneGraph
164 // Declare enum as a message parameter type
165 template <> struct ParameterType< SceneGraph::Sampler::WrapMode > : public BasicType< SceneGraph::Sampler::WrapMode > {};
170 inline void SetWrapModeMessage( EventToUpdate& eventToUpdate, const SceneGraph::Sampler& sampler, SceneGraph::Sampler::WrapMode horizontalWrap, SceneGraph::Sampler::WrapMode verticalWrap )
172 typedef MessageDoubleBuffered2< Sampler, Sampler::WrapMode, Sampler::WrapMode > LocalType;
174 // Reserve some memory inside the message queue
175 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
177 // Construct message in the message queue memory; note that delete should not be called on the return value
178 new (slot) LocalType( &sampler, &Sampler::SetWrapMode, horizontalWrap, verticalWrap );
182 } // namespace SceneGraph
183 } // namespace Internal
187 #endif // DALI_INTERNAL_SCENE_GRAPH_SAMPLER_H