From 5111b05fdff98b46d1210727c0d06d653093f26b Mon Sep 17 00:00:00 2001 From: Elideb Date: Wed, 4 Apr 2012 18:47:48 +0200 Subject: [PATCH 1/6] Implemented Texture.mipmapCount, Texture.GetPixel, different versions of Texture.SetPixels and Texture.GetPixels and Texture.Apply(bool). Added helper methods Texture.GetMipmapSize(miplevel), Texture.GetMipmapWidth(miplevel) and Texture.GetMipmapHeight(miplevel). --- Framework/PressPlay.FFWD/Texture.cs | 136 ++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/Framework/PressPlay.FFWD/Texture.cs b/Framework/PressPlay.FFWD/Texture.cs index 7a73556a..4dc58408 100644 --- a/Framework/PressPlay.FFWD/Texture.cs +++ b/Framework/PressPlay.FFWD/Texture.cs @@ -56,17 +56,120 @@ public int height } } + public int mipmapCount + { + get + { + return (tex == null) ? 0 : tex.LevelCount; + } + } + public void SetPixel(int x, int y, Color color) { byte[] buffer = new byte[4] { color.R, color.G, color.B, color.A }; tex.SetData(buffer, (y - 1) * tex.Width + (x - 1), 4); } + public void SetPixels(Color[] colors, int miplevel = 0) + { + Microsoft.Xna.Framework.Color[] xnaColors = new Microsoft.Xna.Framework.Color[colors.Length]; + + for (int i = 0; i < colors.Length; i++) + { + xnaColors[i] = colors[i]; + } + + tex.SetData(miplevel, null, xnaColors, 0, xnaColors.Length); + } + + public void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors, int miplevel = 0) + { + Microsoft.Xna.Framework.Color[] xnaColors = new Microsoft.Xna.Framework.Color[colors.Length]; + + for (int i = 0; i < colors.Length; i++) + { + xnaColors[i] = colors[i]; + } + + tex.SetData( + miplevel, + new Microsoft.Xna.Framework.Rectangle(x, y, blockWidth, blockHeight), + xnaColors, + 0, + blockWidth * blockHeight); + } + + public Color GetPixel (int x, int y) + { + // By default, textures in Unity are set to Wrap = Repeat. + // Use that as default. + // Calculate the modulus of x and y, so we don't go out of bounds. + int modX = x > 0 && x < tex.Width ? x : x % tex.Width; + // % means remainder, not modulus, so we can get negative values. + if (modX < 0) + { + modX += tex.Width; + } + + int modY = y > 0 && y < tex.Height ? y : y % tex.Height; + if (modY < 0) + { + modY += tex.Height; + } + + Microsoft.Xna.Framework.Color[] color = new Microsoft.Xna.Framework.Color[1]; + tex.GetData (color, modX * tex.Width + modY, 1); + + Color result = color[0]; + return result; + } + + public Color[] GetPixels(int miplevel = 0) + { + int mipSize = GetMipmapSize(miplevel); + + Microsoft.Xna.Framework.Color[] xnaColors = new Microsoft.Xna.Framework.Color[mipSize]; + tex.GetData(miplevel, null, xnaColors, 0, mipSize); + + Color[] colors = new Color[mipSize]; + for (int i = 0; i < mipSize; i++) + { + colors[i] = xnaColors[i]; + } + + return colors; + } + + public Color[] GetPixels(int x, int y, int blockWidth, int blockHeight, int miplevel = 0) + { + Microsoft.Xna.Framework.Color[] xnaColors = new Microsoft.Xna.Framework.Color[blockWidth * blockHeight]; + + tex.GetData( + miplevel, + new Microsoft.Xna.Framework.Rectangle(x, y, blockWidth, blockHeight), + xnaColors, + 0, + blockWidth * blockHeight); + + Color[] colors = new Color[xnaColors.Length]; + for (int i = 0; i < xnaColors.Length; i++) + { + colors[i] = xnaColors[i]; + } + + return colors; + } + public void Apply() { Apply(false, false); } + public void Apply(bool updateMipmaps) + { + Apply(updateMipmaps, false); + } + public void Apply(bool updateMipmaps, bool makeNoLongerReadable) { // TODO: Implement this @@ -101,5 +204,38 @@ protected void CheckPowerOfTwoSize() // NOTE: There must be some genius math function that can do this better?! IsPowerOfTwoSize = ((tex.Width == 1) || (tex.Width == 2) || (tex.Width == 4) || (tex.Width == 8) || (tex.Width == 16) || (tex.Width == 32) || (tex.Width == 64) || (tex.Width == 128) || (tex.Width == 256) || (tex.Width == 512) || (tex.Width == 1024) || (tex.Width == 2048) || (tex.Width == 4096)) && ((tex.Height == 1) || (tex.Height == 2) || (tex.Height == 4) || (tex.Height == 8) || (tex.Height == 16) || (tex.Height == 32) || (tex.Height == 64) || (tex.Height == 128) || (tex.Height == 256) || (tex.Height == 512) || (tex.Height == 1024) || (tex.Height == 2048) || (tex.Height == 4096)); } + + protected int GetMipmapSize(int miplevel) + { + if (miplevel < 0 || miplevel >= mipmapCount) + { + throw new ArgumentOutOfRangeException("miplevel", "Texture has " + mipmapCount + " mipmap levels. Mipmap " + miplevel + " is out of range."); + } + + // Each mip level is one fourth the size of the previous one + return (int)(tex.Width * tex.Height / Math.Pow(4, miplevel)); + } + + protected int GetMipmapWidth(int miplevel = 0) + { + if (miplevel < 0 || miplevel >= mipmapCount) + { + throw new ArgumentOutOfRangeException("miplevel", "Texture has " + mipmapCount + " mipmap levels. Mipmap " + miplevel + " is out of range."); + } + + // Each miplevel is half the width and hwight of the previous one + return (int)(tex.Width / Math.Pow(2, miplevel)); + } + + protected int GetMipmapHeight(int miplevel = 0) + { + if (miplevel < 0 || miplevel >= mipmapCount) + { + throw new ArgumentOutOfRangeException("miplevel", "Texture has " + mipmapCount + " mipmap levels. Mipmap " + miplevel + " is out of range."); + } + + // Each miplevel is half the width and hwight of the previous one + return (int)(tex.Height / Math.Pow(2, miplevel)); + } } } From 7cf1d7da582afa19f481fc5c825983f6e47b26a1 Mon Sep 17 00:00:00 2001 From: Elideb Date: Wed, 11 Apr 2012 14:26:14 +0200 Subject: [PATCH 2/6] Fixed SetPixel ArgumentOutOfRangeException. Also taken wrap behaviour into account to prevent crashing on indexes above or below texture dimensions. --- Framework/PressPlay.FFWD/Texture.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Framework/PressPlay.FFWD/Texture.cs b/Framework/PressPlay.FFWD/Texture.cs index 4dc58408..40cbcb56 100644 --- a/Framework/PressPlay.FFWD/Texture.cs +++ b/Framework/PressPlay.FFWD/Texture.cs @@ -66,8 +66,25 @@ public int mipmapCount public void SetPixel(int x, int y, Color color) { - byte[] buffer = new byte[4] { color.R, color.G, color.B, color.A }; - tex.SetData(buffer, (y - 1) * tex.Width + (x - 1), 4); + ////byte[] buffer = new byte[4] { color.R, color.G, color.B, color.A }; + ////tex.SetData(buffer, (y - 1) * tex.Width + (x - 1), 4); + + // Unity takes Wrap mode into account and so should we. By default, wrap. + int modX = x > 0 && x < tex.Width ? x : x % tex.Width; + // % means remainder, not modulus, so we can get negative values. + if (modX < 0) + { + modX += tex.Width; + } + + int modY = y > 0 && y < tex.Height ? y : y % tex.Height; + if (modY < 0) + { + modY += tex.Height; + } + + Microsoft.Xna.Framework.Color[] xnaColor = new Microsoft.Xna.Framework.Color[] { color }; + tex.SetData(0, new Microsoft.Xna.Framework.Rectangle(modX, tex.Height - modY - 1, 1, 1), xnaColor, 0, 1); } public void SetPixels(Color[] colors, int miplevel = 0) From 8a0ea304a6e74089392186e99d09edb281396765 Mon Sep 17 00:00:00 2001 From: Elideb Date: Wed, 11 Apr 2012 14:46:39 +0200 Subject: [PATCH 3/6] Fixed GetPixel (int, int) ArgumentOutOfRangeException. The only XNA can index in-texture pixels beyond (0, 0) is using GetData/SetData with Rectangle. --- Framework/PressPlay.FFWD/Texture.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Framework/PressPlay.FFWD/Texture.cs b/Framework/PressPlay.FFWD/Texture.cs index 40cbcb56..95f81f18 100644 --- a/Framework/PressPlay.FFWD/Texture.cs +++ b/Framework/PressPlay.FFWD/Texture.cs @@ -135,10 +135,10 @@ public Color GetPixel (int x, int y) } Microsoft.Xna.Framework.Color[] color = new Microsoft.Xna.Framework.Color[1]; - tex.GetData (color, modX * tex.Width + modY, 1); + tex.GetData(0, new Microsoft.Xna.Framework.Rectangle(modX, modY, 1, 1), color, 0, 1); - Color result = color[0]; - return result; + // Implicit conversion to FFWD.Color + return color[0]; } public Color[] GetPixels(int miplevel = 0) From a759facac65085c174edb3d82b551c240f411ca6 Mon Sep 17 00:00:00 2001 From: Elideb Date: Wed, 11 Apr 2012 14:49:04 +0200 Subject: [PATCH 4/6] Removed commented code from SetPixel. --- Framework/PressPlay.FFWD/Texture.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Framework/PressPlay.FFWD/Texture.cs b/Framework/PressPlay.FFWD/Texture.cs index 95f81f18..fced0b62 100644 --- a/Framework/PressPlay.FFWD/Texture.cs +++ b/Framework/PressPlay.FFWD/Texture.cs @@ -66,9 +66,6 @@ public int mipmapCount public void SetPixel(int x, int y, Color color) { - ////byte[] buffer = new byte[4] { color.R, color.G, color.B, color.A }; - ////tex.SetData(buffer, (y - 1) * tex.Width + (x - 1), 4); - // Unity takes Wrap mode into account and so should we. By default, wrap. int modX = x > 0 && x < tex.Width ? x : x % tex.Width; // % means remainder, not modulus, so we can get negative values. From 7d5dc11ea110424a58d86e3ff8423fae878adda9 Mon Sep 17 00:00:00 2001 From: Elideb Date: Thu, 12 Apr 2012 12:55:20 +0200 Subject: [PATCH 5/6] Moved GetPixel and SetPixels operations to Texture2D. No longer unstable. Also, changed Xna.Framework.Color[] operations to byte[]. --- Framework/PressPlay.FFWD/Texture.cs | 151 ------------------------- Framework/PressPlay.FFWD/Texture2D.cs | 154 +++++++++++++++++++++++++- 2 files changed, 150 insertions(+), 155 deletions(-) diff --git a/Framework/PressPlay.FFWD/Texture.cs b/Framework/PressPlay.FFWD/Texture.cs index afc2b0af..efaed66a 100644 --- a/Framework/PressPlay.FFWD/Texture.cs +++ b/Framework/PressPlay.FFWD/Texture.cs @@ -56,124 +56,6 @@ public int height } } - public int mipmapCount - { - get - { - return (tex == null) ? 0 : tex.LevelCount; - } - } - - public void SetPixel(int x, int y, Color color) - { - // Unity takes Wrap mode into account and so should we. By default, wrap. - int modX = x > 0 && x < tex.Width ? x : x % tex.Width; - // % means remainder, not modulus, so we can get negative values. - if (modX < 0) - { - modX += tex.Width; - } - - int modY = y > 0 && y < tex.Height ? y : y % tex.Height; - if (modY < 0) - { - modY += tex.Height; - } - - Microsoft.Xna.Framework.Color[] xnaColor = new Microsoft.Xna.Framework.Color[] { color }; - tex.SetData(0, new Microsoft.Xna.Framework.Rectangle(modX, tex.Height - modY - 1, 1, 1), xnaColor, 0, 1); - } - - public void SetPixels(Color[] colors, int miplevel = 0) - { - Microsoft.Xna.Framework.Color[] xnaColors = new Microsoft.Xna.Framework.Color[colors.Length]; - - for (int i = 0; i < colors.Length; i++) - { - xnaColors[i] = colors[i]; - } - - tex.SetData(miplevel, null, xnaColors, 0, xnaColors.Length); - } - - public void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors, int miplevel = 0) - { - Microsoft.Xna.Framework.Color[] xnaColors = new Microsoft.Xna.Framework.Color[colors.Length]; - - for (int i = 0; i < colors.Length; i++) - { - xnaColors[i] = colors[i]; - } - - tex.SetData( - miplevel, - new Microsoft.Xna.Framework.Rectangle(x, y, blockWidth, blockHeight), - xnaColors, - 0, - blockWidth * blockHeight); - } - - public Color GetPixel (int x, int y) - { - // By default, textures in Unity are set to Wrap = Repeat. - // Use that as default. - // Calculate the modulus of x and y, so we don't go out of bounds. - int modX = x > 0 && x < tex.Width ? x : x % tex.Width; - // % means remainder, not modulus, so we can get negative values. - if (modX < 0) - { - modX += tex.Width; - } - - int modY = y > 0 && y < tex.Height ? y : y % tex.Height; - if (modY < 0) - { - modY += tex.Height; - } - - Microsoft.Xna.Framework.Color[] color = new Microsoft.Xna.Framework.Color[1]; - tex.GetData(0, new Microsoft.Xna.Framework.Rectangle(modX, modY, 1, 1), color, 0, 1); - - // Implicit conversion to FFWD.Color - return color[0]; - } - - public Color[] GetPixels(int miplevel = 0) - { - int mipSize = GetMipmapSize(miplevel); - - Microsoft.Xna.Framework.Color[] xnaColors = new Microsoft.Xna.Framework.Color[mipSize]; - tex.GetData(miplevel, null, xnaColors, 0, mipSize); - - Color[] colors = new Color[mipSize]; - for (int i = 0; i < mipSize; i++) - { - colors[i] = xnaColors[i]; - } - - return colors; - } - - public Color[] GetPixels(int x, int y, int blockWidth, int blockHeight, int miplevel = 0) - { - Microsoft.Xna.Framework.Color[] xnaColors = new Microsoft.Xna.Framework.Color[blockWidth * blockHeight]; - - tex.GetData( - miplevel, - new Microsoft.Xna.Framework.Rectangle(x, y, blockWidth, blockHeight), - xnaColors, - 0, - blockWidth * blockHeight); - - Color[] colors = new Color[xnaColors.Length]; - for (int i = 0; i < xnaColors.Length; i++) - { - colors[i] = xnaColors[i]; - } - - return colors; - } - public void Apply() { Apply(false, false); @@ -218,38 +100,5 @@ protected void CheckPowerOfTwoSize() // NOTE: There must be some genius math function that can do this better?! IsPowerOfTwoSize = ((tex.Width == 1) || (tex.Width == 2) || (tex.Width == 4) || (tex.Width == 8) || (tex.Width == 16) || (tex.Width == 32) || (tex.Width == 64) || (tex.Width == 128) || (tex.Width == 256) || (tex.Width == 512) || (tex.Width == 1024) || (tex.Width == 2048) || (tex.Width == 4096)) && ((tex.Height == 1) || (tex.Height == 2) || (tex.Height == 4) || (tex.Height == 8) || (tex.Height == 16) || (tex.Height == 32) || (tex.Height == 64) || (tex.Height == 128) || (tex.Height == 256) || (tex.Height == 512) || (tex.Height == 1024) || (tex.Height == 2048) || (tex.Height == 4096)); } - - protected int GetMipmapSize(int miplevel) - { - if (miplevel < 0 || miplevel >= mipmapCount) - { - throw new ArgumentOutOfRangeException("miplevel", "Texture has " + mipmapCount + " mipmap levels. Mipmap " + miplevel + " is out of range."); - } - - // Each mip level is one fourth the size of the previous one - return (int)(tex.Width * tex.Height / Math.Pow(4, miplevel)); - } - - protected int GetMipmapWidth(int miplevel = 0) - { - if (miplevel < 0 || miplevel >= mipmapCount) - { - throw new ArgumentOutOfRangeException("miplevel", "Texture has " + mipmapCount + " mipmap levels. Mipmap " + miplevel + " is out of range."); - } - - // Each miplevel is half the width and hwight of the previous one - return (int)(tex.Width / Math.Pow(2, miplevel)); - } - - protected int GetMipmapHeight(int miplevel = 0) - { - if (miplevel < 0 || miplevel >= mipmapCount) - { - throw new ArgumentOutOfRangeException("miplevel", "Texture has " + mipmapCount + " mipmap levels. Mipmap " + miplevel + " is out of range."); - } - - // Each miplevel is half the width and hwight of the previous one - return (int)(tex.Height / Math.Pow(2, miplevel)); - } } } diff --git a/Framework/PressPlay.FFWD/Texture2D.cs b/Framework/PressPlay.FFWD/Texture2D.cs index 6c4b2d28..843da590 100644 --- a/Framework/PressPlay.FFWD/Texture2D.cs +++ b/Framework/PressPlay.FFWD/Texture2D.cs @@ -29,7 +29,42 @@ internal static Texture2D LoadFromResource(string name) return new Texture2D(t); } - public void SetPixels(Color[] colors) + public int mipmapCount + { + get + { + return (tex == null) ? 0 : tex.LevelCount; + } + } + + public void SetPixel(int x, int y, Color color) + { + // Unity takes Wrap mode into account and so should we. By default, wrap. + int modX = x > 0 && x < tex.Width ? x : x % tex.Width; + // % means remainder, not modulus, so we can get negative values. + if (modX < 0) + { + modX += tex.Width; + } + + int modY = y > 0 && y < tex.Height ? y : y % tex.Height; + if (modY < 0) + { + modY += tex.Height; + } + + byte[] buffer = new byte[] + { + color.R, + color.G, + color.B, + color.A + }; + + tex.SetData(0, new Microsoft.Xna.Framework.Rectangle(modX, modY, 1, 1), buffer, 0, buffer.Length); + } + + public void SetPixels(Color[] colors, int miplevel = 0) { byte[] buffer = new byte[colors.Length << 2]; @@ -41,13 +76,124 @@ public void SetPixels(Color[] colors) buffer[(i << 2) + 3] = colors[i].A; } - tex.SetData(buffer); + tex.SetData(miplevel, null, buffer, 0, buffer.Length); } - public void SetPixel(int x, int y, Color color) + public void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors, int miplevel = 0) + { + byte[] buffer = new byte[colors.Length << 2]; + + for (int i = 0; i < colors.Length; ++i) + { + buffer[(i << 2)] = colors[i].R; + buffer[(i << 2) + 1] = colors[i].G; + buffer[(i << 2) + 2] = colors[i].B; + buffer[(i << 2) + 3] = colors[i].A; + } + + tex.SetData(miplevel, new Microsoft.Xna.Framework.Rectangle(x, y, blockWidth, blockHeight), buffer, 0, blockWidth * blockHeight << 2); + } + + public Color GetPixel(int x, int y) + { + // By default, textures in Unity are set to Wrap = Repeat. + // Use that as default. + // Calculate the modulus of x and y, so we don't go out of bounds. + int modX = x > 0 && x < tex.Width ? x : x % tex.Width; + // % means remainder, not modulus, so we can get negative values. + if (modX < 0) + { + modX += tex.Width; + } + + int modY = y > 0 && y < tex.Height ? y : y % tex.Height; + if (modY < 0) + { + modY += tex.Height; + } + + byte[] buffer = new byte[4]; + tex.GetData(0, new Microsoft.Xna.Framework.Rectangle(modX, modY, 1, 1), buffer, 0, 4); + + Color color = new Color(); + color.R = buffer[0]; + color.G = buffer[1]; + color.B = buffer[2]; + color.A = buffer[3]; + + return color; + } + + public Color[] GetPixels(int miplevel = 0) + { + int mipSize = GetMipmapSize(miplevel); + + byte[] buffer = new byte[mipSize << 2]; + tex.GetData(miplevel, null, buffer, 0, mipSize << 2); + + Color[] colors = new Color[mipSize]; + for (int i = 0; i < mipSize; i++) + { + colors[i] = new Color(); + colors[i].R = buffer[(i << 2)]; + colors[i].G = buffer[(i << 2) + 1]; + colors[i].B = buffer[(i << 2) + 2]; + colors[i].A = buffer[(i << 2) + 3]; + } + + return colors; + } + + public Color[] GetPixels(int x, int y, int blockWidth, int blockHeight, int miplevel = 0) { - // TODO: Implement this + byte[] buffer = new byte[(blockWidth * blockHeight) << 2]; + + tex.GetData(miplevel, new Microsoft.Xna.Framework.Rectangle(x, y, blockWidth, blockHeight), buffer, 0, buffer.Length); + + Color[] colors = new Color[blockWidth * blockHeight]; + for (int i = 0; i < colors.Length; i++) + { + colors[i] = new Color(); + colors[i].R = buffer[(i << 2)]; + colors[i].G = buffer[(i << 2) + 1]; + colors[i].B = buffer[(i << 2) + 2]; + colors[i].A = buffer[(i << 2) + 3]; + } + + return colors; } + protected int GetMipmapSize(int miplevel = 0) + { + if (miplevel < 0 || miplevel >= mipmapCount) + { + throw new ArgumentOutOfRangeException("miplevel", "Texture has " + mipmapCount + " mipmap levels. Mipmap " + miplevel + " is out of range."); + } + + // Each mip level is one fourth the size of the previous one + return (int)(tex.Width * tex.Height / Math.Pow(4, miplevel)); + } + + protected int GetMipmapWidth(int miplevel = 0) + { + if (miplevel < 0 || miplevel >= mipmapCount) + { + throw new ArgumentOutOfRangeException("miplevel", "Texture has " + mipmapCount + " mipmap levels. Mipmap " + miplevel + " is out of range."); + } + + // Each miplevel is half the width and hwight of the previous one + return (int)(tex.Width / Math.Pow(2, miplevel)); + } + + protected int GetMipmapHeight(int miplevel = 0) + { + if (miplevel < 0 || miplevel >= mipmapCount) + { + throw new ArgumentOutOfRangeException("miplevel", "Texture has " + mipmapCount + " mipmap levels. Mipmap " + miplevel + " is out of range."); + } + + // Each miplevel is half the width and hwight of the previous one + return (int)(tex.Height / Math.Pow(2, miplevel)); + } } } From 703b77d2fbb8a6d7dcdbdc024cad1d16b29dcdd6 Mon Sep 17 00:00:00 2001 From: Elideb Date: Thu, 19 Apr 2012 13:21:57 +0200 Subject: [PATCH 6/6] Removed optional parameters from SetPixels and GetPixels. Replaced with explicit no mipmap methods calling to mipmap capable ones. --- Framework/PressPlay.FFWD/Texture2D.cs | 49 +++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/Framework/PressPlay.FFWD/Texture2D.cs b/Framework/PressPlay.FFWD/Texture2D.cs index 843da590..4184cade 100644 --- a/Framework/PressPlay.FFWD/Texture2D.cs +++ b/Framework/PressPlay.FFWD/Texture2D.cs @@ -64,7 +64,12 @@ public void SetPixel(int x, int y, Color color) tex.SetData(0, new Microsoft.Xna.Framework.Rectangle(modX, modY, 1, 1), buffer, 0, buffer.Length); } - public void SetPixels(Color[] colors, int miplevel = 0) + public void SetPixels(Color[] colors) + { + SetPixels(colors, 0); + } + + public void SetPixels(Color[] colors, int miplevel) { byte[] buffer = new byte[colors.Length << 2]; @@ -79,7 +84,12 @@ public void SetPixels(Color[] colors, int miplevel = 0) tex.SetData(miplevel, null, buffer, 0, buffer.Length); } - public void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors, int miplevel = 0) + public void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors) + { + SetPixels(x, y, blockWidth, blockHeight, colors, 0); + } + + public void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors, int miplevel) { byte[] buffer = new byte[colors.Length << 2]; @@ -124,7 +134,12 @@ public Color GetPixel(int x, int y) return color; } - public Color[] GetPixels(int miplevel = 0) + public Color[] GetPixels() + { + return GetPixels(0); + } + + public Color[] GetPixels(int miplevel) { int mipSize = GetMipmapSize(miplevel); @@ -144,7 +159,12 @@ public Color[] GetPixels(int miplevel = 0) return colors; } - public Color[] GetPixels(int x, int y, int blockWidth, int blockHeight, int miplevel = 0) + public Color[] GetPixels(int x, int y, int blockWidth, int blockHeight) + { + return GetPixels(x, y, blockWidth, blockHeight, 0); + } + + public Color[] GetPixels(int x, int y, int blockWidth, int blockHeight, int miplevel) { byte[] buffer = new byte[(blockWidth * blockHeight) << 2]; @@ -163,7 +183,12 @@ public Color[] GetPixels(int x, int y, int blockWidth, int blockHeight, int mipl return colors; } - protected int GetMipmapSize(int miplevel = 0) + protected int GetMipmapSize() + { + return GetMipmapSize(0); + } + + protected int GetMipmapSize(int miplevel) { if (miplevel < 0 || miplevel >= mipmapCount) { @@ -174,7 +199,12 @@ protected int GetMipmapSize(int miplevel = 0) return (int)(tex.Width * tex.Height / Math.Pow(4, miplevel)); } - protected int GetMipmapWidth(int miplevel = 0) + protected int GetMipmapWidth() + { + return GetMipmapWidth(0); + } + + protected int GetMipmapWidth(int miplevel) { if (miplevel < 0 || miplevel >= mipmapCount) { @@ -185,7 +215,12 @@ protected int GetMipmapWidth(int miplevel = 0) return (int)(tex.Width / Math.Pow(2, miplevel)); } - protected int GetMipmapHeight(int miplevel = 0) + protected int GetMipmapHeight() + { + return GetMipmapHeight(0); + } + + protected int GetMipmapHeight(int miplevel) { if (miplevel < 0 || miplevel >= mipmapCount) {