Texture image setting functions use the refactored texture conversion and loading functions.

TRAC #22972

Signed-off-by: Jamie Madill
Signed-off-by: Nicolas Capens
Author: Geoff Lang

git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2316 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Texture.cpp b/src/libGLESv2/Texture.cpp
index 929f8af..2465b62 100644
--- a/src/libGLESv2/Texture.cpp
+++ b/src/libGLESv2/Texture.cpp
@@ -216,11 +216,11 @@
     }
 }
 
-void Texture::setImage(GLint unpackAlignment, const void *pixels, rx::Image *image)
+void Texture::setImage(GLint unpackAlignment, GLenum type, const void *pixels, rx::Image *image)
 {
     if (pixels != NULL)
     {
-        image->loadData(0, 0, 0, image->getWidth(), image->getHeight(), image->getDepth(), unpackAlignment, pixels);
+        image->loadData(0, 0, 0, image->getWidth(), image->getHeight(), image->getDepth(), unpackAlignment, type, pixels);
         mDirtyImages = true;
     }
 }
@@ -239,7 +239,7 @@
 {
     if (pixels != NULL)
     {
-        image->loadData(xoffset, yoffset, zoffset, width, height, depth, unpackAlignment, pixels);
+        image->loadData(xoffset, yoffset, zoffset, width, height, depth, unpackAlignment, type, pixels);
         mDirtyImages = true;
     }
 
@@ -447,7 +447,7 @@
                                                                                      : GetSizedInternalFormat(format, type, clientVersion);
     redefineImage(level, sizedInternalFormat, width, height);
 
-    Texture::setImage(unpackAlignment, pixels, mImageArray[level]);
+    Texture::setImage(unpackAlignment, type, pixels, mImageArray[level]);
 }
 
 void Texture2D::bindTexImage(egl::Surface *surface)
@@ -524,8 +524,10 @@
 
 void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
 {
-    GLint internalformat = ConvertSizedInternalFormat(format, GL_UNSIGNED_BYTE);
-    redefineImage(level, internalformat, width, height);
+    GLuint clientVersion = mRenderer->getCurrentClientVersion();
+    GLint sizedInternalFormat = IsSizedInternalFormat(format, clientVersion) ? format
+                                                                             : GetSizedInternalFormat(format, GL_UNSIGNED_BYTE, clientVersion);
+    redefineImage(level, sizedInternalFormat, width, height);
 
     if (!mImageArray[level]->isRenderableFormat())
     {
@@ -577,14 +579,16 @@
 
         if (level < levelCount())
         {
+            GLuint clientVersion = mRenderer->getCurrentClientVersion();
+
             gl::Rectangle sourceRect;
             sourceRect.x = x;
             sourceRect.width = width;
             sourceRect.y = y;
             sourceRect.height = height;
 
-            mRenderer->copyImage(source, sourceRect, 
-                                 gl::ExtractFormat(mImageArray[0]->getInternalFormat()),
+            mRenderer->copyImage(source, sourceRect,
+                                 gl::GetFormat(mImageArray[0]->getInternalFormat(), clientVersion),
                                  xoffset, yoffset, mTexStorage, level);
         }
     }
@@ -1261,7 +1265,7 @@
 
     redefineImage(faceIndex, level, sizedInternalFormat, width, height);
 
-    Texture::setImage(unpackAlignment, pixels, mImageArray[faceIndex][level]);
+    Texture::setImage(unpackAlignment, type, pixels, mImageArray[faceIndex][level]);
 }
 
 unsigned int TextureCubeMap::faceIndex(GLenum face)
@@ -1312,8 +1316,10 @@
 void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
 {
     unsigned int faceindex = faceIndex(target);
-    GLint internalformat = gl::ConvertSizedInternalFormat(format, GL_UNSIGNED_BYTE);
-    redefineImage(faceindex, level, internalformat, width, height);
+    GLuint clientVersion = mRenderer->getCurrentClientVersion();
+    GLint sizedInternalFormat = IsSizedInternalFormat(format, clientVersion) ? format
+                                                                             : GetSizedInternalFormat(format, GL_UNSIGNED_BYTE, clientVersion);
+    redefineImage(faceindex, level, sizedInternalFormat, width, height);
 
     if (!mImageArray[faceindex][level]->isRenderableFormat())
     {
@@ -1371,13 +1377,15 @@
 
         if (level < levelCount())
         {
+            GLuint clientVersion = mRenderer->getCurrentClientVersion();
+
             gl::Rectangle sourceRect;
             sourceRect.x = x;
             sourceRect.width = width;
             sourceRect.y = y;
             sourceRect.height = height;
 
-            mRenderer->copyImage(source, sourceRect, gl::ExtractFormat(mImageArray[0][0]->getInternalFormat()), 
+            mRenderer->copyImage(source, sourceRect, gl::GetFormat(mImageArray[0][0]->getInternalFormat(), clientVersion),
                                  xoffset, yoffset, mTexStorage, target, level);
         }
     }
@@ -1611,7 +1619,7 @@
                                                                                      : GetSizedInternalFormat(format, type, clientVersion);
     redefineImage(level, sizedInternalFormat, width, height, depth);
 
-    Texture::setImage(unpackAlignment, pixels, mImageArray[level]);
+    Texture::setImage(unpackAlignment, type, pixels, mImageArray[level]);
 }
 
 void Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
@@ -1728,8 +1736,10 @@
             sourceRect.y = y;
             sourceRect.height = height;
 
+            GLuint clientVersion = mRenderer->getCurrentClientVersion();
+
             mRenderer->copyImage(source, sourceRect,
-                                 gl::ExtractFormat(mImageArray[0]->getInternalFormat()),
+                                 gl::GetFormat(mImageArray[0]->getInternalFormat(), clientVersion),
                                  xoffset, yoffset, zoffset, mTexStorage, level);
         }
     }
@@ -2053,12 +2063,12 @@
                                                                                      : GetSizedInternalFormat(format, type, clientVersion);
     redefineImage(level, sizedInternalFormat, width, height, depth);
 
-    GLsizei inputDepthPitch = gl::ComputeDepthPitch(width, height, sizedInternalFormat, unpackAlignment);
+    GLsizei inputDepthPitch = gl::GetDepthPitch(sizedInternalFormat, type, clientVersion, width, height, unpackAlignment);
 
     for (int i = 0; i < depth; i++)
     {
         const void *layerPixels = reinterpret_cast<const unsigned char*>(pixels) + (inputDepthPitch * i);
-        Texture::setImage(unpackAlignment, layerPixels, mImageArray[level][i]);
+        Texture::setImage(unpackAlignment, type, layerPixels, mImageArray[level][i]);
     }
 }
 
@@ -2067,7 +2077,8 @@
     // compressed formats don't have separate sized internal formats-- we can just use the compressed format directly
     redefineImage(level, format, width, height, depth);
 
-    GLsizei inputDepthPitch = gl::ComputeCompressedDepthPitch(width, height, format);
+    GLuint clientVersion = mRenderer->getCurrentClientVersion();
+    GLsizei inputDepthPitch = gl::GetDepthPitch(format, GL_UNSIGNED_BYTE, clientVersion, width, height, 1);
 
     for (int i = 0; i < depth; i++)
     {
@@ -2078,8 +2089,9 @@
 
 void Texture2DArray::subImage(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels)
 {
-    GLint internalformat = ConvertSizedInternalFormat(format, type);
-    GLsizei inputDepthPitch = gl::ComputeDepthPitch(width, height, internalformat, unpackAlignment);
+    GLint internalformat = getInternalFormat(level);
+    GLuint clientVersion =  mRenderer->getCurrentClientVersion();
+    GLsizei inputDepthPitch = gl::GetDepthPitch(internalformat, type, width, height, clientVersion, unpackAlignment);
 
     for (int i = 0; i < depth; i++)
     {
@@ -2095,7 +2107,8 @@
 
 void Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
 {
-    GLsizei inputDepthPitch = gl::ComputeCompressedDepthPitch(width, height, format);
+    GLuint clientVersion = mRenderer->getCurrentClientVersion();
+    GLsizei inputDepthPitch = gl::GetDepthPitch(format, GL_UNSIGNED_BYTE, clientVersion, width, height, 1);
 
     for (int i = 0; i < depth; i++)
     {
@@ -2214,13 +2227,15 @@
 
         if (level < levelCount())
         {
+            GLuint clientVersion = mRenderer->getCurrentClientVersion();
+
             gl::Rectangle sourceRect;
             sourceRect.x = x;
             sourceRect.width = width;
             sourceRect.y = y;
             sourceRect.height = height;
 
-            mRenderer->copyImage(source, sourceRect, gl::ExtractFormat(getInternalFormat(0)),
+            mRenderer->copyImage(source, sourceRect, gl::GetFormat(getInternalFormat(0), clientVersion),
                                  xoffset, yoffset, zoffset, mTexStorage, level);
         }
     }
diff --git a/src/libGLESv2/Texture.h b/src/libGLESv2/Texture.h
index 562ad32..b3bb0af 100644
--- a/src/libGLESv2/Texture.h
+++ b/src/libGLESv2/Texture.h
@@ -106,7 +106,7 @@
     static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1);   // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager.
 
   protected:
-    void setImage(GLint unpackAlignment, const void *pixels, rx::Image *image);
+    void setImage(GLint unpackAlignment, GLenum type, const void *pixels, rx::Image *image);
     bool subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
                   GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, rx::Image *image);
     void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image);
diff --git a/src/libGLESv2/renderer/Image.h b/src/libGLESv2/renderer/Image.h
index b116709..3f187d3 100644
--- a/src/libGLESv2/renderer/Image.h
+++ b/src/libGLESv2/renderer/Image.h
@@ -57,7 +57,7 @@
     virtual bool isRenderableFormat() const = 0;
     
     virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
-                          GLint unpackAlignment, const void *input) = 0;
+                          GLint unpackAlignment, GLenum type, const void *input) = 0;
     virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
                                     const void *input) = 0;
 
diff --git a/src/libGLESv2/renderer/Image11.cpp b/src/libGLESv2/renderer/Image11.cpp
index f990b63..2f69014 100644
--- a/src/libGLESv2/renderer/Image11.cpp
+++ b/src/libGLESv2/renderer/Image11.cpp
@@ -16,6 +16,7 @@
 
 #include "libGLESv2/main.h"
 #include "libGLESv2/utilities.h"
+#include "libGLESv2/renderer/formatutils11.h"
 #include "libGLESv2/renderer/renderer11_utils.h"
 #include "libGLESv2/renderer/generatemip.h"
 
@@ -182,8 +183,16 @@
 // Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input
 // into the target pixel rectangle.
 void Image11::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
-                       GLint unpackAlignment, const void *input)
+                       GLint unpackAlignment, GLenum type, const void *input)
 {
+    GLuint clientVersion = mRenderer->getCurrentClientVersion();
+    GLsizei inputRowPitch = gl::GetRowPitch(mInternalFormat, type, clientVersion, width, unpackAlignment);
+    GLsizei inputDepthPitch = gl::GetDepthPitch(mInternalFormat, type, clientVersion, width, height, unpackAlignment);
+    GLuint outputPixelSize = d3d11::GetFormatPixelBytes(mDXGIFormat);
+
+    LoadImageFunction loadFunction = d3d11::GetImageLoadFunction(mInternalFormat, type, clientVersion);
+    ASSERT(loadFunction != NULL);
+
     D3D11_MAPPED_SUBRESOURCE mappedImage;
     HRESULT result = map(D3D11_MAP_WRITE, &mappedImage);
     if (FAILED(result))
@@ -192,72 +201,8 @@
         return;
     }
 
-    GLsizei inputRowPitch = gl::ComputeRowPitch(width, mInternalFormat, unpackAlignment);
-    GLsizei inputDepthPitch = gl::ComputeDepthPitch(width, height, mInternalFormat, unpackAlignment);
-    size_t pixelSize = d3d11::ComputePixelSizeBits(mDXGIFormat) / 8;
-    void* offsetMappedData = (void*)((BYTE *)mappedImage.pData + (yoffset * mappedImage.RowPitch + xoffset * pixelSize + zoffset * mappedImage.DepthPitch));
-
-    switch (mInternalFormat)
-    {
-      case GL_ALPHA8_EXT:
-        loadAlphaDataToNative(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_LUMINANCE8_EXT:
-        loadLuminanceDataToNativeOrBGRA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData, false);
-        break;
-      case GL_ALPHA32F_EXT:
-        loadAlphaFloatDataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_LUMINANCE32F_EXT:
-        loadLuminanceFloatDataToRGB(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_ALPHA16F_EXT:
-        loadAlphaHalfFloatDataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_LUMINANCE16F_EXT:
-        loadLuminanceHalfFloatDataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_LUMINANCE8_ALPHA8_EXT:
-        loadLuminanceAlphaDataToNativeOrBGRA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData, false);
-        break;
-      case GL_LUMINANCE_ALPHA32F_EXT:
-        loadLuminanceAlphaFloatDataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_LUMINANCE_ALPHA16F_EXT:
-        loadLuminanceAlphaHalfFloatDataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_RGB8_OES:
-        loadRGBUByteDataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_RGB565:
-        loadRGB565DataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_RGBA8_OES:
-        loadRGBAUByteDataToNative(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_RGBA4:
-        loadRGBA4444DataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_RGB5_A1:
-        loadRGBA5551DataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_BGRA8_EXT:
-        loadBGRADataToBGRA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_RGB32F_EXT:
-        loadRGBFloatDataToNative(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_RGB16F_EXT:
-        loadRGBHalfFloatDataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_RGBA32F_EXT:
-        loadRGBAFloatDataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      case GL_RGBA16F_EXT:
-        loadRGBAHalfFloatDataToRGBA(width, height, depth, inputRowPitch, inputDepthPitch, input, mappedImage.RowPitch, mappedImage.DepthPitch, offsetMappedData);
-        break;
-      default: UNREACHABLE(); 
-    }
+    void* offsetMappedData = (void*)((BYTE *)mappedImage.pData + (yoffset * mappedImage.RowPitch + xoffset * outputPixelSize + zoffset * mappedImage.DepthPitch));
+    loadFunction(width, height, depth, input, inputRowPitch, inputDepthPitch, offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch);
 
     unmap();
 }
diff --git a/src/libGLESv2/renderer/Image11.h b/src/libGLESv2/renderer/Image11.h
index 2823394..1d2de47 100644
--- a/src/libGLESv2/renderer/Image11.h
+++ b/src/libGLESv2/renderer/Image11.h
@@ -49,7 +49,7 @@
     DXGI_FORMAT getDXGIFormat() const;
     
     virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
-                          GLint unpackAlignment, const void *input);
+                          GLint unpackAlignment, GLenum type, const void *input);
     virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
                                     const void *input);
 
diff --git a/src/libGLESv2/renderer/Image9.cpp b/src/libGLESv2/renderer/Image9.cpp
index 9d01ed6..4aa42c2 100644
--- a/src/libGLESv2/renderer/Image9.cpp
+++ b/src/libGLESv2/renderer/Image9.cpp
@@ -18,6 +18,7 @@
 #include "libGLESv2/renderer/TextureStorage9.h"
 
 #include "libGLESv2/renderer/renderer9_utils.h"
+#include "libGLESv2/renderer/formatutils9.h"
 #include "libGLESv2/renderer/generatemip.h"
 
 namespace rx
@@ -374,11 +375,17 @@
 // Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input
 // into the target pixel rectangle.
 void Image9::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
-                      GLint unpackAlignment, const void *input)
+                      GLint unpackAlignment, GLenum type, const void *input)
 {
     // 3D textures are not supported by the D3D9 backend.
     ASSERT(zoffset == 0 && depth == 1);
 
+    GLuint clientVersion = mRenderer->getCurrentClientVersion();
+    GLsizei inputRowPitch = gl::GetRowPitch(mInternalFormat, type, clientVersion, width, unpackAlignment);
+
+    LoadImageFunction loadFunction = d3d9::GetImageLoadFunction(mInternalFormat, mRenderer);
+    ASSERT(loadFunction != NULL);
+
     RECT lockRect =
     {
         xoffset, yoffset,
@@ -392,85 +399,7 @@
         return;
     }
 
-
-    GLsizei inputPitch = gl::ComputeRowPitch(width, mInternalFormat, unpackAlignment);
-
-    switch (mInternalFormat)
-    {
-      case GL_ALPHA8_EXT:
-        if (gl::supportsSSE2())
-        {
-            loadAlphaDataToBGRASSE2(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        }
-        else
-        {
-            loadAlphaDataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        }
-        break;
-      case GL_LUMINANCE8_EXT:
-        loadLuminanceDataToNativeOrBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits, getD3DFormat() == D3DFMT_L8);
-        break;
-      case GL_ALPHA32F_EXT:
-        loadAlphaFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_LUMINANCE32F_EXT:
-        loadLuminanceFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_ALPHA16F_EXT:
-        loadAlphaHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_LUMINANCE16F_EXT:
-        loadLuminanceHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_LUMINANCE8_ALPHA8_EXT:
-        loadLuminanceAlphaDataToNativeOrBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits, getD3DFormat() == D3DFMT_A8L8);
-        break;
-      case GL_LUMINANCE_ALPHA32F_EXT:
-        loadLuminanceAlphaFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_LUMINANCE_ALPHA16F_EXT:
-        loadLuminanceAlphaHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_RGB8_OES:
-        loadRGBUByteDataToBGRX(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_RGB565:
-        loadRGB565DataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_RGBA8_OES:
-        if (gl::supportsSSE2())
-        {
-            loadRGBAUByteDataToBGRASSE2(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        }
-        else
-        {
-            loadRGBAUByteDataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        }
-        break;
-      case GL_RGBA4:
-        loadRGBA4444DataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_RGB5_A1:
-        loadRGBA5551DataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_BGRA8_EXT:
-        loadBGRADataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      // float textures are converted to RGBA, not BGRA, as they're stored that way in D3D
-      case GL_RGB32F_EXT:
-        loadRGBFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_RGB16F_EXT:
-        loadRGBHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_RGBA32F_EXT:
-        loadRGBAFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      case GL_RGBA16F_EXT:
-        loadRGBAHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
-        break;
-      default: UNREACHABLE(); 
-    }
+    loadFunction(width, height, depth, input, inputRowPitch, 0, locked.pBits, locked.Pitch, 0);
 
     unlock();
 }
diff --git a/src/libGLESv2/renderer/Image9.h b/src/libGLESv2/renderer/Image9.h
index 4c17c93..b8ea910 100644
--- a/src/libGLESv2/renderer/Image9.h
+++ b/src/libGLESv2/renderer/Image9.h
@@ -53,7 +53,7 @@
     virtual bool updateSurface(TextureStorageInterface2DArray *storage, int level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height);
 
     virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
-                          GLint unpackAlignment, const void *input);
+                          GLint unpackAlignment, GLenum type, const void *input);
     virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
                                     const void *input);