1 #ifndef __DALI_INTERNAL_TEXTURE_H__
2 #define __DALI_INTERNAL_TEXTURE_H__
5 * Copyright (c) 2015 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.
22 #include <dali/public-api/actors/sampling.h>
23 #include <dali/public-api/images/image.h>
24 #include <dali/public-api/images/pixel.h>
25 #include <dali/public-api/images/native-image.h>
26 #include <dali/public-api/math/rect.h>
27 #include <dali/public-api/object/ref-object.h>
28 #include <dali/integration-api/bitmap.h>
29 #include <dali/integration-api/gl-abstraction.h>
30 #include <dali/internal/event/images/pixel-data-impl.h>
31 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
32 #include <dali/internal/render/gl-resources/texture-units.h>
49 class Texture: public RefObject,
50 public GlResourceOwner
55 * Used to define the area of the texture to display
57 typedef Rect<int> PixelArea;
60 * Used to define a region of a bitmap.
62 typedef Rect<unsigned int> RectArea; ///< rectangular area (x,y,w,h)
65 * Initialization method for Texture.
66 * Might or might not be needed in specific implementations.
67 * @return true if successful, false otherwise
69 virtual bool Init() = 0;
72 * Update the texture with the bitmap.
74 virtual void Update(Integration::Bitmap* bitmap);
77 * Update the texture from the modified bitmap.
78 * @param area to update
80 virtual void UpdateArea( const RectArea& area );
83 * Update part of the texture with a different bitmap
84 * @param[in] srcBitmap The bitmap to copy from
85 * @param [in] xOffset Specifies an offset in the x direction within the texture
86 * @param [in] yOffset Specifies an offset in the y direction within the texture
88 virtual void Update( Integration::Bitmap* srcBitmap, std::size_t xOffset, std::size_t yOffset ) {}
91 * Update part of the texture with a pixel buffer
92 * @param[in] srcPixelData The pixel data to copy from
93 * @param [in] xOffset Specifies an offset in the x direction within the texture
94 * @param [in] yOffset Specifies an offset in the y direction within the texture
96 virtual void Update( PixelData* srcPixelData, std::size_t xOffset, std::size_t yOffset ) {}
99 * @return Return true if the texture should be updated on GL texture creation.
101 virtual bool UpdateOnCreate();
104 * Binds the texture for use.
105 * If there is no GL texture yet, it tries to create one.
107 * @param target (e.g. GL_TEXTURE_2D)
108 * @param textureunit to bind to
110 * @return true if the bind succeeded, or false if either the create or bind failed
112 virtual bool Bind(GLenum target, TextureUnit textureunit);
115 * Returns GL texture ID
118 unsigned int GetTextureId()
124 * Return the width of image in pixels.
127 virtual unsigned int GetWidth() const;
130 * Return the height of image in pixels.
133 virtual unsigned int GetHeight() const;
136 * Query whether the texture data has an alpha channel.
137 * @return True if the texture data has an alpha channel.
139 virtual bool HasAlphaChannel() const = 0;
142 * Query whether the texture is completely opaque
143 * @return True if all pixels of the texture data are opaque
145 virtual bool IsFullyOpaque() const = 0;
148 * Sets the texture id.
149 * @param id OpenGL texture id
151 void SetTextureId(GLuint id);
154 * @brief Apply the given sampler to the texture.
156 * @param[in] texture unit to use
157 * @param[in] samplerBitfield A bitfield with packed sampler options.
159 void ApplySampler( TextureUnit unit, unsigned int samplerBitfield );
165 * @param[in] context The GL context
166 * @param[in] width The buffer width
167 * @param[in] height The buffer height
168 * @param[in] imageWidth The image width
169 * @param[in] imageHeight The image height
171 Texture( Context& context,
174 unsigned int imageWidth,
175 unsigned int imageHeight );
178 * @param[in] context The GL context
179 * @param[in] width Both the buffer width and the image width (they are equal)
180 * @param[in] height Both the buffer height and the image height.
182 Texture( Context& context,
184 unsigned int height );
187 * Initialize texture for rendering.
188 * @return true on success
190 virtual bool CreateGlTexture() = 0;
194 * Delete the GL texture associated with it.
198 public: // From GlResourceOwner
201 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
203 virtual void GlContextDestroyed();
206 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
208 virtual void GlCleanup();
213 Texture(const Texture&);
216 Texture& operator=(const Texture& rhs);
219 * @brief Apply the given texture filtering parameters.
221 * @param[in] texture unit to use
222 * @param[in] filterType Minification or magnification.
223 * @param[in] currentFilterMode The current filter mode.
224 * @param[in] newFilterMode The new filter mode.
225 * @param[in] daliDefault The default dali filter mode for the given filterType.
226 * @param[in] systemDefault The default system filter mode for the given filterType.
228 void ApplyFilterModeParameter( TextureUnit unit, GLint filterType, FilterMode::Type currentFilterMode, FilterMode::Type newFilterMode, GLint daliDefault, GLint systemDefault );
231 * @brief Apply the given texture wrap mode.
233 * @param[in] texture unit to use
234 * @param[in] wrapType UWrap or VWrap
235 * @param[in] currentWrapMode The current wrap mode.
236 * @param[in] newWrapMode The new wrap mode.
238 void ApplyWrapModeParameter( TextureUnit unit, GLint wrapType, WrapMode::Type currentWrapMode, WrapMode::Type newWrapMode );
242 Context& mContext; ///< The GL Context
244 GLuint mId; ///< Texture id
246 unsigned int mSamplerBitfield; ///< The packed bitfield of the current sampler
248 unsigned int mWidth; ///< texture width, may be scaled power of 2 (if not in an atlas)
249 unsigned int mHeight; ///< texture width, may be scaled power of 2 (if not in an atlas)
251 unsigned int mImageWidth; ///< width of the original image (may be smaller than texture width)
252 unsigned int mImageHeight; ///< height of the original image (may be smaller than texture height)
255 } // namespace Internal
259 #endif // __DALI_INTERNAL_TEXTURE_H__