Only resize images in D3D when really needed

This commit is contained in:
Stephan Sundermann committed 2013-01-10 14:20:03 +01:00
1 parent 66f294f5a0
commit 9c3f1d9ebd
1 file changed
+10 -7
+10 -7
View File
@@ -944,6 +944,8 @@ namespace Vocaluxe.Lib.Draw
texture.w2 = (float)CheckForNextPowerOf2(w); texture.w2 = (float)CheckForNextPowerOf2(w);
texture.h2 = (float)CheckForNextPowerOf2(h); texture.h2 = (float)CheckForNextPowerOf2(h);
if (texture.w2 != bmp.Width || texture.h2 != bmp.Height)
{
//Create a new Bitmap with the new sizes //Create a new Bitmap with the new sizes
Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2); Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2);
//Scale the texture //Scale the texture
@@ -952,15 +954,17 @@ namespace Vocaluxe.Lib.Draw
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height));
g.Dispose(); g.Dispose();
bmp = bmp2;
}
texture.width_ratio = 1f; texture.width_ratio = 1f;
texture.height_ratio = 1f; texture.height_ratio = 1f;
//Fill the new Bitmap with the texture data //Fill the new Bitmap with the texture data
BitmapData bmp_data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, (int)texture.w2, (int)texture.h2), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
byte[] Data = new byte[4 * bmp2.Width * bmp2.Height]; byte[] Data = new byte[4 * (int)texture.w2 * (int)texture.h2];
Marshal.Copy(bmp_data.Scan0, Data, 0, Data.Length); Marshal.Copy(bmp_data.Scan0, Data, 0, Data.Length);
bmp2.UnlockBits(bmp_data); bmp.UnlockBits(bmp_data);
//Create a new texture in the managed pool, which does not need to be recreated on a lost device //Create a new texture in the managed pool, which does not need to be recreated on a lost device
//because a copy of the texture is hold in the Ram //because a copy of the texture is hold in the Ram
@@ -969,14 +973,13 @@ namespace Vocaluxe.Lib.Draw
DataRectangle rect = t.LockRectangle(0, LockFlags.Discard); DataRectangle rect = t.LockRectangle(0, LockFlags.Discard);
for (int i = 0; i < Data.Length; ) for (int i = 0; i < Data.Length; )
{ {
rect.Data.Write(Data, i, 4 * bmp2.Width); rect.Data.Write(Data, i, 4 * (int)texture.w2);
i += 4 * bmp2.Width; i += 4 * (int)texture.w2;
rect.Data.Position = rect.Data.Position - 4 * bmp2.Width; rect.Data.Position = rect.Data.Position - 4 * (int)texture.w2;
rect.Data.Position += rect.Pitch; rect.Data.Position += rect.Pitch;
} }
t.UnlockRectangle(0); t.UnlockRectangle(0);
bmp2.Dispose();
bmp_data = null; bmp_data = null;
// Add to Texture List // Add to Texture List