Sign in to follow this  
Kirill Alpin

Problem by creating texture3d out of a texture2d array

Recommended Posts

Kirill Alpin    325
Hello folks

I use SlimDx and I'm trying to create a texture3d object out of a texture2d array.
Each texture2d object has a height and a width of the variable "scale" and there are "scale" texture2d objects in the array.
But there is a problem. I can't get the data out of that array to write it into that texture3d object. So the texture3d object is always black when I draw it.
Here's my code:


[source lang="csharp"]
byte[] data = new byte[textures.Length * scale * scale * 16];
for (int i = 0; i < textures.Length; i++)
{
System.IO.Stream stream = System.IO.Stream.Null;
Texture2D.ToStream(device.ImmediateContext, textures[i], ImageFileFormat.Png, stream);
stream.Read(data, i * (int)stream.Length, (int)stream.Length);
}
DataBox b = new DataBox(16 * scale, 16 * scale * scale, new DataStream(data, true, true));

volume = new Texture3D(device, new Texture3DDescription()
{
Width = scale,
Height = scale,
Depth = scale,
MipLevels = 1,
Format = SlimDX.DXGI.Format.R32G32B32A32_Float,
BindFlags = BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default
}, b);
[/source]

I hope someone can help me.

Share this post


Link to post
Share on other sites
unbird    8336
I'm not that surprised System.IO.Stream.Null as a temporary stream produces black pixels.

Also: Texture2D.ToStream will write whatever image format you specified, not the raw texture data.

Alternative: Setup a suitable rendering with render targets into the 3D texture.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this