Browse Source

Fixed bug in D3DTexture2D && D3DTextureCube::SetData() when not setting the whole texture.

Lasse Öörni 12 years ago
parent
commit
5da7d24f94

+ 6 - 9
Source/Engine/Graphics/Direct3D9/D3D9Texture2D.cpp

@@ -242,13 +242,10 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     
     unsigned char* src = (unsigned char*)data;
     unsigned rowSize = GetRowDataSize(width);
-    unsigned rowOffset = GetRowDataSize(x);
+    
     // GetRowDataSize() returns CPU-side (source) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
-    {
         rowSize = rowSize / 3 * 4;
-        rowOffset = rowOffset / 3 * 4;
-    }
     
     // Perform conversion from RGB / RGBA as necessary
     switch (format_)
@@ -256,7 +253,7 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     default:
         for (int i = 0; i < height; ++i)
         {
-            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + (y + i) * d3dLockedRect.Pitch + rowOffset;
+            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             memcpy(dest, src, rowSize);
             src += rowSize;
         }
@@ -265,8 +262,8 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     case D3DFMT_X8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
-            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + (y + i) * d3dLockedRect.Pitch + rowOffset;
-            for (int j = 0; j < levelWidth; ++j)
+            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
+            for (int j = 0; j < width; ++j)
             {
                 *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = 255;
                 src += 3;
@@ -277,8 +274,8 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     case D3DFMT_A8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
-            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + (y + i) * d3dLockedRect.Pitch + rowOffset;
-            for (int j = 0; j < levelWidth; ++j)
+            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
+            for (int j = 0; j < width; ++j)
             {
                 *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = src[3];
                 src += 4;

+ 4 - 7
Source/Engine/Graphics/Direct3D9/D3D9TextureCube.cpp

@@ -239,13 +239,10 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     
     unsigned char* src = (unsigned char*)data;
     unsigned rowSize = GetRowDataSize(width);
-    unsigned rowOffset = GetRowDataSize(x);
+    
     // GetRowDataSize() returns CPU-side (source) data size, so need to convert for X8R8G8B8
     if (format_ == D3DFMT_X8R8G8B8)
-    {
         rowSize = rowSize / 3 * 4;
-        rowOffset = rowOffset / 3 * 4;
-    }
     
     // Perform conversion from RGB / RGBA as necessary
     switch (format_)
@@ -253,7 +250,7 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     default:
         for (int i = 0; i < height; ++i)
         {
-            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + (y + i) * d3dLockedRect.Pitch + rowOffset;
+            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             memcpy(dest, src, rowSize);
             src += rowSize;
         }
@@ -262,7 +259,7 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     case D3DFMT_X8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
-            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + (y + i) * d3dLockedRect.Pitch + rowOffset;
+            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < width; ++j)
             {
                 *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = 255;
@@ -274,7 +271,7 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     case D3DFMT_A8R8G8B8:
         for (int i = 0; i < height; ++i)
         {
-            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + (y + i) * d3dLockedRect.Pitch + rowOffset;
+            unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
             for (int j = 0; j < width; ++j)
             {
                 *dest++  = src[2]; *dest++ = src[1]; *dest++ = src[0]; *dest++ = src[3];