1 #ifndef DALI_INTERNAL_RENDER_TEXTURE_H
2 #define DALI_INTERNAL_RENDER_TEXTURE_H
5 * Copyright (c) 2017 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.
24 #include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
25 #include <dali/public-api/rendering/sampler.h>
26 #include <dali/public-api/rendering/texture.h>
27 #include <dali/internal/event/rendering/texture-impl.h>
28 #include <dali/internal/render/gl-resources/context.h>
29 #include <dali/internal/render/renderers/render-sampler.h>
30 #include <dali/integration-api/gl-defines.h>
44 typedef Dali::TextureType::Type Type;
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
52 Texture( Type type, Pixel::Format format, ImageDimensions size );
55 * Constructor from native image
56 * @param[in] nativeImageInterface The native image
58 Texture( NativeImageInterfacePtr nativeImageInterface );
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
70 void Initialize( Context& context );
73 * Deletes the texture from the GPU
74 * @param[in] context The GL context
76 void Destroy( Context& context );
79 * Called by RenderManager to inform the texture that the context has been destroyed
81 void GlContextDestroyed();
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
89 void Upload( Context& context, PixelDataPtr pixelData, const Internal::Texture::UploadParams& params );
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
98 bool Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler );
101 * Auto generates mipmaps for the texture
102 * @param[in] context The GL context
104 void GenerateMipmaps( Context& context );
107 * Retrieve wheter the texture has an alpha channel
108 * @return True if the texture has alpha channel, false otherwise
110 bool HasAlphaChannel();
113 * Get the id of the texture
114 * @return Id of the texture
122 * Get the type of the texture
123 * @return Type of the texture
131 * Check if the texture is a native image
132 * @return if the texture is a native image
134 bool IsNativeImage() const
142 * Helper method to apply a sampler to the texture
143 * @param[in] context The GL context
144 * @param[in] sampler The sampler
146 void ApplySampler( Context& context, Render::Sampler* sampler );
148 NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
149 Render::Sampler mSampler; ///< The current sampler state
150 GLuint mId; ///< Id of the texture
151 GLuint mTarget; ///< Specifies the target to which the texture is bound.
152 GLint mGlInternalFormat; ///< The gl internal format of the pixel data
153 GLenum mGlFormat; ///< The gl format of the pixel data
154 GLenum mPixelDataType; ///< The data type of the pixel data
155 uint16_t mWidth; ///< Width of the texture
156 uint16_t mHeight; ///< Height of the texture
157 uint16_t mMaxMipMapLevel; ///< Maximum mipmap level
158 Type mType:3; ///< Type of the texture
159 bool mHasAlpha : 1; ///< Whether the format has an alpha channel
160 bool mIsCompressed : 1; ///< Whether the format is compressed
165 } // namespace Render
167 } // namespace Internal
172 #endif // DALI_INTERNAL_RENDER_TEXTURE_H