1 #ifndef DALI_INTERNAL_RENDER_TEXTURE_H
2 #define DALI_INTERNAL_RENDER_TEXTURE_H
5 * Copyright (c) 2016 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/devel-api/rendering/sampler.h>
25 #include <dali/devel-api/rendering/texture.h>
26 #include <dali/internal/event/rendering/texture-impl.h>
27 #include <dali/integration-api/resource-declarations.h>
29 #include <dali/internal/render/gl-resources/context.h>
30 #include <dali/integration-api/gl-defines.h>
31 #include <dali/internal/render/renderers/render-sampler.h>
42 * This class is the mapping between texture id, sampler and sampler uniform name
49 * Enumeration to tell that this sampler does not have a unique index yet
61 mTextureId( Integration::InvalidResourceId )
67 Texture( Integration::ResourceId textureId, Render::Sampler* sampler )
68 : mSampler( sampler ),
69 mTextureId( textureId)
79 * Get the Render::Sampler used by the texture
80 * @Return The Render::Sampler being used or 0 if using the default
82 inline const Render::Sampler* GetSampler() const
87 public: // called from RenderThread
90 * @param[in] buffer A vector wit
92 * @return the id of the associated texture
94 inline Integration::ResourceId GetTextureId() const
101 Render::Sampler* mSampler;
102 Integration::ResourceId mTextureId;
106 //TODO : Remove the old Render::Texture class (see above) once it is no longer needed by Image
111 typedef Dali::TextureType::Type Type;
115 * @param[in] type The type of the texture
116 * @param[in] format The format of the pixel data
117 * @param[in] width The width of the texture
118 * @param[in] height The height of the texture
120 NewTexture( Type type, Pixel::Format format, unsigned int width, unsigned int height );
123 * Constructor from native image
124 * @param[in] nativeImageInterface The native image
126 NewTexture( NativeImageInterfacePtr nativeImageInterface );
134 * Creates the texture in the GPU.
135 * Creates the texture and reserves memory for the first mipmap level
136 * @param[in] context The GL context
138 void Initialize(Context& context);
141 * Deletes the texture from the GPU
142 * @param[in] context The GL context
144 void Destroy( Context& context );
147 * Uploads data to the texture.
148 * @param[in] context The GL context
149 * @param[in] buffer A vector with the data to be uploaded
150 * @param[in] params Upload parameters. See UploadParams
152 void Upload( Context& context, Vector<unsigned char>& buffer, const Internal::NewTexture::UploadParams& params );
155 * Bind the texture to the given texture unit and applies the given sampler
156 * @param[in] context The GL context
157 * @param[in] textureUnit the texture unit
158 * @param[in] sampler The sampler to be used with the texture
159 * @return true if the bind succeeded, false otherwise
161 bool Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler );
164 * Auto generates mipmaps for the texture
165 * @param[in] context The GL context
167 void GenerateMipmaps( Context& context );
170 * Retrieve wheter the texture has an alpha channel
171 * @return True if the texture has alpha channel, false otherwise
173 bool HasAlphaChannel();
176 * Get the id of the texture
177 * @return Id of the texture
185 * Get the width of the texture
186 * @return Width of the texture
188 unsigned int GetWidth() const
194 * Get the height of the texture
195 * @return Height of the texture
197 unsigned int GetHeight() const
203 * Get the type of the texture
204 * @return Type of the texture
214 * Helper method to apply a sampler to the texture
215 * @param[in] context The GL context
216 * @param[in] sampler The sampler
218 void ApplySampler( Context& context, Render::Sampler* sampler );
220 GLuint mId; ///<Id of the texture
221 Type mType; ///<Type of the texture
222 Render::Sampler mSampler; ///<The current sampler state
223 NativeImageInterfacePtr mNativeImage; ///<Pointer to native image
224 GLenum mInternalFormat; ///<The format of the pixel data
225 GLenum mPixelDataType; ///<The data type of the pixel data
226 unsigned int mWidth; ///<Widht of the texture
227 unsigned int mHeight; ///<Height of the texture
228 bool mHasAlpha : 1; ///<Whether the format has an alpha channel
232 } // namespace Render
234 } // namespace Internal
239 #endif // DALI_INTERNAL_RENDER_TEXTURE_H