1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
17 #include "../libEGL/Context.hpp"
18 #include "../libEGL/Texture.hpp"
19 #include "../common/debug.h"
20 #include "Common/Math.hpp"
21 #include "Common/Thread.hpp"
23 #include <GLES3/gl3.h>
29 int getNumBlocks(int w, int h, int blockSizeX, int blockSizeY)
31 return ((w + blockSizeX - 1) / blockSizeX) * ((h + blockSizeY - 1) / blockSizeY);
65 template<DataType dataType>
66 void LoadImageRow(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
72 void LoadImageRow<Bytes_1>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
74 memcpy(dest + xoffset, source, width);
78 void LoadImageRow<Bytes_2>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
80 memcpy(dest + xoffset * 2, source, width * 2);
84 void LoadImageRow<Bytes_4>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
86 memcpy(dest + xoffset * 4, source, width * 4);
90 void LoadImageRow<Bytes_8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
92 memcpy(dest + xoffset * 8, source, width * 8);
96 void LoadImageRow<Bytes_16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
98 memcpy(dest + xoffset * 16, source, width * 16);
102 void LoadImageRow<ByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
104 unsigned char *destB = dest + xoffset * 4;
106 for(int x = 0; x < width; x++)
108 destB[4 * x + 0] = source[x * 3 + 0];
109 destB[4 * x + 1] = source[x * 3 + 1];
110 destB[4 * x + 2] = source[x * 3 + 2];
111 destB[4 * x + 3] = 0x7F;
116 void LoadImageRow<UByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
118 unsigned char *destB = dest + xoffset * 4;
120 for(int x = 0; x < width; x++)
122 destB[4 * x + 0] = source[x * 3 + 0];
123 destB[4 * x + 1] = source[x * 3 + 1];
124 destB[4 * x + 2] = source[x * 3 + 2];
125 destB[4 * x + 3] = 0xFF;
130 void LoadImageRow<ShortRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
132 const unsigned short *sourceS = reinterpret_cast<const unsigned short*>(source);
133 unsigned short *destS = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
135 for(int x = 0; x < width; x++)
137 destS[4 * x + 0] = sourceS[x * 3 + 0];
138 destS[4 * x + 1] = sourceS[x * 3 + 1];
139 destS[4 * x + 2] = sourceS[x * 3 + 2];
140 destS[4 * x + 3] = 0x7FFF;
145 void LoadImageRow<UShortRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
147 const unsigned short *sourceS = reinterpret_cast<const unsigned short*>(source);
148 unsigned short *destS = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
150 for(int x = 0; x < width; x++)
152 destS[4 * x + 0] = sourceS[x * 3 + 0];
153 destS[4 * x + 1] = sourceS[x * 3 + 1];
154 destS[4 * x + 2] = sourceS[x * 3 + 2];
155 destS[4 * x + 3] = 0xFFFF;
160 void LoadImageRow<IntRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
162 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
163 unsigned int *destI = reinterpret_cast<unsigned int*>(dest + xoffset * 16);
165 for(int x = 0; x < width; x++)
167 destI[4 * x + 0] = sourceI[x * 3 + 0];
168 destI[4 * x + 1] = sourceI[x * 3 + 1];
169 destI[4 * x + 2] = sourceI[x * 3 + 2];
170 destI[4 * x + 3] = 0x7FFFFFFF;
175 void LoadImageRow<UIntRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
177 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
178 unsigned int *destI = reinterpret_cast<unsigned int*>(dest + xoffset * 16);
180 for(int x = 0; x < width; x++)
182 destI[4 * x + 0] = sourceI[x * 3 + 0];
183 destI[4 * x + 1] = sourceI[x * 3 + 1];
184 destI[4 * x + 2] = sourceI[x * 3 + 2];
185 destI[4 * x + 3] = 0xFFFFFFFF;
190 void LoadImageRow<RGB565>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
192 memcpy(dest + xoffset * 2, source, width * 2);
196 void LoadImageRow<FloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
198 const float *sourceF = reinterpret_cast<const float*>(source);
199 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
201 for(int x = 0; x < width; x++)
203 destF[4 * x + 0] = sourceF[x * 3 + 0];
204 destF[4 * x + 1] = sourceF[x * 3 + 1];
205 destF[4 * x + 2] = sourceF[x * 3 + 2];
206 destF[4 * x + 3] = 1.0f;
211 void LoadImageRow<HalfFloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
213 const unsigned short *sourceH = reinterpret_cast<const unsigned short*>(source);
214 unsigned short *destH = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
216 for(int x = 0; x < width; x++)
218 destH[4 * x + 0] = sourceH[x * 3 + 0];
219 destH[4 * x + 1] = sourceH[x * 3 + 1];
220 destH[4 * x + 2] = sourceH[x * 3 + 2];
221 destH[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
226 void LoadImageRow<RGBA4444>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
228 const unsigned short *source4444 = reinterpret_cast<const unsigned short*>(source);
229 unsigned char *dest4444 = dest + xoffset * 4;
231 for(int x = 0; x < width; x++)
233 unsigned short rgba = source4444[x];
234 dest4444[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
235 dest4444[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
236 dest4444[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
237 dest4444[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
242 void LoadImageRow<RGBA5551>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
244 const unsigned short *source5551 = reinterpret_cast<const unsigned short*>(source);
245 unsigned char *dest5551 = dest + xoffset * 4;
247 for(int x = 0; x < width; x++)
249 unsigned short rgba = source5551[x];
250 dest5551[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
251 dest5551[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
252 dest5551[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
253 dest5551[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
258 void LoadImageRow<RGB10A2UI>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
260 const unsigned int *source1010102U = reinterpret_cast<const unsigned int*>(source);
261 unsigned short *dest16U = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
263 for(int x = 0; x < width; x++)
265 unsigned int rgba = source1010102U[x];
266 dest16U[4 * x + 0] = (rgba & 0x00000FFC) >> 2;
267 dest16U[4 * x + 1] = (rgba & 0x003FF000) >> 12;
268 dest16U[4 * x + 2] = (rgba & 0xFFC00000) >> 22;
269 dest16U[4 * x + 3] = (rgba & 0x00000003);
274 void LoadImageRow<R11G11B10F>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
276 const sw::R11G11B10FData *sourceRGB = reinterpret_cast<const sw::R11G11B10FData*>(source);
277 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
279 for(int x = 0; x < width; x++, sourceRGB++, destF+=4)
281 sourceRGB->toRGBFloats(destF);
287 void LoadImageRow<RGB9E5>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
289 const sw::RGB9E5Data *sourceRGB = reinterpret_cast<const sw::RGB9E5Data*>(source);
290 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
292 for(int x = 0; x < width; x++, sourceRGB++, destF += 4)
294 sourceRGB->toRGBFloats(destF);
300 void LoadImageRow<SRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
304 for(int x = 0; x < width; x++)
306 for(int rgb = 0; rgb < 3; ++rgb)
308 *dest++ = sw::sRGB8toLinear8(*source++);
315 void LoadImageRow<SRGBA>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
319 for(int x = 0; x < width; x++)
321 for(int rgb = 0; rgb < 3; ++rgb)
323 *dest++ = sw::sRGB8toLinear8(*source++);
330 void LoadImageRow<D16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
332 const unsigned short *sourceD16 = reinterpret_cast<const unsigned short*>(source);
333 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
335 for(int x = 0; x < width; x++)
337 destF[x] = (float)sourceD16[x] / 0xFFFF;
342 void LoadImageRow<D24>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
344 const unsigned int *sourceD24 = reinterpret_cast<const unsigned int*>(source);
345 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
347 for(int x = 0; x < width; x++)
349 destF[x] = (float)(sourceD24[x] & 0xFFFFFF00) / 0xFFFFFF00;
354 void LoadImageRow<D32>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
356 const unsigned int *sourceD32 = reinterpret_cast<const unsigned int*>(source);
357 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
359 for(int x = 0; x < width; x++)
361 destF[x] = (float)sourceD32[x] / 0xFFFFFFFF;
366 void LoadImageRow<S8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
368 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
369 unsigned char *destI = dest + xoffset;
371 for(int x = 0; x < width; x++)
373 destI[x] = static_cast<unsigned char>(sourceI[x] & 0x000000FF); // FIXME: Quad layout
378 void LoadImageRow<D32F>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
380 struct D32FS8 { float depth32f; unsigned int stencil24_8; };
381 const D32FS8 *sourceD32FS8 = reinterpret_cast<const D32FS8*>(source);
382 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
384 for(int x = 0; x < width; x++)
386 destF[x] = sourceD32FS8[x].depth32f;
391 void LoadImageRow<S24_8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
393 struct D32FS8 { float depth32f; unsigned int stencil24_8; };
394 const D32FS8 *sourceD32FS8 = reinterpret_cast<const D32FS8*>(source);
395 unsigned char *destI = dest + xoffset;
397 for(int x = 0; x < width; x++)
399 destI[x] = static_cast<unsigned char>(sourceD32FS8[x].stencil24_8 & 0x000000FF); // FIXME: Quad layout
403 template<DataType dataType>
404 void LoadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, int destPitch, GLsizei destHeight, const void *input, void *buffer)
406 for(int z = 0; z < depth; ++z)
408 const unsigned char *inputStart = static_cast<const unsigned char*>(input) + (z * inputPitch * inputHeight);
409 unsigned char *destStart = static_cast<unsigned char*>(buffer) + ((zoffset + z) * destPitch * destHeight);
410 for(int y = 0; y < height; ++y)
412 const unsigned char *source = inputStart + y * inputPitch;
413 unsigned char *dest = destStart + (y + yoffset) * destPitch;
415 LoadImageRow<dataType>(source, dest, xoffset, width);
423 sw::Format ConvertFormatType(GLenum format, GLenum type)
430 case GL_UNSIGNED_BYTE: return sw::FORMAT_L8;
431 case GL_HALF_FLOAT: return sw::FORMAT_L16F;
432 case GL_HALF_FLOAT_OES: return sw::FORMAT_L16F;
433 case GL_FLOAT: return sw::FORMAT_L32F;
434 default: UNREACHABLE(type);
437 case GL_LUMINANCE8_EXT:
438 return sw::FORMAT_L8;
439 case GL_LUMINANCE16F_EXT:
440 return sw::FORMAT_L16F;
441 case GL_LUMINANCE32F_EXT:
442 return sw::FORMAT_L32F;
443 case GL_LUMINANCE_ALPHA:
446 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8L8;
447 case GL_HALF_FLOAT: return sw::FORMAT_A16L16F;
448 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16L16F;
449 case GL_FLOAT: return sw::FORMAT_A32L32F;
450 default: UNREACHABLE(type);
453 case GL_LUMINANCE8_ALPHA8_EXT:
454 return sw::FORMAT_A8L8;
455 case GL_LUMINANCE_ALPHA16F_EXT:
456 return sw::FORMAT_A16L16F;
457 case GL_LUMINANCE_ALPHA32F_EXT:
458 return sw::FORMAT_A32L32F;
462 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8B8G8R8;
463 case GL_UNSIGNED_SHORT_4_4_4_4: return sw::FORMAT_R4G4B4A4;
464 case GL_UNSIGNED_SHORT_5_5_5_1: return sw::FORMAT_R5G5B5A1;
465 case GL_HALF_FLOAT: return sw::FORMAT_A16B16G16R16F;
466 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16B16G16R16F;
467 case GL_FLOAT: return sw::FORMAT_A32B32G32R32F;
468 default: UNREACHABLE(type);
475 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8R8G8B8;
476 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: return sw::FORMAT_A4R4G4B4;
477 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: return sw::FORMAT_A1R5G5B5;
478 default: UNREACHABLE(type);
484 case GL_UNSIGNED_BYTE: return sw::FORMAT_B8G8R8;
485 case GL_UNSIGNED_SHORT_5_6_5: return sw::FORMAT_R5G6B5;
486 case GL_HALF_FLOAT: return sw::FORMAT_B16G16R16F;
487 case GL_HALF_FLOAT_OES: return sw::FORMAT_B16G16R16F;
488 case GL_FLOAT: return sw::FORMAT_B32G32R32F;
489 default: UNREACHABLE(type);
495 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8;
496 case GL_HALF_FLOAT: return sw::FORMAT_A16F;
497 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16F;
498 case GL_FLOAT: return sw::FORMAT_A32F;
499 default: UNREACHABLE(type);
503 return sw::FORMAT_A8;
504 case GL_ALPHA16F_EXT:
505 return sw::FORMAT_A16F;
506 case GL_ALPHA32F_EXT:
507 return sw::FORMAT_A32F;
511 case GL_INT: return sw::FORMAT_R32I;
512 case GL_UNSIGNED_INT: return sw::FORMAT_R32UI;
513 default: UNREACHABLE(type);
519 case GL_INT: return sw::FORMAT_G32R32I;
520 case GL_UNSIGNED_INT: return sw::FORMAT_G32R32UI;
521 default: UNREACHABLE(type);
524 case GL_RGBA_INTEGER:
527 case GL_INT: return sw::FORMAT_A32B32G32R32I;
528 case GL_UNSIGNED_INT: return sw::FORMAT_A32B32G32R32UI;
529 default: UNREACHABLE(type);
532 case GL_DEPTH_COMPONENT:
535 case GL_UNSIGNED_SHORT: return sw::FORMAT_D16;
536 case GL_UNSIGNED_INT_24_8_OES: return sw::FORMAT_D24S8;
537 case GL_UNSIGNED_INT: return sw::FORMAT_D32;
538 case GL_FLOAT: return sw::FORMAT_D32F;
539 default: UNREACHABLE(type);
546 return sw::FORMAT_NULL;
549 sw::Format SelectInternalFormat(GLenum format, GLenum type)
553 case GL_ETC1_RGB8_OES:
554 return sw::FORMAT_ETC1;
555 case GL_COMPRESSED_R11_EAC:
556 return sw::FORMAT_R11_EAC;
557 case GL_COMPRESSED_SIGNED_R11_EAC:
558 return sw::FORMAT_SIGNED_R11_EAC;
559 case GL_COMPRESSED_RG11_EAC:
560 return sw::FORMAT_RG11_EAC;
561 case GL_COMPRESSED_SIGNED_RG11_EAC:
562 return sw::FORMAT_SIGNED_RG11_EAC;
563 case GL_COMPRESSED_RGB8_ETC2:
564 return sw::FORMAT_RGB8_ETC2;
565 case GL_COMPRESSED_SRGB8_ETC2:
566 return sw::FORMAT_SRGB8_ETC2;
567 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
568 return sw::FORMAT_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
569 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
570 return sw::FORMAT_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
571 case GL_COMPRESSED_RGBA8_ETC2_EAC:
572 return sw::FORMAT_RGBA8_ETC2_EAC;
573 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
574 return sw::FORMAT_SRGB8_ALPHA8_ETC2_EAC;
575 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
576 return sw::FORMAT_RGBA_ASTC_4x4_KHR;
577 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
578 return sw::FORMAT_RGBA_ASTC_5x4_KHR;
579 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
580 return sw::FORMAT_RGBA_ASTC_5x5_KHR;
581 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
582 return sw::FORMAT_RGBA_ASTC_6x5_KHR;
583 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
584 return sw::FORMAT_RGBA_ASTC_6x6_KHR;
585 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
586 return sw::FORMAT_RGBA_ASTC_8x5_KHR;
587 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
588 return sw::FORMAT_RGBA_ASTC_8x6_KHR;
589 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
590 return sw::FORMAT_RGBA_ASTC_8x8_KHR;
591 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
592 return sw::FORMAT_RGBA_ASTC_10x5_KHR;
593 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
594 return sw::FORMAT_RGBA_ASTC_10x6_KHR;
595 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
596 return sw::FORMAT_RGBA_ASTC_10x8_KHR;
597 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
598 return sw::FORMAT_RGBA_ASTC_10x10_KHR;
599 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
600 return sw::FORMAT_RGBA_ASTC_12x10_KHR;
601 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
602 return sw::FORMAT_RGBA_ASTC_12x12_KHR;
603 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
604 return sw::FORMAT_SRGB8_ALPHA8_ASTC_4x4_KHR;
605 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
606 return sw::FORMAT_SRGB8_ALPHA8_ASTC_5x4_KHR;
607 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
608 return sw::FORMAT_SRGB8_ALPHA8_ASTC_5x5_KHR;
609 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
610 return sw::FORMAT_SRGB8_ALPHA8_ASTC_6x5_KHR;
611 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
612 return sw::FORMAT_SRGB8_ALPHA8_ASTC_6x6_KHR;
613 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
614 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x5_KHR;
615 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
616 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x6_KHR;
617 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
618 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x8_KHR;
619 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
620 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x5_KHR;
621 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
622 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x6_KHR;
623 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
624 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x8_KHR;
625 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
626 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x10_KHR;
627 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
628 return sw::FORMAT_SRGB8_ALPHA8_ASTC_12x10_KHR;
629 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
630 return sw::FORMAT_SRGB8_ALPHA8_ASTC_12x12_KHR;
632 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
633 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
634 return sw::FORMAT_DXT1;
635 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
636 return sw::FORMAT_DXT3;
637 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
638 return sw::FORMAT_DXT5;
650 case GL_ALPHA32F_EXT:
651 return sw::FORMAT_A32F;
653 case GL_LUMINANCE32F_EXT:
654 return sw::FORMAT_L32F;
655 case GL_LUMINANCE_ALPHA:
656 case GL_LUMINANCE_ALPHA32F_EXT:
657 return sw::FORMAT_A32L32F;
660 return sw::FORMAT_R32F;
663 return sw::FORMAT_G32R32F;
666 return sw::FORMAT_X32B32G32R32F;
669 return sw::FORMAT_A32B32G32R32F;
670 case GL_DEPTH_COMPONENT:
671 case GL_DEPTH_COMPONENT32F:
672 return sw::FORMAT_D32F;
677 case GL_HALF_FLOAT_OES:
681 case GL_ALPHA16F_EXT:
682 return sw::FORMAT_A16F;
684 case GL_LUMINANCE16F_EXT:
685 return sw::FORMAT_L16F;
686 case GL_LUMINANCE_ALPHA:
687 case GL_LUMINANCE_ALPHA16F_EXT:
688 return sw::FORMAT_A16L16F;
691 return sw::FORMAT_R16F;
694 return sw::FORMAT_G16R16F;
699 return sw::FORMAT_A16B16G16R16F;
709 return sw::FORMAT_R8I_SNORM;
712 return sw::FORMAT_R8I;
716 return sw::FORMAT_G8R8I_SNORM;
719 return sw::FORMAT_G8R8I;
723 return sw::FORMAT_X8B8G8R8I_SNORM;
726 return sw::FORMAT_X8B8G8R8I;
730 return sw::FORMAT_A8B8G8R8I_SNORM;
732 case GL_RGBA_INTEGER:
733 return sw::FORMAT_A8B8G8R8I;
737 case GL_UNSIGNED_BYTE:
741 case GL_LUMINANCE8_EXT:
742 return sw::FORMAT_L8;
743 case GL_LUMINANCE_ALPHA:
744 case GL_LUMINANCE8_ALPHA8_EXT:
745 return sw::FORMAT_A8L8;
749 return sw::FORMAT_R8;
752 return sw::FORMAT_R8UI;
756 return sw::FORMAT_G8R8;
759 return sw::FORMAT_G8R8UI;
764 return sw::FORMAT_X8B8G8R8;
767 return sw::FORMAT_X8B8G8R8UI;
771 case GL_SRGB8_ALPHA8:
772 return sw::FORMAT_A8B8G8R8;
774 case GL_RGBA_INTEGER:
775 return sw::FORMAT_A8B8G8R8UI;
778 return sw::FORMAT_A8R8G8B8;
781 return sw::FORMAT_A8;
783 return sw::FORMAT_YV12_BT601;
785 return sw::FORMAT_YV12_BT709;
787 return sw::FORMAT_YV12_JFIF;
796 return sw::FORMAT_R16I;
799 return sw::FORMAT_G16R16I;
802 return sw::FORMAT_X16B16G16R16I;
804 case GL_RGBA_INTEGER:
805 return sw::FORMAT_A16B16G16R16I;
809 case GL_UNSIGNED_SHORT:
814 return sw::FORMAT_R16UI;
817 return sw::FORMAT_G16R16UI;
820 return sw::FORMAT_X16B16G16R16UI;
822 case GL_RGBA_INTEGER:
823 return sw::FORMAT_A16B16G16R16UI;
824 case GL_DEPTH_COMPONENT:
825 case GL_DEPTH_COMPONENT16:
826 return sw::FORMAT_D32FS8_TEXTURE;
835 return sw::FORMAT_R32I;
838 return sw::FORMAT_G32R32I;
841 return sw::FORMAT_X32B32G32R32I;
842 case GL_RGBA_INTEGER:
844 return sw::FORMAT_A32B32G32R32I;
848 case GL_UNSIGNED_INT:
853 return sw::FORMAT_R32UI;
856 return sw::FORMAT_G32R32UI;
859 return sw::FORMAT_X32B32G32R32UI;
860 case GL_RGBA_INTEGER:
862 return sw::FORMAT_A32B32G32R32UI;
863 case GL_DEPTH_COMPONENT:
864 case GL_DEPTH_COMPONENT16:
865 case GL_DEPTH_COMPONENT24:
866 case GL_DEPTH_COMPONENT32_OES:
867 return sw::FORMAT_D32FS8_TEXTURE;
871 case GL_UNSIGNED_INT_24_8_OES:
872 if(format == GL_DEPTH_STENCIL || format == GL_DEPTH24_STENCIL8)
874 return sw::FORMAT_D32FS8_TEXTURE;
876 else UNREACHABLE(format);
877 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
878 if(format == GL_DEPTH_STENCIL || format == GL_DEPTH32F_STENCIL8)
880 return sw::FORMAT_D32FS8_TEXTURE;
882 else UNREACHABLE(format);
883 case GL_UNSIGNED_SHORT_4_4_4_4:
884 return sw::FORMAT_A8R8G8B8;
885 case GL_UNSIGNED_SHORT_5_5_5_1:
886 return sw::FORMAT_A8R8G8B8;
887 case GL_UNSIGNED_SHORT_5_6_5:
888 return sw::FORMAT_R5G6B5;
889 case GL_UNSIGNED_INT_2_10_10_10_REV:
890 if(format == GL_RGB10_A2UI)
892 return sw::FORMAT_A16B16G16R16UI;
896 return sw::FORMAT_A2B10G10R10;
898 case GL_UNSIGNED_INT_10F_11F_11F_REV:
899 case GL_UNSIGNED_INT_5_9_9_9_REV:
900 return sw::FORMAT_A32B32G32R32F;
905 return sw::FORMAT_NULL;
908 // Returns the size, in bytes, of a single texel in an Image
909 static int ComputePixelSize(GLenum format, GLenum type)
919 case GL_RED: return sizeof(char);
920 case GL_RED_INTEGER: return sizeof(char);
924 case GL_RG: return sizeof(char) * 2;
925 case GL_RG_INTEGER: return sizeof(char) * 2;
929 case GL_RGB: return sizeof(char) * 3;
930 case GL_RGB_INTEGER: return sizeof(char) * 3;
934 case GL_RGBA: return sizeof(char) * 4;
935 case GL_RGBA_INTEGER: return sizeof(char) * 4;
936 default: UNREACHABLE(format);
939 case GL_UNSIGNED_BYTE:
944 case GL_RED: return sizeof(unsigned char);
945 case GL_RED_INTEGER: return sizeof(unsigned char);
947 case GL_ALPHA: return sizeof(unsigned char);
948 case GL_LUMINANCE8_EXT:
949 case GL_LUMINANCE: return sizeof(unsigned char);
950 case GL_LUMINANCE8_ALPHA8_EXT:
951 case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;
954 case GL_RG: return sizeof(unsigned char) * 2;
955 case GL_RG_INTEGER: return sizeof(unsigned char) * 2;
959 case GL_RGB: return sizeof(unsigned char) * 3;
960 case GL_RGB_INTEGER: return sizeof(unsigned char) * 3;
963 case GL_SRGB8_ALPHA8:
964 case GL_RGBA: return sizeof(unsigned char) * 4;
965 case GL_RGBA_INTEGER: return sizeof(unsigned char) * 4;
967 case GL_BGRA8_EXT: return sizeof(unsigned char)* 4;
968 default: UNREACHABLE(format);
975 case GL_RED_INTEGER: return sizeof(short);
977 case GL_RG_INTEGER: return sizeof(short) * 2;
979 case GL_RGB_INTEGER: return sizeof(short) * 3;
981 case GL_RGBA_INTEGER: return sizeof(short) * 4;
982 default: UNREACHABLE(format);
985 case GL_UNSIGNED_SHORT:
988 case GL_DEPTH_COMPONENT16:
989 case GL_DEPTH_COMPONENT: return sizeof(unsigned short);
991 case GL_RED_INTEGER: return sizeof(unsigned short);
993 case GL_RG_INTEGER: return sizeof(unsigned short) * 2;
995 case GL_RGB_INTEGER: return sizeof(unsigned short) * 3;
997 case GL_RGBA_INTEGER: return sizeof(unsigned short) * 4;
998 default: UNREACHABLE(format);
1005 case GL_RED_INTEGER: return sizeof(int);
1007 case GL_RG_INTEGER: return sizeof(int) * 2;
1009 case GL_RGB_INTEGER: return sizeof(int) * 3;
1011 case GL_RGBA_INTEGER: return sizeof(int) * 4;
1012 default: UNREACHABLE(format);
1015 case GL_UNSIGNED_INT:
1018 case GL_DEPTH_COMPONENT16:
1019 case GL_DEPTH_COMPONENT24:
1020 case GL_DEPTH_COMPONENT32_OES:
1021 case GL_DEPTH_COMPONENT: return sizeof(unsigned int);
1023 case GL_RED_INTEGER: return sizeof(unsigned int);
1025 case GL_RG_INTEGER: return sizeof(unsigned int) * 2;
1027 case GL_RGB_INTEGER: return sizeof(unsigned int) * 3;
1029 case GL_RGBA_INTEGER: return sizeof(unsigned int) * 4;
1030 default: UNREACHABLE(format);
1033 case GL_UNSIGNED_SHORT_4_4_4_4:
1034 case GL_UNSIGNED_SHORT_5_5_5_1:
1035 case GL_UNSIGNED_SHORT_5_6_5:
1036 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1037 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1038 return sizeof(unsigned short);
1039 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1040 case GL_UNSIGNED_INT_5_9_9_9_REV:
1041 case GL_UNSIGNED_INT_2_10_10_10_REV:
1042 case GL_UNSIGNED_INT_24_8_OES:
1043 return sizeof(unsigned int);
1044 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1045 return sizeof(float) + sizeof(unsigned int);
1049 case GL_DEPTH_COMPONENT32F:
1050 case GL_DEPTH_COMPONENT: return sizeof(float);
1051 case GL_ALPHA32F_EXT:
1052 case GL_ALPHA: return sizeof(float);
1053 case GL_LUMINANCE32F_EXT:
1054 case GL_LUMINANCE: return sizeof(float);
1055 case GL_LUMINANCE_ALPHA32F_EXT:
1056 case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;
1057 case GL_RED: return sizeof(float);
1058 case GL_R32F: return sizeof(float);
1059 case GL_RG: return sizeof(float) * 2;
1060 case GL_RG32F: return sizeof(float) * 2;
1061 case GL_RGB: return sizeof(float) * 3;
1062 case GL_RGB32F: return sizeof(float) * 3;
1063 case GL_RGBA: return sizeof(float) * 4;
1064 case GL_RGBA32F: return sizeof(float) * 4;
1065 default: UNREACHABLE(format);
1069 case GL_HALF_FLOAT_OES:
1072 case GL_ALPHA16F_EXT:
1073 case GL_ALPHA: return sizeof(unsigned short);
1074 case GL_LUMINANCE16F_EXT:
1075 case GL_LUMINANCE: return sizeof(unsigned short);
1076 case GL_LUMINANCE_ALPHA16F_EXT:
1077 case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2;
1078 case GL_RED: return sizeof(unsigned short);
1079 case GL_R16F: return sizeof(unsigned short);
1080 case GL_RG: return sizeof(unsigned short) * 2;
1081 case GL_RG16F: return sizeof(unsigned short) * 2;
1082 case GL_RGB: return sizeof(unsigned short) * 3;
1083 case GL_RGB16F: return sizeof(unsigned short) * 3;
1084 case GL_RGBA: return sizeof(unsigned short) * 4;
1085 case GL_RGBA16F: return sizeof(unsigned short) * 4;
1086 default: UNREACHABLE(format);
1089 default: UNREACHABLE(type);
1095 GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)
1097 ASSERT(alignment > 0 && sw::isPow2(alignment));
1099 GLsizei rawPitch = ComputePixelSize(format, type) * width;
1100 return (rawPitch + alignment - 1) & ~(alignment - 1);
1103 size_t ComputePackingOffset(GLenum format, GLenum type, GLsizei width, GLsizei height, GLint alignment, GLint skipImages, GLint skipRows, GLint skipPixels)
1105 GLsizei pitchB = ComputePitch(width, format, type, alignment);
1106 return (skipImages * height + skipRows) * pitchB + skipPixels * ComputePixelSize(format, type);
1109 inline GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)
1111 return ComputeCompressedSize(width, 1, format);
1114 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format)
1118 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1119 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1120 case GL_ETC1_RGB8_OES:
1121 case GL_COMPRESSED_R11_EAC:
1122 case GL_COMPRESSED_SIGNED_R11_EAC:
1123 case GL_COMPRESSED_RGB8_ETC2:
1124 case GL_COMPRESSED_SRGB8_ETC2:
1125 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1126 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1127 return 8 * getNumBlocks(width, height, 4, 4);
1128 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1129 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1130 case GL_COMPRESSED_RG11_EAC:
1131 case GL_COMPRESSED_SIGNED_RG11_EAC:
1132 case GL_COMPRESSED_RGBA8_ETC2_EAC:
1133 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
1134 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
1135 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
1136 return 16 * getNumBlocks(width, height, 4, 4);
1137 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
1138 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
1139 return 16 * getNumBlocks(width, height, 5, 4);
1140 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
1141 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
1142 return 16 * getNumBlocks(width, height, 5, 5);
1143 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
1144 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
1145 return 16 * getNumBlocks(width, height, 6, 5);
1146 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
1147 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
1148 return 16 * getNumBlocks(width, height, 6, 6);
1149 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
1150 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
1151 return 16 * getNumBlocks(width, height, 8, 5);
1152 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
1153 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
1154 return 16 * getNumBlocks(width, height, 8, 6);
1155 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
1156 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
1157 return 16 * getNumBlocks(width, height, 8, 8);
1158 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
1159 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
1160 return 16 * getNumBlocks(width, height, 10, 5);
1161 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
1162 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
1163 return 16 * getNumBlocks(width, height, 10, 6);
1164 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
1165 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
1166 return 16 * getNumBlocks(width, height, 10, 8);
1167 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
1168 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
1169 return 16 * getNumBlocks(width, height, 10, 10);
1170 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
1171 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
1172 return 16 * getNumBlocks(width, height, 12, 10);
1173 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
1174 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
1175 return 16 * getNumBlocks(width, height, 12, 12);
1181 class ImageImplementation : public Image
1184 ImageImplementation(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
1185 : Image(parentTexture, width, height, format, type) {}
1186 ImageImplementation(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type)
1187 : Image(parentTexture, width, height, depth, format, type) {}
1188 ImageImplementation(GLsizei width, GLsizei height, GLenum format, GLenum type, int pitchP)
1189 : Image(width, height, format, type, pitchP) {}
1190 ImageImplementation(GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable)
1191 : Image(width, height, internalFormat, multiSampleDepth, lockable) {}
1193 ~ImageImplementation() override
1195 sync(); // Wait for any threads that use this image to finish.
1198 void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client) override
1200 return Image::lockInternal(x, y, z, lock, client);
1203 void unlockInternal() override
1205 return Image::unlockInternal();
1208 void release() override
1210 return Image::release();
1214 Image *Image::create(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
1216 return new ImageImplementation(parentTexture, width, height, format, type);
1219 Image *Image::create(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type)
1221 return new ImageImplementation(parentTexture, width, height, depth, format, type);
1224 Image *Image::create(GLsizei width, GLsizei height, GLenum format, GLenum type, int pitchP)
1226 return new ImageImplementation(width, height, format, type, pitchP);
1229 Image *Image::create(GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable)
1231 return new ImageImplementation(width, height, internalFormat, multiSampleDepth, lockable);
1236 // sync() must be called in the destructor of the most derived class to ensure their vtable isn't destroyed
1237 // before all threads are done using this image. Image itself is abstract so it can't be the most derived.
1238 ASSERT(isUnlocked());
1242 parentTexture->release();
1248 void *Image::lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)
1250 return Surface::lockInternal(x, y, z, lock, client);
1253 void Image::unlockInternal()
1255 Surface::unlockInternal();
1258 void Image::release()
1260 int refs = dereference();
1266 parentTexture->sweep();
1275 void Image::unbind(const egl::Texture *parent)
1277 if(parentTexture == parent)
1279 parentTexture = nullptr;
1285 bool Image::isChildOf(const egl::Texture *parent) const
1287 return parentTexture == parent;
1290 void Image::loadImageData(Context *context, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const UnpackInfo& unpackInfo, const void *input)
1292 sw::Format selectedInternalFormat = SelectInternalFormat(format, type);
1293 if(selectedInternalFormat == sw::FORMAT_NULL)
1298 GLsizei inputWidth = (unpackInfo.rowLength == 0) ? width : unpackInfo.rowLength;
1299 GLsizei inputPitch = ComputePitch(inputWidth, format, type, unpackInfo.alignment);
1300 GLsizei inputHeight = (unpackInfo.imageHeight == 0) ? height : unpackInfo.imageHeight;
1301 input = ((char*)input) + ComputePackingOffset(format, type, inputWidth, inputHeight, unpackInfo.alignment, unpackInfo.skipImages, unpackInfo.skipRows, unpackInfo.skipPixels);
1303 if(selectedInternalFormat == internalFormat)
1305 void *buffer = lock(0, 0, sw::LOCK_WRITEONLY);
1318 case GL_RED_INTEGER:
1322 case GL_LUMINANCE8_EXT:
1323 LoadImageData<Bytes_1>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1330 case GL_LUMINANCE_ALPHA:
1331 case GL_LUMINANCE8_ALPHA8_EXT:
1332 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1338 case GL_RGB_INTEGER:
1339 LoadImageData<ByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1343 case GL_RGBA8_SNORM:
1345 case GL_RGBA_INTEGER:
1348 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1350 default: UNREACHABLE(format);
1353 case GL_UNSIGNED_BYTE:
1360 case GL_RED_INTEGER:
1364 case GL_LUMINANCE8_EXT:
1365 LoadImageData<Bytes_1>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1372 case GL_LUMINANCE_ALPHA:
1373 case GL_LUMINANCE8_ALPHA8_EXT:
1374 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1380 case GL_RGB_INTEGER:
1381 LoadImageData<UByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1385 case GL_RGBA8_SNORM:
1387 case GL_RGBA_INTEGER:
1390 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1393 LoadImageData<SRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1395 case GL_SRGB8_ALPHA8:
1396 LoadImageData<SRGBA>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1398 default: UNREACHABLE(format);
1401 case GL_UNSIGNED_SHORT_5_6_5:
1406 LoadImageData<RGB565>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1408 default: UNREACHABLE(format);
1411 case GL_UNSIGNED_SHORT_4_4_4_4:
1416 LoadImageData<RGBA4444>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1418 default: UNREACHABLE(format);
1421 case GL_UNSIGNED_SHORT_5_5_5_1:
1426 LoadImageData<RGBA5551>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1428 default: UNREACHABLE(format);
1431 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1434 case GL_R11F_G11F_B10F:
1436 LoadImageData<R11G11B10F>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1438 default: UNREACHABLE(format);
1441 case GL_UNSIGNED_INT_5_9_9_9_REV:
1446 LoadImageData<RGB9E5>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1448 default: UNREACHABLE(format);
1451 case GL_UNSIGNED_INT_2_10_10_10_REV:
1455 LoadImageData<RGB10A2UI>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1459 case GL_RGBA_INTEGER:
1460 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1462 default: UNREACHABLE(format);
1468 // float textures are converted to RGBA, not BGRA
1470 case GL_ALPHA32F_EXT:
1471 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1474 case GL_LUMINANCE32F_EXT:
1475 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1477 case GL_LUMINANCE_ALPHA:
1478 case GL_LUMINANCE_ALPHA32F_EXT:
1479 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1483 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1487 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1491 LoadImageData<FloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1495 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1497 case GL_DEPTH_COMPONENT:
1498 case GL_DEPTH_COMPONENT32F:
1499 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1501 default: UNREACHABLE(format);
1505 case GL_HALF_FLOAT_OES:
1509 case GL_ALPHA16F_EXT:
1510 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1513 case GL_LUMINANCE16F_EXT:
1514 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1516 case GL_LUMINANCE_ALPHA:
1517 case GL_LUMINANCE_ALPHA16F_EXT:
1518 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1522 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1526 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1530 LoadImageData<HalfFloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1534 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1536 default: UNREACHABLE(format);
1544 case GL_RED_INTEGER:
1547 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1552 case GL_LUMINANCE_ALPHA:
1553 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1557 case GL_RGB_INTEGER:
1558 LoadImageData<ShortRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1562 case GL_RGBA_INTEGER:
1565 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1567 default: UNREACHABLE(format);
1570 case GL_UNSIGNED_SHORT:
1575 case GL_RED_INTEGER:
1578 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1583 case GL_LUMINANCE_ALPHA:
1584 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1588 case GL_RGB_INTEGER:
1589 LoadImageData<UShortRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1593 case GL_RGBA_INTEGER:
1596 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1598 case GL_DEPTH_COMPONENT:
1599 case GL_DEPTH_COMPONENT16:
1600 LoadImageData<D16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1602 default: UNREACHABLE(format);
1610 case GL_RED_INTEGER:
1613 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1618 case GL_LUMINANCE_ALPHA:
1619 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1623 case GL_RGB_INTEGER:
1624 LoadImageData<IntRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1628 case GL_RGBA_INTEGER:
1631 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1633 default: UNREACHABLE(format);
1636 case GL_UNSIGNED_INT:
1641 case GL_RED_INTEGER:
1644 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1649 case GL_LUMINANCE_ALPHA:
1650 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1654 case GL_RGB_INTEGER:
1655 LoadImageData<UIntRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1659 case GL_RGBA_INTEGER:
1662 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1664 case GL_DEPTH_COMPONENT16:
1665 case GL_DEPTH_COMPONENT24:
1666 case GL_DEPTH_COMPONENT32_OES:
1667 case GL_DEPTH_COMPONENT:
1668 LoadImageData<D32>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1670 default: UNREACHABLE(format);
1673 case GL_UNSIGNED_INT_24_8_OES:
1674 loadD24S8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
1676 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1677 loadD32FS8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
1679 default: UNREACHABLE(type);
1687 sw::Surface *source = sw::Surface::create(width, height, depth, ConvertFormatType(format, type), const_cast<void*>(input), inputPitch, inputPitch * inputHeight);
1688 sw::Rect sourceRect(0, 0, width, height);
1689 sw::Rect destRect(xoffset, yoffset, xoffset + width, yoffset + height);
1690 context->blit(source, sourceRect, this, destRect);
1695 void Image::loadD24S8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
1697 LoadImageData<D24>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1699 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, 0, 0, sw::PUBLIC));
1703 LoadImageData<S8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
1709 void Image::loadD32FS8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
1711 LoadImageData<D32F>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1713 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, 0, 0, sw::PUBLIC));
1717 LoadImageData<S24_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
1723 void Image::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
1725 if(zoffset != 0 || depth != 1)
1727 UNIMPLEMENTED(); // FIXME
1730 int inputPitch = ComputeCompressedPitch(width, format);
1731 int rows = imageSize / inputPitch;
1732 void *buffer = lock(xoffset, yoffset, sw::LOCK_WRITEONLY);
1736 for(int i = 0; i < rows; i++)
1738 memcpy((void*)((GLbyte*)buffer + i * getPitch()), (void*)((GLbyte*)pixels + i * inputPitch), inputPitch);