SharpDX:从一组图像创建TextureCube

时间:2015-04-19 13:24:55

标签: direct3d sharpdx direct3d11

所以我有6个单独的图像,我想用它们构建一个textureCube。什么是最好的方法呢?现在这就是我所拥有的,但是当TextureCube尝试创建自己时,我得到了内存访问冲突。

SharpDX.DataBox[] textureData = new SharpDX.DataBox[6];
for(int i = 0; i < 6; i++)
{
    Texture2D tex = Texture2D.Load(device, resources[i].Filepath);
    SharpDX.Direct3D11.Texture2D staged = (SharpDX.Direct3D11.Texture2D)tex.ToStaging();
    textureData[i] = new SharpDX.DataBox(staged.NativePointer, staged.Description.Width, 0);
}

SharpDX.Toolkit.Graphics.TextureCube cube = SharpDX.Toolkit.Graphics.TextureCube.New(
            device,
            2048,
            PixelFormat.R8G8B8A8.UNorm,
            textureData);

纹理负载工作正常。我可以加载纹理,然后从单个图像创建一个textureCube没问题。但这并没有多大用处。当我尝试使用来自我的6个单独图像的原始数据创建一个立方体时,我得到了内存异常。

Result Message: 
Test method ResourceLoadingTests.LoadCubemapAndSave threw exception: 
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Result StackTrace:  
at SharpDX.Direct3D11.Device.CreateTexture2D(Texture2DDescription& descRef, DataBox[] initialDataRef, Texture2D texture2DOut)
at SharpDX.Direct3D11.Texture2D..ctor(Device device, Texture2DDescription description, DataBox[] data)
at SharpDX.Toolkit.Graphics.Texture2DBase..ctor(GraphicsDevice device, Texture2DDescription description2D, DataBox[] dataBoxes)
at SharpDX.Toolkit.Graphics.TextureCube..ctor(GraphicsDevice device, Texture2DDescription description2D, DataBox[] dataBoxes)
at SharpDX.Toolkit.Graphics.TextureCube.New(GraphicsDevice device, Int32 size, PixelFormat format, DataBox[] textureData, TextureFlags flags, ResourceUsage usage)

0 个答案:

没有答案