2 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "test-graphics-texture.h"
18 #include <dali/integration-api/pixel-data-integ.h>
24 // These match the GL specification
25 const GLint GL_MINIFY_DEFAULT = GL_NEAREST_MIPMAP_LINEAR;
26 const GLint GL_MAGNIFY_DEFAULT = GL_LINEAR;
27 const GLint GL_WRAP_DEFAULT = GL_CLAMP_TO_EDGE;
29 // These are the Dali defaults
30 const GLint DALI_MINIFY_DEFAULT = GL_LINEAR;
31 const GLint DALI_MAGNIFY_DEFAULT = GL_LINEAR;
33 GLuint GetTextureTarget(Graphics::TextureType type)
35 GLuint target{GL_TEXTURE_2D};
39 case Graphics::TextureType::TEXTURE_2D:
40 target = GL_TEXTURE_2D; // Native texture may override this with GL_TEXTURE_EXTERNAL_OES
42 case Graphics::TextureType::TEXTURE_3D:
43 target = GL_TEXTURE_3D;
45 case Graphics::TextureType::TEXTURE_CUBEMAP:
46 target = GL_TEXTURE_CUBE_MAP;
53 * @brief Whether specified pixel format is compressed.
55 * @param [in] pixelformat Pixel format
56 * @return true if format is compressed, false otherwise
58 bool IsCompressedFormat(Graphics::Format pixelFormat)
62 case Graphics::Format::UNDEFINED:
63 case Graphics::Format::L8:
64 case Graphics::Format::L8A8:
65 case Graphics::Format::R4G4_UNORM_PACK8:
66 case Graphics::Format::R4G4B4A4_UNORM_PACK16:
67 case Graphics::Format::B4G4R4A4_UNORM_PACK16:
68 case Graphics::Format::R5G6B5_UNORM_PACK16:
69 case Graphics::Format::B5G6R5_UNORM_PACK16:
70 case Graphics::Format::R5G5B5A1_UNORM_PACK16:
71 case Graphics::Format::B5G5R5A1_UNORM_PACK16:
72 case Graphics::Format::A1R5G5B5_UNORM_PACK16:
73 case Graphics::Format::R8_UNORM:
74 case Graphics::Format::R8_SNORM:
75 case Graphics::Format::R8_USCALED:
76 case Graphics::Format::R8_SSCALED:
77 case Graphics::Format::R8_UINT:
78 case Graphics::Format::R8_SINT:
79 case Graphics::Format::R8_SRGB:
80 case Graphics::Format::R8G8_UNORM:
81 case Graphics::Format::R8G8_SNORM:
82 case Graphics::Format::R8G8_USCALED:
83 case Graphics::Format::R8G8_SSCALED:
84 case Graphics::Format::R8G8_UINT:
85 case Graphics::Format::R8G8_SINT:
86 case Graphics::Format::R8G8_SRGB:
87 case Graphics::Format::R8G8B8_UNORM:
88 case Graphics::Format::R8G8B8_SNORM:
89 case Graphics::Format::R8G8B8_USCALED:
90 case Graphics::Format::R8G8B8_SSCALED:
91 case Graphics::Format::R8G8B8_UINT:
92 case Graphics::Format::R8G8B8_SINT:
93 case Graphics::Format::R8G8B8_SRGB:
94 case Graphics::Format::B8G8R8_UNORM:
95 case Graphics::Format::B8G8R8_SNORM:
96 case Graphics::Format::B8G8R8_USCALED:
97 case Graphics::Format::B8G8R8_SSCALED:
98 case Graphics::Format::B8G8R8_UINT:
99 case Graphics::Format::B8G8R8_SINT:
100 case Graphics::Format::B8G8R8_SRGB:
101 case Graphics::Format::R8G8B8A8_UNORM:
102 case Graphics::Format::R8G8B8A8_SNORM:
103 case Graphics::Format::R8G8B8A8_USCALED:
104 case Graphics::Format::R8G8B8A8_SSCALED:
105 case Graphics::Format::R8G8B8A8_UINT:
106 case Graphics::Format::R8G8B8A8_SINT:
107 case Graphics::Format::R8G8B8A8_SRGB:
108 case Graphics::Format::B8G8R8A8_UNORM:
109 case Graphics::Format::B8G8R8A8_SNORM:
110 case Graphics::Format::B8G8R8A8_USCALED:
111 case Graphics::Format::B8G8R8A8_SSCALED:
112 case Graphics::Format::B8G8R8A8_UINT:
113 case Graphics::Format::B8G8R8A8_SINT:
114 case Graphics::Format::B8G8R8A8_SRGB:
115 case Graphics::Format::A8B8G8R8_UNORM_PACK32:
116 case Graphics::Format::A8B8G8R8_SNORM_PACK32:
117 case Graphics::Format::A8B8G8R8_USCALED_PACK32:
118 case Graphics::Format::A8B8G8R8_SSCALED_PACK32:
119 case Graphics::Format::A8B8G8R8_UINT_PACK32:
120 case Graphics::Format::A8B8G8R8_SINT_PACK32:
121 case Graphics::Format::A8B8G8R8_SRGB_PACK32:
122 case Graphics::Format::A2R10G10B10_UNORM_PACK32:
123 case Graphics::Format::A2R10G10B10_SNORM_PACK32:
124 case Graphics::Format::A2R10G10B10_USCALED_PACK32:
125 case Graphics::Format::A2R10G10B10_SSCALED_PACK32:
126 case Graphics::Format::A2R10G10B10_UINT_PACK32:
127 case Graphics::Format::A2R10G10B10_SINT_PACK32:
128 case Graphics::Format::A2B10G10R10_UNORM_PACK32:
129 case Graphics::Format::A2B10G10R10_SNORM_PACK32:
130 case Graphics::Format::A2B10G10R10_USCALED_PACK32:
131 case Graphics::Format::A2B10G10R10_SSCALED_PACK32:
132 case Graphics::Format::A2B10G10R10_UINT_PACK32:
133 case Graphics::Format::A2B10G10R10_SINT_PACK32:
134 case Graphics::Format::R16_UNORM:
135 case Graphics::Format::R16_SNORM:
136 case Graphics::Format::R16_USCALED:
137 case Graphics::Format::R16_SSCALED:
138 case Graphics::Format::R16_UINT:
139 case Graphics::Format::R16_SINT:
140 case Graphics::Format::R16_SFLOAT:
141 case Graphics::Format::R16G16_UNORM:
142 case Graphics::Format::R16G16_SNORM:
143 case Graphics::Format::R16G16_USCALED:
144 case Graphics::Format::R16G16_SSCALED:
145 case Graphics::Format::R16G16_UINT:
146 case Graphics::Format::R16G16_SINT:
147 case Graphics::Format::R16G16_SFLOAT:
148 case Graphics::Format::R16G16B16_UNORM:
149 case Graphics::Format::R16G16B16_SNORM:
150 case Graphics::Format::R16G16B16_USCALED:
151 case Graphics::Format::R16G16B16_SSCALED:
152 case Graphics::Format::R16G16B16_UINT:
153 case Graphics::Format::R16G16B16_SINT:
154 case Graphics::Format::R16G16B16_SFLOAT:
155 case Graphics::Format::R16G16B16A16_UNORM:
156 case Graphics::Format::R16G16B16A16_SNORM:
157 case Graphics::Format::R16G16B16A16_USCALED:
158 case Graphics::Format::R16G16B16A16_SSCALED:
159 case Graphics::Format::R16G16B16A16_UINT:
160 case Graphics::Format::R16G16B16A16_SINT:
161 case Graphics::Format::R16G16B16A16_SFLOAT:
162 case Graphics::Format::R32_UINT:
163 case Graphics::Format::R32_SINT:
164 case Graphics::Format::R32_SFLOAT:
165 case Graphics::Format::R32G32_UINT:
166 case Graphics::Format::R32G32_SINT:
167 case Graphics::Format::R32G32_SFLOAT:
168 case Graphics::Format::R32G32B32_UINT:
169 case Graphics::Format::R32G32B32_SINT:
170 case Graphics::Format::R32G32B32_SFLOAT:
171 case Graphics::Format::R32G32B32A32_UINT:
172 case Graphics::Format::R32G32B32A32_SINT:
173 case Graphics::Format::R32G32B32A32_SFLOAT:
174 case Graphics::Format::R64_UINT:
175 case Graphics::Format::R64_SINT:
176 case Graphics::Format::R64_SFLOAT:
177 case Graphics::Format::R64G64_UINT:
178 case Graphics::Format::R64G64_SINT:
179 case Graphics::Format::R64G64_SFLOAT:
180 case Graphics::Format::R64G64B64_UINT:
181 case Graphics::Format::R64G64B64_SINT:
182 case Graphics::Format::R64G64B64_SFLOAT:
183 case Graphics::Format::R64G64B64A64_UINT:
184 case Graphics::Format::R64G64B64A64_SINT:
185 case Graphics::Format::R64G64B64A64_SFLOAT:
186 case Graphics::Format::B10G11R11_UFLOAT_PACK32:
187 case Graphics::Format::R11G11B10_UFLOAT_PACK32:
188 case Graphics::Format::E5B9G9R9_UFLOAT_PACK32:
189 case Graphics::Format::D16_UNORM:
190 case Graphics::Format::X8_D24_UNORM_PACK32:
191 case Graphics::Format::D32_SFLOAT:
192 case Graphics::Format::S8_UINT:
193 case Graphics::Format::D16_UNORM_S8_UINT:
194 case Graphics::Format::D24_UNORM_S8_UINT:
195 case Graphics::Format::D32_SFLOAT_S8_UINT:
196 case Graphics::Format::BC1_RGB_UNORM_BLOCK:
197 case Graphics::Format::BC1_RGB_SRGB_BLOCK:
198 case Graphics::Format::BC1_RGBA_UNORM_BLOCK:
199 case Graphics::Format::BC1_RGBA_SRGB_BLOCK:
200 case Graphics::Format::BC2_UNORM_BLOCK:
201 case Graphics::Format::BC2_SRGB_BLOCK:
202 case Graphics::Format::BC3_UNORM_BLOCK:
203 case Graphics::Format::BC3_SRGB_BLOCK:
204 case Graphics::Format::BC4_UNORM_BLOCK:
205 case Graphics::Format::BC4_SNORM_BLOCK:
206 case Graphics::Format::BC5_UNORM_BLOCK:
207 case Graphics::Format::BC5_SNORM_BLOCK:
208 case Graphics::Format::BC6H_UFLOAT_BLOCK:
209 case Graphics::Format::BC6H_SFLOAT_BLOCK:
210 case Graphics::Format::BC7_UNORM_BLOCK:
211 case Graphics::Format::BC7_SRGB_BLOCK:
216 case Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK:
217 case Graphics::Format::ETC2_R8G8B8_SRGB_BLOCK:
218 case Graphics::Format::ETC2_R8G8B8A1_UNORM_BLOCK:
219 case Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK:
220 case Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK:
221 case Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK:
222 case Graphics::Format::EAC_R11_UNORM_BLOCK:
223 case Graphics::Format::EAC_R11_SNORM_BLOCK:
224 case Graphics::Format::EAC_R11G11_UNORM_BLOCK:
225 case Graphics::Format::EAC_R11G11_SNORM_BLOCK:
226 case Graphics::Format::ASTC_4x4_UNORM_BLOCK:
227 case Graphics::Format::ASTC_4x4_SRGB_BLOCK:
228 case Graphics::Format::ASTC_5x4_UNORM_BLOCK:
229 case Graphics::Format::ASTC_5x4_SRGB_BLOCK:
230 case Graphics::Format::ASTC_5x5_UNORM_BLOCK:
231 case Graphics::Format::ASTC_5x5_SRGB_BLOCK:
232 case Graphics::Format::ASTC_6x5_UNORM_BLOCK:
233 case Graphics::Format::ASTC_6x5_SRGB_BLOCK:
234 case Graphics::Format::ASTC_6x6_UNORM_BLOCK:
235 case Graphics::Format::ASTC_6x6_SRGB_BLOCK:
236 case Graphics::Format::ASTC_8x5_UNORM_BLOCK:
237 case Graphics::Format::ASTC_8x5_SRGB_BLOCK:
238 case Graphics::Format::ASTC_8x6_UNORM_BLOCK:
239 case Graphics::Format::ASTC_8x6_SRGB_BLOCK:
240 case Graphics::Format::ASTC_8x8_UNORM_BLOCK:
241 case Graphics::Format::ASTC_8x8_SRGB_BLOCK:
242 case Graphics::Format::ASTC_10x5_UNORM_BLOCK:
243 case Graphics::Format::ASTC_10x5_SRGB_BLOCK:
244 case Graphics::Format::ASTC_10x6_UNORM_BLOCK:
245 case Graphics::Format::ASTC_10x6_SRGB_BLOCK:
246 case Graphics::Format::ASTC_10x8_UNORM_BLOCK:
247 case Graphics::Format::ASTC_10x8_SRGB_BLOCK:
248 case Graphics::Format::ASTC_10x10_UNORM_BLOCK:
249 case Graphics::Format::ASTC_10x10_SRGB_BLOCK:
250 case Graphics::Format::ASTC_12x10_UNORM_BLOCK:
251 case Graphics::Format::ASTC_12x10_SRGB_BLOCK:
252 case Graphics::Format::ASTC_12x12_UNORM_BLOCK:
253 case Graphics::Format::ASTC_12x12_SRGB_BLOCK:
254 case Graphics::Format::PVRTC1_2BPP_UNORM_BLOCK_IMG:
255 case Graphics::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG:
256 case Graphics::Format::PVRTC2_2BPP_UNORM_BLOCK_IMG:
257 case Graphics::Format::PVRTC2_4BPP_UNORM_BLOCK_IMG:
258 case Graphics::Format::PVRTC1_2BPP_SRGB_BLOCK_IMG:
259 case Graphics::Format::PVRTC1_4BPP_SRGB_BLOCK_IMG:
260 case Graphics::Format::PVRTC2_2BPP_SRGB_BLOCK_IMG:
261 case Graphics::Format::PVRTC2_4BPP_SRGB_BLOCK_IMG:
271 * @brief Retrives the GL format, GL internal format and pixel data type from a Graphics::Format
272 * @param[in] pixelFormat The pixel format.
273 * @param[out] glFormat The gl format.
274 * @param[out] glInternalFormat The gl internal format.
275 * @param[out] pixelDataType The data type of the pixel data.
277 void PixelFormatToGl(Graphics::Format pixelFormat, GLenum& glFormat, GLint& glInternalFormat, GLenum& pixelDataType)
279 // Compressed textures have no pixelDataType, so init to an invalid value:
284 case Graphics::Format::R8_UNORM:
286 pixelDataType = GL_UNSIGNED_BYTE;
291 case Graphics::Format::L8:
293 pixelDataType = GL_UNSIGNED_BYTE;
294 glFormat = GL_LUMINANCE;
298 case Graphics::Format::L8A8:
300 pixelDataType = GL_UNSIGNED_BYTE;
301 glFormat = GL_LUMINANCE_ALPHA;
305 case Graphics::Format::R5G6B5_UNORM_PACK16:
307 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
312 case Graphics::Format::B5G6R5_UNORM_PACK16:
314 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
316 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
318 glFormat = GL_RGBA; // alpha is reserved but not used
323 case Graphics::Format::R4G4B4A4_UNORM_PACK16:
325 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
330 case Graphics::Format::B4G4R4A4_UNORM_PACK16:
332 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
334 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
336 glFormat = GL_RGBA; // alpha is reserved but not used
341 case Graphics::Format::R5G5B5A1_UNORM_PACK16:
343 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
348 case Graphics::Format::B5G5R5A1_UNORM_PACK16:
350 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
352 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
354 glFormat = GL_RGBA; // alpha is reserved but not used
359 case Graphics::Format::R8G8B8_UNORM:
361 pixelDataType = GL_UNSIGNED_BYTE;
366 case Graphics::Format::R8G8B8A8_UNORM:
368 pixelDataType = GL_UNSIGNED_BYTE;
369 glFormat = GL_RGBA; // alpha is reserved but not used
373 case Graphics::Format::B8G8R8A8_UNORM:
375 pixelDataType = GL_UNSIGNED_BYTE;
377 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
379 glFormat = GL_RGBA; // alpha is reserved but not used
384 case Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK:
386 glFormat = GL_COMPRESSED_RGB8_ETC2;
390 case Graphics::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG:
392 glFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
396 // GLES 3.0 standard compressed formats:
397 case Graphics::Format::EAC_R11_UNORM_BLOCK:
399 glFormat = GL_COMPRESSED_R11_EAC;
402 case Graphics::Format::EAC_R11_SNORM_BLOCK:
404 glFormat = GL_COMPRESSED_SIGNED_R11_EAC;
407 case Graphics::Format::EAC_R11G11_UNORM_BLOCK:
409 glFormat = GL_COMPRESSED_RG11_EAC;
412 case Graphics::Format::EAC_R11G11_SNORM_BLOCK:
414 glFormat = GL_COMPRESSED_SIGNED_RG11_EAC;
417 case Graphics::Format::ETC2_R8G8B8_SRGB_BLOCK:
419 glFormat = GL_COMPRESSED_SRGB8_ETC2;
422 case Graphics::Format::ETC2_R8G8B8A1_UNORM_BLOCK:
424 glFormat = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
427 case Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK:
429 glFormat = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
432 case Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK:
434 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
438 // GLES 3.1 extension compressed formats:
439 case Graphics::Format::ASTC_4x4_UNORM_BLOCK:
441 glFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
444 case Graphics::Format::ASTC_5x4_UNORM_BLOCK:
446 glFormat = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
449 case Graphics::Format::ASTC_5x5_UNORM_BLOCK:
451 glFormat = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
454 case Graphics::Format::ASTC_6x5_UNORM_BLOCK:
456 glFormat = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
459 case Graphics::Format::ASTC_6x6_UNORM_BLOCK:
461 glFormat = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
464 case Graphics::Format::ASTC_8x5_UNORM_BLOCK:
466 glFormat = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
469 case Graphics::Format::ASTC_8x6_UNORM_BLOCK:
471 glFormat = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
474 case Graphics::Format::ASTC_8x8_UNORM_BLOCK:
476 glFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
479 case Graphics::Format::ASTC_10x5_UNORM_BLOCK:
481 glFormat = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
484 case Graphics::Format::ASTC_10x6_UNORM_BLOCK:
486 glFormat = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
489 case Graphics::Format::ASTC_10x8_UNORM_BLOCK:
491 glFormat = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
494 case Graphics::Format::ASTC_10x10_UNORM_BLOCK:
496 glFormat = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
499 case Graphics::Format::ASTC_12x10_UNORM_BLOCK:
501 glFormat = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
504 case Graphics::Format::ASTC_12x12_UNORM_BLOCK:
506 glFormat = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
510 case Graphics::Format::ASTC_4x4_SRGB_BLOCK:
512 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
515 case Graphics::Format::ASTC_5x4_SRGB_BLOCK:
517 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
520 case Graphics::Format::ASTC_5x5_SRGB_BLOCK:
522 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
525 case Graphics::Format::ASTC_6x5_SRGB_BLOCK:
527 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
530 case Graphics::Format::ASTC_6x6_SRGB_BLOCK:
532 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
535 case Graphics::Format::ASTC_8x5_SRGB_BLOCK:
537 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
540 case Graphics::Format::ASTC_8x6_SRGB_BLOCK:
542 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
545 case Graphics::Format::ASTC_8x8_SRGB_BLOCK:
547 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
550 case Graphics::Format::ASTC_10x5_SRGB_BLOCK:
552 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
555 case Graphics::Format::ASTC_10x6_SRGB_BLOCK:
557 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
560 case Graphics::Format::ASTC_10x8_SRGB_BLOCK:
562 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
565 case Graphics::Format::ASTC_10x10_SRGB_BLOCK:
567 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
570 case Graphics::Format::ASTC_12x10_SRGB_BLOCK:
572 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
575 case Graphics::Format::ASTC_12x12_SRGB_BLOCK:
577 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
581 // GLES 3.0 floating point formats.
582 case Graphics::Format::R16G16B16_SFLOAT:
585 pixelDataType = GL_HALF_FLOAT;
588 case Graphics::Format::R32G32B32_SFLOAT:
591 pixelDataType = GL_FLOAT;
595 // GLES 3.0 depth and stencil formats
596 case Graphics::Format::D16_UNORM:
598 glFormat = GL_DEPTH_COMPONENT;
599 pixelDataType = GL_UNSIGNED_INT;
603 case Graphics::Format::D32_SFLOAT:
605 glFormat = GL_DEPTH_COMPONENT;
606 pixelDataType = GL_FLOAT;
610 case Graphics::Format::D24_UNORM_S8_UINT:
612 glFormat = GL_DEPTH_STENCIL;
613 pixelDataType = GL_UNSIGNED_INT_24_8;
617 case Graphics::Format::UNDEFINED:
619 //DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
623 case Graphics::Format::R11G11B10_UFLOAT_PACK32:
626 pixelDataType = GL_FLOAT;
630 case Graphics::Format::R4G4_UNORM_PACK8:
631 case Graphics::Format::A1R5G5B5_UNORM_PACK16:
632 case Graphics::Format::R8_SNORM:
633 case Graphics::Format::R8_USCALED:
634 case Graphics::Format::R8_SSCALED:
635 case Graphics::Format::R8_UINT:
636 case Graphics::Format::R8_SINT:
637 case Graphics::Format::R8_SRGB:
638 case Graphics::Format::R8G8_UNORM:
639 case Graphics::Format::R8G8_SNORM:
640 case Graphics::Format::R8G8_USCALED:
641 case Graphics::Format::R8G8_SSCALED:
642 case Graphics::Format::R8G8_UINT:
643 case Graphics::Format::R8G8_SINT:
644 case Graphics::Format::R8G8_SRGB:
645 case Graphics::Format::R8G8B8_SNORM:
646 case Graphics::Format::R8G8B8_USCALED:
647 case Graphics::Format::R8G8B8_SSCALED:
648 case Graphics::Format::R8G8B8_UINT:
649 case Graphics::Format::R8G8B8_SINT:
650 case Graphics::Format::R8G8B8_SRGB:
651 case Graphics::Format::B8G8R8_UNORM:
652 case Graphics::Format::B8G8R8_SNORM:
653 case Graphics::Format::B8G8R8_USCALED:
654 case Graphics::Format::B8G8R8_SSCALED:
655 case Graphics::Format::B8G8R8_UINT:
656 case Graphics::Format::B8G8R8_SINT:
657 case Graphics::Format::B8G8R8_SRGB:
658 case Graphics::Format::R8G8B8A8_SNORM:
659 case Graphics::Format::R8G8B8A8_USCALED:
660 case Graphics::Format::R8G8B8A8_SSCALED:
661 case Graphics::Format::R8G8B8A8_UINT:
662 case Graphics::Format::R8G8B8A8_SINT:
663 case Graphics::Format::R8G8B8A8_SRGB:
664 case Graphics::Format::B8G8R8A8_SNORM:
665 case Graphics::Format::B8G8R8A8_USCALED:
666 case Graphics::Format::B8G8R8A8_SSCALED:
667 case Graphics::Format::B8G8R8A8_UINT:
668 case Graphics::Format::B8G8R8A8_SINT:
669 case Graphics::Format::B8G8R8A8_SRGB:
670 case Graphics::Format::A8B8G8R8_UNORM_PACK32:
671 case Graphics::Format::A8B8G8R8_SNORM_PACK32:
672 case Graphics::Format::A8B8G8R8_USCALED_PACK32:
673 case Graphics::Format::A8B8G8R8_SSCALED_PACK32:
674 case Graphics::Format::A8B8G8R8_UINT_PACK32:
675 case Graphics::Format::A8B8G8R8_SINT_PACK32:
676 case Graphics::Format::A8B8G8R8_SRGB_PACK32:
677 case Graphics::Format::A2R10G10B10_UNORM_PACK32:
678 case Graphics::Format::A2R10G10B10_SNORM_PACK32:
679 case Graphics::Format::A2R10G10B10_USCALED_PACK32:
680 case Graphics::Format::A2R10G10B10_SSCALED_PACK32:
681 case Graphics::Format::A2R10G10B10_UINT_PACK32:
682 case Graphics::Format::A2R10G10B10_SINT_PACK32:
683 case Graphics::Format::A2B10G10R10_UNORM_PACK32:
684 case Graphics::Format::A2B10G10R10_SNORM_PACK32:
685 case Graphics::Format::A2B10G10R10_USCALED_PACK32:
686 case Graphics::Format::A2B10G10R10_SSCALED_PACK32:
687 case Graphics::Format::A2B10G10R10_UINT_PACK32:
688 case Graphics::Format::A2B10G10R10_SINT_PACK32:
689 case Graphics::Format::R16_UNORM:
690 case Graphics::Format::R16_SNORM:
691 case Graphics::Format::R16_USCALED:
692 case Graphics::Format::R16_SSCALED:
693 case Graphics::Format::R16_UINT:
694 case Graphics::Format::R16_SINT:
695 case Graphics::Format::R16_SFLOAT:
696 case Graphics::Format::R16G16_UNORM:
697 case Graphics::Format::R16G16_SNORM:
698 case Graphics::Format::R16G16_USCALED:
699 case Graphics::Format::R16G16_SSCALED:
700 case Graphics::Format::R16G16_UINT:
701 case Graphics::Format::R16G16_SINT:
702 case Graphics::Format::R16G16_SFLOAT:
703 case Graphics::Format::R16G16B16_UNORM:
704 case Graphics::Format::R16G16B16_SNORM:
705 case Graphics::Format::R16G16B16_USCALED:
706 case Graphics::Format::R16G16B16_SSCALED:
707 case Graphics::Format::R16G16B16_UINT:
708 case Graphics::Format::R16G16B16_SINT:
709 case Graphics::Format::R16G16B16A16_UNORM:
710 case Graphics::Format::R16G16B16A16_SNORM:
711 case Graphics::Format::R16G16B16A16_USCALED:
712 case Graphics::Format::R16G16B16A16_SSCALED:
713 case Graphics::Format::R16G16B16A16_UINT:
714 case Graphics::Format::R16G16B16A16_SINT:
715 case Graphics::Format::R16G16B16A16_SFLOAT:
716 case Graphics::Format::R32_UINT:
717 case Graphics::Format::R32_SINT:
718 case Graphics::Format::R32_SFLOAT:
719 case Graphics::Format::R32G32_UINT:
720 case Graphics::Format::R32G32_SINT:
721 case Graphics::Format::R32G32_SFLOAT:
722 case Graphics::Format::R32G32B32_UINT:
723 case Graphics::Format::R32G32B32_SINT:
724 case Graphics::Format::R32G32B32A32_UINT:
725 case Graphics::Format::R32G32B32A32_SINT:
726 case Graphics::Format::R32G32B32A32_SFLOAT:
727 case Graphics::Format::R64_UINT:
728 case Graphics::Format::R64_SINT:
729 case Graphics::Format::R64_SFLOAT:
730 case Graphics::Format::R64G64_UINT:
731 case Graphics::Format::R64G64_SINT:
732 case Graphics::Format::R64G64_SFLOAT:
733 case Graphics::Format::R64G64B64_UINT:
734 case Graphics::Format::R64G64B64_SINT:
735 case Graphics::Format::R64G64B64_SFLOAT:
736 case Graphics::Format::R64G64B64A64_UINT:
737 case Graphics::Format::R64G64B64A64_SINT:
738 case Graphics::Format::R64G64B64A64_SFLOAT:
739 case Graphics::Format::B10G11R11_UFLOAT_PACK32:
740 case Graphics::Format::E5B9G9R9_UFLOAT_PACK32:
741 case Graphics::Format::X8_D24_UNORM_PACK32:
742 case Graphics::Format::S8_UINT:
743 case Graphics::Format::D16_UNORM_S8_UINT:
744 case Graphics::Format::D32_SFLOAT_S8_UINT:
745 case Graphics::Format::BC1_RGB_UNORM_BLOCK:
746 case Graphics::Format::BC1_RGB_SRGB_BLOCK:
747 case Graphics::Format::BC1_RGBA_UNORM_BLOCK:
748 case Graphics::Format::BC1_RGBA_SRGB_BLOCK:
749 case Graphics::Format::BC2_UNORM_BLOCK:
750 case Graphics::Format::BC2_SRGB_BLOCK:
751 case Graphics::Format::BC3_UNORM_BLOCK:
752 case Graphics::Format::BC3_SRGB_BLOCK:
753 case Graphics::Format::BC4_UNORM_BLOCK:
754 case Graphics::Format::BC4_SNORM_BLOCK:
755 case Graphics::Format::BC5_UNORM_BLOCK:
756 case Graphics::Format::BC5_SNORM_BLOCK:
757 case Graphics::Format::BC6H_UFLOAT_BLOCK:
758 case Graphics::Format::BC6H_SFLOAT_BLOCK:
759 case Graphics::Format::BC7_UNORM_BLOCK:
760 case Graphics::Format::BC7_SRGB_BLOCK:
761 case Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK:
762 case Graphics::Format::PVRTC1_2BPP_UNORM_BLOCK_IMG:
763 case Graphics::Format::PVRTC2_2BPP_UNORM_BLOCK_IMG:
764 case Graphics::Format::PVRTC2_4BPP_UNORM_BLOCK_IMG:
765 case Graphics::Format::PVRTC1_2BPP_SRGB_BLOCK_IMG:
766 case Graphics::Format::PVRTC1_4BPP_SRGB_BLOCK_IMG:
767 case Graphics::Format::PVRTC2_2BPP_SRGB_BLOCK_IMG:
768 case Graphics::Format::PVRTC2_4BPP_SRGB_BLOCK_IMG:
777 case Graphics::Format::R16G16B16A16_SFLOAT:
778 case Graphics::Format::R32G32B32A32_SFLOAT:
779 case Graphics::Format::R11G11B10_UFLOAT_PACK32:
781 glInternalFormat = GL_R11F_G11F_B10F;
784 case Graphics::Format::D32_SFLOAT:
786 glInternalFormat = GL_DEPTH_COMPONENT32F;
789 case Graphics::Format::D24_UNORM_S8_UINT:
791 glInternalFormat = GL_DEPTH24_STENCIL8;
796 glInternalFormat = glFormat;
803 TestGraphicsTexture::TestGraphicsTexture(TestGlAbstraction& glAbstraction, const Graphics::TextureCreateInfo& createInfo)
804 : mGlAbstraction(glAbstraction),
805 mCreateInfo(createInfo),
806 mIsCompressed(IsCompressedFormat(createInfo.format))
808 GLuint target = GetTarget();
809 if(mCreateInfo.nativeImagePtr)
811 InitializeNativeImage(target);
817 if(mCreateInfo.textureType == Graphics::TextureType::TEXTURE_2D)
821 glAbstraction.TexImage2D(target, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, mGlFormat, mPixelDataType, nullptr);
825 glAbstraction.CompressedTexImage2D(target, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, 0, nullptr);
828 else if(mCreateInfo.textureType == Graphics::TextureType::TEXTURE_CUBEMAP)
832 for(uint32_t i(0); i < 6; ++i)
834 glAbstraction.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, mGlFormat, mPixelDataType, nullptr);
839 for(uint32_t i(0); i < 6; ++i)
841 glAbstraction.CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, 0, nullptr);
844 TestGraphicsSampler::SetTexParameter(glAbstraction, target, GL_TEXTURE_WRAP_R, GL_WRAP_DEFAULT);
849 TestGraphicsTexture::~TestGraphicsTexture()
851 mGlAbstraction.DeleteTextures(1, &mId);
852 if(mCreateInfo.nativeImagePtr)
854 mCreateInfo.nativeImagePtr->DestroyResource();
858 void TestGraphicsTexture::Initialize(GLuint target)
860 PixelFormatToGl(mCreateInfo.format,
865 mGlAbstraction.GenTextures(1, &mId);
866 mGlAbstraction.BindTexture(target, mId);
867 mGlAbstraction.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
869 //Apply default sampling parameters
870 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT);
871 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT);
872 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT);
873 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT);
876 void TestGraphicsTexture::InitializeNativeImage(GLuint target)
878 mCreateInfo.nativeImagePtr->CreateResource();
881 if(mCreateInfo.nativeImagePtr->TargetTexture() != 0u) // This can definitely fail
883 mGlAbstraction.DeleteTextures(1, &mId);
884 mCreateInfo.nativeImagePtr->DestroyResource();
889 GLuint TestGraphicsTexture::GetTarget()
892 if(mCreateInfo.nativeImagePtr)
894 target = mCreateInfo.nativeImagePtr->GetTextureTarget(); // Could be GL_TEXTURE_2D or GL_TEXTURE_EXTERNAL_OES
898 target = GetTextureTarget(mCreateInfo.textureType);
903 void TestGraphicsTexture::Bind(uint32_t textureUnit)
905 if(mCreateInfo.nativeImagePtr)
909 InitializeNativeImage(GetTarget());
912 mGlAbstraction.ActiveTexture(textureUnit + GL_TEXTURE0);
913 mGlAbstraction.BindTexture(GetTarget(), mId);
916 void TestGraphicsTexture::Prepare()
918 if(mCreateInfo.nativeImagePtr)
920 // Ensure the native image is up-to-date
921 mCreateInfo.nativeImagePtr->PrepareTexture();
925 void TestGraphicsTexture::Update(Graphics::TextureUpdateInfo updateInfo, Graphics::TextureUpdateSourceInfo source)
927 GLenum target{GetTarget()};
928 if(mCreateInfo.textureType == Graphics::TextureType::TEXTURE_CUBEMAP)
930 target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + updateInfo.layer;
933 mGlAbstraction.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
935 const bool isSubImage(updateInfo.dstOffset2D.x != 0 || updateInfo.dstOffset2D.y != 0 ||
936 updateInfo.srcExtent2D.width != (mCreateInfo.size.width / (1 << updateInfo.level)) ||
937 updateInfo.srcExtent2D.height != (mCreateInfo.size.height / (1 << updateInfo.level)));
939 uint8_t* pixels = nullptr;
940 bool releasePixels = false;
942 switch(source.sourceType)
944 case Graphics::TextureUpdateSourceInfo::Type::PIXEL_DATA:
946 auto pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(source.pixelDataSource.pixelData);
948 pixels = pixelDataBuffer.buffer;
949 releasePixels = Dali::Integration::IsPixelDataReleaseAfterUpload(source.pixelDataSource.pixelData) && updateInfo.srcOffset == 0u;
952 case Graphics::TextureUpdateSourceInfo::Type::MEMORY:
954 pixels = reinterpret_cast<uint8_t*>(source.memorySource.memory);
955 releasePixels = true;
960 // TODO : Implement here
969 mGlAbstraction.TexImage2D(target, updateInfo.level, mGlInternalFormat, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, 0, mGlFormat, mPixelDataType, pixels);
973 mGlAbstraction.CompressedTexImage2D(target, updateInfo.level, mGlInternalFormat, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, 0, updateInfo.srcSize, pixels);
980 mGlAbstraction.TexSubImage2D(target, updateInfo.level, updateInfo.dstOffset2D.x, updateInfo.dstOffset2D.y, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, mGlFormat, mPixelDataType, pixels);
984 mGlAbstraction.CompressedTexSubImage2D(target, updateInfo.level, updateInfo.dstOffset2D.x, updateInfo.dstOffset2D.y, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, mGlFormat, updateInfo.srcSize, pixels);
988 if(releasePixels && pixels != nullptr)
990 switch(source.sourceType)
992 case Graphics::TextureUpdateSourceInfo::Type::PIXEL_DATA:
994 Dali::Integration::ReleasePixelDataBuffer(source.pixelDataSource.pixelData);
997 case Graphics::TextureUpdateSourceInfo::Type::MEMORY:
999 free(reinterpret_cast<void*>(pixels));
1004 // TODO : Implement here