1 #ifndef DALI_INTERNAL_RENDER_TEXTURE_H
2 #define DALI_INTERNAL_RENDER_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.
21 #include <cstdint> // uint16_t, uint32_t
25 #include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
26 #include <dali/public-api/rendering/sampler.h>
27 #include <dali/public-api/rendering/texture.h>
29 #include <dali/graphics-api/graphics-controller.h>
30 #include <dali/graphics-api/graphics-texture-create-info.h>
31 #include <dali/graphics-api/graphics-texture.h>
32 #include <dali/graphics-api/graphics-types.h>
33 #include <dali/internal/event/rendering/texture-impl.h>
34 #include <dali/internal/render/renderers/render-sampler.h>
47 using Type = Dali::TextureType::Type;
51 * @param[in] type The type of the texture
52 * @param[in] format The format of the pixel data
53 * @param[in] size The size of the texture
55 Texture(Type type, Pixel::Format format, ImageDimensions size);
58 * Constructor from native image
59 * @param[in] nativeImageInterface The native image
61 explicit Texture(NativeImageInterfacePtr nativeImageInterface);
69 * Stores the graphics controller for use when required.
71 * @param[in] graphicsController The graphics controller to use
73 void Initialize(Graphics::Controller& graphicsController);
76 * Create the texture without a buffer
77 * @param[in] usage How texture will be used
79 void Create(Graphics::TextureUsageFlags usage);
82 * Create a texture with a buffer if non-null
83 * @param[in] usage How texture will be used
84 * @param[in] buffer Buffer to copy
86 void CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* buffer, uint32_t bufferSize);
89 * Deletes the texture from the GPU
94 * Uploads data to the texture.
95 * @param[in] pixelData A pixel data object
96 * @param[in] params Upload parameters. See UploadParams
98 void Upload(PixelDataPtr pixelData, const Internal::Texture::UploadParams& params);
101 * Auto generates mipmaps for the texture
103 void GenerateMipmaps();
106 * Retrieve whether the texture has an alpha channel
107 * @return True if the texture has alpha channel, false otherwise
109 [[nodiscard]] bool HasAlphaChannel() const;
112 * Get the graphics object associated with this texture
114 [[nodiscard]] Graphics::Texture* GetGraphicsObject() const;
117 * Get the type of the texture
118 * @return Type of the texture
120 [[nodiscard]] Type GetType() const
126 * Check if the texture is a native image
127 * @return if the texture is a native image
129 [[nodiscard]] bool IsNativeImage() const
136 * Helper method to apply a sampler to the texture
137 * @param[in] sampler The sampler
139 void ApplySampler(Render::Sampler* sampler);
142 Graphics::Controller* mGraphicsController;
143 Graphics::UniquePtr<Graphics::Texture> mGraphicsTexture;
145 NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
146 Render::Sampler mSampler; ///< The current sampler state
148 Pixel::Format mPixelFormat; ///< Pixel format of the texture
149 uint16_t mWidth; ///< Width of the texture
150 uint16_t mHeight; ///< Height of the texture
151 Type mType : 3; ///< Type of the texture
152 bool mHasAlpha : 1; ///< Whether the format has an alpha channel
155 } // namespace Render
157 } // namespace Internal
161 #endif // DALI_INTERNAL_RENDER_TEXTURE_H