Thunder2002

Hi,

i am reading of a Texture2D the given colors to extract my height data of a heightmap image. Therefor i use this code:

Int32[] data = new Int32[heightMap.Width * heightMap.Height];
heightMap.GetData<Int32>(data);

heightMap is a Texture2D object with a width and height of 500, so the data-array gets at runtime a size of 250.000. Fine but it fails on getting the data from the Texture2D by using the GetData function with this error:

The type you are using for T in this method is an invalid size for this resource.

I found something with google where people switched to Color instead of Int32 but for me it doesn't work it's returns the same error
I used a smaller heightmap before with a resolution of 128x128 this works!!

Does someone know how to solve this


Re: XNA Framework Texture2D.GetData fails on 500x500 texture

Catalin Zima

Did you try with other non-power-of-two texture sizes



Re: XNA Framework Texture2D.GetData fails on 500x500 texture

Thunder2002

Argh, thats really the solution, if its a power of 2 it works 512x512 for example, sorry for this stupid question, i had never thought that it could be such a .... thing.

Is there any good reason for that




Re: XNA Framework Texture2D.GetData fails on 500x500 texture

dczraptor

Thunder2002 wrote:
Argh, thats really the solution, if its a power of 2 it works 512x512 for example, sorry for this stupid question, i had never thought that it could be such a .... thing.

Is there any good reason for that

I read somewhere that even if the texture is not a power of two, it will be scaled up to the closest power of two. I'm guessing it's easier for the GPU to process. Then again, everything on computers is based off binary.






Re: XNA Framework Texture2D.GetData fails on 500x500 texture

Nick Darnell

I believe it's a graphics card dependent feature. Like in OpenGL you have to use an extension to load non-pow-2 textures. I'm sure the underlying code to DirectX performs a similar check to see if your graphics card has that capability. *shrug*




Re: XNA Framework Texture2D.GetData fails on 500x500 texture

Catalin Zima

Indeed it is Graphics Card dependent.

Some older cards (like Geforce 5700) do not support non power of two textures





Re: XNA Framework Texture2D.GetData fails on 500x500 texture

Thunder2002

Hmm ok, my newer Geforce 7950 GT also seems to support only power-of-two textures.

Btw. i found something interessing:

Debug.WriteLine(graphics.GraphicsDevice.GraphicsDeviceCapabilities.TextureCapabilities.RequiresPower2.ToString());
Debug.WriteLine(graphics.GraphicsDevice.GraphicsDeviceCapabilities.TextureCapabilities.SupportsNonPower2Conditional.ToString());


Both returns False here, so at general is should support non-power-of-two but "under certain conditions" (quote from MSDN) it doesn't.