Implements a special case for temporary surface creation for DXT low mip levels.
TRAC #12908
The lowest mip levels for DXT textures will have dimensions < 4, so a D3D
texture cannot be created to hold them offscreen directly. Instead, we must
create a larger texture one of whose mip levels would be the desired dimension,
and store the surface from that texture for later inclusion in the final
texture.
Signed-off-by: Daniel Koch

Author:    Shannon Woods

git-svn-id: https://angleproject.googlecode.com/svn/trunk@398 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Texture.cpp b/src/libGLESv2/Texture.cpp
index 612d795..7f50c5b 100644
--- a/src/libGLESv2/Texture.cpp
+++ b/src/libGLESv2/Texture.cpp
@@ -320,7 +320,28 @@
 
     if (width != 0 && height != 0)
     {
-        HRESULT result = getDevice()->CreateTexture(width, height, 1, NULL, selectFormat(format), D3DPOOL_SYSTEMMEM, &newTexture, NULL);
+        int levelToFetch = 0;
+        GLsizei requestWidth = width;
+        GLsizei requestHeight = height;
+        if (IsCompressed(format) && (width % 4 != 0 || height % 4 != 0))
+        {
+            bool isMult4 = false;
+            int upsampleCount = 0;
+            while (!isMult4)
+            {
+                requestWidth <<= 1;
+                requestHeight <<= 1;
+                upsampleCount++;
+                if (requestWidth % 4 == 0 && requestHeight % 4 == 0)
+                {
+                    isMult4 = true;
+                }
+            }
+            levelToFetch = upsampleCount;
+        }
+
+        HRESULT result = getDevice()->CreateTexture(requestWidth, requestHeight, levelToFetch + 1, NULL, selectFormat(format),
+                                                    D3DPOOL_SYSTEMMEM, &newTexture, NULL);
 
         if (FAILED(result))
         {
@@ -328,7 +349,7 @@
             return error(GL_OUT_OF_MEMORY);
         }
 
-        newTexture->GetSurfaceLevel(0, &newSurface);
+        newTexture->GetSurfaceLevel(levelToFetch, &newSurface);
         newTexture->Release();
     }