[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / texture-set-impl.h
1 #ifndef DALI_INTERNAL_TEXTURE_SET_H
2 #define DALI_INTERNAL_TEXTURE_SET_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h> // std::vector
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/event/common/object-impl.h>     // Dali::Internal::Object
26 #include <dali/internal/event/rendering/sampler-impl.h> // Dali::Internal::Sampler
27 #include <dali/internal/event/rendering/shader-impl.h>  // Dali::Internal::Shader
28 #include <dali/internal/event/rendering/texture-impl.h> // Dali::Internal::Texture
29 #include <dali/public-api/common/dali-common.h>         // DALI_ASSERT_ALWAYS
30 #include <dali/public-api/common/intrusive-ptr.h>       // Dali::IntrusivePtr
31 #include <dali/public-api/rendering/texture-set.h>      // Dali::TextureSet
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 namespace SceneGraph
38 {
39 class TextureSet;
40 }
41
42 class TextureSet;
43 using TextureSetPtr = IntrusivePtr<TextureSet>;
44
45 /**
46  * TextureSet is an object that holds all the textures used by a renderer
47  */
48 class TextureSet : public BaseObject
49 {
50 public:
51   /**
52    * @copydoc Dali::TextureSet::New()
53    */
54   static TextureSetPtr New();
55
56   /**
57    * @copydoc Dali::TextureSet::SetTexture()
58    */
59   void SetTexture(uint32_t index, TexturePtr texture);
60
61   /**
62    * @copydoc Dali::TextureSet::GetTexture()
63    */
64   Texture* GetTexture(uint32_t index) const;
65
66   /**
67    * @copydoc Dali::TextureSet::SetSampler()
68    */
69   void SetSampler(uint32_t index, SamplerPtr sampler);
70
71   /**
72    * @copydoc Dali::TextureSet::GetSampler()
73    */
74   Sampler* GetSampler(uint32_t index) const;
75
76   /**
77    * @copydoc Dali::TextureSet::GetTextureCount()
78    */
79   uint32_t GetTextureCount() const;
80
81   /**
82    * @brief Get the TextureSet scene object
83    *
84    * @return the texture set scene object
85    */
86   const SceneGraph::TextureSet* GetTextureSetSceneObject() const;
87
88 private: // implementation
89   TextureSet();
90
91   /**
92    * Second stage initialization
93    */
94   void Initialize();
95
96   /**
97    * @brief Change the count of texture and sampler. It will increase count automatically if we need more textures.
98    *
99    * @param[in] count The number of textures what this texture set want to hold
100    */
101   void SetTextureCount(uint32_t count);
102
103   /**
104    * @brief Change the count of sampler. It will increase count automatically if we need more samplers.
105    *
106    * @param[in] count The number of samplers what this texture set want to hold
107    */
108   void SetSamplerCount(uint32_t count);
109
110   /**
111    * @brief Remove empty textures and samplers at the back of container, and resize.
112    */
113   void TrimContainers();
114
115 protected:
116   /**
117    * A reference counted object may only be deleted by calling Unreference()
118    */
119   ~TextureSet() override;
120
121 private: // unimplemented methods
122   TextureSet(const TextureSet&);
123   TextureSet& operator=(const TextureSet&);
124
125 private:                                        // Data
126   EventThreadServices&    mEventThreadServices; ///<Used to send messages to the update thread
127   SceneGraph::TextureSet* mSceneObject;
128   std::vector<SamplerPtr> mSamplers;
129   std::vector<TexturePtr> mTextures;
130 };
131
132 } // namespace Internal
133
134 // Helpers for public-api forwarding methods
135 inline Internal::TextureSet& GetImplementation(Dali::TextureSet& handle)
136 {
137   DALI_ASSERT_ALWAYS(handle && "TextureSet handle is empty");
138
139   BaseObject& object = handle.GetBaseObject();
140
141   return static_cast<Internal::TextureSet&>(object);
142 }
143
144 inline const Internal::TextureSet& GetImplementation(const Dali::TextureSet& handle)
145 {
146   DALI_ASSERT_ALWAYS(handle && "TextureSet handle is empty");
147
148   const BaseObject& object = handle.GetBaseObject();
149
150   return static_cast<const Internal::TextureSet&>(object);
151 }
152
153 } // namespace Dali
154
155 #endif // DALI_INTERNAL_TEXTURE_SET_H