sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.69k stars 638 forks source link

Texture2D1 in UWP #834

Closed jarmohh closed 7 years ago

jarmohh commented 7 years ago

I am creating template UWP project to windows. I an porting default C++ template to C# to create xbox (and other) C# UWP projects. Some issues left. So I create Texture2DDescription1 and next is Texture2D1. There is only one constructor with native pointer. Question is how to create Texture2D1.

C++ code CD3D11_TEXTURE2D_DESC1 depthStencilDesc(DXGI_FORMAT_D24_UNORM_S8_UINT, lround(m_d3dRenderTargetSize.Width), lround(m_d3dRenderTargetSize.Height), 1, 1, D3D11_BIND_DEPTH_STENCIL);

ComPtr<ID3D11Texture2D1> depthStencil;
DX::ThrowIfFailed(m_d3dDevice->CreateTexture2D1(&depthStencilDesc, nullptr, &depthStencil));

C# code Texture2DDescription1 depthStencilDesc = new Texture2DDescription1(); depthStencilDesc.Format = Format.D24_UNorm_S8_UInt; depthStencilDesc.Width = (int)_d3dRenderTargetSize.Width; depthStencilDesc.Height = (int)_d3dRenderTargetSize.Height; depthStencilDesc.ArraySize = 0; depthStencilDesc.MipLevels = 1; depthStencilDesc.BindFlags = BindFlags.DepthStencil;

//THIS DOES NOT WORK SharpDX.Direct3D11.Texture2D1 depthStencil = new Texture2D1(_d3dDevice.NativePointer);

How to create Texture2D1 with Texture2DDescription1 ?

xoofx commented 7 years ago

You should use the constructor public Texture2D1(Device3 device, Texture2DDescription1 description)

Gavin-Williams commented 7 years ago

Here's my depth stencil code ..

        depthStencilTexture = new Texture2D(Dx11Graphics.Device3d, new Texture2DDescription()
        {
            Format = Format.D16_UNorm,
            ArraySize = 1,
            MipLevels = 1,
            Width = width,
            Height = height,
            SampleDescription = new SampleDescription(1, 0),
            Usage = ResourceUsage.Default,
            BindFlags = BindFlags.DepthStencil,
            CpuAccessFlags = CpuAccessFlags.None,
            OptionFlags = ResourceOptionFlags.None
        });
        {
            depthStencilView = new DepthStencilView(Dx11Graphics.Device3d, depthStencilTexture);
        }

.. xoofx just answered. But I would add that I almost never use NativePointers for day to day SharpDX code. Always go for the 'managed style' option, SharpDX is 100% (or near to) written for typical C# code style.

jarmohh commented 7 years ago

Thanks I must try this. Hope that do what I want. depthStencilView = new DepthStencilView(Dx11Graphics.Device3d, depthStencilTexture);

This does not exist in latest UWP public Texture2D1(Device3 device, Texture2DDescription1 description) It exist in Texture2D but not in Texture2D1. That is why I ask :) Only one constructor and only one parameter.

jarmohh commented 7 years ago

Latest UWP nuget paket v3.1.1. Picture of error in VS2015.

https://onedrive.live.com/?cid=FD8073F3502D075D&id=FD8073F3502D075D%21154810&parId=FD8073F3502D075D%21154811&o=OneUp

xoofx commented 7 years ago

ah yes, it was maybe added after. You can grab dll directly from latest artifacts

jarmohh commented 7 years ago

I have other same kind of problems. Look pictures. SharpDX.Direct2D1.Factory3 and SharpDX.DirectWrite.Factory3 has only one constuctor with nativepointer. One of the nuget was old, when I update that it resolve first problem :), but not those.

https://onedrive.live.com/?cid=FD8073F3502D075D&id=FD8073F3502D075D%21155008&parId=FD8073F3502D075D%21155006&o=OneUp

https://onedrive.live.com/?cid=FD8073F3502D075D&id=FD8073F3502D075D%21155007&parId=FD8073F3502D075D%21155006&o=OneUp

jarmohh commented 7 years ago

I take latest artifacts, still those two has only one constructor with nativepointer parameter.