sharpdx texture related questions

Started by
0 comments, last by AlexandreMutel 12 years, 5 months ago
Hi, all, I got some questions about using sharpdx texture creation API.
1. I haven't find an API D3D11CalcSubresource mapping in sharpdx, even it's merely a very simple calculation that I can write one line myself, just want to know is it somewhere existed in sharpdx?
2. I have 3 classes called DX11Texture1D, DX11Texture2D, DX11Texture3D,
I have a class which host initial data for texture
[color="blue"]public [color="blue"]struct [color="#2b91af"]ElementInitData
{
[color="blue"]public System.[color="#2b91af"]IntPtr data;
[color="blue"]public [color="blue"]uint row_pitch;
[color="blue"]public [color="blue"]uint slice_pitch;
}
in directx11, it's like D3D11_SUBRESOURCE_DATA.
in DX11Texture3D constructor
...
[color="#2b91af"] DataBox[] subres_data = [color="blue"]null;
[color="blue"]if (init_data != [color="blue"]null)
{
subres_data = [color="blue"]new [color="#2b91af"]DataBox[num_mip_maps_];
[color="blue"]for ([color="blue"]uint i = 0; i < num_mip_maps_; ++i)
{
subres_data.DataPointer = init_data.data;
subres_data.RowPitch = ([color="blue"]int)init_data.row_pitch;
subres_data.SlicePitch = ([color="blue"]int)init_data.slice_pitch;
}
}
d3dTexture3D_ = [color="blue"]new [color="#2b91af"]Texture3D([color="#2b91af"]DX11RenderFactory.Instance.D3DDevice, desc_, subres_data);

in DX11Texture2D constructor:
...

[color="#2b91af"] DataRectangle[] subres_data = [color="blue"]null;
[color="blue"]if (init_data != [color="blue"]null)
{
[color="blue"]uint numRectangles = array_size_ * num_mip_maps_;
subres_data = [color="blue"]new [color="#2b91af"]DataRectangle[numRectangles];
[color="blue"]for ([color="blue"]uint j = 0; j < array_size_; ++j)
{
[color="blue"]for ([color="blue"]uint i = 0; i < num_mip_maps_; ++i)
{
subres_data[j * num_mip_maps_ + i].DataPointer = init_data[j * num_mip_maps_ + i].data;
subres_data[j * num_mip_maps_ + i].Pitch = ([color="blue"]int)init_data[j * num_mip_maps_ + i].row_pitch * ([color="blue"]int)init_data[j * num_mip_maps_ + i].slice_pitch; } }
}
d3dTexture2D_ = [color="blue"]new [color="#2b91af"]Texture2D([color="#2b91af"]DX11RenderFactory.Instance.D3DDevice, desc_, subres_data);in DX11Texture1D constructor
[color="#2b91af"] ....
DataStream[] subres_data = [color="blue"]null;
[color="blue"]if (init_data != [color="blue"]null)
{
[color="blue"]uint numStreams = array_size_ * num_mip_maps_;
subres_data = [color="blue"]new [color="#2b91af"]DataStream[numStreams];
[color="blue"]for ([color="blue"]uint j = 0; j < array_size_; ++j)
{
[color="blue"]for ([color="blue"]uint i = 0; i < num_mip_maps_; ++i)
{
subres_data[j * num_mip_maps_ + i] = [color="blue"]new [color="#2b91af"]DataStream(init_data[j * num_mip_maps_ + i].data, ([color="blue"]int)init_data[j * num_mip_maps_ + i].row_pitch, [color="blue"]true, [color="blue"]true);
}
}
}
d3dTexture1D_ = [color="blue"]new [color="#2b91af"]Texture1D([color="#2b91af"]DX11RenderFactory.Instance.D3DDevice, desc_, subres_data);
...
is this correct? the problem I found is in Texture3D creation, even subres_data == null, it will create one success, however in Texture1D, if subres_data == null
it will give me an exception saying object is null. And for Texture1D I don't know how to assign DataPointer as 2d or 3d, so I have to call a new constructor for
every data stream in the array. Any suggestions for this?
Advertisement

Hi, all, I got some questions about using sharpdx texture creation API.
1. I haven't find an API D3D11CalcSubresource mapping in sharpdx, even it's merely a very simple calculation that I can write one line myself, just want to know is it somewhere existed in sharpdx?
2. I have 3 classes called DX11Texture1D, DX11Texture2D, DX11Texture3D,
is this correct? the problem I found is in Texture3D creation, even subres_data == null, it will create one success, however in Texture1D, if subres_data == null
it will give me an exception saying object is null. And for Texture1D I don't know how to assign DataPointer as 2d or 3d, so I have to call a new constructor for
every data stream in the array. Any suggestions for this?

1) The equivalent of D3D11CalcSubresource is the method Resource.CalculateSubResourceIndex but this method is only available from the devel branch and will be available for the next release (end of year).
2) Texture1D was indeed not using the same code path than Texture2D/Texture3D. It will be fixed on the repository.
For the initialization of your code, It is difficult to see if it is correct as everything must be setup correctly according to the texture size (See msdn doc). You should better identify for each texture 1D/2D/3D if you have an error while uploading a texture, and provide the texture description you are using in your test case.
I don't understand your last question about Texture1D and initialization.
If you find any error (like the constructor of Texture1D), it is recommended to report directly to SharpDX issues page.

This topic is closed to new replies.

Advertisement