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 NewTexture( Type type, Pixel::Format format, unsigned int width, unsigned int height );
123 * Creates the texture in the GPU.
124 * Creates the texture and reserves memory for the first mipmap level
125 * @param[in] context The GL context
127 void Initialize(Context& context);
130 * Deletes the texture from the GPU
131 * @param[in] context The GL context
133 void Destroy( Context& context );
136 * Uploads data to the texture.
137 * @param[in] context The GL context
138 * @param[in] buffer A vector with the data to be uploaded
139 * @param[in] params Upload parameters. See UploadParams
141 void Upload( Context& context, Vector<unsigned char>& buffer, const Internal::NewTexture::UploadParams& params );
144 * Bind the texture to the given texture unit and applies the given sampler
145 * @param[in] context The GL context
146 * @param[in] textureUnit the texture unit
147 * @param[in] sampler The sampler to be used with the texture
149 void Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler );
152 * Auto generates mipmaps for the texture
153 * @param[in] context The GL context
155 void GenerateMipmaps( Context& context );
158 * Retrieve wheter the texture has an alpha channel
159 * @return True if the texture has alpha channel, false otherwise
161 bool HasAlphaChannel();
164 * Get the id of the texture
165 * @return Id of the texture
173 * Get the width of the texture
174 * @return Width of the texture
176 unsigned int GetWidth() const
182 * Get the height of the texture
183 * @return Height of the texture
185 unsigned int GetHeight() const
191 * Get the type of the texture
192 * @return Type of the texture
202 * Helper method to apply a sampler to the texture
203 * @param[in] context The GL context
204 * @param[in] sampler The sampler
206 void ApplySampler( Context& context, Render::Sampler* sampler );
209 GLuint mId; ///<Id of the texture
210 Type mType; ///<Type of the texture
211 GLenum mInternalFormat; ///<The format of the pixel data
212 GLenum mPixelDataType; ///<The data type of the pixel data
213 unsigned int mWidth; ///<Widht of the texture
214 unsigned int mHeight; ///<Height of the texture
215 Render::Sampler mSampler; ///<The current sampler state
216 bool mHasAlpha : 1; ///<Whether the format has an alpha channel
220 } // namespace Render
222 } // namespace Internal
227 #endif // DALI_INTERNAL_RENDER_TEXTURE_H