[dali_1.1.32] 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) 2016 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/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
26 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
27 #include <dali/devel-api/rendering/texture-set.h> // Dali::TextureSet
28 #include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
29 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
30 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
31 #include <dali/internal/event/common/property-buffer-impl.h> // Dali::Internal::PropertyBuffer
32 #include <dali/internal/event/rendering/sampler-impl.h> // Dali::Internal::Sampler
33 #include <dali/internal/event/rendering/shader-impl.h> // Dali::Internal::Shader
34
35 namespace Dali
36 {
37 namespace Internal
38 {
39 namespace SceneGraph
40 {
41 class TextureSet;
42 }
43
44
45 class TextureSet;
46 typedef IntrusivePtr<TextureSet> TextureSetPtr;
47
48 /**
49  * TextureSet is an object that holds all the textures used by a renderer
50  */
51 class TextureSet : public BaseObject, public Connectable
52 {
53 public:
54
55   /**
56    * @copydoc Dali::TextureSet::New()
57    */
58   static TextureSetPtr New();
59
60   /**
61    * @copydoc Dali::TextureSet::SetImage()
62    */
63   void SetImage( size_t index, ImagePtr image );
64
65   /**
66    * @copydoc Dali::TextureSet::GetImage()
67    */
68   Image* GetImage( size_t index ) const;
69
70   /**
71    * @copydoc Dali::TextureSet::SetSampler()
72    */
73   void SetSampler( size_t index, SamplerPtr sampler );
74
75   /**
76    * @copydoc Dali::TextureSet::GetSampler()
77    */
78   Sampler* GetSampler( size_t index ) const;
79
80   /**
81    * @copydoc Dali::TextureSet::GetTextureCount()
82    */
83   size_t GetTextureCount() const;
84
85  /**
86    * @brief Get the TextureSet scene object
87    *
88    * @return the texture set scene object
89    */
90   const SceneGraph::TextureSet* GetTextureSetSceneObject() const;
91
92 public: // Functions from Connectable
93   /**
94    * @copydoc Dali::Internal::Connectable::OnStage()
95    */
96   virtual bool OnStage() const;
97
98   /**
99    * @copydoc Dali::Internal::Connectable::Connect()
100    */
101   virtual void Connect();
102
103   /**
104    * @copydoc Dali::Internal::Connectable::Disconnect()
105    */
106   virtual void Disconnect();
107
108 private: // implementation
109
110   struct Texture
111   {
112     Texture()
113     :image(NULL),
114      sampler( NULL )
115     {}
116
117     ImagePtr    image;
118     SamplerPtr  sampler;
119   };
120
121   TextureSet();
122
123   /**
124    * Second stage initialization
125    */
126   void Initialize();
127
128 protected:
129   /**
130    * A reference counted object may only be deleted by calling Unreference()
131    */
132   virtual ~TextureSet();
133
134 private: // unimplemented methods
135   TextureSet( const TextureSet& );
136   TextureSet& operator=( const TextureSet& );
137
138 private: // Data
139   EventThreadServices& mEventThreadServices;    ///<Used to send messages to the update thread
140   SceneGraph::TextureSet* mSceneObject;
141   std::vector<Texture> mTextures;
142   bool mOnStage;
143
144 };
145
146 } // namespace Internal
147
148 // Helpers for public-api forwarding methods
149 inline Internal::TextureSet& GetImplementation( Dali::TextureSet& handle )
150 {
151   DALI_ASSERT_ALWAYS(handle && "TextureSet handle is empty");
152
153   BaseObject& object = handle.GetBaseObject();
154
155   return static_cast<Internal::TextureSet&>(object);
156 }
157
158 inline const Internal::TextureSet& GetImplementation( const Dali::TextureSet& handle )
159 {
160   DALI_ASSERT_ALWAYS(handle && "TextureSet handle is empty");
161
162   const BaseObject& object = handle.GetBaseObject();
163
164   return static_cast<const Internal::TextureSet&>(object);
165 }
166
167 } // namespace Dali
168
169 #endif // DALI_INTERNAL_TEXTURE_SET_H