mirror of
https://github.com/amerkoleci/Vortice.Win32.git
synced 2026-01-14 16:16:04 +08:00
Direct3D11: Add some helper methods.
This commit is contained in:
@@ -963,6 +963,11 @@ public static class Program
|
||||
|
||||
// D3D11
|
||||
{ "ID3D11DeviceContext::Map::MapFlags", "D3D11_MAP_FLAG" },
|
||||
{ "ID3D11DeviceContext::ClearDepthStencilView::ClearFlags", "D3D11_CLEAR_FLAG" },
|
||||
{ "ID3D11DeviceContext1::ClearDepthStencilView::ClearFlags", "D3D11_CLEAR_FLAG" },
|
||||
{ "ID3D11DeviceContext2::ClearDepthStencilView::ClearFlags", "D3D11_CLEAR_FLAG" },
|
||||
{ "ID3D11DeviceContext3::ClearDepthStencilView::ClearFlags", "D3D11_CLEAR_FLAG" },
|
||||
{ "ID3D11DeviceContext4::ClearDepthStencilView::ClearFlags", "D3D11_CLEAR_FLAG" },
|
||||
|
||||
// D3D12
|
||||
|
||||
|
||||
@@ -473,9 +473,9 @@ public unsafe partial struct ID3D11DeviceContext
|
||||
/// <include file='../../Direct3D11.xml' path='doc/member[@name="ID3D11DeviceContext::ClearDepthStencilView"]/*' />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(53)]
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, uint ClearFlags, float Depth, byte Stencil)
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, ClearFlags ClearFlags, float Depth, byte Stencil)
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext*, ID3D11DepthStencilView*, uint, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext*, ID3D11DepthStencilView*, ClearFlags, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
}
|
||||
|
||||
/// <include file='../../Direct3D11.xml' path='doc/member[@name="ID3D11DeviceContext::GenerateMips"]/*' />
|
||||
|
||||
@@ -473,9 +473,9 @@ public unsafe partial struct ID3D11DeviceContext1
|
||||
/// <inheritdoc cref="ID3D11DeviceContext.ClearDepthStencilView" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(53)]
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, uint ClearFlags, float Depth, byte Stencil)
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, ClearFlags ClearFlags, float Depth, byte Stencil)
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext1*, ID3D11DepthStencilView*, uint, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext1*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext1*, ID3D11DepthStencilView*, ClearFlags, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext1*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D11DeviceContext.GenerateMips" />
|
||||
|
||||
@@ -473,9 +473,9 @@ public unsafe partial struct ID3D11DeviceContext2
|
||||
/// <inheritdoc cref="ID3D11DeviceContext.ClearDepthStencilView" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(53)]
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, uint ClearFlags, float Depth, byte Stencil)
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, ClearFlags ClearFlags, float Depth, byte Stencil)
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext2*, ID3D11DepthStencilView*, uint, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext2*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext2*, ID3D11DepthStencilView*, ClearFlags, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext2*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D11DeviceContext.GenerateMips" />
|
||||
|
||||
@@ -473,9 +473,9 @@ public unsafe partial struct ID3D11DeviceContext3
|
||||
/// <inheritdoc cref="ID3D11DeviceContext.ClearDepthStencilView" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(53)]
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, uint ClearFlags, float Depth, byte Stencil)
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, ClearFlags ClearFlags, float Depth, byte Stencil)
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext3*, ID3D11DepthStencilView*, uint, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext3*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext3*, ID3D11DepthStencilView*, ClearFlags, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext3*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D11DeviceContext.GenerateMips" />
|
||||
|
||||
@@ -473,9 +473,9 @@ public unsafe partial struct ID3D11DeviceContext4
|
||||
/// <inheritdoc cref="ID3D11DeviceContext.ClearDepthStencilView" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(53)]
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, uint ClearFlags, float Depth, byte Stencil)
|
||||
public void ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView, ClearFlags ClearFlags, float Depth, byte Stencil)
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext4*, ID3D11DepthStencilView*, uint, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext4*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
((delegate* unmanaged[Stdcall]<ID3D11DeviceContext4*, ID3D11DepthStencilView*, ClearFlags, float, byte, void>)(lpVtbl[53]))((ID3D11DeviceContext4*)Unsafe.AsPointer(ref this), pDepthStencilView, ClearFlags, Depth, Stencil);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D11DeviceContext.GenerateMips" />
|
||||
|
||||
@@ -5,6 +5,13 @@ namespace Win32.Graphics.Direct3D11;
|
||||
|
||||
public unsafe partial struct ID3D11Device
|
||||
{
|
||||
public ComPtr<ID3D11Buffer> CreateBuffe(BufferDescription* description, SubresourceData* initialData = default)
|
||||
{
|
||||
using ComPtr<ID3D11Buffer> buffer = default;
|
||||
CreateBuffer(description, initialData, buffer.GetAddressOf()).ThrowIfFailed();
|
||||
return buffer.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11Buffer> CreateBuffer<T>(
|
||||
in T data,
|
||||
BufferDescription description) where T : unmanaged
|
||||
@@ -47,7 +54,6 @@ public unsafe partial struct ID3D11Device
|
||||
/// Creates a new instance of the <see cref="ID3D11Buffer"/> class.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the data to upload</typeparam>
|
||||
/// <param name="device">The <see cref="ID3D11Device"/> instance.</param>
|
||||
/// <param name="bindFlags">Flags specifying how the buffer will be bound to the pipeline.</param>
|
||||
/// <param name="data">Initial data used to initialize the buffer.</param>
|
||||
/// <param name="sizeInBytes">The size, in bytes, of the buffer. If 0 is specified, sizeof(T) * data.Length is used.</param>
|
||||
@@ -87,4 +93,156 @@ public unsafe partial struct ID3D11Device
|
||||
return buffer.Move();
|
||||
}
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11RenderTargetView> CreateRenderTargetView(
|
||||
ID3D11Resource* resource,
|
||||
RenderTargetViewDescription* description)
|
||||
{
|
||||
using ComPtr<ID3D11RenderTargetView> view = default;
|
||||
CreateRenderTargetView(resource, description, view.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return view.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11DepthStencilView> CreateDepthStencilView(
|
||||
ID3D11Resource* resource,
|
||||
DepthStencilViewDescription* description)
|
||||
{
|
||||
using ComPtr<ID3D11DepthStencilView> view = default;
|
||||
CreateDepthStencilView(resource, description, view.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return view.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11ShaderResourceView> CreateShaderResourceView(
|
||||
ID3D11Resource* resource,
|
||||
ShaderResourceViewDescription* description)
|
||||
{
|
||||
using ComPtr<ID3D11ShaderResourceView> view = default;
|
||||
CreateShaderResourceView(resource, description, view.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return view.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11UnorderedAccessView> CreateUnorderedAccessView(
|
||||
ID3D11Resource* resource,
|
||||
UnorderedAccessViewDescription* description)
|
||||
{
|
||||
using ComPtr<ID3D11UnorderedAccessView> view = default;
|
||||
CreateUnorderedAccessView(resource, description, view.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return view.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11BlendState> CreateBlendState(BlendDescription* description)
|
||||
{
|
||||
using ComPtr<ID3D11BlendState> state = default;
|
||||
CreateBlendState(description, state.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return state.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11BlendState> CreateBlendState(BlendDescription description)
|
||||
{
|
||||
using ComPtr<ID3D11BlendState> state = default;
|
||||
CreateBlendState(&description, state.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return state.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11DepthStencilState> CreateDepthStencilState(DepthStencilDescription* description)
|
||||
{
|
||||
using ComPtr<ID3D11DepthStencilState> state = default;
|
||||
CreateDepthStencilState(description, state.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return state.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11DepthStencilState> CreateDepthStencilState(DepthStencilDescription description)
|
||||
{
|
||||
using ComPtr<ID3D11DepthStencilState> state = default;
|
||||
CreateDepthStencilState(&description, state.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return state.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11RasterizerState> CreateRasterizerState(RasterizerDescription* description)
|
||||
{
|
||||
using ComPtr<ID3D11RasterizerState> state = default;
|
||||
CreateRasterizerState(description, state.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return state.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11RasterizerState> CreateRasterizerState(RasterizerDescription description)
|
||||
{
|
||||
using ComPtr<ID3D11RasterizerState> state = default;
|
||||
CreateRasterizerState(&description, state.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return state.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11SamplerState> CreateSamplerState(SamplerDescription* description)
|
||||
{
|
||||
using ComPtr<ID3D11SamplerState> state = default;
|
||||
CreateSamplerState(description, state.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return state.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11SamplerState> CreateSamplerState(SamplerDescription description)
|
||||
{
|
||||
using ComPtr<ID3D11SamplerState> state = default;
|
||||
CreateSamplerState(&description, state.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return state.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11Texture1D> CreateTexture1D(Texture1DDescription* description, SubresourceData* initialData = default)
|
||||
{
|
||||
using ComPtr<ID3D11Texture1D> texture = default;
|
||||
CreateTexture1D(description, initialData, texture.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return texture.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11Texture1D> CreateTexture1D(Texture1DDescription description, SubresourceData* initialData = default)
|
||||
{
|
||||
using ComPtr<ID3D11Texture1D> texture = default;
|
||||
CreateTexture1D(&description, initialData, texture.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return texture.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11Texture2D> CreateTexture2D(Texture2DDescription* description, SubresourceData* initialData = default)
|
||||
{
|
||||
using ComPtr<ID3D11Texture2D> texture = default;
|
||||
CreateTexture2D(description, initialData, texture.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return texture.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11Texture2D> CreateTexture2D(Texture2DDescription description, SubresourceData* initialData = default)
|
||||
{
|
||||
using ComPtr<ID3D11Texture2D> texture = default;
|
||||
CreateTexture2D(&description, initialData, texture.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return texture.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11Texture3D> CreateTexture3D(Texture3DDescription* description, SubresourceData* initialData = default)
|
||||
{
|
||||
using ComPtr<ID3D11Texture3D> texture = default;
|
||||
CreateTexture3D(description, initialData, texture.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return texture.Move();
|
||||
}
|
||||
|
||||
public ComPtr<ID3D11Texture3D> CreateTexture3D(Texture3DDescription description, SubresourceData* initialData = default)
|
||||
{
|
||||
using ComPtr<ID3D11Texture3D> texture = default;
|
||||
CreateTexture3D(&description, initialData, texture.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return texture.Move();
|
||||
}
|
||||
}
|
||||
|
||||
45
src/Vortice.Win32/Graphics/Direct3D11/ID3D11DeviceChild.cs
Normal file
45
src/Vortice.Win32/Graphics/Direct3D11/ID3D11DeviceChild.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright © Amer Koleci and Contributors.
|
||||
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
|
||||
|
||||
using static Win32.Graphics.Direct3D.Apis;
|
||||
using static Win32.StringUtilities;
|
||||
|
||||
namespace Win32.Graphics.Direct3D11;
|
||||
|
||||
public unsafe partial struct ID3D11DeviceChild
|
||||
{
|
||||
public static Guid* D3DDebugObjectNameGuid => (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in WKPDID_D3DDebugObjectName));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the debug-name for this object.
|
||||
/// </summary>
|
||||
public string? DebugName
|
||||
{
|
||||
get
|
||||
{
|
||||
sbyte* pname = stackalloc sbyte[1024];
|
||||
uint size = 1024 - 1;
|
||||
if (GetPrivateData(D3DDebugObjectNameGuid, &size, pname).Failure)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
pname[size] = 0;
|
||||
return GetString(pname);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
SetPrivateData(D3DDebugObjectNameGuid, 0, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
fixed (sbyte* valuePtr = value.GetUtf8Span())
|
||||
{
|
||||
SetPrivateData(D3DDebugObjectNameGuid, (uint)value.Length, valuePtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/Vortice.Win32/Graphics/Direct3D11/ID3D11DeviceContext.cs
Normal file
38
src/Vortice.Win32/Graphics/Direct3D11/ID3D11DeviceContext.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright © Amer Koleci and Contributors.
|
||||
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
|
||||
|
||||
namespace Win32.Graphics.Direct3D11;
|
||||
|
||||
public unsafe partial struct ID3D11DeviceContext
|
||||
{
|
||||
public void RSSetViewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f)
|
||||
{
|
||||
var viewport = new Viewport(x, y, width, height, minDepth, maxDepth);
|
||||
RSSetViewports(1, &viewport);
|
||||
}
|
||||
|
||||
public void RSSetViewport(Viewport viewport)
|
||||
{
|
||||
RSSetViewports(1, &viewport);
|
||||
}
|
||||
|
||||
public void RSSetScissorRect(int x, int y, int width, int height)
|
||||
{
|
||||
RawRect rawRect = new(x, y, x + width, y + height);
|
||||
RSSetScissorRects(1, &rawRect);
|
||||
}
|
||||
|
||||
public void RSSetScissorRect(RawRect rect)
|
||||
{
|
||||
RSSetScissorRects(1, &rect);
|
||||
}
|
||||
|
||||
|
||||
public ComPtr<ID3D11CommandList> FinishCommandList(bool RestoreDeferredContextState = false)
|
||||
{
|
||||
using ComPtr<ID3D11CommandList> commandList = default;
|
||||
FinishCommandList(RestoreDeferredContextState, commandList.GetAddressOf()).ThrowIfFailed();
|
||||
|
||||
return commandList.Move();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
|
||||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using static Win32.UnsafeUtilities;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
|
||||
<Description>Windows API low level bindings.</Description>
|
||||
<VersionPrefix>1.6.3</VersionPrefix>
|
||||
<VersionPrefix>1.6.4</VersionPrefix>
|
||||
<VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<EnablePreviewFeatures>True</EnablePreviewFeatures>
|
||||
|
||||
@@ -253,6 +253,7 @@ public static unsafe class Program
|
||||
Texture2DDescription texture2DDesc = new(Format.D32Float, 256, 256, 1, 1, BindFlags.DepthStencil);
|
||||
tempDevice.Get()->CreateTexture2D(&texture2DDesc, null, depthStencilTexture.GetAddressOf()).ThrowIfFailed();
|
||||
depthStencilTexture.Get()->GetDesc(&texture2DDesc);
|
||||
((ID3D11DeviceChild*)depthStencilTexture.Get())->DebugName = "CIAO";
|
||||
|
||||
tempDevice.Get()->CreateDepthStencilView((ID3D11Resource*)depthStencilTexture.Get(), null, depthStencilTextureView.GetAddressOf()).ThrowIfFailed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user