本文整理汇总了C#中SharpDX.Direct3D11.Texture2D.QueryInterfaceOrNull方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.QueryInterfaceOrNull方法的具体用法?C# Texture2D.QueryInterfaceOrNull怎么用?C# Texture2D.QueryInterfaceOrNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpDX.Direct3D11.Texture2D
的用法示例。
在下文中一共展示了Texture2D.QueryInterfaceOrNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnsureResources
void EnsureResources(SharpDX.Direct3D11.Device device, Texture2DDescription description, Rectangle captureRegion, ScreenshotRequest request)
{
if (_device != null && request.Resize != null && (_resizedRT == null || (_resizedRT.Device.NativePointer != _device.NativePointer || _resizedRT.Description.Width != request.Resize.Value.Width || _resizedRT.Description.Height != request.Resize.Value.Height)))
{
// Create/Recreate resources for resizing
RemoveAndDispose(ref _resizedRT);
RemoveAndDispose(ref _resizedRTV);
RemoveAndDispose(ref _saQuad);
_resizedRT = ToDispose(new Texture2D(_device, new Texture2DDescription() {
Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm, // Supports BMP/PNG/etc
Height = request.Resize.Value.Height,
Width = request.Resize.Value.Width,
ArraySize = 1,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
BindFlags = BindFlags.RenderTarget,
MipLevels = 1,
Usage = ResourceUsage.Default,
OptionFlags = ResourceOptionFlags.None
}));
_resizedRTV = ToDispose(new RenderTargetView(_device, _resizedRT));
_saQuad = ToDispose(new DX11.ScreenAlignedQuadRenderer());
_saQuad.Initialize(new DX11.DeviceManager(_device));
}
// Check if _resolvedRT or _finalRT require creation
if (_finalRT != null && _finalRT.Device.NativePointer == _device.NativePointer &&
_finalRT.Description.Height == captureRegion.Height && _finalRT.Description.Width == captureRegion.Width &&
_resolvedRT != null && _resolvedRT.Description.Height == description.Height && _resolvedRT.Description.Width == description.Width &&
_resolvedRT.Device.NativePointer == device.NativePointer && _resolvedRT.Description.Format == description.Format
)
{
return;
}
RemoveAndDispose(ref _query);
RemoveAndDispose(ref _resolvedRT);
RemoveAndDispose(ref _resolvedSharedSRV);
RemoveAndDispose(ref _finalRT);
RemoveAndDispose(ref _resolvedRTShared);
_query = new Query(_device, new QueryDescription()
{
Flags = QueryFlags.None,
Type = QueryType.Event
});
_queryIssued = false;
_resolvedRT = ToDispose(new Texture2D(device, new Texture2DDescription() {
CpuAccessFlags = CpuAccessFlags.None,
Format = description.Format, // for multisampled backbuffer, this must be same format
Height = description.Height,
Usage = ResourceUsage.Default,
Width = description.Width,
ArraySize = 1,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), // Ensure single sample
BindFlags = BindFlags.ShaderResource,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.SharedKeyedmutex
}));
// Retrieve reference to the keyed mutex
_resolvedRTKeyedMutex = ToDispose(_resolvedRT.QueryInterfaceOrNull<SharpDX.DXGI.KeyedMutex>());
using (var resource = _resolvedRT.QueryInterface<SharpDX.DXGI.Resource>())
{
_resolvedRTShared = ToDispose(_device.OpenSharedResource<Texture2D>(resource.SharedHandle));
_resolvedRTKeyedMutex_Dev2 = ToDispose(_resolvedRTShared.QueryInterfaceOrNull<SharpDX.DXGI.KeyedMutex>());
}
// SRV for use if resizing
_resolvedSharedSRV = ToDispose(new ShaderResourceView(_device, _resolvedRTShared));
_finalRT = ToDispose(new Texture2D(_device, new Texture2DDescription()
{
CpuAccessFlags = CpuAccessFlags.Read,
Format = description.Format,
Height = captureRegion.Height,
Usage = ResourceUsage.Staging,
Width = captureRegion.Width,
ArraySize = 1,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
BindFlags = BindFlags.None,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None
}));
_finalRTMapped = false;
}