Use modern construct 'using' instead of typedef.
[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) 2018 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 #include <cstdint> // uint16_t, uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
26 #include <dali/public-api/rendering/sampler.h>
27 #include <dali/public-api/rendering/texture.h>
28 #include <dali/internal/event/rendering/texture-impl.h>
29 #include <dali/internal/render/gl-resources/context.h>
30 #include <dali/internal/render/renderers/render-sampler.h>
31 #include <dali/integration-api/gl-defines.h>
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 namespace Render
38 {
39 struct Sampler;
40
41 class Texture
42 {
43 public:
44   using Type = Dali::TextureType::Type;
45
46   /**
47    * Constructor
48    * @param[in] type The type of the texture
49    * @param[in] format The format of the pixel data
50    * @param[in] size The size of the texture
51    */
52   Texture( Type type, Pixel::Format format, ImageDimensions size );
53
54   /**
55    * Constructor from native image
56    * @param[in] nativeImageInterface The native image
57    */
58   Texture( NativeImageInterfacePtr nativeImageInterface );
59
60   /**
61    * Destructor
62    */
63   ~Texture();
64
65   /**
66    * Creates the texture in the GPU.
67    * Creates the texture and reserves memory for the first mipmap level
68    * @param[in] context The GL context
69    */
70   void Initialize( Context& context );
71
72   /**
73    * Deletes the texture from the GPU
74    * @param[in] context The GL context
75    */
76   void Destroy( Context& context );
77
78   /**
79    * Called by RenderManager to inform the texture that the context has been destroyed
80    */
81   void GlContextDestroyed();
82
83   /**
84    * Uploads data to the texture.
85    * @param[in] context The GL context
86    * @param[in] pixelData A pixel data object
87    * @param[in] params Upload parameters. See UploadParams
88    */
89   void Upload( Context& context, PixelDataPtr pixelData, const Internal::Texture::UploadParams& params );
90
91   /**
92    * Bind the texture to the given texture unit and applies the given sampler
93    * @param[in] context The GL context
94    * @param[in] textureUnit the texture unit
95    * @param[in] sampler The sampler to be used with the texture
96    * @return true if the bind succeeded, false otherwise
97    */
98   bool Bind( Context& context, uint32_t textureUnit, Render::Sampler* sampler );
99
100   /**
101    * Auto generates mipmaps for the texture
102    * @param[in] context The GL context
103    */
104   void GenerateMipmaps( Context& context );
105
106   /**
107    * Retrieve wheter the texture has an alpha channel
108    * @return True if the texture has alpha channel, false otherwise
109    */
110   bool HasAlphaChannel() const;
111
112   /**
113    * Get the id of the texture
114    * @return Id of the texture
115    */
116   GLuint GetId() const
117   {
118     return mId;
119   }
120
121   /**
122    * Get the target to which the texture is bound
123    * @return target to which the texture is bound
124    */
125   GLuint GetTarget() const
126   {
127     return mTarget;
128   }
129
130   /**
131    * Get the type of the texture
132    * @return Type of the texture
133    */
134   Type GetType() const
135   {
136     return mType;
137   }
138
139   /**
140    * Check if the texture is a native image
141    * @return if the texture is a native image
142    */
143   bool IsNativeImage() const
144   {
145     return mNativeImage;
146   }
147
148 private:
149
150   /**
151    * Helper method to apply a sampler to the texture
152    * @param[in] context The GL context
153    * @param[in] sampler The sampler
154    */
155   void ApplySampler( Context& context, Render::Sampler* sampler );
156
157   NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
158   Render::Sampler mSampler;             ///< The current sampler state
159   GLuint mId;                           ///< Id of the texture
160   GLuint mTarget;                       ///< Specifies the target to which the texture is bound.
161   GLint mGlInternalFormat;              ///< The gl internal format of the pixel data
162   GLenum mGlFormat;                     ///< The gl format of the pixel data
163   GLenum mPixelDataType;                ///< The data type of the pixel data
164   uint16_t mWidth;                      ///< Width of the texture
165   uint16_t mHeight;                     ///< Height of the texture
166   uint16_t mMaxMipMapLevel;             ///< Maximum mipmap level
167   Type mType:3;                         ///< Type of the texture
168   bool mHasAlpha : 1;                   ///< Whether the format has an alpha channel
169   bool mIsCompressed : 1;               ///< Whether the format is compressed
170
171 };
172
173
174 } // namespace Render
175
176 } // namespace Internal
177
178 } // namespace Dali
179
180
181 #endif //  DALI_INTERNAL_RENDER_TEXTURE_H