1 #ifndef DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
2 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
5 * Copyright (c) 2018 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.
21 #include <dali/public-api/rendering/texture-set.h>
22 #include <dali/internal/common/buffer-index.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/event/common/event-thread-services.h>
42 * Construct a new TextureSet.
44 static TextureSet* New();
49 virtual ~TextureSet();
52 * Overriden delete operator
53 * Deletes the texture set from its global memory pool
55 void operator delete( void* ptr );
58 * Set the sampler to be used by the texture at position "index"
59 * @param[in] index The index of the texture
60 * @param[in] sampler The sampler to be used by the texture
62 void SetSampler( size_t index, SceneGraph::Sampler* sampler );
65 * Set the texture at position "index"
66 * @param[in] index The index of the texture
67 * @param[in] texture The texture
69 void SetTexture( size_t index, SceneGraph::Texture* texture );
72 * Return whether any texture in the texture set has an alpha channel
73 * @return true if at least one texture in the texture set has an alpha channel, false otherwise
75 bool HasAlpha() const;
78 * Adds a renderer to the Renderers list of the texture set.
79 * Renderers using the TextureSet get a notification when the texture set changes
81 * @param[in] renderer The renderer using the TextureSet
83 void AddObserver( Renderer* renderer );
86 * Removes a renderer from the TextureSet renderers list
88 * @param[in] renderer The renderer no longer using the TextureSet
90 void RemoveObserver( Renderer* renderer );
93 * Get the sampler of a texture in the TextureSet
94 * @param[in] index The index of the texture in the textures array
95 * @return the sampler used by the texture
97 SceneGraph::Sampler* GetTextureSampler( size_t index )
99 return mSamplers[index];
103 * Get the number of Textures in the texture set
104 * @return The number of Textures
106 size_t GetTextureCount()
108 return mTextures.Size();
112 * Get the pointer to a Texture in the TextureSet
113 * @param[in] index The index of the texture in the textures array
114 * @return the pointer to the Texture in that position
116 SceneGraph::Texture* GetTexture( size_t index )
118 return mTextures[index];
124 * Protected constructor; See also TextureSet::New()
129 * Helper method to notify the renderers observing the TextureSet
130 * that the TextureSet has changed
132 void NotifyChangeToRenderers();
136 Vector< SceneGraph::Sampler* > mSamplers; ///< List of samplers used by each texture. Not owned
137 Vector< SceneGraph::Texture* > mTextures; ///< List of Textures. Not owned
138 Vector<Renderer*> mRenderers; ///< List of renderers using the TextureSet
139 bool mHasAlpha; ///< if any of the textures has an alpha channel
142 inline void SetTextureMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, SceneGraph::Texture* texture )
144 typedef MessageValue2< TextureSet, size_t, SceneGraph::Texture* > LocalType;
146 // Reserve some memory inside the message queue
147 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
149 // Construct message in the message queue memory; note that delete should not be called on the return value
150 new (slot) LocalType( &textureSet, &TextureSet::SetTexture, index, texture );
153 inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, SceneGraph::Sampler* sampler )
155 typedef MessageValue2< TextureSet, size_t, SceneGraph::Sampler* > LocalType;
157 // Reserve some memory inside the message queue
158 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
160 // Construct message in the message queue memory; note that delete should not be called on the return value
161 new (slot) LocalType( &textureSet, &TextureSet::SetSampler, index, sampler );
164 } // namespace SceneGraph
166 } // namespace Internal
170 #endif // DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H