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>
45 * Construct a new TextureSet.
47 static TextureSet* New();
50 * Destructor. Not virtual as not a base class and not inheriting anything
55 * Overriden delete operator
56 * Deletes the texture set from its global memory pool
58 void operator delete( void* ptr );
61 * Set the sampler to be used by the texture at position "index"
62 * @param[in] index The index of the texture
63 * @param[in] sampler The sampler to be used by the texture
65 void SetSampler( uint32_t index, Render::Sampler* sampler );
68 * Set the texture at position "index"
69 * @param[in] index The index of the texture
70 * @param[in] texture The texture
72 void SetTexture( uint32_t index, Render::Texture* texture );
75 * Return whether any texture in the texture set has an alpha channel
76 * @return true if at least one texture in the texture set has an alpha channel, false otherwise
78 bool HasAlpha() const;
81 * Adds a renderer to the Renderers list of the texture set.
82 * Renderers using the TextureSet get a notification when the texture set changes
84 * @param[in] renderer The renderer using the TextureSet
86 void AddObserver( Renderer* renderer );
89 * Removes a renderer from the TextureSet renderers list
91 * @param[in] renderer The renderer no longer using the TextureSet
93 void RemoveObserver( Renderer* renderer );
96 * Get the sampler of a texture in the TextureSet
97 * @param[in] index The index of the texture in the textures array
98 * @return the sampler used by the texture
100 Render::Sampler* GetTextureSampler( uint32_t index )
102 return mSamplers[index];
106 * Get the number of Textures in the texture set
107 * @return The number of Textures
109 uint32_t GetTextureCount()
111 return static_cast<uint32_t>( mTextures.Size() );
115 * Get the pointer to a Texture in the TextureSet
116 * @param[in] index The index of the texture in the textures array
117 * @return the pointer to the Texture in that position
119 Render::Texture* GetTexture( uint32_t index )
121 return mTextures[index];
127 * Protected constructor; See also TextureSet::New()
132 * Helper method to notify the renderers observing the TextureSet
133 * that the TextureSet has changed
135 void NotifyChangeToRenderers();
139 Vector< Render::Sampler* > mSamplers; ///< List of samplers used by each texture. Not owned
140 Vector< Render::Texture* > mTextures; ///< List of Textures. Not owned
141 Vector<Renderer*> mRenderers; ///< List of renderers using the TextureSet
142 bool mHasAlpha; ///< if any of the textures has an alpha channel
145 inline void SetTextureMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Texture* texture )
147 typedef MessageValue2< TextureSet, uint32_t, Render::Texture* > LocalType;
149 // Reserve some memory inside the message queue
150 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
152 // Construct message in the message queue memory; note that delete should not be called on the return value
153 new (slot) LocalType( &textureSet, &TextureSet::SetTexture, index, texture );
156 inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Sampler* sampler )
158 typedef MessageValue2< TextureSet, uint32_t, Render::Sampler* > LocalType;
160 // Reserve some memory inside the message queue
161 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
163 // Construct message in the message queue memory; note that delete should not be called on the return value
164 new (slot) LocalType( &textureSet, &TextureSet::SetSampler, index, sampler );
167 } // namespace SceneGraph
169 } // namespace Internal
173 #endif // DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H