Add UniformNameCache to keep track of unique uniform ids to avoid calculating hash...
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-texture.h
1 #ifndef DALI_INTERNAL_RENDER_TEXTURE_H
2 #define DALI_INTERNAL_RENDER_TEXTURE_H
3
4 /*
5  * Copyright (c) 2015 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 // EXTERNAL INCLUDES
21 #include <string>
22
23 // INTERNAL INCLUDES
24 #include <dali/devel-api/rendering/sampler.h>
25 #include <dali/integration-api/resource-declarations.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace Render
32 {
33 class Sampler;
34
35 /**
36  * This class is the mapping between texture id, sampler and sampler uniform name
37  */
38 class Texture
39 {
40 public:
41
42   /**
43    * Enumeration to tell that this sampler does not have a unique index yet
44    */
45   enum
46   {
47     NOT_INITIALIZED = -1
48   };
49
50   /**
51    * Constructor
52    */
53   Texture()
54   : mSampler( 0 ),
55     mUniformName(),
56     mTextureId( Integration::InvalidResourceId ),
57     mUniformUniqueIndex( NOT_INITIALIZED )
58   {}
59
60   /**
61    * Constructor
62    */
63   Texture( const std::string& samplerName, Integration::ResourceId textureId, Render::Sampler* sampler )
64   : mSampler( sampler ),
65     mUniformName( samplerName ),
66     mTextureId( textureId),
67     mUniformUniqueIndex( NOT_INITIALIZED )
68   {}
69
70   /**
71    * Destructor
72    */
73   ~Texture()
74   {}
75
76   /*
77    * Get the Render::Sampler used by the texture
78    * @Return The Render::Sampler being used or 0 if using the default
79    */
80   inline const Render::Sampler* GetSampler() const
81   {
82     return mSampler;
83   }
84
85 public: // called from RenderThread
86
87   /**
88    * Get the texture unit uniform name
89    * @return the name of the texture unit uniform
90    */
91   inline const std::string& GetUniformName() const
92   {
93     return mUniformName;
94   }
95
96   /**
97    * Get the texture ID
98    * @return the id of the associated texture
99    */
100   inline Integration::ResourceId GetTextureId() const
101   {
102     return mTextureId;
103   }
104
105   /**
106    * Get the Uniform unique index
107    * @return the identity of the associated texture
108    */
109   inline void SetUniformUniqueIndex( int32_t index )
110   {
111     mUniformUniqueIndex = index;
112   }
113
114   /**
115    * Get the Uniform unique index
116    * @return the identity of the associated texture
117    */
118   inline int32_t GetUniformUniqueIndex() const
119   {
120     return mUniformUniqueIndex;
121   }
122
123 private:
124
125   Render::Sampler*        mSampler;
126   std::string             mUniformName;
127   Integration::ResourceId mTextureId;
128   int32_t                 mUniformUniqueIndex;
129
130 };
131
132 } // namespace Render
133
134 } // namespace Internal
135
136 } // namespace Dali
137
138
139 #endif //  DALI_INTERNAL_RENDER_TEXTURE_H