1 #ifndef DALI_GRAPHICS_GLES_TEXTURE_H
2 #define DALI_GRAPHICS_GLES_TEXTURE_H
5 * Copyright (c) 2021 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/graphics-api/graphics-command-buffer.h>
23 #include <dali/graphics-api/graphics-texture-create-info.h>
24 #include <dali/graphics-api/graphics-texture.h>
25 #include <dali/integration-api/gl-abstraction.h>
28 #include "gles-graphics-resource.h"
29 #include "gles-graphics-types.h"
31 namespace Dali::Graphics::GLES
33 using TextureResource = Resource<Graphics::Texture, Graphics::TextureCreateInfo>;
37 * The Texture class represents a GPU texture object. It's slightly
38 * higher level than the Vulkan VkImage (more like combined image sampler).
40 class Texture : public TextureResource
45 * @param[in] createInfo valid TextureCreateInfo structure
46 * @param[in] controller Reference to the Controller
48 Texture(const Graphics::TextureCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
53 ~Texture() override = default;
56 * @brief Called when GL resources are destroyed
58 void DestroyResource() override;
61 * @brief Returns the Gl texture
62 * @return GL texture id
64 [[nodiscard]] uint32_t GetGLTexture() const
70 * @brief Returns the type of the bound Gl texture
71 * @return The type of the bound Gl texture
73 [[nodiscard]] BoundTextureType GetTextureTypeId() const
75 return mCreateInfo.nativeImagePtr ? BoundTextureType::TEXTURE_EXTERNAL_OES : static_cast<BoundTextureType>(mCreateInfo.textureType);
79 * @brief Called when initializing the resource
81 * @return True on success
83 bool InitializeResource() override;
86 * @brief Called when UniquePtr<> on client-side dies
88 void DiscardResource() override;
90 void Bind(const TextureBinding& binding) const;
93 * @brief used to prepare native texture before drawing.
95 * Checks if native texture has changed size (e.g. if rotated)
96 * and updates as appropriate.
98 * Gives the callback a chance to draw to the backing texture.
103 * @brief Returns the GL Target
104 * @return the Gl target
106 [[nodiscard]] GLenum GetGlTarget() const
112 * @brief Sets the maximum mipmap level
113 * @param[in] maxMipMapLevel The maximum mipmap level
115 void SetMaxMipMapLevel(const uint32_t maxMipMapLevel)
117 mMaxMipMapLevel = maxMipMapLevel;
121 * @brief Returns the maximum mipmap level
122 * @return The maximum mipmap level
124 [[nodiscard]] uint32_t GetMaxMipMapLevel() const
126 return mMaxMipMapLevel;
130 * @param pData Input data
131 * @param sizeInBytes Size of the input data in bytes
132 * @param width Width of the output buffer
133 * @param height height of the output buffer
134 * @param outputBuffer The buffer to write to
135 * @return true if converted, or false otherwise
137 bool TryConvertPixelData(const void* pData, Graphics::Format srcFormat, Graphics::Format destFormat, uint32_t sizeInBytes, uint32_t width, uint32_t height, std::vector<uint8_t>& outputBuffer);
139 bool InitializeNativeImage();
141 bool InitializeTexture();
143 Format ValidateFormat(Format sourceFormat);
147 return mIsCompressed;
150 void SetSamplerParameter(uint32_t param, uint32_t& cacheValue, uint32_t value) const;
153 mutable struct SamplerStateCache
155 uint32_t minFilter{0};
156 uint32_t magFilter{0};
160 uint32_t maxLevel{0};
161 } mDefaultSamplerState;
163 std::vector<char> mStagingBuffer;
164 uint32_t mTextureId{0u};
165 GLenum mGlTarget{0u};
166 uint32_t mMaxMipMapLevel{0u};
167 void* mGLOwnerContext{nullptr};
168 bool mIsCompressed{false};
171 } // namespace Dali::Graphics::GLES