2 * Copyright (c) 2021 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"
23 // These match the GL specification
24 const GLint GL_MINIFY_DEFAULT = GL_NEAREST_MIPMAP_LINEAR;
25 const GLint GL_MAGNIFY_DEFAULT = GL_LINEAR;
26 const GLint GL_WRAP_DEFAULT = GL_CLAMP_TO_EDGE;
28 // These are the Dali defaults
29 const GLint DALI_MINIFY_DEFAULT = GL_LINEAR;
30 const GLint DALI_MAGNIFY_DEFAULT = GL_LINEAR;
32 GLuint GetTextureTarget(Graphics::TextureType type)
34 GLuint target{GL_TEXTURE_2D};
38 case Graphics::TextureType::TEXTURE_2D:
39 target = GL_TEXTURE_2D; // Native texture may override this with GL_TEXTURE_EXTERNAL_OES
41 case Graphics::TextureType::TEXTURE_3D:
42 target = GL_TEXTURE_3D;
44 case Graphics::TextureType::TEXTURE_CUBEMAP:
45 target = GL_TEXTURE_CUBE_MAP;
52 * @brief Whether specified pixel format is compressed.
54 * @param [in] pixelformat Pixel format
55 * @return true if format is compressed, false otherwise
57 bool IsCompressedFormat(Graphics::Format pixelFormat)
61 case Graphics::Format::UNDEFINED:
62 case Graphics::Format::L8:
63 case Graphics::Format::L8A8:
64 case Graphics::Format::R4G4_UNORM_PACK8:
65 case Graphics::Format::R4G4B4A4_UNORM_PACK16:
66 case Graphics::Format::B4G4R4A4_UNORM_PACK16:
67 case Graphics::Format::R5G6B5_UNORM_PACK16:
68 case Graphics::Format::B5G6R5_UNORM_PACK16:
69 case Graphics::Format::R5G5B5A1_UNORM_PACK16:
70 case Graphics::Format::B5G5R5A1_UNORM_PACK16:
71 case Graphics::Format::A1R5G5B5_UNORM_PACK16:
72 case Graphics::Format::R8_UNORM:
73 case Graphics::Format::R8_SNORM:
74 case Graphics::Format::R8_USCALED:
75 case Graphics::Format::R8_SSCALED:
76 case Graphics::Format::R8_UINT:
77 case Graphics::Format::R8_SINT:
78 case Graphics::Format::R8_SRGB:
79 case Graphics::Format::R8G8_UNORM:
80 case Graphics::Format::R8G8_SNORM:
81 case Graphics::Format::R8G8_USCALED:
82 case Graphics::Format::R8G8_SSCALED:
83 case Graphics::Format::R8G8_UINT:
84 case Graphics::Format::R8G8_SINT:
85 case Graphics::Format::R8G8_SRGB:
86 case Graphics::Format::R8G8B8_UNORM:
87 case Graphics::Format::R8G8B8_SNORM:
88 case Graphics::Format::R8G8B8_USCALED:
89 case Graphics::Format::R8G8B8_SSCALED:
90 case Graphics::Format::R8G8B8_UINT:
91 case Graphics::Format::R8G8B8_SINT:
92 case Graphics::Format::R8G8B8_SRGB:
93 case Graphics::Format::B8G8R8_UNORM:
94 case Graphics::Format::B8G8R8_SNORM:
95 case Graphics::Format::B8G8R8_USCALED:
96 case Graphics::Format::B8G8R8_SSCALED:
97 case Graphics::Format::B8G8R8_UINT:
98 case Graphics::Format::B8G8R8_SINT:
99 case Graphics::Format::B8G8R8_SRGB:
100 case Graphics::Format::R8G8B8A8_UNORM:
101 case Graphics::Format::R8G8B8A8_SNORM:
102 case Graphics::Format::R8G8B8A8_USCALED:
103 case Graphics::Format::R8G8B8A8_SSCALED:
104 case Graphics::Format::R8G8B8A8_UINT:
105 case Graphics::Format::R8G8B8A8_SINT:
106 case Graphics::Format::R8G8B8A8_SRGB:
107 case Graphics::Format::B8G8R8A8_UNORM:
108 case Graphics::Format::B8G8R8A8_SNORM:
109 case Graphics::Format::B8G8R8A8_USCALED:
110 case Graphics::Format::B8G8R8A8_SSCALED:
111 case Graphics::Format::B8G8R8A8_UINT:
112 case Graphics::Format::B8G8R8A8_SINT:
113 case Graphics::Format::B8G8R8A8_SRGB:
114 case Graphics::Format::A8B8G8R8_UNORM_PACK32:
115 case Graphics::Format::A8B8G8R8_SNORM_PACK32:
116 case Graphics::Format::A8B8G8R8_USCALED_PACK32:
117 case Graphics::Format::A8B8G8R8_SSCALED_PACK32:
118 case Graphics::Format::A8B8G8R8_UINT_PACK32:
119 case Graphics::Format::A8B8G8R8_SINT_PACK32:
120 case Graphics::Format::A8B8G8R8_SRGB_PACK32:
121 case Graphics::Format::A2R10G10B10_UNORM_PACK32:
122 case Graphics::Format::A2R10G10B10_SNORM_PACK32:
123 case Graphics::Format::A2R10G10B10_USCALED_PACK32:
124 case Graphics::Format::A2R10G10B10_SSCALED_PACK32:
125 case Graphics::Format::A2R10G10B10_UINT_PACK32:
126 case Graphics::Format::A2R10G10B10_SINT_PACK32:
127 case Graphics::Format::A2B10G10R10_UNORM_PACK32:
128 case Graphics::Format::A2B10G10R10_SNORM_PACK32:
129 case Graphics::Format::A2B10G10R10_USCALED_PACK32:
130 case Graphics::Format::A2B10G10R10_SSCALED_PACK32:
131 case Graphics::Format::A2B10G10R10_UINT_PACK32:
132 case Graphics::Format::A2B10G10R10_SINT_PACK32:
133 case Graphics::Format::R16_UNORM:
134 case Graphics::Format::R16_SNORM:
135 case Graphics::Format::R16_USCALED:
136 case Graphics::Format::R16_SSCALED:
137 case Graphics::Format::R16_UINT:
138 case Graphics::Format::R16_SINT:
139 case Graphics::Format::R16_SFLOAT:
140 case Graphics::Format::R16G16_UNORM:
141 case Graphics::Format::R16G16_SNORM:
142 case Graphics::Format::R16G16_USCALED:
143 case Graphics::Format::R16G16_SSCALED:
144 case Graphics::Format::R16G16_UINT:
145 case Graphics::Format::R16G16_SINT:
146 case Graphics::Format::R16G16_SFLOAT:
147 case Graphics::Format::R16G16B16_UNORM:
148 case Graphics::Format::R16G16B16_SNORM:
149 case Graphics::Format::R16G16B16_USCALED:
150 case Graphics::Format::R16G16B16_SSCALED:
151 case Graphics::Format::R16G16B16_UINT:
152 case Graphics::Format::R16G16B16_SINT:
153 case Graphics::Format::R16G16B16_SFLOAT:
154 case Graphics::Format::R16G16B16A16_UNORM:
155 case Graphics::Format::R16G16B16A16_SNORM:
156 case Graphics::Format::R16G16B16A16_USCALED:
157 case Graphics::Format::R16G16B16A16_SSCALED:
158 case Graphics::Format::R16G16B16A16_UINT:
159 case Graphics::Format::R16G16B16A16_SINT:
160 case Graphics::Format::R16G16B16A16_SFLOAT:
161 case Graphics::Format::R32_UINT:
162 case Graphics::Format::R32_SINT:
163 case Graphics::Format::R32_SFLOAT:
164 case Graphics::Format::R32G32_UINT:
165 case Graphics::Format::R32G32_SINT:
166 case Graphics::Format::R32G32_SFLOAT:
167 case Graphics::Format::R32G32B32_UINT:
168 case Graphics::Format::R32G32B32_SINT:
169 case Graphics::Format::R32G32B32_SFLOAT:
170 case Graphics::Format::R32G32B32A32_UINT:
171 case Graphics::Format::R32G32B32A32_SINT:
172 case Graphics::Format::R32G32B32A32_SFLOAT:
173 case Graphics::Format::R64_UINT:
174 case Graphics::Format::R64_SINT:
175 case Graphics::Format::R64_SFLOAT:
176 case Graphics::Format::R64G64_UINT:
177 case Graphics::Format::R64G64_SINT:
178 case Graphics::Format::R64G64_SFLOAT:
179 case Graphics::Format::R64G64B64_UINT:
180 case Graphics::Format::R64G64B64_SINT:
181 case Graphics::Format::R64G64B64_SFLOAT:
182 case Graphics::Format::R64G64B64A64_UINT:
183 case Graphics::Format::R64G64B64A64_SINT:
184 case Graphics::Format::R64G64B64A64_SFLOAT:
185 case Graphics::Format::B10G11R11_UFLOAT_PACK32:
186 case Graphics::Format::R11G11B10_UFLOAT_PACK32:
187 case Graphics::Format::E5B9G9R9_UFLOAT_PACK32:
188 case Graphics::Format::D16_UNORM:
189 case Graphics::Format::X8_D24_UNORM_PACK32:
190 case Graphics::Format::D32_SFLOAT:
191 case Graphics::Format::S8_UINT:
192 case Graphics::Format::D16_UNORM_S8_UINT:
193 case Graphics::Format::D24_UNORM_S8_UINT:
194 case Graphics::Format::D32_SFLOAT_S8_UINT:
195 case Graphics::Format::BC1_RGB_UNORM_BLOCK:
196 case Graphics::Format::BC1_RGB_SRGB_BLOCK:
197 case Graphics::Format::BC1_RGBA_UNORM_BLOCK:
198 case Graphics::Format::BC1_RGBA_SRGB_BLOCK:
199 case Graphics::Format::BC2_UNORM_BLOCK:
200 case Graphics::Format::BC2_SRGB_BLOCK:
201 case Graphics::Format::BC3_UNORM_BLOCK:
202 case Graphics::Format::BC3_SRGB_BLOCK:
203 case Graphics::Format::BC4_UNORM_BLOCK:
204 case Graphics::Format::BC4_SNORM_BLOCK:
205 case Graphics::Format::BC5_UNORM_BLOCK:
206 case Graphics::Format::BC5_SNORM_BLOCK:
207 case Graphics::Format::BC6H_UFLOAT_BLOCK:
208 case Graphics::Format::BC6H_SFLOAT_BLOCK:
209 case Graphics::Format::BC7_UNORM_BLOCK:
210 case Graphics::Format::BC7_SRGB_BLOCK:
215 case Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK:
216 case Graphics::Format::ETC2_R8G8B8_SRGB_BLOCK:
217 case Graphics::Format::ETC2_R8G8B8A1_UNORM_BLOCK:
218 case Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK:
219 case Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK:
220 case Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK:
221 case Graphics::Format::EAC_R11_UNORM_BLOCK:
222 case Graphics::Format::EAC_R11_SNORM_BLOCK:
223 case Graphics::Format::EAC_R11G11_UNORM_BLOCK:
224 case Graphics::Format::EAC_R11G11_SNORM_BLOCK:
225 case Graphics::Format::ASTC_4x4_UNORM_BLOCK:
226 case Graphics::Format::ASTC_4x4_SRGB_BLOCK:
227 case Graphics::Format::ASTC_5x4_UNORM_BLOCK:
228 case Graphics::Format::ASTC_5x4_SRGB_BLOCK:
229 case Graphics::Format::ASTC_5x5_UNORM_BLOCK:
230 case Graphics::Format::ASTC_5x5_SRGB_BLOCK:
231 case Graphics::Format::ASTC_6x5_UNORM_BLOCK:
232 case Graphics::Format::ASTC_6x5_SRGB_BLOCK:
233 case Graphics::Format::ASTC_6x6_UNORM_BLOCK:
234 case Graphics::Format::ASTC_6x6_SRGB_BLOCK:
235 case Graphics::Format::ASTC_8x5_UNORM_BLOCK:
236 case Graphics::Format::ASTC_8x5_SRGB_BLOCK:
237 case Graphics::Format::ASTC_8x6_UNORM_BLOCK:
238 case Graphics::Format::ASTC_8x6_SRGB_BLOCK:
239 case Graphics::Format::ASTC_8x8_UNORM_BLOCK:
240 case Graphics::Format::ASTC_8x8_SRGB_BLOCK:
241 case Graphics::Format::ASTC_10x5_UNORM_BLOCK:
242 case Graphics::Format::ASTC_10x5_SRGB_BLOCK:
243 case Graphics::Format::ASTC_10x6_UNORM_BLOCK:
244 case Graphics::Format::ASTC_10x6_SRGB_BLOCK:
245 case Graphics::Format::ASTC_10x8_UNORM_BLOCK:
246 case Graphics::Format::ASTC_10x8_SRGB_BLOCK:
247 case Graphics::Format::ASTC_10x10_UNORM_BLOCK:
248 case Graphics::Format::ASTC_10x10_SRGB_BLOCK:
249 case Graphics::Format::ASTC_12x10_UNORM_BLOCK:
250 case Graphics::Format::ASTC_12x10_SRGB_BLOCK:
251 case Graphics::Format::ASTC_12x12_UNORM_BLOCK:
252 case Graphics::Format::ASTC_12x12_SRGB_BLOCK:
253 case Graphics::Format::PVRTC1_2BPP_UNORM_BLOCK_IMG:
254 case Graphics::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG:
255 case Graphics::Format::PVRTC2_2BPP_UNORM_BLOCK_IMG:
256 case Graphics::Format::PVRTC2_4BPP_UNORM_BLOCK_IMG:
257 case Graphics::Format::PVRTC1_2BPP_SRGB_BLOCK_IMG:
258 case Graphics::Format::PVRTC1_4BPP_SRGB_BLOCK_IMG:
259 case Graphics::Format::PVRTC2_2BPP_SRGB_BLOCK_IMG:
260 case Graphics::Format::PVRTC2_4BPP_SRGB_BLOCK_IMG:
270 * @brief Retrives the GL format, GL internal format and pixel data type from a Graphics::Format
271 * @param[in] pixelFormat The pixel format.
272 * @param[out] glFormat The gl format.
273 * @param[out] glInternalFormat The gl internal format.
274 * @param[out] pixelDataType The data type of the pixel data.
276 void PixelFormatToGl(Graphics::Format pixelFormat, GLenum& glFormat, GLint& glInternalFormat, GLenum& pixelDataType)
278 // Compressed textures have no pixelDataType, so init to an invalid value:
283 case Graphics::Format::R8_UNORM:
285 pixelDataType = GL_UNSIGNED_BYTE;
290 case Graphics::Format::L8:
292 pixelDataType = GL_UNSIGNED_BYTE;
293 glFormat = GL_LUMINANCE;
297 case Graphics::Format::L8A8:
299 pixelDataType = GL_UNSIGNED_BYTE;
300 glFormat = GL_LUMINANCE_ALPHA;
304 case Graphics::Format::R5G6B5_UNORM_PACK16:
306 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
311 case Graphics::Format::B5G6R5_UNORM_PACK16:
313 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
315 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
317 glFormat = GL_RGBA; // alpha is reserved but not used
322 case Graphics::Format::R4G4B4A4_UNORM_PACK16:
324 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
329 case Graphics::Format::B4G4R4A4_UNORM_PACK16:
331 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
333 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
335 glFormat = GL_RGBA; // alpha is reserved but not used
340 case Graphics::Format::R5G5B5A1_UNORM_PACK16:
342 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
347 case Graphics::Format::B5G5R5A1_UNORM_PACK16:
349 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
351 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
353 glFormat = GL_RGBA; // alpha is reserved but not used
358 case Graphics::Format::R8G8B8_UNORM:
360 pixelDataType = GL_UNSIGNED_BYTE;
365 case Graphics::Format::R8G8B8A8_UNORM:
367 pixelDataType = GL_UNSIGNED_BYTE;
368 glFormat = GL_RGBA; // alpha is reserved but not used
372 case Graphics::Format::B8G8R8A8_UNORM:
374 pixelDataType = GL_UNSIGNED_BYTE;
376 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
378 glFormat = GL_RGBA; // alpha is reserved but not used
383 case Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK:
385 glFormat = GL_COMPRESSED_RGB8_ETC2;
389 case Graphics::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG:
391 glFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
395 // GLES 3.0 standard compressed formats:
396 case Graphics::Format::EAC_R11_UNORM_BLOCK:
398 glFormat = GL_COMPRESSED_R11_EAC;
401 case Graphics::Format::EAC_R11_SNORM_BLOCK:
403 glFormat = GL_COMPRESSED_SIGNED_R11_EAC;
406 case Graphics::Format::EAC_R11G11_UNORM_BLOCK:
408 glFormat = GL_COMPRESSED_RG11_EAC;
411 case Graphics::Format::EAC_R11G11_SNORM_BLOCK:
413 glFormat = GL_COMPRESSED_SIGNED_RG11_EAC;
416 case Graphics::Format::ETC2_R8G8B8_SRGB_BLOCK:
418 glFormat = GL_COMPRESSED_SRGB8_ETC2;
421 case Graphics::Format::ETC2_R8G8B8A1_UNORM_BLOCK:
423 glFormat = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
426 case Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK:
428 glFormat = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
431 case Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK:
433 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
437 // GLES 3.1 extension compressed formats:
438 case Graphics::Format::ASTC_4x4_UNORM_BLOCK:
440 glFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
443 case Graphics::Format::ASTC_5x4_UNORM_BLOCK:
445 glFormat = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
448 case Graphics::Format::ASTC_5x5_UNORM_BLOCK:
450 glFormat = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
453 case Graphics::Format::ASTC_6x5_UNORM_BLOCK:
455 glFormat = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
458 case Graphics::Format::ASTC_6x6_UNORM_BLOCK:
460 glFormat = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
463 case Graphics::Format::ASTC_8x5_UNORM_BLOCK:
465 glFormat = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
468 case Graphics::Format::ASTC_8x6_UNORM_BLOCK:
470 glFormat = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
473 case Graphics::Format::ASTC_8x8_UNORM_BLOCK:
475 glFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
478 case Graphics::Format::ASTC_10x5_UNORM_BLOCK:
480 glFormat = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
483 case Graphics::Format::ASTC_10x6_UNORM_BLOCK:
485 glFormat = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
488 case Graphics::Format::ASTC_10x8_UNORM_BLOCK:
490 glFormat = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
493 case Graphics::Format::ASTC_10x10_UNORM_BLOCK:
495 glFormat = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
498 case Graphics::Format::ASTC_12x10_UNORM_BLOCK:
500 glFormat = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
503 case Graphics::Format::ASTC_12x12_UNORM_BLOCK:
505 glFormat = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
509 case Graphics::Format::ASTC_4x4_SRGB_BLOCK:
511 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
514 case Graphics::Format::ASTC_5x4_SRGB_BLOCK:
516 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
519 case Graphics::Format::ASTC_5x5_SRGB_BLOCK:
521 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
524 case Graphics::Format::ASTC_6x5_SRGB_BLOCK:
526 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
529 case Graphics::Format::ASTC_6x6_SRGB_BLOCK:
531 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
534 case Graphics::Format::ASTC_8x5_SRGB_BLOCK:
536 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
539 case Graphics::Format::ASTC_8x6_SRGB_BLOCK:
541 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
544 case Graphics::Format::ASTC_8x8_SRGB_BLOCK:
546 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
549 case Graphics::Format::ASTC_10x5_SRGB_BLOCK:
551 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
554 case Graphics::Format::ASTC_10x6_SRGB_BLOCK:
556 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
559 case Graphics::Format::ASTC_10x8_SRGB_BLOCK:
561 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
564 case Graphics::Format::ASTC_10x10_SRGB_BLOCK:
566 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
569 case Graphics::Format::ASTC_12x10_SRGB_BLOCK:
571 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
574 case Graphics::Format::ASTC_12x12_SRGB_BLOCK:
576 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
580 // GLES 3.0 floating point formats.
581 case Graphics::Format::R16G16B16_SFLOAT:
584 pixelDataType = GL_HALF_FLOAT;
587 case Graphics::Format::R32G32B32_SFLOAT:
590 pixelDataType = GL_FLOAT;
594 // GLES 3.0 depth and stencil formats
595 case Graphics::Format::D16_UNORM:
597 glFormat = GL_DEPTH_COMPONENT;
598 pixelDataType = GL_UNSIGNED_INT;
602 case Graphics::Format::D32_SFLOAT:
604 glFormat = GL_DEPTH_COMPONENT;
605 pixelDataType = GL_FLOAT;
609 case Graphics::Format::D24_UNORM_S8_UINT:
611 glFormat = GL_DEPTH_STENCIL;
612 pixelDataType = GL_UNSIGNED_INT_24_8;
616 case Graphics::Format::UNDEFINED:
618 //DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
622 case Graphics::Format::R11G11B10_UFLOAT_PACK32:
625 pixelDataType = GL_FLOAT;
629 case Graphics::Format::R4G4_UNORM_PACK8:
630 case Graphics::Format::A1R5G5B5_UNORM_PACK16:
631 case Graphics::Format::R8_SNORM:
632 case Graphics::Format::R8_USCALED:
633 case Graphics::Format::R8_SSCALED:
634 case Graphics::Format::R8_UINT:
635 case Graphics::Format::R8_SINT:
636 case Graphics::Format::R8_SRGB:
637 case Graphics::Format::R8G8_UNORM:
638 case Graphics::Format::R8G8_SNORM:
639 case Graphics::Format::R8G8_USCALED:
640 case Graphics::Format::R8G8_SSCALED:
641 case Graphics::Format::R8G8_UINT:
642 case Graphics::Format::R8G8_SINT:
643 case Graphics::Format::R8G8_SRGB:
644 case Graphics::Format::R8G8B8_SNORM:
645 case Graphics::Format::R8G8B8_USCALED:
646 case Graphics::Format::R8G8B8_SSCALED:
647 case Graphics::Format::R8G8B8_UINT:
648 case Graphics::Format::R8G8B8_SINT:
649 case Graphics::Format::R8G8B8_SRGB:
650 case Graphics::Format::B8G8R8_UNORM:
651 case Graphics::Format::B8G8R8_SNORM:
652 case Graphics::Format::B8G8R8_USCALED:
653 case Graphics::Format::B8G8R8_SSCALED:
654 case Graphics::Format::B8G8R8_UINT:
655 case Graphics::Format::B8G8R8_SINT:
656 case Graphics::Format::B8G8R8_SRGB:
657 case Graphics::Format::R8G8B8A8_SNORM:
658 case Graphics::Format::R8G8B8A8_USCALED:
659 case Graphics::Format::R8G8B8A8_SSCALED:
660 case Graphics::Format::R8G8B8A8_UINT:
661 case Graphics::Format::R8G8B8A8_SINT:
662 case Graphics::Format::R8G8B8A8_SRGB:
663 case Graphics::Format::B8G8R8A8_SNORM:
664 case Graphics::Format::B8G8R8A8_USCALED:
665 case Graphics::Format::B8G8R8A8_SSCALED:
666 case Graphics::Format::B8G8R8A8_UINT:
667 case Graphics::Format::B8G8R8A8_SINT:
668 case Graphics::Format::B8G8R8A8_SRGB:
669 case Graphics::Format::A8B8G8R8_UNORM_PACK32:
670 case Graphics::Format::A8B8G8R8_SNORM_PACK32:
671 case Graphics::Format::A8B8G8R8_USCALED_PACK32:
672 case Graphics::Format::A8B8G8R8_SSCALED_PACK32:
673 case Graphics::Format::A8B8G8R8_UINT_PACK32:
674 case Graphics::Format::A8B8G8R8_SINT_PACK32:
675 case Graphics::Format::A8B8G8R8_SRGB_PACK32:
676 case Graphics::Format::A2R10G10B10_UNORM_PACK32:
677 case Graphics::Format::A2R10G10B10_SNORM_PACK32:
678 case Graphics::Format::A2R10G10B10_USCALED_PACK32:
679 case Graphics::Format::A2R10G10B10_SSCALED_PACK32:
680 case Graphics::Format::A2R10G10B10_UINT_PACK32:
681 case Graphics::Format::A2R10G10B10_SINT_PACK32:
682 case Graphics::Format::A2B10G10R10_UNORM_PACK32:
683 case Graphics::Format::A2B10G10R10_SNORM_PACK32:
684 case Graphics::Format::A2B10G10R10_USCALED_PACK32:
685 case Graphics::Format::A2B10G10R10_SSCALED_PACK32:
686 case Graphics::Format::A2B10G10R10_UINT_PACK32:
687 case Graphics::Format::A2B10G10R10_SINT_PACK32:
688 case Graphics::Format::R16_UNORM:
689 case Graphics::Format::R16_SNORM:
690 case Graphics::Format::R16_USCALED:
691 case Graphics::Format::R16_SSCALED:
692 case Graphics::Format::R16_UINT:
693 case Graphics::Format::R16_SINT:
694 case Graphics::Format::R16_SFLOAT:
695 case Graphics::Format::R16G16_UNORM:
696 case Graphics::Format::R16G16_SNORM:
697 case Graphics::Format::R16G16_USCALED:
698 case Graphics::Format::R16G16_SSCALED:
699 case Graphics::Format::R16G16_UINT:
700 case Graphics::Format::R16G16_SINT:
701 case Graphics::Format::R16G16_SFLOAT:
702 case Graphics::Format::R16G16B16_UNORM:
703 case Graphics::Format::R16G16B16_SNORM:
704 case Graphics::Format::R16G16B16_USCALED:
705 case Graphics::Format::R16G16B16_SSCALED:
706 case Graphics::Format::R16G16B16_UINT:
707 case Graphics::Format::R16G16B16_SINT:
708 case Graphics::Format::R16G16B16A16_UNORM:
709 case Graphics::Format::R16G16B16A16_SNORM:
710 case Graphics::Format::R16G16B16A16_USCALED:
711 case Graphics::Format::R16G16B16A16_SSCALED:
712 case Graphics::Format::R16G16B16A16_UINT:
713 case Graphics::Format::R16G16B16A16_SINT:
714 case Graphics::Format::R16G16B16A16_SFLOAT:
715 case Graphics::Format::R32_UINT:
716 case Graphics::Format::R32_SINT:
717 case Graphics::Format::R32_SFLOAT:
718 case Graphics::Format::R32G32_UINT:
719 case Graphics::Format::R32G32_SINT:
720 case Graphics::Format::R32G32_SFLOAT:
721 case Graphics::Format::R32G32B32_UINT:
722 case Graphics::Format::R32G32B32_SINT:
723 case Graphics::Format::R32G32B32A32_UINT:
724 case Graphics::Format::R32G32B32A32_SINT:
725 case Graphics::Format::R32G32B32A32_SFLOAT:
726 case Graphics::Format::R64_UINT:
727 case Graphics::Format::R64_SINT:
728 case Graphics::Format::R64_SFLOAT:
729 case Graphics::Format::R64G64_UINT:
730 case Graphics::Format::R64G64_SINT:
731 case Graphics::Format::R64G64_SFLOAT:
732 case Graphics::Format::R64G64B64_UINT:
733 case Graphics::Format::R64G64B64_SINT:
734 case Graphics::Format::R64G64B64_SFLOAT:
735 case Graphics::Format::R64G64B64A64_UINT:
736 case Graphics::Format::R64G64B64A64_SINT:
737 case Graphics::Format::R64G64B64A64_SFLOAT:
738 case Graphics::Format::B10G11R11_UFLOAT_PACK32:
739 case Graphics::Format::E5B9G9R9_UFLOAT_PACK32:
740 case Graphics::Format::X8_D24_UNORM_PACK32:
741 case Graphics::Format::S8_UINT:
742 case Graphics::Format::D16_UNORM_S8_UINT:
743 case Graphics::Format::D32_SFLOAT_S8_UINT:
744 case Graphics::Format::BC1_RGB_UNORM_BLOCK:
745 case Graphics::Format::BC1_RGB_SRGB_BLOCK:
746 case Graphics::Format::BC1_RGBA_UNORM_BLOCK:
747 case Graphics::Format::BC1_RGBA_SRGB_BLOCK:
748 case Graphics::Format::BC2_UNORM_BLOCK:
749 case Graphics::Format::BC2_SRGB_BLOCK:
750 case Graphics::Format::BC3_UNORM_BLOCK:
751 case Graphics::Format::BC3_SRGB_BLOCK:
752 case Graphics::Format::BC4_UNORM_BLOCK:
753 case Graphics::Format::BC4_SNORM_BLOCK:
754 case Graphics::Format::BC5_UNORM_BLOCK:
755 case Graphics::Format::BC5_SNORM_BLOCK:
756 case Graphics::Format::BC6H_UFLOAT_BLOCK:
757 case Graphics::Format::BC6H_SFLOAT_BLOCK:
758 case Graphics::Format::BC7_UNORM_BLOCK:
759 case Graphics::Format::BC7_SRGB_BLOCK:
760 case Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK:
761 case Graphics::Format::PVRTC1_2BPP_UNORM_BLOCK_IMG:
762 case Graphics::Format::PVRTC2_2BPP_UNORM_BLOCK_IMG:
763 case Graphics::Format::PVRTC2_4BPP_UNORM_BLOCK_IMG:
764 case Graphics::Format::PVRTC1_2BPP_SRGB_BLOCK_IMG:
765 case Graphics::Format::PVRTC1_4BPP_SRGB_BLOCK_IMG:
766 case Graphics::Format::PVRTC2_2BPP_SRGB_BLOCK_IMG:
767 case Graphics::Format::PVRTC2_4BPP_SRGB_BLOCK_IMG:
776 case Graphics::Format::R16G16B16A16_SFLOAT:
777 case Graphics::Format::R32G32B32A32_SFLOAT:
778 case Graphics::Format::R11G11B10_UFLOAT_PACK32:
780 glInternalFormat = GL_R11F_G11F_B10F;
783 case Graphics::Format::D32_SFLOAT:
785 glInternalFormat = GL_DEPTH_COMPONENT32F;
788 case Graphics::Format::D24_UNORM_S8_UINT:
790 glInternalFormat = GL_DEPTH24_STENCIL8;
795 glInternalFormat = glFormat;
802 TestGraphicsTexture::TestGraphicsTexture(TestGlAbstraction& glAbstraction, const Graphics::TextureCreateInfo& createInfo)
803 : mGlAbstraction(glAbstraction),
804 mCreateInfo(createInfo),
805 mIsCompressed(IsCompressedFormat(createInfo.format))
807 GLuint target = GetTarget();
808 if(mCreateInfo.nativeImagePtr)
810 InitializeNativeImage(target);
816 if(mCreateInfo.textureType == Graphics::TextureType::TEXTURE_2D)
820 glAbstraction.TexImage2D(target, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, mGlFormat, mPixelDataType, nullptr);
824 glAbstraction.CompressedTexImage2D(target, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, 0, nullptr);
827 else if(mCreateInfo.textureType == Graphics::TextureType::TEXTURE_CUBEMAP)
831 for(uint32_t i(0); i < 6; ++i)
833 glAbstraction.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, mGlFormat, mPixelDataType, nullptr);
838 for(uint32_t i(0); i < 6; ++i)
840 glAbstraction.CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, 0, nullptr);
843 TestGraphicsSampler::SetTexParameter(glAbstraction, target, GL_TEXTURE_WRAP_R, GL_WRAP_DEFAULT);
848 TestGraphicsTexture::~TestGraphicsTexture()
850 mGlAbstraction.DeleteTextures(1, &mId);
851 if(mCreateInfo.nativeImagePtr)
853 mCreateInfo.nativeImagePtr->DestroyResource();
857 void TestGraphicsTexture::Initialize(GLuint target)
859 PixelFormatToGl(mCreateInfo.format,
864 mGlAbstraction.GenTextures(1, &mId);
865 mGlAbstraction.BindTexture(target, mId);
866 mGlAbstraction.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
868 //Apply default sampling parameters
869 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT);
870 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT);
871 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT);
872 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT);
875 void TestGraphicsTexture::InitializeNativeImage(GLuint target)
877 mCreateInfo.nativeImagePtr->CreateResource();
880 if(mCreateInfo.nativeImagePtr->TargetTexture() != 0u) // This can definitely fail
882 mGlAbstraction.DeleteTextures(1, &mId);
883 mCreateInfo.nativeImagePtr->DestroyResource();
888 GLuint TestGraphicsTexture::GetTarget()
891 if(mCreateInfo.nativeImagePtr)
893 target = mCreateInfo.nativeImagePtr->GetTextureTarget(); // Could be GL_TEXTURE_2D or GL_TEXTURE_EXTERNAL_OES
897 target = GetTextureTarget(mCreateInfo.textureType);
902 void TestGraphicsTexture::Bind(uint32_t textureUnit)
904 if(mCreateInfo.nativeImagePtr)
908 InitializeNativeImage(GetTarget());
911 mGlAbstraction.ActiveTexture(textureUnit + GL_TEXTURE0);
912 mGlAbstraction.BindTexture(GetTarget(), mId);
915 void TestGraphicsTexture::Prepare()
917 if(mCreateInfo.nativeImagePtr)
919 /***********************************************************************************
920 * If the native image source changes, we need to re-create the texture. *
921 * In EGL, this is done in native image implementation in PrepareTexture below. *
923 * In Vulkan impl, this was done in dali-core side. I think we should make this *
924 * work in the graphics implementation instead. *
925 ***********************************************************************************/
926 if(mCreateInfo.nativeImagePtr->SourceChanged())
928 uint32_t width = mCreateInfo.nativeImagePtr->GetWidth();
929 uint32_t height = mCreateInfo.nativeImagePtr->GetHeight();
930 mCreateInfo.SetSize({width, height}); // Size may change
932 // @todo Re-initialize this texture from the new create info.
935 // Ensure the native image is up-to-date
936 mCreateInfo.nativeImagePtr->PrepareTexture();
940 void TestGraphicsTexture::Update(Graphics::TextureUpdateInfo updateInfo, Graphics::TextureUpdateSourceInfo source)
942 GLenum target{GetTarget()};
943 if(mCreateInfo.textureType == Graphics::TextureType::TEXTURE_CUBEMAP)
945 target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + updateInfo.layer;
948 mGlAbstraction.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
950 const bool isSubImage(updateInfo.dstOffset2D.x != 0 || updateInfo.dstOffset2D.y != 0 ||
951 updateInfo.srcExtent2D.width != (mCreateInfo.size.width / (1 << updateInfo.level)) ||
952 updateInfo.srcExtent2D.height != (mCreateInfo.size.height / (1 << updateInfo.level)));
958 mGlAbstraction.TexImage2D(target, updateInfo.level, mGlInternalFormat, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, 0, mGlFormat, mPixelDataType, source.memorySource.memory);
962 mGlAbstraction.CompressedTexImage2D(target, updateInfo.level, mGlInternalFormat, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, 0, updateInfo.srcSize, source.memorySource.memory);
969 mGlAbstraction.TexSubImage2D(target, updateInfo.level, updateInfo.dstOffset2D.x, updateInfo.dstOffset2D.y, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, mGlFormat, mPixelDataType, source.memorySource.memory);
973 mGlAbstraction.CompressedTexSubImage2D(target, updateInfo.level, updateInfo.dstOffset2D.x, updateInfo.dstOffset2D.y, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, mGlFormat, updateInfo.srcSize, source.memorySource.memory);