1 #ifndef DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
2 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
5 * Copyright (c) 2016 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>
30 class ResourceManager;
46 * Construct a new TextureSet.
48 static TextureSet* New();
53 virtual ~TextureSet();
56 * Overriden delete operator
57 * Deletes the texture set from its global memory pool
59 void operator delete( void* ptr );
62 * Set the sampler to be used by the texture at position "index"
63 * @param[in] index The index of the texture
64 * @param[in] sampler The sampler to be used by the texture
66 void SetSampler( size_t index, Render::Sampler* sampler );
69 * Set the texture at position "index"
70 * @param[in] index The index of the texture
71 * @param[in] texture The texture
73 void SetTexture( size_t index, Render::NewTexture* texture );
76 * Return whether any texture in the texture set has an alpha channel
77 * @return true if at least one texture in the texture set has an alpha channel, false otherwise
79 bool HasAlpha() const;
82 * Adds a renderer to the Renderers list of the texture set.
83 * Renderers using the TextureSet get a notification when the texture set changes
85 * @param[in] renderer The renderer using the TextureSet
87 void AddObserver( Renderer* renderer );
90 * Removes a renderer from the TextureSet renderers list
92 * @param[in] renderer The renderer no longer using the TextureSet
94 void RemoveObserver( Renderer* renderer );
97 * Get the sampler of a texture in the TextureSet
98 * @param[in] index The index of the texture in the textures array
99 * @return the sampler used by the texture
101 Render::Sampler* GetTextureSampler( size_t index )
103 return mSamplers[index];
107 * Get the number of NewTextures in the texture set
108 * @return The number of NewTextures
110 size_t GetNewTextureCount()
112 return mTextures.Size();
116 * Get the pointer to a NewTexture in the TextureSet
117 * @param[in] index The index of the texture in the textures array
118 * @return the pointer to the NewTexture in that position
120 Render::NewTexture* GetNewTexture( size_t index )
122 return mTextures[index];
128 * Protected constructor; See also TextureSet::New()
133 * Helper method to notify the renderers observing the TextureSet
134 * that the TextureSet has changed
136 void NotifyChangeToRenderers();
140 Vector< Render::Sampler* > mSamplers; ///< List of samplers used by each texture. Not owned
141 Vector< Render::NewTexture* > mTextures; ///< List of NewTextures. Not owned
142 Vector<Renderer*> mRenderers; ///< List of renderers using the TextureSet
143 bool mHasAlpha; ///< if any of the textures has an alpha channel
146 inline void SetTextureMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, Render::NewTexture* texture )
148 typedef MessageValue2< TextureSet, size_t, Render::NewTexture* > LocalType;
150 // Reserve some memory inside the message queue
151 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
153 // Construct message in the message queue memory; note that delete should not be called on the return value
154 new (slot) LocalType( &textureSet, &TextureSet::SetTexture, index, texture );
157 inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, Render::Sampler* sampler )
159 typedef MessageValue2< TextureSet, size_t, Render::Sampler* > LocalType;
161 // Reserve some memory inside the message queue
162 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
164 // Construct message in the message queue memory; note that delete should not be called on the return value
165 new (slot) LocalType( &textureSet, &TextureSet::SetSampler, index, sampler );
168 } // namespace SceneGraph
170 } // namespace Internal
174 #endif // DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H