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/integration-api/resource-declarations.h>
28 #include <dali/internal/render/gl-resources/context.h>
29 #include <dali/integration-api/gl-defines.h>
30 #include <dali/internal/render/renderers/render-sampler.h>
41 * This class is the mapping between texture id, sampler and sampler uniform name
48 * Enumeration to tell that this sampler does not have a unique index yet
60 mTextureId( Integration::InvalidResourceId )
66 Texture( Integration::ResourceId textureId, Render::Sampler* sampler )
67 : mSampler( sampler ),
68 mTextureId( textureId)
78 * Get the Render::Sampler used by the texture
79 * @Return The Render::Sampler being used or 0 if using the default
81 inline const Render::Sampler* GetSampler() const
86 public: // called from RenderThread
89 * @param[in] buffer A vector wit
91 * @return the id of the associated texture
93 inline Integration::ResourceId GetTextureId() const
100 Render::Sampler* mSampler;
101 Integration::ResourceId mTextureId;
105 //TODO : Remove the old Render::Texture class (see above) once it is no longer needed by Image
110 typedef Dali::TextureType::Type Type;
114 NewTexture( Type type, Pixel::Format format, unsigned int width, unsigned int height );
122 * Creates the texture in the GPU.
123 * Creates the texture and reserves memory for the first mipmap level
124 * @param[in] context The GL context
126 void Initialize(Context& context);
129 * Deletes the texture from the GPU
130 * @param[in] context The GL context
132 void Destroy( Context& context );
135 * Uploads data to the texture.
136 * @param[in] context The GL context
137 * @param[in] buffer A vector with the data to be uploaded
138 * @param[in] params Upload parameters. See TextureUploadParams
140 void Upload( Context& context, Vector<unsigned char>& buffer, const Dali::TextureUploadParams& params );
143 * Bind the texture to the given texture unit and applies the given sampler
144 * @param[in] context The GL context
145 * @param[in] textureUnit the texture unit
146 * @param[in] sampler The sampler to be used with the texture
148 void Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler );
151 * Auto generates mipmaps for the texture
153 void GenerateMipmaps( Context& context );
156 * Retrieve wheter the texture has an alpha channel
157 * @return True if the texture has alpha channel, false otherwise
159 bool HasAlphaChannel();
166 unsigned int GetWidth() const
171 unsigned int GetHeight() const
184 * Helper method to apply a sampler to the texture
185 * @param[in] context The GL context
186 * @param[in] sampler The sampler
188 void ApplySampler( Context& context, Render::Sampler* sampler );
191 GLuint mId; ///<Id of the texture
192 Type mType; ///<Type of the texture
193 GLenum mInternalFormat; ///<The format of the pixel data
194 GLenum mPixelDataType; ///<The data type of the pixel data
195 unsigned int mWidth; ///<Widht of the texture
196 unsigned int mHeight; ///<Height of the texture
197 Render::Sampler mSampler; ///<The current sampler state
198 bool mHasAlpha : 1; ///<Whether the format has an alpha channel
202 } // namespace Render
204 } // namespace Internal
209 #endif // DALI_INTERNAL_RENDER_TEXTURE_H