1 // SwiftShader Software Renderer
3 // Copyright(c) 2005-2013 TransGaming Inc.
5 // All rights reserved. No part of this software may be copied, distributed, transmitted,
6 // transcribed, stored in a retrieval system, translated into any human or computer
7 // language by any means, or disclosed to third parties without the explicit written
8 // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9 // or implied, including but not limited to any patent rights, are granted to you.
14 #include "Renderer/Blitter.hpp"
15 #include "../libEGL/Texture.hpp"
16 #include "../common/debug.h"
17 #include "Common/Math.hpp"
18 #include "Common/Thread.hpp"
20 #include <GLES2/gl2ext.h>
21 #include <GLES3/gl3.h>
27 int getNumBlocks(int w, int h, int blockSizeX, int blockSizeY)
29 return ((w + blockSizeX - 1) / blockSizeX) * ((h + blockSizeY - 1) / blockSizeY);
63 template<DataType dataType>
64 void LoadImageRow(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
70 void LoadImageRow<Bytes_1>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
72 memcpy(dest + xoffset, source, width);
76 void LoadImageRow<Bytes_2>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
78 memcpy(dest + xoffset * 2, source, width * 2);
82 void LoadImageRow<Bytes_4>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
84 memcpy(dest + xoffset * 4, source, width * 4);
88 void LoadImageRow<Bytes_8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
90 memcpy(dest + xoffset * 8, source, width * 8);
94 void LoadImageRow<Bytes_16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
96 memcpy(dest + xoffset * 16, source, width * 16);
100 void LoadImageRow<ByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
102 unsigned char *destB = dest + xoffset * 4;
104 for(int x = 0; x < width; x++)
106 destB[4 * x + 0] = source[x * 3 + 0];
107 destB[4 * x + 1] = source[x * 3 + 1];
108 destB[4 * x + 2] = source[x * 3 + 2];
109 destB[4 * x + 3] = 0x7F;
114 void LoadImageRow<UByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
116 unsigned char *destB = dest + xoffset * 4;
118 for(int x = 0; x < width; x++)
120 destB[4 * x + 0] = source[x * 3 + 0];
121 destB[4 * x + 1] = source[x * 3 + 1];
122 destB[4 * x + 2] = source[x * 3 + 2];
123 destB[4 * x + 3] = 0xFF;
128 void LoadImageRow<ShortRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
130 const unsigned short *sourceS = reinterpret_cast<const unsigned short*>(source);
131 unsigned short *destS = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
133 for(int x = 0; x < width; x++)
135 destS[4 * x + 0] = sourceS[x * 3 + 0];
136 destS[4 * x + 1] = sourceS[x * 3 + 1];
137 destS[4 * x + 2] = sourceS[x * 3 + 2];
138 destS[4 * x + 3] = 0x7FFF;
143 void LoadImageRow<UShortRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
145 const unsigned short *sourceS = reinterpret_cast<const unsigned short*>(source);
146 unsigned short *destS = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
148 for(int x = 0; x < width; x++)
150 destS[4 * x + 0] = sourceS[x * 3 + 0];
151 destS[4 * x + 1] = sourceS[x * 3 + 1];
152 destS[4 * x + 2] = sourceS[x * 3 + 2];
153 destS[4 * x + 3] = 0xFFFF;
158 void LoadImageRow<IntRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
160 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
161 unsigned int *destI = reinterpret_cast<unsigned int*>(dest + xoffset * 16);
163 for(int x = 0; x < width; x++)
165 destI[4 * x + 0] = sourceI[x * 3 + 0];
166 destI[4 * x + 1] = sourceI[x * 3 + 1];
167 destI[4 * x + 2] = sourceI[x * 3 + 2];
168 destI[4 * x + 3] = 0x7FFFFFFF;
173 void LoadImageRow<UIntRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
175 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
176 unsigned int *destI = reinterpret_cast<unsigned int*>(dest + xoffset * 16);
178 for(int x = 0; x < width; x++)
180 destI[4 * x + 0] = sourceI[x * 3 + 0];
181 destI[4 * x + 1] = sourceI[x * 3 + 1];
182 destI[4 * x + 2] = sourceI[x * 3 + 2];
183 destI[4 * x + 3] = 0xFFFFFFFF;
188 void LoadImageRow<RGB565>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
190 memcpy(dest + xoffset * 2, source, width * 2);
194 void LoadImageRow<FloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
196 const float *sourceF = reinterpret_cast<const float*>(source);
197 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
199 for(int x = 0; x < width; x++)
201 destF[4 * x + 0] = sourceF[x * 3 + 0];
202 destF[4 * x + 1] = sourceF[x * 3 + 1];
203 destF[4 * x + 2] = sourceF[x * 3 + 2];
204 destF[4 * x + 3] = 1.0f;
209 void LoadImageRow<HalfFloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
211 const unsigned short *sourceH = reinterpret_cast<const unsigned short*>(source);
212 unsigned short *destH = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
214 for(int x = 0; x < width; x++)
216 destH[4 * x + 0] = sourceH[x * 3 + 0];
217 destH[4 * x + 1] = sourceH[x * 3 + 1];
218 destH[4 * x + 2] = sourceH[x * 3 + 2];
219 destH[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
224 void LoadImageRow<RGBA4444>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
226 const unsigned short *source4444 = reinterpret_cast<const unsigned short*>(source);
227 unsigned char *dest4444 = dest + xoffset * 4;
229 for(int x = 0; x < width; x++)
231 unsigned short rgba = source4444[x];
232 dest4444[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
233 dest4444[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
234 dest4444[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
235 dest4444[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
240 void LoadImageRow<RGBA5551>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
242 const unsigned short *source5551 = reinterpret_cast<const unsigned short*>(source);
243 unsigned char *dest5551 = dest + xoffset * 4;
245 for(int x = 0; x < width; x++)
247 unsigned short rgba = source5551[x];
248 dest5551[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
249 dest5551[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
250 dest5551[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
251 dest5551[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
256 void LoadImageRow<RGB10A2UI>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
258 const unsigned int *source1010102U = reinterpret_cast<const unsigned int*>(source);
259 unsigned short *dest16U = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
261 for(int x = 0; x < width; x++)
263 unsigned int rgba = source1010102U[x];
264 dest16U[4 * x + 0] = (rgba & 0x00000FFC) >> 2;
265 dest16U[4 * x + 1] = (rgba & 0x003FF000) >> 12;
266 dest16U[4 * x + 2] = (rgba & 0xFFC00000) >> 22;
267 dest16U[4 * x + 3] = (rgba & 0x00000003);
272 void LoadImageRow<R11G11B10F>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
274 const sw::R11G11B10FData *sourceRGB = reinterpret_cast<const sw::R11G11B10FData*>(source);
275 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
277 for(int x = 0; x < width; x++, sourceRGB++, destF+=4)
279 sourceRGB->toRGBFloats(destF);
285 void LoadImageRow<RGB9E5>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
287 const sw::RGB9E5Data *sourceRGB = reinterpret_cast<const sw::RGB9E5Data*>(source);
288 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
290 for(int x = 0; x < width; x++, sourceRGB++, destF += 4)
292 sourceRGB->toRGBFloats(destF);
298 void LoadImageRow<SRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
302 for(int x = 0; x < width; x++)
304 for(int rgb = 0; rgb < 3; ++rgb)
306 *dest++ = sw::sRGB8toLinear8(*source++);
313 void LoadImageRow<SRGBA>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
317 for(int x = 0; x < width; x++)
319 for(int rgb = 0; rgb < 3; ++rgb)
321 *dest++ = sw::sRGB8toLinear8(*source++);
328 void LoadImageRow<D16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
330 const unsigned short *sourceD16 = reinterpret_cast<const unsigned short*>(source);
331 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
333 for(int x = 0; x < width; x++)
335 destF[x] = (float)sourceD16[x] / 0xFFFF;
340 void LoadImageRow<D24>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
342 const unsigned int *sourceD24 = reinterpret_cast<const unsigned int*>(source);
343 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
345 for(int x = 0; x < width; x++)
347 destF[x] = (float)(sourceD24[x] & 0xFFFFFF00) / 0xFFFFFF00;
352 void LoadImageRow<D32>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
354 const unsigned int *sourceD32 = reinterpret_cast<const unsigned int*>(source);
355 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
357 for(int x = 0; x < width; x++)
359 destF[x] = (float)sourceD32[x] / 0xFFFFFFFF;
364 void LoadImageRow<S8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
366 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
367 unsigned char *destI = dest + xoffset;
369 for(int x = 0; x < width; x++)
371 destI[x] = static_cast<unsigned char>(sourceI[x] & 0x000000FF); // FIXME: Quad layout
376 void LoadImageRow<D32F>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
378 struct D32FS8 { float depth32f; unsigned int stencil24_8; };
379 const D32FS8 *sourceD32FS8 = reinterpret_cast<const D32FS8*>(source);
380 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
382 for(int x = 0; x < width; x++)
384 destF[x] = sourceD32FS8[x].depth32f;
389 void LoadImageRow<S24_8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
391 struct D32FS8 { float depth32f; unsigned int stencil24_8; };
392 const D32FS8 *sourceD32FS8 = reinterpret_cast<const D32FS8*>(source);
393 unsigned char *destI = dest + xoffset;
395 for(int x = 0; x < width; x++)
397 destI[x] = static_cast<unsigned char>(sourceD32FS8[x].stencil24_8 & 0x000000FF); // FIXME: Quad layout
401 template<DataType dataType>
402 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)
404 for(int z = 0; z < depth; ++z)
406 const unsigned char *inputStart = static_cast<const unsigned char*>(input) + (z * inputPitch * inputHeight);
407 unsigned char *destStart = static_cast<unsigned char*>(buffer) + ((zoffset + z) * destPitch * destHeight);
408 for(int y = 0; y < height; ++y)
410 const unsigned char *source = inputStart + y * inputPitch;
411 unsigned char *dest = destStart + (y + yoffset) * destPitch;
413 LoadImageRow<dataType>(source, dest, xoffset, width);
421 sw::Format ConvertFormatType(GLenum format, GLenum type)
428 case GL_UNSIGNED_BYTE: return sw::FORMAT_L8;
429 case GL_HALF_FLOAT: return sw::FORMAT_L16F;
430 case GL_HALF_FLOAT_OES: return sw::FORMAT_L16F;
431 case GL_FLOAT: return sw::FORMAT_L32F;
432 default: UNREACHABLE(type);
435 case GL_LUMINANCE8_EXT:
436 return sw::FORMAT_L8;
437 case GL_LUMINANCE16F_EXT:
438 return sw::FORMAT_L16F;
439 case GL_LUMINANCE32F_EXT:
440 return sw::FORMAT_L32F;
441 case GL_LUMINANCE_ALPHA:
444 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8L8;
445 case GL_HALF_FLOAT: return sw::FORMAT_A16L16F;
446 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16L16F;
447 case GL_FLOAT: return sw::FORMAT_A32L32F;
448 default: UNREACHABLE(type);
451 case GL_LUMINANCE8_ALPHA8_EXT:
452 return sw::FORMAT_A8L8;
453 case GL_LUMINANCE_ALPHA16F_EXT:
454 return sw::FORMAT_A16L16F;
455 case GL_LUMINANCE_ALPHA32F_EXT:
456 return sw::FORMAT_A32L32F;
460 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8B8G8R8;
461 case GL_UNSIGNED_SHORT_4_4_4_4: return sw::FORMAT_R4G4B4A4;
462 case GL_UNSIGNED_SHORT_5_5_5_1: return sw::FORMAT_R5G5B5A1;
463 case GL_HALF_FLOAT: return sw::FORMAT_A16B16G16R16F;
464 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16B16G16R16F;
465 case GL_FLOAT: return sw::FORMAT_A32B32G32R32F;
466 default: UNREACHABLE(type);
473 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8R8G8B8;
474 default: UNREACHABLE(type);
480 case GL_UNSIGNED_BYTE: return sw::FORMAT_B8G8R8;
481 case GL_UNSIGNED_SHORT_5_6_5: return sw::FORMAT_R5G6B5;
482 case GL_HALF_FLOAT: return sw::FORMAT_B16G16R16F;
483 case GL_HALF_FLOAT_OES: return sw::FORMAT_B16G16R16F;
484 case GL_FLOAT: return sw::FORMAT_B32G32R32F;
485 default: UNREACHABLE(type);
491 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8;
492 case GL_HALF_FLOAT: return sw::FORMAT_A16F;
493 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16F;
494 case GL_FLOAT: return sw::FORMAT_A32F;
495 default: UNREACHABLE(type);
499 return sw::FORMAT_A8;
500 case GL_ALPHA16F_EXT:
501 return sw::FORMAT_A16F;
502 case GL_ALPHA32F_EXT:
503 return sw::FORMAT_A32F;
508 return sw::FORMAT_NULL;
511 sw::Format SelectInternalFormat(GLenum format, GLenum type)
515 case GL_ETC1_RGB8_OES:
516 return sw::FORMAT_ETC1;
517 case GL_COMPRESSED_R11_EAC:
518 return sw::FORMAT_R11_EAC;
519 case GL_COMPRESSED_SIGNED_R11_EAC:
520 return sw::FORMAT_SIGNED_R11_EAC;
521 case GL_COMPRESSED_RG11_EAC:
522 return sw::FORMAT_RG11_EAC;
523 case GL_COMPRESSED_SIGNED_RG11_EAC:
524 return sw::FORMAT_SIGNED_RG11_EAC;
525 case GL_COMPRESSED_RGB8_ETC2:
526 return sw::FORMAT_RGB8_ETC2;
527 case GL_COMPRESSED_SRGB8_ETC2:
528 return sw::FORMAT_SRGB8_ETC2;
529 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
530 return sw::FORMAT_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
531 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
532 return sw::FORMAT_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
533 case GL_COMPRESSED_RGBA8_ETC2_EAC:
534 return sw::FORMAT_RGBA8_ETC2_EAC;
535 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
536 return sw::FORMAT_SRGB8_ALPHA8_ETC2_EAC;
537 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
538 return sw::FORMAT_RGBA_ASTC_4x4_KHR;
539 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
540 return sw::FORMAT_RGBA_ASTC_5x4_KHR;
541 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
542 return sw::FORMAT_RGBA_ASTC_5x5_KHR;
543 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
544 return sw::FORMAT_RGBA_ASTC_6x5_KHR;
545 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
546 return sw::FORMAT_RGBA_ASTC_6x6_KHR;
547 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
548 return sw::FORMAT_RGBA_ASTC_8x5_KHR;
549 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
550 return sw::FORMAT_RGBA_ASTC_8x6_KHR;
551 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
552 return sw::FORMAT_RGBA_ASTC_8x8_KHR;
553 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
554 return sw::FORMAT_RGBA_ASTC_10x5_KHR;
555 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
556 return sw::FORMAT_RGBA_ASTC_10x6_KHR;
557 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
558 return sw::FORMAT_RGBA_ASTC_10x8_KHR;
559 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
560 return sw::FORMAT_RGBA_ASTC_10x10_KHR;
561 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
562 return sw::FORMAT_RGBA_ASTC_12x10_KHR;
563 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
564 return sw::FORMAT_RGBA_ASTC_12x12_KHR;
565 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
566 return sw::FORMAT_SRGB8_ALPHA8_ASTC_4x4_KHR;
567 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
568 return sw::FORMAT_SRGB8_ALPHA8_ASTC_5x4_KHR;
569 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
570 return sw::FORMAT_SRGB8_ALPHA8_ASTC_5x5_KHR;
571 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
572 return sw::FORMAT_SRGB8_ALPHA8_ASTC_6x5_KHR;
573 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
574 return sw::FORMAT_SRGB8_ALPHA8_ASTC_6x6_KHR;
575 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
576 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x5_KHR;
577 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
578 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x6_KHR;
579 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
580 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x8_KHR;
581 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
582 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x5_KHR;
583 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
584 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x6_KHR;
585 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
586 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x8_KHR;
587 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
588 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x10_KHR;
589 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
590 return sw::FORMAT_SRGB8_ALPHA8_ASTC_12x10_KHR;
591 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
592 return sw::FORMAT_SRGB8_ALPHA8_ASTC_12x12_KHR;
594 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
595 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
596 return sw::FORMAT_DXT1;
597 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
598 return sw::FORMAT_DXT3;
599 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
600 return sw::FORMAT_DXT5;
612 case GL_ALPHA32F_EXT:
613 return sw::FORMAT_A32F;
615 case GL_LUMINANCE32F_EXT:
616 return sw::FORMAT_L32F;
617 case GL_LUMINANCE_ALPHA:
618 case GL_LUMINANCE_ALPHA32F_EXT:
619 return sw::FORMAT_A32L32F;
622 return sw::FORMAT_R32F;
625 return sw::FORMAT_G32R32F;
630 return sw::FORMAT_A32B32G32R32F;
631 case GL_DEPTH_COMPONENT:
632 case GL_DEPTH_COMPONENT32F:
633 return sw::FORMAT_D32F;
638 case GL_HALF_FLOAT_OES:
642 case GL_ALPHA16F_EXT:
643 return sw::FORMAT_A16F;
645 case GL_LUMINANCE16F_EXT:
646 return sw::FORMAT_L16F;
647 case GL_LUMINANCE_ALPHA:
648 case GL_LUMINANCE_ALPHA16F_EXT:
649 return sw::FORMAT_A16L16F;
652 return sw::FORMAT_R16F;
655 return sw::FORMAT_G16R16F;
660 return sw::FORMAT_A16B16G16R16F;
670 return sw::FORMAT_R8I_SNORM;
673 return sw::FORMAT_R8I;
677 return sw::FORMAT_G8R8I_SNORM;
680 return sw::FORMAT_G8R8I;
684 return sw::FORMAT_X8B8G8R8I_SNORM;
687 return sw::FORMAT_X8B8G8R8I;
691 return sw::FORMAT_A8B8G8R8I_SNORM;
693 case GL_RGBA_INTEGER:
694 return sw::FORMAT_A8B8G8R8I;
698 case GL_UNSIGNED_BYTE:
702 case GL_LUMINANCE8_EXT:
703 return sw::FORMAT_L8;
704 case GL_LUMINANCE_ALPHA:
705 case GL_LUMINANCE8_ALPHA8_EXT:
706 return sw::FORMAT_A8L8;
710 return sw::FORMAT_R8;
713 return sw::FORMAT_R8UI;
717 return sw::FORMAT_G8R8;
720 return sw::FORMAT_G8R8UI;
725 return sw::FORMAT_X8B8G8R8;
728 return sw::FORMAT_X8B8G8R8UI;
732 case GL_SRGB8_ALPHA8:
733 return sw::FORMAT_A8B8G8R8;
735 case GL_RGBA_INTEGER:
736 return sw::FORMAT_A8B8G8R8UI;
739 return sw::FORMAT_A8R8G8B8;
742 return sw::FORMAT_A8;
744 return sw::FORMAT_YV12_BT601;
746 return sw::FORMAT_YV12_BT709;
748 return sw::FORMAT_YV12_JFIF;
757 return sw::FORMAT_R16I;
760 return sw::FORMAT_G16R16I;
763 return sw::FORMAT_X16B16G16R16I;
765 case GL_RGBA_INTEGER:
766 return sw::FORMAT_A16B16G16R16I;
770 case GL_UNSIGNED_SHORT:
775 return sw::FORMAT_R16UI;
778 return sw::FORMAT_G16R16UI;
781 return sw::FORMAT_X16B16G16R16UI;
783 case GL_RGBA_INTEGER:
784 return sw::FORMAT_A16B16G16R16UI;
785 case GL_DEPTH_COMPONENT:
786 case GL_DEPTH_COMPONENT16:
787 return sw::FORMAT_D32FS8_TEXTURE;
796 return sw::FORMAT_R32I;
799 return sw::FORMAT_G32R32I;
802 return sw::FORMAT_X32B32G32R32I;
803 case GL_RGBA_INTEGER:
805 return sw::FORMAT_A32B32G32R32I;
809 case GL_UNSIGNED_INT:
814 return sw::FORMAT_R32UI;
817 return sw::FORMAT_G32R32UI;
820 return sw::FORMAT_X32B32G32R32UI;
821 case GL_RGBA_INTEGER:
823 return sw::FORMAT_A32B32G32R32UI;
824 case GL_DEPTH_COMPONENT:
825 case GL_DEPTH_COMPONENT16:
826 case GL_DEPTH_COMPONENT24:
827 case GL_DEPTH_COMPONENT32_OES:
828 return sw::FORMAT_D32FS8_TEXTURE;
832 case GL_UNSIGNED_INT_24_8_OES:
833 if(format == GL_DEPTH_STENCIL || format == GL_DEPTH24_STENCIL8)
835 return sw::FORMAT_D32FS8_TEXTURE;
837 else UNREACHABLE(format);
838 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
839 if(format == GL_DEPTH_STENCIL || format == GL_DEPTH32F_STENCIL8)
841 return sw::FORMAT_D32FS8_TEXTURE;
843 else UNREACHABLE(format);
844 case GL_UNSIGNED_SHORT_4_4_4_4:
845 return sw::FORMAT_A8R8G8B8;
846 case GL_UNSIGNED_SHORT_5_5_5_1:
847 return sw::FORMAT_A8R8G8B8;
848 case GL_UNSIGNED_SHORT_5_6_5:
849 return sw::FORMAT_R5G6B5;
850 case GL_UNSIGNED_INT_2_10_10_10_REV:
851 if(format == GL_RGB10_A2UI)
853 return sw::FORMAT_A16B16G16R16UI;
857 return sw::FORMAT_A2B10G10R10;
859 case GL_UNSIGNED_INT_10F_11F_11F_REV:
860 case GL_UNSIGNED_INT_5_9_9_9_REV:
861 return sw::FORMAT_A32B32G32R32F;
866 return sw::FORMAT_NULL;
869 // Returns the size, in bytes, of a single texel in an Image
870 static int ComputePixelSize(GLenum format, GLenum type)
880 case GL_RED: return sizeof(char);
881 case GL_RED_INTEGER: return sizeof(char);
885 case GL_RG: return sizeof(char) * 2;
886 case GL_RG_INTEGER: return sizeof(char) * 2;
890 case GL_RGB: return sizeof(char) * 3;
891 case GL_RGB_INTEGER: return sizeof(char) * 3;
895 case GL_RGBA: return sizeof(char) * 4;
896 case GL_RGBA_INTEGER: return sizeof(char) * 4;
897 default: UNREACHABLE(format);
900 case GL_UNSIGNED_BYTE:
905 case GL_RED: return sizeof(unsigned char);
906 case GL_RED_INTEGER: return sizeof(unsigned char);
908 case GL_ALPHA: return sizeof(unsigned char);
909 case GL_LUMINANCE8_EXT:
910 case GL_LUMINANCE: return sizeof(unsigned char);
911 case GL_LUMINANCE8_ALPHA8_EXT:
912 case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;
915 case GL_RG: return sizeof(unsigned char) * 2;
916 case GL_RG_INTEGER: return sizeof(unsigned char) * 2;
920 case GL_RGB: return sizeof(unsigned char) * 3;
921 case GL_RGB_INTEGER: return sizeof(unsigned char) * 3;
924 case GL_SRGB8_ALPHA8:
925 case GL_RGBA: return sizeof(unsigned char) * 4;
926 case GL_RGBA_INTEGER: return sizeof(unsigned char) * 4;
928 case GL_BGRA8_EXT: return sizeof(unsigned char)* 4;
929 default: UNREACHABLE(format);
936 case GL_RED_INTEGER: return sizeof(short);
938 case GL_RG_INTEGER: return sizeof(short) * 2;
940 case GL_RGB_INTEGER: return sizeof(short) * 3;
942 case GL_RGBA_INTEGER: return sizeof(short) * 4;
943 default: UNREACHABLE(format);
946 case GL_UNSIGNED_SHORT:
949 case GL_DEPTH_COMPONENT16:
950 case GL_DEPTH_COMPONENT: return sizeof(unsigned short);
952 case GL_RED_INTEGER: return sizeof(unsigned short);
954 case GL_RG_INTEGER: return sizeof(unsigned short) * 2;
956 case GL_RGB_INTEGER: return sizeof(unsigned short) * 3;
958 case GL_RGBA_INTEGER: return sizeof(unsigned short) * 4;
959 default: UNREACHABLE(format);
966 case GL_RED_INTEGER: return sizeof(int);
968 case GL_RG_INTEGER: return sizeof(int) * 2;
970 case GL_RGB_INTEGER: return sizeof(int) * 3;
972 case GL_RGBA_INTEGER: return sizeof(int) * 4;
973 default: UNREACHABLE(format);
976 case GL_UNSIGNED_INT:
979 case GL_DEPTH_COMPONENT16:
980 case GL_DEPTH_COMPONENT24:
981 case GL_DEPTH_COMPONENT32_OES:
982 case GL_DEPTH_COMPONENT: return sizeof(unsigned int);
984 case GL_RED_INTEGER: return sizeof(unsigned int);
986 case GL_RG_INTEGER: return sizeof(unsigned int) * 2;
988 case GL_RGB_INTEGER: return sizeof(unsigned int) * 3;
990 case GL_RGBA_INTEGER: return sizeof(unsigned int) * 4;
991 default: UNREACHABLE(format);
994 case GL_UNSIGNED_SHORT_4_4_4_4:
995 case GL_UNSIGNED_SHORT_5_5_5_1:
996 case GL_UNSIGNED_SHORT_5_6_5:
997 return sizeof(unsigned short);
998 case GL_UNSIGNED_INT_10F_11F_11F_REV:
999 case GL_UNSIGNED_INT_5_9_9_9_REV:
1000 case GL_UNSIGNED_INT_2_10_10_10_REV:
1001 case GL_UNSIGNED_INT_24_8_OES:
1002 return sizeof(unsigned int);
1003 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1004 return sizeof(float) + sizeof(unsigned int);
1008 case GL_DEPTH_COMPONENT32F:
1009 case GL_DEPTH_COMPONENT: return sizeof(float);
1010 case GL_ALPHA32F_EXT:
1011 case GL_ALPHA: return sizeof(float);
1012 case GL_LUMINANCE32F_EXT:
1013 case GL_LUMINANCE: return sizeof(float);
1014 case GL_LUMINANCE_ALPHA32F_EXT:
1015 case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;
1016 case GL_RED: return sizeof(float);
1017 case GL_R32F: return sizeof(float);
1018 case GL_RG: return sizeof(float) * 2;
1019 case GL_RG32F: return sizeof(float) * 2;
1020 case GL_RGB: return sizeof(float) * 3;
1021 case GL_RGB32F: return sizeof(float) * 3;
1022 case GL_RGBA: return sizeof(float) * 4;
1023 case GL_RGBA32F: return sizeof(float) * 4;
1024 default: UNREACHABLE(format);
1028 case GL_HALF_FLOAT_OES:
1031 case GL_ALPHA16F_EXT:
1032 case GL_ALPHA: return sizeof(unsigned short);
1033 case GL_LUMINANCE16F_EXT:
1034 case GL_LUMINANCE: return sizeof(unsigned short);
1035 case GL_LUMINANCE_ALPHA16F_EXT:
1036 case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2;
1037 case GL_RED: return sizeof(unsigned short);
1038 case GL_R16F: return sizeof(unsigned short);
1039 case GL_RG: return sizeof(unsigned short) * 2;
1040 case GL_RG16F: return sizeof(unsigned short) * 2;
1041 case GL_RGB: return sizeof(unsigned short) * 3;
1042 case GL_RGB16F: return sizeof(unsigned short) * 3;
1043 case GL_RGBA: return sizeof(unsigned short) * 4;
1044 case GL_RGBA16F: return sizeof(unsigned short) * 4;
1045 default: UNREACHABLE(format);
1048 default: UNREACHABLE(type);
1054 GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)
1056 ASSERT(alignment > 0 && sw::isPow2(alignment));
1058 GLsizei rawPitch = ComputePixelSize(format, type) * width;
1059 return (rawPitch + alignment - 1) & ~(alignment - 1);
1063 GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)
1065 return ComputeCompressedSize(width, 1, format);
1068 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format)
1072 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1073 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1074 case GL_ETC1_RGB8_OES:
1075 case GL_COMPRESSED_R11_EAC:
1076 case GL_COMPRESSED_SIGNED_R11_EAC:
1077 case GL_COMPRESSED_RGB8_ETC2:
1078 case GL_COMPRESSED_SRGB8_ETC2:
1079 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1080 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1081 return 8 * getNumBlocks(width, height, 4, 4);
1082 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1083 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1084 case GL_COMPRESSED_RG11_EAC:
1085 case GL_COMPRESSED_SIGNED_RG11_EAC:
1086 case GL_COMPRESSED_RGBA8_ETC2_EAC:
1087 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
1088 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
1089 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
1090 return 16 * getNumBlocks(width, height, 4, 4);
1091 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
1092 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
1093 return 16 * getNumBlocks(width, height, 5, 4);
1094 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
1095 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
1096 return 16 * getNumBlocks(width, height, 5, 5);
1097 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
1098 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
1099 return 16 * getNumBlocks(width, height, 6, 5);
1100 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
1101 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
1102 return 16 * getNumBlocks(width, height, 6, 6);
1103 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
1104 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
1105 return 16 * getNumBlocks(width, height, 8, 5);
1106 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
1107 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
1108 return 16 * getNumBlocks(width, height, 8, 6);
1109 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
1110 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
1111 return 16 * getNumBlocks(width, height, 8, 8);
1112 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
1113 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
1114 return 16 * getNumBlocks(width, height, 10, 5);
1115 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
1116 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
1117 return 16 * getNumBlocks(width, height, 10, 6);
1118 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
1119 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
1120 return 16 * getNumBlocks(width, height, 10, 8);
1121 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
1122 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
1123 return 16 * getNumBlocks(width, height, 10, 10);
1124 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
1125 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
1126 return 16 * getNumBlocks(width, height, 12, 10);
1127 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
1128 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
1129 return 16 * getNumBlocks(width, height, 12, 12);
1137 ASSERT(referenceCount == 0);
1140 void Image::addRef()
1144 return parentTexture->addRef();
1146 int newCount = sw::atomicIncrement(&referenceCount);
1147 LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
1150 void Image::release()
1154 return parentTexture->release();
1157 int newCount = sw::atomicDecrement(&referenceCount);
1158 LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
1161 ASSERT(!shared); // Should still hold a reference if eglDestroyImage hasn't been called
1166 void Image::unbind(const egl::Texture *parent)
1168 if(parentTexture == parent)
1176 void Image::loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const UnpackInfo& unpackInfo, const void *input)
1178 GLsizei inputPitch = ComputePitch((unpackInfo.rowLength == 0) ? width : unpackInfo.rowLength, format, type, unpackInfo.alignment);
1179 GLsizei inputHeight = (unpackInfo.imageHeight == 0) ? height : unpackInfo.imageHeight;
1180 input = ((char*)input) + (unpackInfo.skipImages * inputHeight + unpackInfo.skipRows) * inputPitch + unpackInfo.skipPixels;
1181 sw::Format selectedInternalFormat = SelectInternalFormat(format, type);
1182 if(selectedInternalFormat == sw::FORMAT_NULL)
1187 if(selectedInternalFormat == internalFormat)
1189 void *buffer = lock(0, 0, sw::LOCK_WRITEONLY);
1202 case GL_RED_INTEGER:
1206 case GL_LUMINANCE8_EXT:
1207 LoadImageData<Bytes_1>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1214 case GL_LUMINANCE_ALPHA:
1215 case GL_LUMINANCE8_ALPHA8_EXT:
1216 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1222 case GL_RGB_INTEGER:
1223 LoadImageData<ByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1227 case GL_RGBA8_SNORM:
1229 case GL_RGBA_INTEGER:
1232 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1234 default: UNREACHABLE(format);
1237 case GL_UNSIGNED_BYTE:
1244 case GL_RED_INTEGER:
1248 case GL_LUMINANCE8_EXT:
1249 LoadImageData<Bytes_1>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1256 case GL_LUMINANCE_ALPHA:
1257 case GL_LUMINANCE8_ALPHA8_EXT:
1258 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1264 case GL_RGB_INTEGER:
1265 LoadImageData<UByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1269 case GL_RGBA8_SNORM:
1271 case GL_RGBA_INTEGER:
1274 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1277 LoadImageData<SRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1279 case GL_SRGB8_ALPHA8:
1280 LoadImageData<SRGBA>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1282 default: UNREACHABLE(format);
1285 case GL_UNSIGNED_SHORT_5_6_5:
1290 LoadImageData<RGB565>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1292 default: UNREACHABLE(format);
1295 case GL_UNSIGNED_SHORT_4_4_4_4:
1300 LoadImageData<RGBA4444>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1302 default: UNREACHABLE(format);
1305 case GL_UNSIGNED_SHORT_5_5_5_1:
1310 LoadImageData<RGBA5551>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1312 default: UNREACHABLE(format);
1315 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1318 case GL_R11F_G11F_B10F:
1320 LoadImageData<R11G11B10F>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1322 default: UNREACHABLE(format);
1325 case GL_UNSIGNED_INT_5_9_9_9_REV:
1330 LoadImageData<RGB9E5>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1332 default: UNREACHABLE(format);
1335 case GL_UNSIGNED_INT_2_10_10_10_REV:
1339 LoadImageData<RGB10A2UI>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1343 case GL_RGBA_INTEGER:
1344 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1346 default: UNREACHABLE(format);
1352 // float textures are converted to RGBA, not BGRA
1354 case GL_ALPHA32F_EXT:
1355 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1358 case GL_LUMINANCE32F_EXT:
1359 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1361 case GL_LUMINANCE_ALPHA:
1362 case GL_LUMINANCE_ALPHA32F_EXT:
1363 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1367 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1371 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1375 LoadImageData<FloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1379 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1381 case GL_DEPTH_COMPONENT:
1382 case GL_DEPTH_COMPONENT32F:
1383 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1385 default: UNREACHABLE(format);
1389 case GL_HALF_FLOAT_OES:
1393 case GL_ALPHA16F_EXT:
1394 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1397 case GL_LUMINANCE16F_EXT:
1398 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1400 case GL_LUMINANCE_ALPHA:
1401 case GL_LUMINANCE_ALPHA16F_EXT:
1402 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1406 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1410 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1414 LoadImageData<HalfFloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1418 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1420 default: UNREACHABLE(format);
1428 case GL_RED_INTEGER:
1431 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1436 case GL_LUMINANCE_ALPHA:
1437 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1441 case GL_RGB_INTEGER:
1442 LoadImageData<ShortRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1446 case GL_RGBA_INTEGER:
1449 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1451 default: UNREACHABLE(format);
1454 case GL_UNSIGNED_SHORT:
1459 case GL_RED_INTEGER:
1462 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1467 case GL_LUMINANCE_ALPHA:
1468 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1472 case GL_RGB_INTEGER:
1473 LoadImageData<UShortRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1477 case GL_RGBA_INTEGER:
1480 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1482 case GL_DEPTH_COMPONENT:
1483 case GL_DEPTH_COMPONENT16:
1484 LoadImageData<D16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1486 default: UNREACHABLE(format);
1494 case GL_RED_INTEGER:
1497 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1502 case GL_LUMINANCE_ALPHA:
1503 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1507 case GL_RGB_INTEGER:
1508 LoadImageData<IntRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1512 case GL_RGBA_INTEGER:
1515 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1517 default: UNREACHABLE(format);
1520 case GL_UNSIGNED_INT:
1525 case GL_RED_INTEGER:
1528 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1533 case GL_LUMINANCE_ALPHA:
1534 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1538 case GL_RGB_INTEGER:
1539 LoadImageData<UIntRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1543 case GL_RGBA_INTEGER:
1546 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1548 case GL_DEPTH_COMPONENT16:
1549 case GL_DEPTH_COMPONENT24:
1550 case GL_DEPTH_COMPONENT32_OES:
1551 case GL_DEPTH_COMPONENT:
1552 LoadImageData<D32>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1554 default: UNREACHABLE(format);
1557 case GL_UNSIGNED_INT_24_8_OES:
1558 loadD24S8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
1560 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1561 loadD32FS8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
1563 default: UNREACHABLE(type);
1571 sw::Surface source(width, height, depth, ConvertFormatType(format, type), const_cast<void*>(input), inputPitch, inputPitch * inputHeight);
1572 sw::Rect sourceRect(0, 0, width, height);
1573 sw::Rect destRect(xoffset, yoffset, xoffset + width, yoffset + height);
1574 sw::blitter.blit(&source, sourceRect, this, destRect, false);
1578 void Image::loadD24S8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
1580 LoadImageData<D24>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1582 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, sw::PUBLIC));
1586 LoadImageData<S8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
1592 void Image::loadD32FS8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
1594 LoadImageData<D32F>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1596 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, sw::PUBLIC));
1600 LoadImageData<S24_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
1606 void Image::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
1608 if(zoffset != 0 || depth != 1)
1610 UNIMPLEMENTED(); // FIXME
1613 int inputPitch = ComputeCompressedPitch(width, format);
1614 int rows = imageSize / inputPitch;
1615 void *buffer = lock(xoffset, yoffset, sw::LOCK_WRITEONLY);
1619 for(int i = 0; i < rows; i++)
1621 memcpy((void*)((GLbyte*)buffer + i * getPitch()), (void*)((GLbyte*)pixels + i * inputPitch), inputPitch);