24bit depth formats need to flip the depth and stencil bits when loading.

TRAC #23540

Signed-off-by: Jamie Madill
Signed-off-by: Shannon Woods
diff --git a/src/libGLESv2/renderer/d3d11/formatutils11.cpp b/src/libGLESv2/renderer/d3d11/formatutils11.cpp
index 3207816..ffb9900 100644
--- a/src/libGLESv2/renderer/d3d11/formatutils11.cpp
+++ b/src/libGLESv2/renderer/d3d11/formatutils11.cpp
@@ -268,10 +268,10 @@
     insertLoadFunction(&map, GL_R32UI,              GL_UNSIGNED_INT,                   loadToNative<GLuint, 1>              );
     insertLoadFunction(&map, GL_R32I,               GL_INT,                            loadToNative<GLint, 1>               );
     insertLoadFunction(&map, GL_DEPTH_COMPONENT16,  GL_UNSIGNED_SHORT,                 loadToNative<GLushort, 1>            );
-    insertLoadFunction(&map, GL_DEPTH_COMPONENT24,  GL_UNSIGNED_INT,                   loadToNative<GLuint, 1>              );
+    insertLoadFunction(&map, GL_DEPTH_COMPONENT24,  GL_UNSIGNED_INT,                   loadG8R24DataToR24G8                 );
     insertLoadFunction(&map, GL_DEPTH_COMPONENT16,  GL_UNSIGNED_INT,                   loadUintDataToUshort                 );
     insertLoadFunction(&map, GL_DEPTH_COMPONENT32F, GL_FLOAT,                          loadToNative<GLfloat, 1>             );
-    insertLoadFunction(&map, GL_DEPTH24_STENCIL8,   GL_UNSIGNED_INT_24_8,              loadToNative<GLuint, 1>              );
+    insertLoadFunction(&map, GL_DEPTH24_STENCIL8,   GL_UNSIGNED_INT_24_8,              loadG8R24DataToR24G8                 );
     insertLoadFunction(&map, GL_DEPTH32F_STENCIL8,  GL_FLOAT_32_UNSIGNED_INT_24_8_REV, loadToNative<GLuint, 2>              );
 
     // Unsized formats
diff --git a/src/libGLESv2/renderer/loadimage.cpp b/src/libGLESv2/renderer/loadimage.cpp
index fd642a0..366d26e 100644
--- a/src/libGLESv2/renderer/loadimage.cpp
+++ b/src/libGLESv2/renderer/loadimage.cpp
@@ -828,6 +828,31 @@
     }
 }
 
+
+void loadG8R24DataToR24G8(int width, int height, int depth,
+                          const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
+                          void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
+{
+    const unsigned int *source = NULL;
+    unsigned int *dest = NULL;
+
+    for (int z = 0; z < depth; z++)
+    {
+        for (int y = 0; y < height; y++)
+        {
+            source = offsetDataPointer<const unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
+            dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
+
+            for (int x = 0; x < width; x++)
+            {
+                unsigned int depth = source[x] >> 8;
+                unsigned int stencil = source[x] & 0xFF;
+                dest[x] = depth | (stencil << 24);
+            }
+        }
+    }
+}
+
 void loadFloatRGBDataToHalfFloatRGBA(int width, int height, int depth,
                                      const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
                                      void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
diff --git a/src/libGLESv2/renderer/loadimage.h b/src/libGLESv2/renderer/loadimage.h
index 62433ab..4ac1e56 100644
--- a/src/libGLESv2/renderer/loadimage.h
+++ b/src/libGLESv2/renderer/loadimage.h
@@ -178,6 +178,10 @@
                                    const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
                                    void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
 
+void loadG8R24DataToR24G8(int width, int height, int depth,
+                        const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
+                        void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
+
 template <typename type, unsigned int componentCount>
 void loadToNative(int width, int height, int depth,
                   const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,