Adds new functions to support load*Data for DX11-supported formats
TRAC #22294
Author: Shannon Woods
Signed-off-by: Geoff Lang
Signed-off-by: Nicolas Capens
git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1617 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/renderer/Image.cpp b/src/libGLESv2/renderer/Image.cpp
index 1792837..e84eff5 100644
--- a/src/libGLESv2/renderer/Image.cpp
+++ b/src/libGLESv2/renderer/Image.cpp
@@ -241,6 +241,26 @@
}
}
+void Image::loadRGBUByteDataToRGBA(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output)
+{
+ const unsigned char *source = NULL;
+ unsigned char *dest = NULL;
+
+ for (int y = 0; y < height; y++)
+ {
+ source = static_cast<const unsigned char*>(input) + y * inputPitch;
+ dest = static_cast<unsigned char*>(output) + y * outputPitch;
+ for (int x = 0; x < width; x++)
+ {
+ dest[4 * x + 0] = source[x * 3 + 0];
+ dest[4 * x + 1] = source[x * 3 + 1];
+ dest[4 * x + 2] = source[x * 3 + 2];
+ dest[4 * x + 3] = 0xFF;
+ }
+ }
+}
+
void Image::loadRGB565DataToBGRA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output)
{
@@ -262,6 +282,27 @@
}
}
+void Image::loadRGB565DataToRGBA(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output)
+{
+ const unsigned short *source = NULL;
+ unsigned char *dest = NULL;
+
+ for (int y = 0; y < height; y++)
+ {
+ source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
+ dest = static_cast<unsigned char*>(output) + y * outputPitch;
+ for (int x = 0; x < width; x++)
+ {
+ unsigned short rgba = source[x];
+ dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
+ dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
+ dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
+ dest[4 * x + 3] = 0xFF;
+ }
+ }
+}
+
void Image::loadRGBFloatDataToRGBA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output)
{
@@ -282,6 +323,20 @@
}
}
+void Image::loadRGBFloatDataToNative(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output)
+{
+ const float *source = NULL;
+ float *dest = NULL;
+
+ for (int y = 0; y < height; y++)
+ {
+ source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
+ dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch);
+ memcpy(dest, source, width * 12);
+ }
+}
+
void Image::loadRGBHalfFloatDataToRGBA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output)
{
@@ -320,6 +375,20 @@
}
}
+void Image::loadRGBAUByteDataToNative(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output)
+{
+ const unsigned int *source = NULL;
+ unsigned int *dest = NULL;
+ for (int y = 0; y < height; y++)
+ {
+ source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch);
+ dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch);
+
+ memcpy(dest, source, width * 4);
+ }
+}
+
void Image::loadRGBA4444DataToBGRA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output)
{
@@ -341,6 +410,27 @@
}
}
+void Image::loadRGBA4444DataToRGBA(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output)
+{
+ const unsigned short *source = NULL;
+ unsigned char *dest = NULL;
+
+ for (int y = 0; y < height; y++)
+ {
+ source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
+ dest = static_cast<unsigned char*>(output) + y * outputPitch;
+ for (int x = 0; x < width; x++)
+ {
+ unsigned short rgba = source[x];
+ dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
+ dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
+ dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
+ dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
+ }
+ }
+}
+
void Image::loadRGBA5551DataToBGRA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output)
{
@@ -362,6 +452,27 @@
}
}
+void Image::loadRGBA5551DataToRGBA(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output)
+{
+ const unsigned short *source = NULL;
+ unsigned char *dest = NULL;
+
+ for (int y = 0; y < height; y++)
+ {
+ source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
+ dest = static_cast<unsigned char*>(output) + y * outputPitch;
+ for (int x = 0; x < width; x++)
+ {
+ unsigned short rgba = source[x];
+ dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
+ dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
+ dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
+ dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
+ }
+ }
+}
+
void Image::loadRGBAFloatDataToRGBA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output)
{
diff --git a/src/libGLESv2/renderer/Image.h b/src/libGLESv2/renderer/Image.h
index ad114f3..454e83e 100644
--- a/src/libGLESv2/renderer/Image.h
+++ b/src/libGLESv2/renderer/Image.h
@@ -57,6 +57,8 @@
static void loadAlphaDataToBGRA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
+ static void loadAlphaDataToNative(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadAlphaDataToBGRASSE2(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadAlphaFloatDataToRGBA(GLsizei width, GLsizei height,
@@ -67,6 +69,8 @@
int inputPitch, const void *input, size_t outputPitch, void *output, bool native);
static void loadLuminanceFloatDataToRGBA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
+ static void loadLuminanceFloatDataToRGB(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadLuminanceHalfFloatDataToRGBA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadLuminanceAlphaDataToNativeOrBGRA(GLsizei width, GLsizei height,
@@ -77,20 +81,32 @@
int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGBUByteDataToBGRX(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
+ static void loadRGBUByteDataToRGBA(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGB565DataToBGRA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
+ static void loadRGB565DataToRGBA(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGBFloatDataToRGBA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
+ static void loadRGBFloatDataToNative(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGBHalfFloatDataToRGBA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGBAUByteDataToBGRASSE2(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGBAUByteDataToBGRA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
+ static void loadRGBAUByteDataToNative(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGBA4444DataToBGRA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
+ static void loadRGBA4444DataToRGBA(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGBA5551DataToBGRA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
+ static void loadRGBA5551DataToRGBA(GLsizei width, GLsizei height,
+ int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGBAFloatDataToRGBA(GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output);
static void loadRGBAHalfFloatDataToRGBA(GLsizei width, GLsizei height,
diff --git a/src/libGLESv2/renderer/Image11.cpp b/src/libGLESv2/renderer/Image11.cpp
index c67e9aa..e0cfe93 100644
--- a/src/libGLESv2/renderer/Image11.cpp
+++ b/src/libGLESv2/renderer/Image11.cpp
@@ -148,25 +148,25 @@
loadLuminanceAlphaHalfFloatDataToRGBA(width, height, inputPitch, input, mappedImage.RowPitch, offsetMappedData);
break;
case GL_RGB8_OES:
- UNIMPLEMENTED(); // TODO - new function for D3D11-supported formats
+ loadRGBUByteDataToRGBA(width, height, inputPitch, input, mappedImage.RowPitch, offsetMappedData);
break;
case GL_RGB565:
- UNIMPLEMENTED(); // TODO - new function for D3D11-supported formats
+ loadRGB565DataToRGBA(width, height, inputPitch, input, mappedImage.RowPitch, offsetMappedData);
break;
case GL_RGBA8_OES:
- UNIMPLEMENTED(); // TODO - new function for D3D11-supported formats
+ loadRGBAUByteDataToNative(width, height, inputPitch, input, mappedImage.RowPitch, offsetMappedData);
break;
case GL_RGBA4:
- UNIMPLEMENTED(); // TODO - new function for D3D11-supported formats
+ loadRGBA4444DataToRGBA(width, height, inputPitch, input, mappedImage.RowPitch, offsetMappedData);
break;
case GL_RGB5_A1:
- UNIMPLEMENTED(); // TODO - new function for D3D11-supported formats
+ loadRGBA5551DataToRGBA(width, height, inputPitch, input, mappedImage.RowPitch, offsetMappedData);
break;
case GL_BGRA8_EXT:
loadBGRADataToBGRA(width, height, inputPitch, input, mappedImage.RowPitch, offsetMappedData);
break;
case GL_RGB32F_EXT:
- UNIMPLEMENTED(); // TODO - new function for D3D11-supported formats
+ loadRGBFloatDataToNative(width, height, inputPitch, input, mappedImage.RowPitch, offsetMappedData);
break;
case GL_RGB16F_EXT:
loadRGBHalfFloatDataToRGBA(width, height, inputPitch, input, mappedImage.RowPitch, offsetMappedData);