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::E5B9G9R9_UFLOAT_PACK32:
187 case Graphics::Format::D16_UNORM:
188 case Graphics::Format::X8_D24_UNORM_PACK32:
189 case Graphics::Format::D32_SFLOAT:
190 case Graphics::Format::S8_UINT:
191 case Graphics::Format::D16_UNORM_S8_UINT:
192 case Graphics::Format::D24_UNORM_S8_UINT:
193 case Graphics::Format::D32_SFLOAT_S8_UINT:
194 case Graphics::Format::BC1_RGB_UNORM_BLOCK:
195 case Graphics::Format::BC1_RGB_SRGB_BLOCK:
196 case Graphics::Format::BC1_RGBA_UNORM_BLOCK:
197 case Graphics::Format::BC1_RGBA_SRGB_BLOCK:
198 case Graphics::Format::BC2_UNORM_BLOCK:
199 case Graphics::Format::BC2_SRGB_BLOCK:
200 case Graphics::Format::BC3_UNORM_BLOCK:
201 case Graphics::Format::BC3_SRGB_BLOCK:
202 case Graphics::Format::BC4_UNORM_BLOCK:
203 case Graphics::Format::BC4_SNORM_BLOCK:
204 case Graphics::Format::BC5_UNORM_BLOCK:
205 case Graphics::Format::BC5_SNORM_BLOCK:
206 case Graphics::Format::BC6H_UFLOAT_BLOCK:
207 case Graphics::Format::BC6H_SFLOAT_BLOCK:
208 case Graphics::Format::BC7_UNORM_BLOCK:
209 case Graphics::Format::BC7_SRGB_BLOCK:
214 case Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK:
215 case Graphics::Format::ETC2_R8G8B8_SRGB_BLOCK:
216 case Graphics::Format::ETC2_R8G8B8A1_UNORM_BLOCK:
217 case Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK:
218 case Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK:
219 case Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK:
220 case Graphics::Format::EAC_R11_UNORM_BLOCK:
221 case Graphics::Format::EAC_R11_SNORM_BLOCK:
222 case Graphics::Format::EAC_R11G11_UNORM_BLOCK:
223 case Graphics::Format::EAC_R11G11_SNORM_BLOCK:
224 case Graphics::Format::ASTC_4x4_UNORM_BLOCK:
225 case Graphics::Format::ASTC_4x4_SRGB_BLOCK:
226 case Graphics::Format::ASTC_5x4_UNORM_BLOCK:
227 case Graphics::Format::ASTC_5x4_SRGB_BLOCK:
228 case Graphics::Format::ASTC_5x5_UNORM_BLOCK:
229 case Graphics::Format::ASTC_5x5_SRGB_BLOCK:
230 case Graphics::Format::ASTC_6x5_UNORM_BLOCK:
231 case Graphics::Format::ASTC_6x5_SRGB_BLOCK:
232 case Graphics::Format::ASTC_6x6_UNORM_BLOCK:
233 case Graphics::Format::ASTC_6x6_SRGB_BLOCK:
234 case Graphics::Format::ASTC_8x5_UNORM_BLOCK:
235 case Graphics::Format::ASTC_8x5_SRGB_BLOCK:
236 case Graphics::Format::ASTC_8x6_UNORM_BLOCK:
237 case Graphics::Format::ASTC_8x6_SRGB_BLOCK:
238 case Graphics::Format::ASTC_8x8_UNORM_BLOCK:
239 case Graphics::Format::ASTC_8x8_SRGB_BLOCK:
240 case Graphics::Format::ASTC_10x5_UNORM_BLOCK:
241 case Graphics::Format::ASTC_10x5_SRGB_BLOCK:
242 case Graphics::Format::ASTC_10x6_UNORM_BLOCK:
243 case Graphics::Format::ASTC_10x6_SRGB_BLOCK:
244 case Graphics::Format::ASTC_10x8_UNORM_BLOCK:
245 case Graphics::Format::ASTC_10x8_SRGB_BLOCK:
246 case Graphics::Format::ASTC_10x10_UNORM_BLOCK:
247 case Graphics::Format::ASTC_10x10_SRGB_BLOCK:
248 case Graphics::Format::ASTC_12x10_UNORM_BLOCK:
249 case Graphics::Format::ASTC_12x10_SRGB_BLOCK:
250 case Graphics::Format::ASTC_12x12_UNORM_BLOCK:
251 case Graphics::Format::ASTC_12x12_SRGB_BLOCK:
252 case Graphics::Format::PVRTC1_2BPP_UNORM_BLOCK_IMG:
253 case Graphics::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG:
254 case Graphics::Format::PVRTC2_2BPP_UNORM_BLOCK_IMG:
255 case Graphics::Format::PVRTC2_4BPP_UNORM_BLOCK_IMG:
256 case Graphics::Format::PVRTC1_2BPP_SRGB_BLOCK_IMG:
257 case Graphics::Format::PVRTC1_4BPP_SRGB_BLOCK_IMG:
258 case Graphics::Format::PVRTC2_2BPP_SRGB_BLOCK_IMG:
259 case Graphics::Format::PVRTC2_4BPP_SRGB_BLOCK_IMG:
269 * @brief Retrives the GL format, GL internal format and pixel data type from a Graphics::Format
270 * @param[in] pixelFormat The pixel format.
271 * @param[out] glFormat The gl format.
272 * @param[out] glInternalFormat The gl internal format.
273 * @param[out] pixelDataType The data type of the pixel data.
275 void PixelFormatToGl(Graphics::Format pixelFormat, GLenum& glFormat, GLint& glInternalFormat, GLenum& pixelDataType)
277 // Compressed textures have no pixelDataType, so init to an invalid value:
282 case Graphics::Format::R8_UNORM:
284 pixelDataType = GL_UNSIGNED_BYTE;
289 case Graphics::Format::L8:
291 pixelDataType = GL_UNSIGNED_BYTE;
292 glFormat = GL_LUMINANCE;
296 case Graphics::Format::L8A8:
298 pixelDataType = GL_UNSIGNED_BYTE;
299 glFormat = GL_LUMINANCE_ALPHA;
303 case Graphics::Format::R5G6B5_UNORM_PACK16:
305 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
310 case Graphics::Format::B5G6R5_UNORM_PACK16:
312 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
314 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
316 glFormat = GL_RGBA; // alpha is reserved but not used
321 case Graphics::Format::R4G4B4A4_UNORM_PACK16:
323 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
328 case Graphics::Format::B4G4R4A4_UNORM_PACK16:
330 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
332 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
334 glFormat = GL_RGBA; // alpha is reserved but not used
339 case Graphics::Format::R5G5B5A1_UNORM_PACK16:
341 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
346 case Graphics::Format::B5G5R5A1_UNORM_PACK16:
348 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
350 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
352 glFormat = GL_RGBA; // alpha is reserved but not used
357 case Graphics::Format::R8G8B8_UNORM:
359 pixelDataType = GL_UNSIGNED_BYTE;
364 case Graphics::Format::R8G8B8A8_UNORM:
366 pixelDataType = GL_UNSIGNED_BYTE;
367 glFormat = GL_RGBA; // alpha is reserved but not used
371 case Graphics::Format::B8G8R8A8_UNORM:
373 pixelDataType = GL_UNSIGNED_BYTE;
375 glFormat = GL_BGRA_EXT; // alpha is reserved but not used
377 glFormat = GL_RGBA; // alpha is reserved but not used
382 case Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK:
384 glFormat = GL_COMPRESSED_RGB8_ETC2;
388 case Graphics::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG:
390 glFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
394 // GLES 3.0 standard compressed formats:
395 case Graphics::Format::EAC_R11_UNORM_BLOCK:
397 glFormat = GL_COMPRESSED_R11_EAC;
400 case Graphics::Format::EAC_R11_SNORM_BLOCK:
402 glFormat = GL_COMPRESSED_SIGNED_R11_EAC;
405 case Graphics::Format::EAC_R11G11_UNORM_BLOCK:
407 glFormat = GL_COMPRESSED_RG11_EAC;
410 case Graphics::Format::EAC_R11G11_SNORM_BLOCK:
412 glFormat = GL_COMPRESSED_SIGNED_RG11_EAC;
415 case Graphics::Format::ETC2_R8G8B8_SRGB_BLOCK:
417 glFormat = GL_COMPRESSED_SRGB8_ETC2;
420 case Graphics::Format::ETC2_R8G8B8A1_UNORM_BLOCK:
422 glFormat = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
425 case Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK:
427 glFormat = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
430 case Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK:
432 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
436 // GLES 3.1 extension compressed formats:
437 case Graphics::Format::ASTC_4x4_UNORM_BLOCK:
439 glFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
442 case Graphics::Format::ASTC_5x4_UNORM_BLOCK:
444 glFormat = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
447 case Graphics::Format::ASTC_5x5_UNORM_BLOCK:
449 glFormat = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
452 case Graphics::Format::ASTC_6x5_UNORM_BLOCK:
454 glFormat = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
457 case Graphics::Format::ASTC_6x6_UNORM_BLOCK:
459 glFormat = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
462 case Graphics::Format::ASTC_8x5_UNORM_BLOCK:
464 glFormat = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
467 case Graphics::Format::ASTC_8x6_UNORM_BLOCK:
469 glFormat = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
472 case Graphics::Format::ASTC_8x8_UNORM_BLOCK:
474 glFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
477 case Graphics::Format::ASTC_10x5_UNORM_BLOCK:
479 glFormat = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
482 case Graphics::Format::ASTC_10x6_UNORM_BLOCK:
484 glFormat = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
487 case Graphics::Format::ASTC_10x8_UNORM_BLOCK:
489 glFormat = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
492 case Graphics::Format::ASTC_10x10_UNORM_BLOCK:
494 glFormat = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
497 case Graphics::Format::ASTC_12x10_UNORM_BLOCK:
499 glFormat = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
502 case Graphics::Format::ASTC_12x12_UNORM_BLOCK:
504 glFormat = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
508 case Graphics::Format::ASTC_4x4_SRGB_BLOCK:
510 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
513 case Graphics::Format::ASTC_5x4_SRGB_BLOCK:
515 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
518 case Graphics::Format::ASTC_5x5_SRGB_BLOCK:
520 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
523 case Graphics::Format::ASTC_6x5_SRGB_BLOCK:
525 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
528 case Graphics::Format::ASTC_6x6_SRGB_BLOCK:
530 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
533 case Graphics::Format::ASTC_8x5_SRGB_BLOCK:
535 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
538 case Graphics::Format::ASTC_8x6_SRGB_BLOCK:
540 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
543 case Graphics::Format::ASTC_8x8_SRGB_BLOCK:
545 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
548 case Graphics::Format::ASTC_10x5_SRGB_BLOCK:
550 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
553 case Graphics::Format::ASTC_10x6_SRGB_BLOCK:
555 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
558 case Graphics::Format::ASTC_10x8_SRGB_BLOCK:
560 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
563 case Graphics::Format::ASTC_10x10_SRGB_BLOCK:
565 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
568 case Graphics::Format::ASTC_12x10_SRGB_BLOCK:
570 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
573 case Graphics::Format::ASTC_12x12_SRGB_BLOCK:
575 glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
579 // GLES 3.0 floating point formats.
580 case Graphics::Format::R16G16B16_SFLOAT:
583 pixelDataType = GL_HALF_FLOAT;
586 case Graphics::Format::R32G32B32_SFLOAT:
589 pixelDataType = GL_FLOAT;
593 // GLES 3.0 depth and stencil formats
594 case Graphics::Format::D16_UNORM:
596 glFormat = GL_DEPTH_COMPONENT;
597 pixelDataType = GL_UNSIGNED_INT;
601 case Graphics::Format::D32_SFLOAT:
603 glFormat = GL_DEPTH_COMPONENT;
604 pixelDataType = GL_FLOAT;
608 case Graphics::Format::D24_UNORM_S8_UINT:
610 glFormat = GL_DEPTH_STENCIL;
611 pixelDataType = GL_UNSIGNED_INT_24_8;
615 case Graphics::Format::UNDEFINED:
617 //DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
622 case Graphics::Format::R4G4_UNORM_PACK8:
623 case Graphics::Format::A1R5G5B5_UNORM_PACK16:
624 case Graphics::Format::R8_SNORM:
625 case Graphics::Format::R8_USCALED:
626 case Graphics::Format::R8_SSCALED:
627 case Graphics::Format::R8_UINT:
628 case Graphics::Format::R8_SINT:
629 case Graphics::Format::R8_SRGB:
630 case Graphics::Format::R8G8_UNORM:
631 case Graphics::Format::R8G8_SNORM:
632 case Graphics::Format::R8G8_USCALED:
633 case Graphics::Format::R8G8_SSCALED:
634 case Graphics::Format::R8G8_UINT:
635 case Graphics::Format::R8G8_SINT:
636 case Graphics::Format::R8G8_SRGB:
637 case Graphics::Format::R8G8B8_SNORM:
638 case Graphics::Format::R8G8B8_USCALED:
639 case Graphics::Format::R8G8B8_SSCALED:
640 case Graphics::Format::R8G8B8_UINT:
641 case Graphics::Format::R8G8B8_SINT:
642 case Graphics::Format::R8G8B8_SRGB:
643 case Graphics::Format::B8G8R8_UNORM:
644 case Graphics::Format::B8G8R8_SNORM:
645 case Graphics::Format::B8G8R8_USCALED:
646 case Graphics::Format::B8G8R8_SSCALED:
647 case Graphics::Format::B8G8R8_UINT:
648 case Graphics::Format::B8G8R8_SINT:
649 case Graphics::Format::B8G8R8_SRGB:
650 case Graphics::Format::R8G8B8A8_SNORM:
651 case Graphics::Format::R8G8B8A8_USCALED:
652 case Graphics::Format::R8G8B8A8_SSCALED:
653 case Graphics::Format::R8G8B8A8_UINT:
654 case Graphics::Format::R8G8B8A8_SINT:
655 case Graphics::Format::R8G8B8A8_SRGB:
656 case Graphics::Format::B8G8R8A8_SNORM:
657 case Graphics::Format::B8G8R8A8_USCALED:
658 case Graphics::Format::B8G8R8A8_SSCALED:
659 case Graphics::Format::B8G8R8A8_UINT:
660 case Graphics::Format::B8G8R8A8_SINT:
661 case Graphics::Format::B8G8R8A8_SRGB:
662 case Graphics::Format::A8B8G8R8_UNORM_PACK32:
663 case Graphics::Format::A8B8G8R8_SNORM_PACK32:
664 case Graphics::Format::A8B8G8R8_USCALED_PACK32:
665 case Graphics::Format::A8B8G8R8_SSCALED_PACK32:
666 case Graphics::Format::A8B8G8R8_UINT_PACK32:
667 case Graphics::Format::A8B8G8R8_SINT_PACK32:
668 case Graphics::Format::A8B8G8R8_SRGB_PACK32:
669 case Graphics::Format::A2R10G10B10_UNORM_PACK32:
670 case Graphics::Format::A2R10G10B10_SNORM_PACK32:
671 case Graphics::Format::A2R10G10B10_USCALED_PACK32:
672 case Graphics::Format::A2R10G10B10_SSCALED_PACK32:
673 case Graphics::Format::A2R10G10B10_UINT_PACK32:
674 case Graphics::Format::A2R10G10B10_SINT_PACK32:
675 case Graphics::Format::A2B10G10R10_UNORM_PACK32:
676 case Graphics::Format::A2B10G10R10_SNORM_PACK32:
677 case Graphics::Format::A2B10G10R10_USCALED_PACK32:
678 case Graphics::Format::A2B10G10R10_SSCALED_PACK32:
679 case Graphics::Format::A2B10G10R10_UINT_PACK32:
680 case Graphics::Format::A2B10G10R10_SINT_PACK32:
681 case Graphics::Format::R16_UNORM:
682 case Graphics::Format::R16_SNORM:
683 case Graphics::Format::R16_USCALED:
684 case Graphics::Format::R16_SSCALED:
685 case Graphics::Format::R16_UINT:
686 case Graphics::Format::R16_SINT:
687 case Graphics::Format::R16_SFLOAT:
688 case Graphics::Format::R16G16_UNORM:
689 case Graphics::Format::R16G16_SNORM:
690 case Graphics::Format::R16G16_USCALED:
691 case Graphics::Format::R16G16_SSCALED:
692 case Graphics::Format::R16G16_UINT:
693 case Graphics::Format::R16G16_SINT:
694 case Graphics::Format::R16G16_SFLOAT:
695 case Graphics::Format::R16G16B16_UNORM:
696 case Graphics::Format::R16G16B16_SNORM:
697 case Graphics::Format::R16G16B16_USCALED:
698 case Graphics::Format::R16G16B16_SSCALED:
699 case Graphics::Format::R16G16B16_UINT:
700 case Graphics::Format::R16G16B16_SINT:
701 case Graphics::Format::R16G16B16A16_UNORM:
702 case Graphics::Format::R16G16B16A16_SNORM:
703 case Graphics::Format::R16G16B16A16_USCALED:
704 case Graphics::Format::R16G16B16A16_SSCALED:
705 case Graphics::Format::R16G16B16A16_UINT:
706 case Graphics::Format::R16G16B16A16_SINT:
707 case Graphics::Format::R16G16B16A16_SFLOAT:
708 case Graphics::Format::R32_UINT:
709 case Graphics::Format::R32_SINT:
710 case Graphics::Format::R32_SFLOAT:
711 case Graphics::Format::R32G32_UINT:
712 case Graphics::Format::R32G32_SINT:
713 case Graphics::Format::R32G32_SFLOAT:
714 case Graphics::Format::R32G32B32_UINT:
715 case Graphics::Format::R32G32B32_SINT:
716 case Graphics::Format::R32G32B32A32_UINT:
717 case Graphics::Format::R32G32B32A32_SINT:
718 case Graphics::Format::R32G32B32A32_SFLOAT:
719 case Graphics::Format::R64_UINT:
720 case Graphics::Format::R64_SINT:
721 case Graphics::Format::R64_SFLOAT:
722 case Graphics::Format::R64G64_UINT:
723 case Graphics::Format::R64G64_SINT:
724 case Graphics::Format::R64G64_SFLOAT:
725 case Graphics::Format::R64G64B64_UINT:
726 case Graphics::Format::R64G64B64_SINT:
727 case Graphics::Format::R64G64B64_SFLOAT:
728 case Graphics::Format::R64G64B64A64_UINT:
729 case Graphics::Format::R64G64B64A64_SINT:
730 case Graphics::Format::R64G64B64A64_SFLOAT:
731 case Graphics::Format::B10G11R11_UFLOAT_PACK32:
732 case Graphics::Format::E5B9G9R9_UFLOAT_PACK32:
733 case Graphics::Format::X8_D24_UNORM_PACK32:
734 case Graphics::Format::S8_UINT:
735 case Graphics::Format::D16_UNORM_S8_UINT:
736 case Graphics::Format::D32_SFLOAT_S8_UINT:
737 case Graphics::Format::BC1_RGB_UNORM_BLOCK:
738 case Graphics::Format::BC1_RGB_SRGB_BLOCK:
739 case Graphics::Format::BC1_RGBA_UNORM_BLOCK:
740 case Graphics::Format::BC1_RGBA_SRGB_BLOCK:
741 case Graphics::Format::BC2_UNORM_BLOCK:
742 case Graphics::Format::BC2_SRGB_BLOCK:
743 case Graphics::Format::BC3_UNORM_BLOCK:
744 case Graphics::Format::BC3_SRGB_BLOCK:
745 case Graphics::Format::BC4_UNORM_BLOCK:
746 case Graphics::Format::BC4_SNORM_BLOCK:
747 case Graphics::Format::BC5_UNORM_BLOCK:
748 case Graphics::Format::BC5_SNORM_BLOCK:
749 case Graphics::Format::BC6H_UFLOAT_BLOCK:
750 case Graphics::Format::BC6H_SFLOAT_BLOCK:
751 case Graphics::Format::BC7_UNORM_BLOCK:
752 case Graphics::Format::BC7_SRGB_BLOCK:
753 case Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK:
754 case Graphics::Format::PVRTC1_2BPP_UNORM_BLOCK_IMG:
755 case Graphics::Format::PVRTC2_2BPP_UNORM_BLOCK_IMG:
756 case Graphics::Format::PVRTC2_4BPP_UNORM_BLOCK_IMG:
757 case Graphics::Format::PVRTC1_2BPP_SRGB_BLOCK_IMG:
758 case Graphics::Format::PVRTC1_4BPP_SRGB_BLOCK_IMG:
759 case Graphics::Format::PVRTC2_2BPP_SRGB_BLOCK_IMG:
760 case Graphics::Format::PVRTC2_4BPP_SRGB_BLOCK_IMG:
769 case Graphics::Format::R16G16B16A16_SFLOAT:
770 case Graphics::Format::R32G32B32A32_SFLOAT:
772 glInternalFormat = GL_R11F_G11F_B10F;
775 case Graphics::Format::D32_SFLOAT:
777 glInternalFormat = GL_DEPTH_COMPONENT32F;
780 case Graphics::Format::D24_UNORM_S8_UINT:
782 glInternalFormat = GL_DEPTH24_STENCIL8;
787 glInternalFormat = glFormat;
794 TestGraphicsTexture::TestGraphicsTexture(TestGlAbstraction& glAbstraction, const Graphics::TextureCreateInfo& createInfo)
795 : mGlAbstraction(glAbstraction),
796 mCreateInfo(createInfo),
797 mIsCompressed(IsCompressedFormat(createInfo.format))
799 GLuint target = GetTarget();
800 if(mCreateInfo.nativeImagePtr)
802 InitializeNativeImage(target);
808 if(mCreateInfo.textureType == Graphics::TextureType::TEXTURE_2D)
812 glAbstraction.TexImage2D(target, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, mGlFormat, mPixelDataType, nullptr);
816 glAbstraction.CompressedTexImage2D(target, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, 0, nullptr);
819 else if(mCreateInfo.textureType == Graphics::TextureType::TEXTURE_CUBEMAP)
823 for(uint32_t i(0); i < 6; ++i)
825 glAbstraction.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, mGlFormat, mPixelDataType, nullptr);
830 for(uint32_t i(0); i < 6; ++i)
832 glAbstraction.CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, createInfo.size.width, createInfo.size.height, 0, 0, nullptr);
835 TestGraphicsSampler::SetTexParameter(glAbstraction, target, GL_TEXTURE_WRAP_R, GL_WRAP_DEFAULT);
840 TestGraphicsTexture::~TestGraphicsTexture()
842 mGlAbstraction.DeleteTextures(1, &mId);
843 if(mCreateInfo.nativeImagePtr)
845 mCreateInfo.nativeImagePtr->DestroyResource();
849 void TestGraphicsTexture::Initialize(GLuint target)
851 PixelFormatToGl(mCreateInfo.format,
856 mGlAbstraction.GenTextures(1, &mId);
857 mGlAbstraction.BindTexture(target, mId);
858 mGlAbstraction.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
860 //Apply default sampling parameters
861 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT);
862 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT);
863 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT);
864 TestGraphicsSampler::SetTexParameter(mGlAbstraction, target, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT);
867 void TestGraphicsTexture::InitializeNativeImage(GLuint target)
869 mCreateInfo.nativeImagePtr->CreateResource();
872 if(mCreateInfo.nativeImagePtr->TargetTexture() != 0u) // This can definitely fail
874 mGlAbstraction.DeleteTextures(1, &mId);
875 mCreateInfo.nativeImagePtr->DestroyResource();
880 GLuint TestGraphicsTexture::GetTarget()
883 if(mCreateInfo.nativeImagePtr)
885 target = mCreateInfo.nativeImagePtr->GetTextureTarget(); // Could be GL_TEXTURE_2D or GL_TEXTURE_EXTERNAL_OES
889 target = GetTextureTarget(mCreateInfo.textureType);
894 void TestGraphicsTexture::Bind(uint32_t textureUnit)
896 if(mCreateInfo.nativeImagePtr)
900 InitializeNativeImage(GetTarget());
903 mGlAbstraction.ActiveTexture(textureUnit + GL_TEXTURE0);
904 mGlAbstraction.BindTexture(GetTarget(), mId);
907 void TestGraphicsTexture::Prepare()
909 if(mCreateInfo.nativeImagePtr)
911 /***********************************************************************************
912 * If the native image source changes, we need to re-create the texture. *
913 * In EGL, this is done in native image implementation in PrepareTexture below. *
915 * In Vulkan impl, this was done in dali-core side. I think we should make this *
916 * work in the graphics implementation instead. *
917 ***********************************************************************************/
918 if(mCreateInfo.nativeImagePtr->SourceChanged())
920 uint32_t width = mCreateInfo.nativeImagePtr->GetWidth();
921 uint32_t height = mCreateInfo.nativeImagePtr->GetHeight();
922 mCreateInfo.SetSize({width, height}); // Size may change
924 // @todo Re-initialize this texture from the new create info.
927 // Ensure the native image is up-to-date
928 mCreateInfo.nativeImagePtr->PrepareTexture();
932 void TestGraphicsTexture::Update(Graphics::TextureUpdateInfo updateInfo, Graphics::TextureUpdateSourceInfo source)
934 GLenum target{GetTarget()};
935 if(mCreateInfo.textureType == Graphics::TextureType::TEXTURE_CUBEMAP)
937 target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + updateInfo.layer;
940 mGlAbstraction.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
942 const bool isSubImage(updateInfo.dstOffset2D.x != 0 || updateInfo.dstOffset2D.y != 0 ||
943 updateInfo.srcExtent2D.width != (mCreateInfo.size.width / (1 << updateInfo.level)) ||
944 updateInfo.srcExtent2D.height != (mCreateInfo.size.height / (1 << updateInfo.level)));
950 mGlAbstraction.TexImage2D(target, updateInfo.level, mGlInternalFormat, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, 0, mGlFormat, mPixelDataType, source.memorySource.memory);
954 mGlAbstraction.CompressedTexImage2D(target, updateInfo.level, mGlInternalFormat, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, 0, updateInfo.srcSize, source.memorySource.memory);
961 mGlAbstraction.TexSubImage2D(target, updateInfo.level, updateInfo.dstOffset2D.x, updateInfo.dstOffset2D.y, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, mGlFormat, mPixelDataType, source.memorySource.memory);
965 mGlAbstraction.CompressedTexSubImage2D(target, updateInfo.level, updateInfo.dstOffset2D.x, updateInfo.dstOffset2D.y, updateInfo.srcExtent2D.width, updateInfo.srcExtent2D.height, mGlFormat, updateInfo.srcSize, source.memorySource.memory);