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/Thread.hpp"
19 #include <GLES/glext.h>
20 #include <GLES2/gl2ext.h>
21 #include <GLES3/gl3.h>
37 LuminanceAlphaHalfFloat,
53 template<DataType dataType>
54 void LoadImageRow(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
60 void LoadImageRow<Alpha>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
62 memcpy(dest + xoffset, source, width);
66 void LoadImageRow<AlphaFloat>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
68 const float *sourceF = reinterpret_cast<const float*>(source);
69 float *destF = reinterpret_cast<float*>(dest + (xoffset * 16));
71 for(int x = 0; x < width; x++)
76 destF[4 * x + 3] = sourceF[x];
81 void LoadImageRow<AlphaHalfFloat>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
83 const unsigned short *sourceH = reinterpret_cast<const unsigned short*>(source);
84 unsigned short *destH = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
86 for(int x = 0; x < width; x++)
91 destH[4 * x + 3] = sourceH[x];
96 void LoadImageRow<Luminance>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
98 memcpy(dest + xoffset, source, width);
102 void LoadImageRow<LuminanceFloat>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
104 const float *sourceF = reinterpret_cast<const float*>(source);
105 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
107 for(int x = 0; x < width; x++)
109 destF[4 * x + 0] = sourceF[x];
110 destF[4 * x + 1] = sourceF[x];
111 destF[4 * x + 2] = sourceF[x];
112 destF[4 * x + 3] = 1.0f;
117 void LoadImageRow<LuminanceHalfFloat>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
119 const unsigned short *sourceH = reinterpret_cast<const unsigned short*>(source);
120 unsigned short *destH = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
122 for(int x = 0; x < width; x++)
124 destH[4 * x + 0] = sourceH[x];
125 destH[4 * x + 1] = sourceH[x];
126 destH[4 * x + 2] = sourceH[x];
127 destH[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
132 void LoadImageRow<LuminanceAlpha>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
134 memcpy(dest + xoffset * 2, source, width * 2);
138 void LoadImageRow<LuminanceAlphaFloat>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
140 const float *sourceF = reinterpret_cast<const float*>(source);
141 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
143 for(int x = 0; x < width; x++)
145 destF[4 * x + 0] = sourceF[2 * x + 0];
146 destF[4 * x + 1] = sourceF[2 * x + 0];
147 destF[4 * x + 2] = sourceF[2 * x + 0];
148 destF[4 * x + 3] = sourceF[2 * x + 1];
153 void LoadImageRow<LuminanceAlphaHalfFloat>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
155 const unsigned short *sourceH = reinterpret_cast<const unsigned short*>(source);
156 unsigned short *destH = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
158 for(int x = 0; x < width; x++)
160 destH[4 * x + 0] = sourceH[2 * x + 0];
161 destH[4 * x + 1] = sourceH[2 * x + 0];
162 destH[4 * x + 2] = sourceH[2 * x + 0];
163 destH[4 * x + 3] = sourceH[2 * x + 1];
168 void LoadImageRow<UByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
170 unsigned char *destB = dest + xoffset * 4;
172 for(int x = 0; x < width; x++)
174 destB[4 * x + 0] = source[x * 3 + 0];
175 destB[4 * x + 1] = source[x * 3 + 1];
176 destB[4 * x + 2] = source[x * 3 + 2];
177 destB[4 * x + 3] = 0xFF;
182 void LoadImageRow<RGB565>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
184 const unsigned short *source565 = reinterpret_cast<const unsigned short*>(source);
185 unsigned char *destB = dest + xoffset * 4;
187 for(int x = 0; x < width; x++)
189 unsigned short rgba = source565[x];
190 destB[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
191 destB[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
192 destB[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
193 destB[4 * x + 3] = 0xFF;
198 void LoadImageRow<FloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
200 const float *sourceF = reinterpret_cast<const float*>(source);
201 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
203 for(int x = 0; x < width; x++)
205 destF[4 * x + 0] = sourceF[x * 3 + 0];
206 destF[4 * x + 1] = sourceF[x * 3 + 1];
207 destF[4 * x + 2] = sourceF[x * 3 + 2];
208 destF[4 * x + 3] = 1.0f;
213 void LoadImageRow<HalfFloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
215 const unsigned short *sourceH = reinterpret_cast<const unsigned short*>(source);
216 unsigned short *destH = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
218 for(int x = 0; x < width; x++)
220 destH[4 * x + 0] = sourceH[x * 3 + 0];
221 destH[4 * x + 1] = sourceH[x * 3 + 1];
222 destH[4 * x + 2] = sourceH[x * 3 + 2];
223 destH[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
228 void LoadImageRow<UByte4>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
230 memcpy(dest + xoffset * 4, source, width * 4);
234 void LoadImageRow<RGBA4444>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
236 const unsigned short *source4444 = reinterpret_cast<const unsigned short*>(source);
237 unsigned char *dest4444 = dest + xoffset * 4;
239 for(int x = 0; x < width; x++)
241 unsigned short rgba = source4444[x];
242 dest4444[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
243 dest4444[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
244 dest4444[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
245 dest4444[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
250 void LoadImageRow<RGBA5551>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
252 const unsigned short *source5551 = reinterpret_cast<const unsigned short*>(source);
253 unsigned char *dest5551 = dest + xoffset * 4;
255 for(int x = 0; x < width; x++)
257 unsigned short rgba = source5551[x];
258 dest5551[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
259 dest5551[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
260 dest5551[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
261 dest5551[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
266 void LoadImageRow<Float4>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
268 memcpy(dest + xoffset * 16, source, width * 16);
272 void LoadImageRow<HalfFloat4>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
274 memcpy(dest + xoffset * 8, source, width * 8);
278 void LoadImageRow<D16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
280 const unsigned short *sourceD16 = reinterpret_cast<const unsigned short*>(source);
281 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
283 for(int x = 0; x < width; x++)
285 destF[x] = (float)sourceD16[x] / 0xFFFF;
290 void LoadImageRow<D24>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
292 const unsigned int *sourceD24 = reinterpret_cast<const unsigned int*>(source);
293 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
295 for(int x = 0; x < width; x++)
297 destF[x] = (float)(sourceD24[x] & 0xFFFFFF00) / 0xFFFFFF00;
302 void LoadImageRow<D32>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
304 const unsigned int *sourceD32 = reinterpret_cast<const unsigned int*>(source);
305 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
307 for(int x = 0; x < width; x++)
309 destF[x] = (float)sourceD32[x] / 0xFFFFFFFF;
314 void LoadImageRow<S8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
316 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
317 unsigned char *destI = dest + xoffset;
319 for(int x = 0; x < width; x++)
321 destI[x] = static_cast<unsigned char>(sourceI[x] & 0x000000FF); // FIXME: Quad layout
325 template<DataType dataType>
326 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)
328 for(int z = 0; z < depth; ++z)
330 const unsigned char *inputStart = static_cast<const unsigned char*>(input) + (z * inputPitch * inputHeight);
331 unsigned char *destStart = static_cast<unsigned char*>(buffer) + ((zoffset + z) * destPitch * destHeight);
332 for(int y = 0; y < height; ++y)
334 const unsigned char *source = inputStart + y * inputPitch;
335 unsigned char *dest = destStart + (y + yoffset) * destPitch;
337 LoadImageRow<dataType>(source, dest, xoffset, width);
345 sw::Format ConvertFormatType(GLenum format, GLenum type)
352 case GL_UNSIGNED_BYTE: return sw::FORMAT_L8;
353 case GL_HALF_FLOAT: return sw::FORMAT_L16F;
354 case GL_HALF_FLOAT_OES: return sw::FORMAT_L16F;
355 case GL_FLOAT: return sw::FORMAT_L32F;
356 default: UNREACHABLE(type);
359 case GL_LUMINANCE_ALPHA:
362 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8L8;
363 case GL_HALF_FLOAT: return sw::FORMAT_A16L16F;
364 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16L16F;
365 case GL_FLOAT: return sw::FORMAT_A32L32F;
366 default: UNREACHABLE(type);
372 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8B8G8R8;
373 case GL_UNSIGNED_SHORT_4_4_4_4: return sw::FORMAT_R4G4B4A4;
374 case GL_UNSIGNED_SHORT_5_5_5_1: return sw::FORMAT_R5G5B5A1;
375 case GL_HALF_FLOAT: return sw::FORMAT_A16B16G16R16F;
376 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16B16G16R16F;
377 case GL_FLOAT: return sw::FORMAT_A32B32G32R32F;
378 default: UNREACHABLE(type);
384 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8R8G8B8;
385 default: UNREACHABLE(type);
391 case GL_UNSIGNED_BYTE: return sw::FORMAT_B8G8R8;
392 case GL_UNSIGNED_SHORT_5_6_5: return sw::FORMAT_R5G6B5;
393 case GL_HALF_FLOAT: return sw::FORMAT_B16G16R16F;
394 case GL_HALF_FLOAT_OES: return sw::FORMAT_B16G16R16F;
395 case GL_FLOAT: return sw::FORMAT_B32G32R32F;
396 default: UNREACHABLE(type);
402 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8;
403 case GL_HALF_FLOAT: return sw::FORMAT_A16F;
404 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16F;
405 case GL_FLOAT: return sw::FORMAT_A32F;
406 default: UNREACHABLE(type);
413 return sw::FORMAT_NULL;
416 sw::Format SelectInternalFormat(GLenum format, GLenum type)
418 if(format == GL_ETC1_RGB8_OES)
420 return sw::FORMAT_ETC1;
424 if(format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
425 format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
427 return sw::FORMAT_DXT1;
429 else if(format == GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE)
431 return sw::FORMAT_DXT3;
433 else if(format == GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE)
435 return sw::FORMAT_DXT5;
441 return sw::FORMAT_A32B32G32R32F;
443 else if(type == GL_HALF_FLOAT || type == GL_HALF_FLOAT_OES)
445 return sw::FORMAT_A16B16G16R16F;
447 else if(type == GL_UNSIGNED_BYTE)
449 if(format == GL_LUMINANCE)
451 return sw::FORMAT_L8;
453 else if(format == GL_LUMINANCE_ALPHA)
455 return sw::FORMAT_A8L8;
457 else if(format == GL_RGBA)
459 return sw::FORMAT_A8B8G8R8;
461 else if(format == GL_BGRA_EXT)
463 return sw::FORMAT_A8R8G8B8;
465 else if(format == GL_RGB)
467 return sw::FORMAT_X8B8G8R8;
469 else if(format == GL_ALPHA)
471 return sw::FORMAT_A8;
473 else if(format == SW_YV12_BT601)
475 return sw::FORMAT_YV12_BT601;
477 else if(format == SW_YV12_BT709)
479 return sw::FORMAT_YV12_BT709;
481 else if(format == SW_YV12_JFIF)
483 return sw::FORMAT_YV12_JFIF;
485 else UNREACHABLE(format);
487 else if(type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT)
489 if(format == GL_DEPTH_COMPONENT)
491 return sw::FORMAT_D32FS8_TEXTURE;
493 else UNREACHABLE(format);
495 else if(type == GL_UNSIGNED_INT_24_8_OES)
497 if(format == GL_DEPTH_STENCIL_OES)
499 return sw::FORMAT_D32FS8_TEXTURE;
501 else UNREACHABLE(format);
503 else if(type == GL_UNSIGNED_SHORT_4_4_4_4)
505 return sw::FORMAT_A8R8G8B8;
507 else if(type == GL_UNSIGNED_SHORT_5_5_5_1)
509 return sw::FORMAT_A8R8G8B8;
511 else if(type == GL_UNSIGNED_SHORT_5_6_5)
513 return sw::FORMAT_X8R8G8B8;
515 else UNREACHABLE(type);
517 return sw::FORMAT_A8B8G8R8;
520 // Returns the size, in bytes, of a single texel in an Image
521 static int ComputePixelSize(GLenum format, GLenum type)
525 case GL_UNSIGNED_BYTE:
528 case GL_ALPHA: return sizeof(unsigned char);
529 case GL_LUMINANCE: return sizeof(unsigned char);
530 case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;
531 case GL_RGB: return sizeof(unsigned char) * 3;
532 case GL_RGBA: return sizeof(unsigned char) * 4;
533 case GL_BGRA_EXT: return sizeof(unsigned char) * 4;
534 default: UNREACHABLE(format);
537 case GL_UNSIGNED_SHORT_4_4_4_4:
538 case GL_UNSIGNED_SHORT_5_5_5_1:
539 case GL_UNSIGNED_SHORT_5_6_5:
540 case GL_UNSIGNED_SHORT:
541 return sizeof(unsigned short);
542 case GL_UNSIGNED_INT:
543 case GL_UNSIGNED_INT_24_8_OES:
544 return sizeof(unsigned int);
548 case GL_ALPHA: return sizeof(float);
549 case GL_LUMINANCE: return sizeof(float);
550 case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;
551 case GL_RGB: return sizeof(float) * 3;
552 case GL_RGBA: return sizeof(float) * 4;
553 default: UNREACHABLE(format);
557 case GL_HALF_FLOAT_OES:
560 case GL_ALPHA: return sizeof(unsigned short);
561 case GL_LUMINANCE: return sizeof(unsigned short);
562 case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2;
563 case GL_RGB: return sizeof(unsigned short) * 3;
564 case GL_RGBA: return sizeof(unsigned short) * 4;
565 default: UNREACHABLE(format);
568 default: UNREACHABLE(type);
574 GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)
576 ASSERT(alignment > 0 && sw::isPow2(alignment));
578 GLsizei rawPitch = ComputePixelSize(format, type) * width;
579 return (rawPitch + alignment - 1) & ~(alignment - 1);
583 GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)
585 return ComputeCompressedSize(width, 1, format);
588 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format)
592 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
593 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
594 case GL_ETC1_RGB8_OES:
595 case GL_COMPRESSED_R11_EAC:
596 case GL_COMPRESSED_SIGNED_R11_EAC:
597 case GL_COMPRESSED_RGB8_ETC2:
598 case GL_COMPRESSED_SRGB8_ETC2:
599 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
600 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
601 return 8 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
602 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
603 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
604 case GL_COMPRESSED_RG11_EAC:
605 case GL_COMPRESSED_SIGNED_RG11_EAC:
606 case GL_COMPRESSED_RGBA8_ETC2_EAC:
607 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
608 return 16 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
616 ASSERT(referenceCount == 0);
623 return parentTexture->addRef();
625 int newCount = sw::atomicIncrement(&referenceCount);
626 LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
629 void Image::release()
633 return parentTexture->release();
636 int newCount = sw::atomicDecrement(&referenceCount);
637 LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
640 ASSERT(!shared); // Should still hold a reference if eglDestroyImage hasn't been called
645 void Image::unbind(const egl::Texture *parent)
647 if(parentTexture == parent)
655 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)
657 GLsizei inputPitch = (unpackInfo.rowLength == 0) ? ComputePitch(width, format, type, unpackInfo.alignment) : unpackInfo.rowLength;
658 GLsizei inputHeight = (unpackInfo.imageHeight == 0) ? height : unpackInfo.imageHeight;
659 input = ((char*)input) + (unpackInfo.skipImages * inputHeight + unpackInfo.skipRows) * inputPitch + unpackInfo.skipPixels;
661 if(SelectInternalFormat(format, type) == internalFormat)
663 void *buffer = lock(0, 0, sw::LOCK_WRITEONLY);
669 case GL_UNSIGNED_BYTE:
673 LoadImageData<Alpha>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
676 LoadImageData<Luminance>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
678 case GL_LUMINANCE_ALPHA:
679 LoadImageData<LuminanceAlpha>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
682 LoadImageData<UByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
686 LoadImageData<UByte4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
688 default: UNREACHABLE(format);
691 case GL_UNSIGNED_SHORT_5_6_5:
695 LoadImageData<RGB565>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
697 default: UNREACHABLE(format);
700 case GL_UNSIGNED_SHORT_4_4_4_4:
704 LoadImageData<RGBA4444>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
706 default: UNREACHABLE(format);
709 case GL_UNSIGNED_SHORT_5_5_5_1:
713 LoadImageData<RGBA5551>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
715 default: UNREACHABLE(format);
721 // float textures are converted to RGBA, not BGRA
723 LoadImageData<AlphaFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
726 LoadImageData<LuminanceFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
728 case GL_LUMINANCE_ALPHA:
729 LoadImageData<LuminanceAlphaFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
732 LoadImageData<FloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
735 LoadImageData<Float4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
737 default: UNREACHABLE(format);
741 case GL_HALF_FLOAT_OES:
745 LoadImageData<AlphaHalfFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
748 LoadImageData<LuminanceHalfFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
750 case GL_LUMINANCE_ALPHA:
751 LoadImageData<LuminanceAlphaHalfFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
754 LoadImageData<HalfFloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
757 LoadImageData<HalfFloat4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
759 default: UNREACHABLE(format);
762 case GL_UNSIGNED_SHORT:
763 LoadImageData<D16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
765 case GL_UNSIGNED_INT:
766 LoadImageData<D32>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
768 case GL_UNSIGNED_INT_24_8_OES:
769 loadD24S8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
771 default: UNREACHABLE(type);
779 sw::Surface source(width, height, depth, ConvertFormatType(format, type), const_cast<void*>(input), inputPitch, inputPitch * inputHeight);
780 sw::Rect sourceRect(0, 0, width, height);
781 sw::Rect destRect(xoffset, yoffset, xoffset + width, yoffset + height);
782 sw::blitter.blit(&source, sourceRect, this, destRect, false);
786 void Image::loadD24S8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
788 LoadImageData<D24>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
790 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, sw::PUBLIC));
794 LoadImageData<S8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
800 void Image::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
802 if(zoffset != 0 || depth != 1)
804 UNIMPLEMENTED(); // FIXME
807 int inputPitch = ComputeCompressedPitch(width, format);
808 int rows = imageSize / inputPitch;
809 void *buffer = lock(xoffset, yoffset, sw::LOCK_WRITEONLY);
813 for(int i = 0; i < rows; i++)
815 memcpy((void*)((GLbyte*)buffer + i * getPitch()), (void*)((GLbyte*)pixels + i * inputPitch), inputPitch);