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 UNREACHABLE(format);
475 else if(type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT)
477 if(format == GL_DEPTH_COMPONENT)
479 return sw::FORMAT_D32FS8_TEXTURE;
481 else UNREACHABLE(format);
483 else if(type == GL_UNSIGNED_INT_24_8_OES)
485 if(format == GL_DEPTH_STENCIL_OES)
487 return sw::FORMAT_D32FS8_TEXTURE;
489 else UNREACHABLE(format);
491 else if(type == GL_UNSIGNED_SHORT_4_4_4_4)
493 return sw::FORMAT_A8R8G8B8;
495 else if(type == GL_UNSIGNED_SHORT_5_5_5_1)
497 return sw::FORMAT_A8R8G8B8;
499 else if(type == GL_UNSIGNED_SHORT_5_6_5)
501 return sw::FORMAT_X8R8G8B8;
503 else UNREACHABLE(type);
505 return sw::FORMAT_A8B8G8R8;
508 // Returns the size, in bytes, of a single texel in an Image
509 int ComputePixelSize(GLenum format, GLenum type)
513 case GL_UNSIGNED_BYTE:
516 case GL_ALPHA: return sizeof(unsigned char);
517 case GL_LUMINANCE: return sizeof(unsigned char);
518 case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;
519 case GL_RGB: return sizeof(unsigned char) * 3;
520 case GL_RGBA: return sizeof(unsigned char) * 4;
521 case GL_BGRA_EXT: return sizeof(unsigned char) * 4;
522 default: UNREACHABLE(format);
525 case GL_UNSIGNED_SHORT_4_4_4_4:
526 case GL_UNSIGNED_SHORT_5_5_5_1:
527 case GL_UNSIGNED_SHORT_5_6_5:
528 case GL_UNSIGNED_SHORT:
529 return sizeof(unsigned short);
530 case GL_UNSIGNED_INT:
531 case GL_UNSIGNED_INT_24_8_OES:
532 return sizeof(unsigned int);
536 case GL_ALPHA: return sizeof(float);
537 case GL_LUMINANCE: return sizeof(float);
538 case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;
539 case GL_RGB: return sizeof(float) * 3;
540 case GL_RGBA: return sizeof(float) * 4;
541 default: UNREACHABLE(format);
545 case GL_HALF_FLOAT_OES:
548 case GL_ALPHA: return sizeof(unsigned short);
549 case GL_LUMINANCE: return sizeof(unsigned short);
550 case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2;
551 case GL_RGB: return sizeof(unsigned short) * 3;
552 case GL_RGBA: return sizeof(unsigned short) * 4;
553 default: UNREACHABLE(format);
556 default: UNREACHABLE(type);
562 GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)
564 ASSERT(alignment > 0 && sw::isPow2(alignment));
566 GLsizei rawPitch = ComputePixelSize(format, type) * width;
567 return (rawPitch + alignment - 1) & ~(alignment - 1);
571 GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)
573 return ComputeCompressedSize(width, 1, format);
576 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format)
580 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
581 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
582 case GL_ETC1_RGB8_OES:
583 case GL_COMPRESSED_R11_EAC:
584 case GL_COMPRESSED_SIGNED_R11_EAC:
585 case GL_COMPRESSED_RGB8_ETC2:
586 case GL_COMPRESSED_SRGB8_ETC2:
587 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
588 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
589 return 8 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
590 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
591 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
592 case GL_COMPRESSED_RG11_EAC:
593 case GL_COMPRESSED_SIGNED_RG11_EAC:
594 case GL_COMPRESSED_RGBA8_ETC2_EAC:
595 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
596 return 16 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
604 ASSERT(referenceCount == 0);
611 return parentTexture->addRef();
613 int newCount = sw::atomicIncrement(&referenceCount);
614 LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
617 void Image::release()
621 return parentTexture->release();
624 int newCount = sw::atomicDecrement(&referenceCount);
625 LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
628 ASSERT(!shared); // Should still hold a reference if eglDestroyImage hasn't been called
633 void Image::unbind(const egl::Texture *parent)
635 if(parentTexture == parent)
643 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)
645 GLsizei inputPitch = (unpackInfo.rowLength == 0) ? ComputePitch(width, format, type, unpackInfo.alignment) : unpackInfo.rowLength;
646 GLsizei inputHeight = (unpackInfo.imageHeight == 0) ? height : unpackInfo.imageHeight;
647 input = ((char*)input) + (unpackInfo.skipImages * inputHeight + unpackInfo.skipRows) * inputPitch + unpackInfo.skipPixels;
649 if(SelectInternalFormat(format, type) == internalFormat)
651 void *buffer = lock(0, 0, sw::LOCK_WRITEONLY);
657 case GL_UNSIGNED_BYTE:
661 LoadImageData<Alpha>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
664 LoadImageData<Luminance>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
666 case GL_LUMINANCE_ALPHA:
667 LoadImageData<LuminanceAlpha>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
670 LoadImageData<UByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
674 LoadImageData<UByte4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
676 default: UNREACHABLE(format);
679 case GL_UNSIGNED_SHORT_5_6_5:
683 LoadImageData<RGB565>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
685 default: UNREACHABLE(format);
688 case GL_UNSIGNED_SHORT_4_4_4_4:
692 LoadImageData<RGBA4444>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
694 default: UNREACHABLE(format);
697 case GL_UNSIGNED_SHORT_5_5_5_1:
701 LoadImageData<RGBA5551>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
703 default: UNREACHABLE(format);
709 // float textures are converted to RGBA, not BGRA
711 LoadImageData<AlphaFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
714 LoadImageData<LuminanceFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
716 case GL_LUMINANCE_ALPHA:
717 LoadImageData<LuminanceAlphaFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
720 LoadImageData<FloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
723 LoadImageData<Float4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
725 default: UNREACHABLE(format);
729 case GL_HALF_FLOAT_OES:
733 LoadImageData<AlphaHalfFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
736 LoadImageData<LuminanceHalfFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
738 case GL_LUMINANCE_ALPHA:
739 LoadImageData<LuminanceAlphaHalfFloat>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
742 LoadImageData<HalfFloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
745 LoadImageData<HalfFloat4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
747 default: UNREACHABLE(format);
750 case GL_UNSIGNED_SHORT:
751 LoadImageData<D16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
753 case GL_UNSIGNED_INT:
754 LoadImageData<D32>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
756 case GL_UNSIGNED_INT_24_8_OES:
757 loadD24S8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
759 default: UNREACHABLE(type);
767 sw::Surface source(width, height, depth, ConvertFormatType(format, type), const_cast<void*>(input), inputPitch, inputPitch * inputHeight);
768 sw::Rect sourceRect(0, 0, width, height);
769 sw::Rect destRect(xoffset, yoffset, xoffset + width, yoffset + height);
770 sw::blitter.blit(&source, sourceRect, this, destRect, false);
774 void Image::loadD24S8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
776 LoadImageData<D24>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
778 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, sw::PUBLIC));
782 LoadImageData<S8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
788 void Image::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
790 if(zoffset != 0 || depth != 1)
792 UNIMPLEMENTED(); // FIXME
795 int inputPitch = ComputeCompressedPitch(width, format);
796 int rows = imageSize / inputPitch;
797 void *buffer = lock(xoffset, yoffset, sw::LOCK_WRITEONLY);
801 for(int i = 0; i < rows; i++)
803 memcpy((void*)((GLbyte*)buffer + i * getPitch()), (void*)((GLbyte*)pixels + i * inputPitch), inputPitch);