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 <GLES3/gl3.h>
26 int getNumBlocks(int w, int h, int blockSizeX, int blockSizeY)
28 return ((w + blockSizeX - 1) / blockSizeX) * ((h + blockSizeY - 1) / blockSizeY);
62 template<DataType dataType>
63 void LoadImageRow(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
69 void LoadImageRow<Bytes_1>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
71 memcpy(dest + xoffset, source, width);
75 void LoadImageRow<Bytes_2>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
77 memcpy(dest + xoffset * 2, source, width * 2);
81 void LoadImageRow<Bytes_4>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
83 memcpy(dest + xoffset * 4, source, width * 4);
87 void LoadImageRow<Bytes_8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
89 memcpy(dest + xoffset * 8, source, width * 8);
93 void LoadImageRow<Bytes_16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
95 memcpy(dest + xoffset * 16, source, width * 16);
99 void LoadImageRow<ByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
101 unsigned char *destB = dest + xoffset * 4;
103 for(int x = 0; x < width; x++)
105 destB[4 * x + 0] = source[x * 3 + 0];
106 destB[4 * x + 1] = source[x * 3 + 1];
107 destB[4 * x + 2] = source[x * 3 + 2];
108 destB[4 * x + 3] = 0x7F;
113 void LoadImageRow<UByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
115 unsigned char *destB = dest + xoffset * 4;
117 for(int x = 0; x < width; x++)
119 destB[4 * x + 0] = source[x * 3 + 0];
120 destB[4 * x + 1] = source[x * 3 + 1];
121 destB[4 * x + 2] = source[x * 3 + 2];
122 destB[4 * x + 3] = 0xFF;
127 void LoadImageRow<ShortRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
129 const unsigned short *sourceS = reinterpret_cast<const unsigned short*>(source);
130 unsigned short *destS = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
132 for(int x = 0; x < width; x++)
134 destS[4 * x + 0] = sourceS[x * 3 + 0];
135 destS[4 * x + 1] = sourceS[x * 3 + 1];
136 destS[4 * x + 2] = sourceS[x * 3 + 2];
137 destS[4 * x + 3] = 0x7FFF;
142 void LoadImageRow<UShortRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
144 const unsigned short *sourceS = reinterpret_cast<const unsigned short*>(source);
145 unsigned short *destS = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
147 for(int x = 0; x < width; x++)
149 destS[4 * x + 0] = sourceS[x * 3 + 0];
150 destS[4 * x + 1] = sourceS[x * 3 + 1];
151 destS[4 * x + 2] = sourceS[x * 3 + 2];
152 destS[4 * x + 3] = 0xFFFF;
157 void LoadImageRow<IntRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
159 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
160 unsigned int *destI = reinterpret_cast<unsigned int*>(dest + xoffset * 16);
162 for(int x = 0; x < width; x++)
164 destI[4 * x + 0] = sourceI[x * 3 + 0];
165 destI[4 * x + 1] = sourceI[x * 3 + 1];
166 destI[4 * x + 2] = sourceI[x * 3 + 2];
167 destI[4 * x + 3] = 0x7FFFFFFF;
172 void LoadImageRow<UIntRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
174 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
175 unsigned int *destI = reinterpret_cast<unsigned int*>(dest + xoffset * 16);
177 for(int x = 0; x < width; x++)
179 destI[4 * x + 0] = sourceI[x * 3 + 0];
180 destI[4 * x + 1] = sourceI[x * 3 + 1];
181 destI[4 * x + 2] = sourceI[x * 3 + 2];
182 destI[4 * x + 3] = 0xFFFFFFFF;
187 void LoadImageRow<RGB565>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
189 memcpy(dest + xoffset * 2, source, width * 2);
193 void LoadImageRow<FloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
195 const float *sourceF = reinterpret_cast<const float*>(source);
196 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
198 for(int x = 0; x < width; x++)
200 destF[4 * x + 0] = sourceF[x * 3 + 0];
201 destF[4 * x + 1] = sourceF[x * 3 + 1];
202 destF[4 * x + 2] = sourceF[x * 3 + 2];
203 destF[4 * x + 3] = 1.0f;
208 void LoadImageRow<HalfFloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
210 const unsigned short *sourceH = reinterpret_cast<const unsigned short*>(source);
211 unsigned short *destH = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
213 for(int x = 0; x < width; x++)
215 destH[4 * x + 0] = sourceH[x * 3 + 0];
216 destH[4 * x + 1] = sourceH[x * 3 + 1];
217 destH[4 * x + 2] = sourceH[x * 3 + 2];
218 destH[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
223 void LoadImageRow<RGBA4444>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
225 const unsigned short *source4444 = reinterpret_cast<const unsigned short*>(source);
226 unsigned char *dest4444 = dest + xoffset * 4;
228 for(int x = 0; x < width; x++)
230 unsigned short rgba = source4444[x];
231 dest4444[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
232 dest4444[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
233 dest4444[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
234 dest4444[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
239 void LoadImageRow<RGBA5551>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
241 const unsigned short *source5551 = reinterpret_cast<const unsigned short*>(source);
242 unsigned char *dest5551 = dest + xoffset * 4;
244 for(int x = 0; x < width; x++)
246 unsigned short rgba = source5551[x];
247 dest5551[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
248 dest5551[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
249 dest5551[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
250 dest5551[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
255 void LoadImageRow<RGB10A2UI>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
257 const unsigned int *source1010102U = reinterpret_cast<const unsigned int*>(source);
258 unsigned short *dest16U = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
260 for(int x = 0; x < width; x++)
262 unsigned int rgba = source1010102U[x];
263 dest16U[4 * x + 0] = (rgba & 0x00000FFC) >> 2;
264 dest16U[4 * x + 1] = (rgba & 0x003FF000) >> 12;
265 dest16U[4 * x + 2] = (rgba & 0xFFC00000) >> 22;
266 dest16U[4 * x + 3] = (rgba & 0x00000003);
271 void LoadImageRow<R11G11B10F>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
273 const sw::R11G11B10FData *sourceRGB = reinterpret_cast<const sw::R11G11B10FData*>(source);
274 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
276 for(int x = 0; x < width; x++, sourceRGB++, destF+=4)
278 sourceRGB->toRGBFloats(destF);
284 void LoadImageRow<RGB9E5>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
286 const sw::RGB9E5Data *sourceRGB = reinterpret_cast<const sw::RGB9E5Data*>(source);
287 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
289 for(int x = 0; x < width; x++, sourceRGB++, destF += 4)
291 sourceRGB->toRGBFloats(destF);
297 void LoadImageRow<SRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
301 for(int x = 0; x < width; x++)
303 for(int rgb = 0; rgb < 3; ++rgb)
305 *dest++ = sw::sRGB8toLinear8(*source++);
312 void LoadImageRow<SRGBA>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
316 for(int x = 0; x < width; x++)
318 for(int rgb = 0; rgb < 3; ++rgb)
320 *dest++ = sw::sRGB8toLinear8(*source++);
327 void LoadImageRow<D16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
329 const unsigned short *sourceD16 = reinterpret_cast<const unsigned short*>(source);
330 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
332 for(int x = 0; x < width; x++)
334 destF[x] = (float)sourceD16[x] / 0xFFFF;
339 void LoadImageRow<D24>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
341 const unsigned int *sourceD24 = reinterpret_cast<const unsigned int*>(source);
342 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
344 for(int x = 0; x < width; x++)
346 destF[x] = (float)(sourceD24[x] & 0xFFFFFF00) / 0xFFFFFF00;
351 void LoadImageRow<D32>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
353 const unsigned int *sourceD32 = reinterpret_cast<const unsigned int*>(source);
354 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
356 for(int x = 0; x < width; x++)
358 destF[x] = (float)sourceD32[x] / 0xFFFFFFFF;
363 void LoadImageRow<S8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
365 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
366 unsigned char *destI = dest + xoffset;
368 for(int x = 0; x < width; x++)
370 destI[x] = static_cast<unsigned char>(sourceI[x] & 0x000000FF); // FIXME: Quad layout
375 void LoadImageRow<D32F>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
377 struct D32FS8 { float depth32f; unsigned int stencil24_8; };
378 const D32FS8 *sourceD32FS8 = reinterpret_cast<const D32FS8*>(source);
379 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
381 for(int x = 0; x < width; x++)
383 destF[x] = sourceD32FS8[x].depth32f;
388 void LoadImageRow<S24_8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
390 struct D32FS8 { float depth32f; unsigned int stencil24_8; };
391 const D32FS8 *sourceD32FS8 = reinterpret_cast<const D32FS8*>(source);
392 unsigned char *destI = dest + xoffset;
394 for(int x = 0; x < width; x++)
396 destI[x] = static_cast<unsigned char>(sourceD32FS8[x].stencil24_8 & 0x000000FF); // FIXME: Quad layout
400 template<DataType dataType>
401 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)
403 for(int z = 0; z < depth; ++z)
405 const unsigned char *inputStart = static_cast<const unsigned char*>(input) + (z * inputPitch * inputHeight);
406 unsigned char *destStart = static_cast<unsigned char*>(buffer) + ((zoffset + z) * destPitch * destHeight);
407 for(int y = 0; y < height; ++y)
409 const unsigned char *source = inputStart + y * inputPitch;
410 unsigned char *dest = destStart + (y + yoffset) * destPitch;
412 LoadImageRow<dataType>(source, dest, xoffset, width);
420 sw::Format ConvertFormatType(GLenum format, GLenum type)
427 case GL_UNSIGNED_BYTE: return sw::FORMAT_L8;
428 case GL_HALF_FLOAT: return sw::FORMAT_L16F;
429 case GL_HALF_FLOAT_OES: return sw::FORMAT_L16F;
430 case GL_FLOAT: return sw::FORMAT_L32F;
431 default: UNREACHABLE(type);
434 case GL_LUMINANCE8_EXT:
435 return sw::FORMAT_L8;
436 case GL_LUMINANCE16F_EXT:
437 return sw::FORMAT_L16F;
438 case GL_LUMINANCE32F_EXT:
439 return sw::FORMAT_L32F;
440 case GL_LUMINANCE_ALPHA:
443 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8L8;
444 case GL_HALF_FLOAT: return sw::FORMAT_A16L16F;
445 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16L16F;
446 case GL_FLOAT: return sw::FORMAT_A32L32F;
447 default: UNREACHABLE(type);
450 case GL_LUMINANCE8_ALPHA8_EXT:
451 return sw::FORMAT_A8L8;
452 case GL_LUMINANCE_ALPHA16F_EXT:
453 return sw::FORMAT_A16L16F;
454 case GL_LUMINANCE_ALPHA32F_EXT:
455 return sw::FORMAT_A32L32F;
459 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8B8G8R8;
460 case GL_UNSIGNED_SHORT_4_4_4_4: return sw::FORMAT_R4G4B4A4;
461 case GL_UNSIGNED_SHORT_5_5_5_1: return sw::FORMAT_R5G5B5A1;
462 case GL_HALF_FLOAT: return sw::FORMAT_A16B16G16R16F;
463 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16B16G16R16F;
464 case GL_FLOAT: return sw::FORMAT_A32B32G32R32F;
465 default: UNREACHABLE(type);
472 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8R8G8B8;
473 default: UNREACHABLE(type);
479 case GL_UNSIGNED_BYTE: return sw::FORMAT_B8G8R8;
480 case GL_UNSIGNED_SHORT_5_6_5: return sw::FORMAT_R5G6B5;
481 case GL_HALF_FLOAT: return sw::FORMAT_B16G16R16F;
482 case GL_HALF_FLOAT_OES: return sw::FORMAT_B16G16R16F;
483 case GL_FLOAT: return sw::FORMAT_B32G32R32F;
484 default: UNREACHABLE(type);
490 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8;
491 case GL_HALF_FLOAT: return sw::FORMAT_A16F;
492 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16F;
493 case GL_FLOAT: return sw::FORMAT_A32F;
494 default: UNREACHABLE(type);
498 return sw::FORMAT_A8;
499 case GL_ALPHA16F_EXT:
500 return sw::FORMAT_A16F;
501 case GL_ALPHA32F_EXT:
502 return sw::FORMAT_A32F;
507 return sw::FORMAT_NULL;
510 sw::Format SelectInternalFormat(GLenum format, GLenum type)
514 case GL_ETC1_RGB8_OES:
515 return sw::FORMAT_ETC1;
516 case GL_COMPRESSED_R11_EAC:
517 return sw::FORMAT_R11_EAC;
518 case GL_COMPRESSED_SIGNED_R11_EAC:
519 return sw::FORMAT_SIGNED_R11_EAC;
520 case GL_COMPRESSED_RG11_EAC:
521 return sw::FORMAT_RG11_EAC;
522 case GL_COMPRESSED_SIGNED_RG11_EAC:
523 return sw::FORMAT_SIGNED_RG11_EAC;
524 case GL_COMPRESSED_RGB8_ETC2:
525 return sw::FORMAT_RGB8_ETC2;
526 case GL_COMPRESSED_SRGB8_ETC2:
527 return sw::FORMAT_SRGB8_ETC2;
528 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
529 return sw::FORMAT_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
530 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
531 return sw::FORMAT_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
532 case GL_COMPRESSED_RGBA8_ETC2_EAC:
533 return sw::FORMAT_RGBA8_ETC2_EAC;
534 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
535 return sw::FORMAT_SRGB8_ALPHA8_ETC2_EAC;
536 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
537 return sw::FORMAT_RGBA_ASTC_4x4_KHR;
538 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
539 return sw::FORMAT_RGBA_ASTC_5x4_KHR;
540 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
541 return sw::FORMAT_RGBA_ASTC_5x5_KHR;
542 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
543 return sw::FORMAT_RGBA_ASTC_6x5_KHR;
544 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
545 return sw::FORMAT_RGBA_ASTC_6x6_KHR;
546 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
547 return sw::FORMAT_RGBA_ASTC_8x5_KHR;
548 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
549 return sw::FORMAT_RGBA_ASTC_8x6_KHR;
550 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
551 return sw::FORMAT_RGBA_ASTC_8x8_KHR;
552 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
553 return sw::FORMAT_RGBA_ASTC_10x5_KHR;
554 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
555 return sw::FORMAT_RGBA_ASTC_10x6_KHR;
556 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
557 return sw::FORMAT_RGBA_ASTC_10x8_KHR;
558 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
559 return sw::FORMAT_RGBA_ASTC_10x10_KHR;
560 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
561 return sw::FORMAT_RGBA_ASTC_12x10_KHR;
562 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
563 return sw::FORMAT_RGBA_ASTC_12x12_KHR;
564 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
565 return sw::FORMAT_SRGB8_ALPHA8_ASTC_4x4_KHR;
566 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
567 return sw::FORMAT_SRGB8_ALPHA8_ASTC_5x4_KHR;
568 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
569 return sw::FORMAT_SRGB8_ALPHA8_ASTC_5x5_KHR;
570 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
571 return sw::FORMAT_SRGB8_ALPHA8_ASTC_6x5_KHR;
572 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
573 return sw::FORMAT_SRGB8_ALPHA8_ASTC_6x6_KHR;
574 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
575 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x5_KHR;
576 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
577 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x6_KHR;
578 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
579 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x8_KHR;
580 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
581 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x5_KHR;
582 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
583 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x6_KHR;
584 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
585 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x8_KHR;
586 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
587 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x10_KHR;
588 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
589 return sw::FORMAT_SRGB8_ALPHA8_ASTC_12x10_KHR;
590 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
591 return sw::FORMAT_SRGB8_ALPHA8_ASTC_12x12_KHR;
593 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
594 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
595 return sw::FORMAT_DXT1;
596 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
597 return sw::FORMAT_DXT3;
598 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
599 return sw::FORMAT_DXT5;
611 case GL_ALPHA32F_EXT:
612 return sw::FORMAT_A32F;
614 case GL_LUMINANCE32F_EXT:
615 return sw::FORMAT_L32F;
616 case GL_LUMINANCE_ALPHA:
617 case GL_LUMINANCE_ALPHA32F_EXT:
618 return sw::FORMAT_A32L32F;
621 return sw::FORMAT_R32F;
624 return sw::FORMAT_G32R32F;
629 return sw::FORMAT_A32B32G32R32F;
630 case GL_DEPTH_COMPONENT:
631 case GL_DEPTH_COMPONENT32F:
632 return sw::FORMAT_D32F;
637 case GL_HALF_FLOAT_OES:
641 case GL_ALPHA16F_EXT:
642 return sw::FORMAT_A16F;
644 case GL_LUMINANCE16F_EXT:
645 return sw::FORMAT_L16F;
646 case GL_LUMINANCE_ALPHA:
647 case GL_LUMINANCE_ALPHA16F_EXT:
648 return sw::FORMAT_A16L16F;
651 return sw::FORMAT_R16F;
654 return sw::FORMAT_G16R16F;
659 return sw::FORMAT_A16B16G16R16F;
669 return sw::FORMAT_R8I_SNORM;
672 return sw::FORMAT_R8I;
676 return sw::FORMAT_G8R8I_SNORM;
679 return sw::FORMAT_G8R8I;
683 return sw::FORMAT_X8B8G8R8I_SNORM;
686 return sw::FORMAT_X8B8G8R8I;
690 return sw::FORMAT_A8B8G8R8I_SNORM;
692 case GL_RGBA_INTEGER:
693 return sw::FORMAT_A8B8G8R8I;
697 case GL_UNSIGNED_BYTE:
701 case GL_LUMINANCE8_EXT:
702 return sw::FORMAT_L8;
703 case GL_LUMINANCE_ALPHA:
704 case GL_LUMINANCE8_ALPHA8_EXT:
705 return sw::FORMAT_A8L8;
709 return sw::FORMAT_R8;
712 return sw::FORMAT_R8UI;
716 return sw::FORMAT_G8R8;
719 return sw::FORMAT_G8R8UI;
724 return sw::FORMAT_X8B8G8R8;
727 return sw::FORMAT_X8B8G8R8UI;
731 case GL_SRGB8_ALPHA8:
732 return sw::FORMAT_A8B8G8R8;
734 case GL_RGBA_INTEGER:
735 return sw::FORMAT_A8B8G8R8UI;
738 return sw::FORMAT_A8R8G8B8;
741 return sw::FORMAT_A8;
743 return sw::FORMAT_YV12_BT601;
745 return sw::FORMAT_YV12_BT709;
747 return sw::FORMAT_YV12_JFIF;
756 return sw::FORMAT_R16I;
759 return sw::FORMAT_G16R16I;
762 return sw::FORMAT_X16B16G16R16I;
764 case GL_RGBA_INTEGER:
765 return sw::FORMAT_A16B16G16R16I;
769 case GL_UNSIGNED_SHORT:
774 return sw::FORMAT_R16UI;
777 return sw::FORMAT_G16R16UI;
780 return sw::FORMAT_X16B16G16R16UI;
782 case GL_RGBA_INTEGER:
783 return sw::FORMAT_A16B16G16R16UI;
784 case GL_DEPTH_COMPONENT:
785 case GL_DEPTH_COMPONENT16:
786 return sw::FORMAT_D32FS8_TEXTURE;
795 return sw::FORMAT_R32I;
798 return sw::FORMAT_G32R32I;
801 return sw::FORMAT_X32B32G32R32I;
802 case GL_RGBA_INTEGER:
804 return sw::FORMAT_A32B32G32R32I;
808 case GL_UNSIGNED_INT:
813 return sw::FORMAT_R32UI;
816 return sw::FORMAT_G32R32UI;
819 return sw::FORMAT_X32B32G32R32UI;
820 case GL_RGBA_INTEGER:
822 return sw::FORMAT_A32B32G32R32UI;
823 case GL_DEPTH_COMPONENT:
824 case GL_DEPTH_COMPONENT16:
825 case GL_DEPTH_COMPONENT24:
826 case GL_DEPTH_COMPONENT32_OES:
827 return sw::FORMAT_D32FS8_TEXTURE;
831 case GL_UNSIGNED_INT_24_8_OES:
832 if(format == GL_DEPTH_STENCIL || format == GL_DEPTH24_STENCIL8)
834 return sw::FORMAT_D32FS8_TEXTURE;
836 else UNREACHABLE(format);
837 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
838 if(format == GL_DEPTH_STENCIL || format == GL_DEPTH32F_STENCIL8)
840 return sw::FORMAT_D32FS8_TEXTURE;
842 else UNREACHABLE(format);
843 case GL_UNSIGNED_SHORT_4_4_4_4:
844 return sw::FORMAT_A8R8G8B8;
845 case GL_UNSIGNED_SHORT_5_5_5_1:
846 return sw::FORMAT_A8R8G8B8;
847 case GL_UNSIGNED_SHORT_5_6_5:
848 return sw::FORMAT_R5G6B5;
849 case GL_UNSIGNED_INT_2_10_10_10_REV:
850 if(format == GL_RGB10_A2UI)
852 return sw::FORMAT_A16B16G16R16UI;
856 return sw::FORMAT_A2B10G10R10;
858 case GL_UNSIGNED_INT_10F_11F_11F_REV:
859 case GL_UNSIGNED_INT_5_9_9_9_REV:
860 return sw::FORMAT_A32B32G32R32F;
865 return sw::FORMAT_NULL;
868 // Returns the size, in bytes, of a single texel in an Image
869 static int ComputePixelSize(GLenum format, GLenum type)
879 case GL_RED: return sizeof(char);
880 case GL_RED_INTEGER: return sizeof(char);
884 case GL_RG: return sizeof(char) * 2;
885 case GL_RG_INTEGER: return sizeof(char) * 2;
889 case GL_RGB: return sizeof(char) * 3;
890 case GL_RGB_INTEGER: return sizeof(char) * 3;
894 case GL_RGBA: return sizeof(char) * 4;
895 case GL_RGBA_INTEGER: return sizeof(char) * 4;
896 default: UNREACHABLE(format);
899 case GL_UNSIGNED_BYTE:
904 case GL_RED: return sizeof(unsigned char);
905 case GL_RED_INTEGER: return sizeof(unsigned char);
907 case GL_ALPHA: return sizeof(unsigned char);
908 case GL_LUMINANCE8_EXT:
909 case GL_LUMINANCE: return sizeof(unsigned char);
910 case GL_LUMINANCE8_ALPHA8_EXT:
911 case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;
914 case GL_RG: return sizeof(unsigned char) * 2;
915 case GL_RG_INTEGER: return sizeof(unsigned char) * 2;
919 case GL_RGB: return sizeof(unsigned char) * 3;
920 case GL_RGB_INTEGER: return sizeof(unsigned char) * 3;
923 case GL_SRGB8_ALPHA8:
924 case GL_RGBA: return sizeof(unsigned char) * 4;
925 case GL_RGBA_INTEGER: return sizeof(unsigned char) * 4;
927 case GL_BGRA8_EXT: return sizeof(unsigned char)* 4;
928 default: UNREACHABLE(format);
935 case GL_RED_INTEGER: return sizeof(short);
937 case GL_RG_INTEGER: return sizeof(short) * 2;
939 case GL_RGB_INTEGER: return sizeof(short) * 3;
941 case GL_RGBA_INTEGER: return sizeof(short) * 4;
942 default: UNREACHABLE(format);
945 case GL_UNSIGNED_SHORT:
948 case GL_DEPTH_COMPONENT16:
949 case GL_DEPTH_COMPONENT: return sizeof(unsigned short);
951 case GL_RED_INTEGER: return sizeof(unsigned short);
953 case GL_RG_INTEGER: return sizeof(unsigned short) * 2;
955 case GL_RGB_INTEGER: return sizeof(unsigned short) * 3;
957 case GL_RGBA_INTEGER: return sizeof(unsigned short) * 4;
958 default: UNREACHABLE(format);
965 case GL_RED_INTEGER: return sizeof(int);
967 case GL_RG_INTEGER: return sizeof(int) * 2;
969 case GL_RGB_INTEGER: return sizeof(int) * 3;
971 case GL_RGBA_INTEGER: return sizeof(int) * 4;
972 default: UNREACHABLE(format);
975 case GL_UNSIGNED_INT:
978 case GL_DEPTH_COMPONENT16:
979 case GL_DEPTH_COMPONENT24:
980 case GL_DEPTH_COMPONENT32_OES:
981 case GL_DEPTH_COMPONENT: return sizeof(unsigned int);
983 case GL_RED_INTEGER: return sizeof(unsigned int);
985 case GL_RG_INTEGER: return sizeof(unsigned int) * 2;
987 case GL_RGB_INTEGER: return sizeof(unsigned int) * 3;
989 case GL_RGBA_INTEGER: return sizeof(unsigned int) * 4;
990 default: UNREACHABLE(format);
993 case GL_UNSIGNED_SHORT_4_4_4_4:
994 case GL_UNSIGNED_SHORT_5_5_5_1:
995 case GL_UNSIGNED_SHORT_5_6_5:
996 return sizeof(unsigned short);
997 case GL_UNSIGNED_INT_10F_11F_11F_REV:
998 case GL_UNSIGNED_INT_5_9_9_9_REV:
999 case GL_UNSIGNED_INT_2_10_10_10_REV:
1000 case GL_UNSIGNED_INT_24_8_OES:
1001 return sizeof(unsigned int);
1002 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1003 return sizeof(float) + sizeof(unsigned int);
1007 case GL_DEPTH_COMPONENT32F:
1008 case GL_DEPTH_COMPONENT: return sizeof(float);
1009 case GL_ALPHA32F_EXT:
1010 case GL_ALPHA: return sizeof(float);
1011 case GL_LUMINANCE32F_EXT:
1012 case GL_LUMINANCE: return sizeof(float);
1013 case GL_LUMINANCE_ALPHA32F_EXT:
1014 case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;
1015 case GL_RED: return sizeof(float);
1016 case GL_R32F: return sizeof(float);
1017 case GL_RG: return sizeof(float) * 2;
1018 case GL_RG32F: return sizeof(float) * 2;
1019 case GL_RGB: return sizeof(float) * 3;
1020 case GL_RGB32F: return sizeof(float) * 3;
1021 case GL_RGBA: return sizeof(float) * 4;
1022 case GL_RGBA32F: return sizeof(float) * 4;
1023 default: UNREACHABLE(format);
1027 case GL_HALF_FLOAT_OES:
1030 case GL_ALPHA16F_EXT:
1031 case GL_ALPHA: return sizeof(unsigned short);
1032 case GL_LUMINANCE16F_EXT:
1033 case GL_LUMINANCE: return sizeof(unsigned short);
1034 case GL_LUMINANCE_ALPHA16F_EXT:
1035 case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2;
1036 case GL_RED: return sizeof(unsigned short);
1037 case GL_R16F: return sizeof(unsigned short);
1038 case GL_RG: return sizeof(unsigned short) * 2;
1039 case GL_RG16F: return sizeof(unsigned short) * 2;
1040 case GL_RGB: return sizeof(unsigned short) * 3;
1041 case GL_RGB16F: return sizeof(unsigned short) * 3;
1042 case GL_RGBA: return sizeof(unsigned short) * 4;
1043 case GL_RGBA16F: return sizeof(unsigned short) * 4;
1044 default: UNREACHABLE(format);
1047 default: UNREACHABLE(type);
1053 GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)
1055 ASSERT(alignment > 0 && sw::isPow2(alignment));
1057 GLsizei rawPitch = ComputePixelSize(format, type) * width;
1058 return (rawPitch + alignment - 1) & ~(alignment - 1);
1062 GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)
1064 return ComputeCompressedSize(width, 1, format);
1067 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format)
1071 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1072 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1073 case GL_ETC1_RGB8_OES:
1074 case GL_COMPRESSED_R11_EAC:
1075 case GL_COMPRESSED_SIGNED_R11_EAC:
1076 case GL_COMPRESSED_RGB8_ETC2:
1077 case GL_COMPRESSED_SRGB8_ETC2:
1078 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1079 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1080 return 8 * getNumBlocks(width, height, 4, 4);
1081 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1082 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1083 case GL_COMPRESSED_RG11_EAC:
1084 case GL_COMPRESSED_SIGNED_RG11_EAC:
1085 case GL_COMPRESSED_RGBA8_ETC2_EAC:
1086 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
1087 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
1088 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
1089 return 16 * getNumBlocks(width, height, 4, 4);
1090 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
1091 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
1092 return 16 * getNumBlocks(width, height, 5, 4);
1093 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
1094 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
1095 return 16 * getNumBlocks(width, height, 5, 5);
1096 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
1097 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
1098 return 16 * getNumBlocks(width, height, 6, 5);
1099 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
1100 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
1101 return 16 * getNumBlocks(width, height, 6, 6);
1102 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
1103 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
1104 return 16 * getNumBlocks(width, height, 8, 5);
1105 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
1106 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
1107 return 16 * getNumBlocks(width, height, 8, 6);
1108 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
1109 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
1110 return 16 * getNumBlocks(width, height, 8, 8);
1111 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
1112 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
1113 return 16 * getNumBlocks(width, height, 10, 5);
1114 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
1115 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
1116 return 16 * getNumBlocks(width, height, 10, 6);
1117 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
1118 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
1119 return 16 * getNumBlocks(width, height, 10, 8);
1120 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
1121 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
1122 return 16 * getNumBlocks(width, height, 10, 10);
1123 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
1124 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
1125 return 16 * getNumBlocks(width, height, 12, 10);
1126 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
1127 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
1128 return 16 * getNumBlocks(width, height, 12, 12);
1136 ASSERT(referenceCount == 0);
1139 void Image::addRef()
1143 return parentTexture->addRef();
1145 int newCount = sw::atomicIncrement(&referenceCount);
1146 LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
1149 void Image::release()
1153 return parentTexture->release();
1156 int newCount = sw::atomicDecrement(&referenceCount);
1157 LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
1160 ASSERT(!shared); // Should still hold a reference if eglDestroyImage hasn't been called
1165 void Image::unbind(const egl::Texture *parent)
1167 if(parentTexture == parent)
1175 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)
1177 GLsizei inputPitch = ComputePitch((unpackInfo.rowLength == 0) ? width : unpackInfo.rowLength, format, type, unpackInfo.alignment);
1178 GLsizei inputHeight = (unpackInfo.imageHeight == 0) ? height : unpackInfo.imageHeight;
1179 input = ((char*)input) + (unpackInfo.skipImages * inputHeight + unpackInfo.skipRows) * inputPitch + unpackInfo.skipPixels;
1180 sw::Format selectedInternalFormat = SelectInternalFormat(format, type);
1181 if(selectedInternalFormat == sw::FORMAT_NULL)
1186 if(selectedInternalFormat == internalFormat)
1188 void *buffer = lock(0, 0, sw::LOCK_WRITEONLY);
1201 case GL_RED_INTEGER:
1205 case GL_LUMINANCE8_EXT:
1206 LoadImageData<Bytes_1>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1213 case GL_LUMINANCE_ALPHA:
1214 case GL_LUMINANCE8_ALPHA8_EXT:
1215 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1221 case GL_RGB_INTEGER:
1222 LoadImageData<ByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1226 case GL_RGBA8_SNORM:
1228 case GL_RGBA_INTEGER:
1231 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1233 default: UNREACHABLE(format);
1236 case GL_UNSIGNED_BYTE:
1243 case GL_RED_INTEGER:
1247 case GL_LUMINANCE8_EXT:
1248 LoadImageData<Bytes_1>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1255 case GL_LUMINANCE_ALPHA:
1256 case GL_LUMINANCE8_ALPHA8_EXT:
1257 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1263 case GL_RGB_INTEGER:
1264 LoadImageData<UByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1268 case GL_RGBA8_SNORM:
1270 case GL_RGBA_INTEGER:
1273 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1276 LoadImageData<SRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1278 case GL_SRGB8_ALPHA8:
1279 LoadImageData<SRGBA>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1281 default: UNREACHABLE(format);
1284 case GL_UNSIGNED_SHORT_5_6_5:
1289 LoadImageData<RGB565>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1291 default: UNREACHABLE(format);
1294 case GL_UNSIGNED_SHORT_4_4_4_4:
1299 LoadImageData<RGBA4444>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1301 default: UNREACHABLE(format);
1304 case GL_UNSIGNED_SHORT_5_5_5_1:
1309 LoadImageData<RGBA5551>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1311 default: UNREACHABLE(format);
1314 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1317 case GL_R11F_G11F_B10F:
1319 LoadImageData<R11G11B10F>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1321 default: UNREACHABLE(format);
1324 case GL_UNSIGNED_INT_5_9_9_9_REV:
1329 LoadImageData<RGB9E5>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1331 default: UNREACHABLE(format);
1334 case GL_UNSIGNED_INT_2_10_10_10_REV:
1338 LoadImageData<RGB10A2UI>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1342 case GL_RGBA_INTEGER:
1343 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1345 default: UNREACHABLE(format);
1351 // float textures are converted to RGBA, not BGRA
1353 case GL_ALPHA32F_EXT:
1354 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1357 case GL_LUMINANCE32F_EXT:
1358 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1360 case GL_LUMINANCE_ALPHA:
1361 case GL_LUMINANCE_ALPHA32F_EXT:
1362 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1366 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1370 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1374 LoadImageData<FloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1378 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1380 case GL_DEPTH_COMPONENT:
1381 case GL_DEPTH_COMPONENT32F:
1382 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1384 default: UNREACHABLE(format);
1388 case GL_HALF_FLOAT_OES:
1392 case GL_ALPHA16F_EXT:
1393 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1396 case GL_LUMINANCE16F_EXT:
1397 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1399 case GL_LUMINANCE_ALPHA:
1400 case GL_LUMINANCE_ALPHA16F_EXT:
1401 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1405 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1409 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1413 LoadImageData<HalfFloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1417 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1419 default: UNREACHABLE(format);
1427 case GL_RED_INTEGER:
1430 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1435 case GL_LUMINANCE_ALPHA:
1436 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1440 case GL_RGB_INTEGER:
1441 LoadImageData<ShortRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1445 case GL_RGBA_INTEGER:
1448 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1450 default: UNREACHABLE(format);
1453 case GL_UNSIGNED_SHORT:
1458 case GL_RED_INTEGER:
1461 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1466 case GL_LUMINANCE_ALPHA:
1467 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1471 case GL_RGB_INTEGER:
1472 LoadImageData<UShortRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1476 case GL_RGBA_INTEGER:
1479 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1481 case GL_DEPTH_COMPONENT:
1482 case GL_DEPTH_COMPONENT16:
1483 LoadImageData<D16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1485 default: UNREACHABLE(format);
1493 case GL_RED_INTEGER:
1496 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1501 case GL_LUMINANCE_ALPHA:
1502 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1506 case GL_RGB_INTEGER:
1507 LoadImageData<IntRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1511 case GL_RGBA_INTEGER:
1514 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1516 default: UNREACHABLE(format);
1519 case GL_UNSIGNED_INT:
1524 case GL_RED_INTEGER:
1527 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1532 case GL_LUMINANCE_ALPHA:
1533 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1537 case GL_RGB_INTEGER:
1538 LoadImageData<UIntRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1542 case GL_RGBA_INTEGER:
1545 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1547 case GL_DEPTH_COMPONENT16:
1548 case GL_DEPTH_COMPONENT24:
1549 case GL_DEPTH_COMPONENT32_OES:
1550 case GL_DEPTH_COMPONENT:
1551 LoadImageData<D32>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1553 default: UNREACHABLE(format);
1556 case GL_UNSIGNED_INT_24_8_OES:
1557 loadD24S8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
1559 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1560 loadD32FS8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
1562 default: UNREACHABLE(type);
1570 sw::Surface source(width, height, depth, ConvertFormatType(format, type), const_cast<void*>(input), inputPitch, inputPitch * inputHeight);
1571 sw::Rect sourceRect(0, 0, width, height);
1572 sw::Rect destRect(xoffset, yoffset, xoffset + width, yoffset + height);
1573 sw::blitter.blit(&source, sourceRect, this, destRect, false);
1577 void Image::loadD24S8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
1579 LoadImageData<D24>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1581 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, sw::PUBLIC));
1585 LoadImageData<S8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
1591 void Image::loadD32FS8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
1593 LoadImageData<D32F>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1595 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, sw::PUBLIC));
1599 LoadImageData<S24_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
1605 void Image::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
1607 if(zoffset != 0 || depth != 1)
1609 UNIMPLEMENTED(); // FIXME
1612 int inputPitch = ComputeCompressedPitch(width, format);
1613 int rows = imageSize / inputPitch;
1614 void *buffer = lock(xoffset, yoffset, sw::LOCK_WRITEONLY);
1618 for(int i = 0; i < rows; i++)
1620 memcpy((void*)((GLbyte*)buffer + i * getPitch()), (void*)((GLbyte*)pixels + i * inputPitch), inputPitch);