How can pass a Texture2D array from XNA to HLSL?

Started by
2 comments, last by Hector San Roman Lanza 11 years, 8 months ago
Hi!
I am trying send a Texture2D array from XNA in a EffectParameter to a HLSLTexture2DArray variable. The problem: XNA give me an error when i do it: [color=#4A4A4A]

[color=#4A4A4A]cannot convert from 'Microsoft.Xna.Framework.Graphics.Texture2D[]' to 'bool'

The code in XNA file:


Texture2D[] tex;
EffectParameter texArray
texArray.Parameter["xTextures"].SetValue(tex);


The code in HLSL file

Texture2DArray xTextures;
Advertisement
Hmmm.... texture arrays aren't supported in DirectX 9 (and hence XNA). I'm surprised the HLSL compiles.
It would probably compile alright as the shader compiler is a separate program, and all it knows about is the shader source code, the type of shader (vs, ps, etc) and the shader profile to be used (2_0, 3_0, etc). If the OP had set things up appropriately then there's no reason for the shader compiler to choke on it.

Just for the OP's info, a Texture2DArray in HLSL (for SM4.0+ hardware and with the appropriate API support) does not take an array of Texture2D objects like you are doing. The API defines a Texture2DArray type which is a different type of texture, taking an "arraysize" parameter that defines how many textures are in the array. This is much the same way as 3D textures or cubemaps are different types of textures. E.g. for D3D11 it is specified as part of the D3D11_TEXTURE2D_DESC struct which is used when creating the texture. If your API (XNA in this case) doesn't support this type of texture then you can't use one.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Ok, thanks for the answers!

This topic is closed to new replies.

Advertisement