本文整理汇总了C#中SharpDX.Direct3D11.Texture2D.QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.QueryInterface方法的具体用法?C# Texture2D.QueryInterface怎么用?C# Texture2D.QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpDX.Direct3D11.Texture2D
的用法示例。
在下文中一共展示了Texture2D.QueryInterface方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SharpDXDevice
public SharpDXDevice(Window window)
{
this.window = window;
width = (int)window.ViewportSize.Width;
height = (int)window.ViewportSize.Height;
DxDevice.CreateWithSwapChain(DriverType.Hardware,
#if DEBUG
DeviceCreationFlags.Debug |
#endif
DeviceCreationFlags.BgraSupport,
CreateSwapChainDescription(), out device, out swapChain);
direct2DFactory = new D2dFactory();
backBuffer = Resource.FromSwapChain<Texture2D>(swapChain, 0);
surface = backBuffer.QueryInterface<Surface>();
RenderTarget = new RenderTarget(direct2DFactory, surface, defaultRenderTargetProperties);
window.ViewportSizeChanged += ResetDeviceToNewViewportSize;
Screen = new ScreenSpace(window.ViewportSize);
}
示例2: createSwapChain
private void createSwapChain()
{
lock (deviceManager.DeviceLock)
{
var factory = new DXGI.Factory();
var description = new DXGI.SwapChainDescription()
{
BufferCount = 1,
ModeDescription =
new DXGI.ModeDescription(
control.ClientSize.Width,
control.ClientSize.Height,
new DXGI.Rational(60, 1),
DXGI.Format.R8G8B8A8_UNorm),
IsWindowed = true,
SampleDescription = new DXGI.SampleDescription(1, 0),
SwapEffect = DXGI.SwapEffect.Discard,
Usage = DXGI.Usage.RenderTargetOutput,
OutputHandle = control.Handle
};
swapChain = new DXGI.SwapChain(factory, deviceContext.Device, description);
backbuffer = D3D11.Texture2D.FromSwapChain<D3D11.Texture2D>(swapChain, 0);
backbufferView = new D3D11.RenderTargetView(deviceContext.Device, backbuffer);
}
var d2dFactory = deviceManager.Direct2dFactory;
var surface = backbuffer.QueryInterface<DXGI.Surface>();
renderTarget = new D2D.RenderTarget(
d2dFactory,
surface,
new D2D.RenderTargetProperties(
new D2D.PixelFormat(
DXGI.Format.Unknown,
D2D.AlphaMode.Premultiplied)));
renderTarget.AntialiasMode = D2D.AntialiasMode.Aliased;
createViewport();
}
示例3: CreateAndBindTargets
private void CreateAndBindTargets() {
d3DSurface.SetRenderTarget( null );
Disposer.SafeDispose( ref d2DRenderTarget );
Disposer.SafeDispose( ref d2DFactory );
Disposer.SafeDispose( ref renderTarget );
var width = Math.Max((int)ActualWidth , 100);
var height = Math.Max((int)ActualHeight, 100);
var renderDesc = new Texture2DDescription {
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
Format = Format.B8G8R8A8_UNorm,
Width = width,
Height = height,
MipLevels = 1,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
OptionFlags = ResourceOptionFlags.Shared,
CpuAccessFlags = CpuAccessFlags.None,
ArraySize = 1
};
renderTarget = new Texture2D( device, renderDesc );
var surface = renderTarget.QueryInterface<Surface>();
d2DFactory = new SharpDX.Direct2D1.Factory();
var rtp = new RenderTargetProperties(new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied));
d2DRenderTarget = new RenderTarget( d2DFactory, surface, rtp );
resCache.RenderTarget = d2DRenderTarget;
d3DSurface.SetRenderTarget( renderTarget );
device.ImmediateContext.Rasterizer.SetViewport( 0, 0, width, height, 0.0f, 1.0f );
}
示例4: Run
public void Run()
{
var form = new RenderForm("2d and 3d combined...it's like magic");
form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) form.Close(); };
// DirectX DXGI 1.1 factory
var factory1 = new Factory1();
// The 1st graphics adapter
var adapter1 = factory1.GetAdapter1(0);
// ---------------------------------------------------------------------------------------------
// Setup direct 3d version 11. It's context will be used to combine the two elements
// ---------------------------------------------------------------------------------------------
var description = new SwapChainDescription
{
BufferCount = 1,
ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput,
Flags = SwapChainFlags.AllowModeSwitch
};
Device11 device11;
SwapChain swapChain;
Device11.CreateWithSwapChain(adapter1, DeviceCreationFlags.None, description, out device11, out swapChain);
// create a view of our render target, which is the backbuffer of the swap chain we just created
RenderTargetView renderTargetView;
using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
renderTargetView = new RenderTargetView(device11, resource);
// setting a viewport is required if you want to actually see anything
var context = device11.ImmediateContext;
var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
context.OutputMerger.SetTargets(renderTargetView);
context.Rasterizer.SetViewports(viewport);
//
// Create the DirectX11 texture2D. This texture will be shared with the DirectX10 device.
//
// The DirectX10 device will be used to render text onto this texture.
// DirectX11 will then draw this texture (blended) onto the screen.
// The KeyedMutex flag is required in order to share this resource between the two devices.
var textureD3D11 = new Texture2D(device11, new Texture2DDescription
{
Width = form.ClientSize.Width,
Height = form.ClientSize.Height,
MipLevels = 1,
ArraySize = 1,
Format = Format.B8G8R8A8_UNorm,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.SharedKeyedmutex
});
// ---------------------------------------------------------------------------------------------
// Setup a direct 3d version 10.1 adapter
// ---------------------------------------------------------------------------------------------
var device10 = new Device10(adapter1, SharpDX.Direct3D10.DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);
// ---------------------------------------------------------------------------------------------
// Setup Direct 2d
// ---------------------------------------------------------------------------------------------
// Direct2D Factory
var factory2D = new SharpDX.Direct2D1.Factory(FactoryType.SingleThreaded, DebugLevel.Information);
// Here we bind the texture we've created on our direct3d11 device through the direct3d10
// to the direct 2d render target....
var sharedResource = textureD3D11.QueryInterface<SharpDX.DXGI.Resource>();
var textureD3D10 = device10.OpenSharedResource<SharpDX.Direct3D10.Texture2D>(sharedResource.SharedHandle);
var surface = textureD3D10.AsSurface();
var rtp = new RenderTargetProperties
{
MinLevel = SharpDX.Direct2D1.FeatureLevel.Level_10,
Type = RenderTargetType.Hardware,
PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
};
var renderTarget2D = new RenderTarget(factory2D, surface, rtp);
var solidColorBrush = new SolidColorBrush(renderTarget2D, Colors.Red);
// ---------------------------------------------------------------------------------------------------
// Setup the rendering data
// ---------------------------------------------------------------------------------------------------
// Load Effect. This includes both the vertex and pixel shaders.
// Also can include more than one technique.
ShaderBytecode shaderByteCode = ShaderBytecode.CompileFromFile(
"effectDx11.fx",
//.........这里部分代码省略.........
示例5: ResetDeviceToNewViewportSize
private void ResetDeviceToNewViewportSize(Size newSizeInPixel)
{
backBuffer.Dispose();
surface.Dispose();
RenderTarget.Dispose();
width = (int)newSizeInPixel.Width;
height = (int)newSizeInPixel.Height;
swapChain.ResizeBuffers(BackBufferCount, width, height, BackBufferFormat, SwapChainFlags.None);
backBuffer = Resource.FromSwapChain<Texture2D>(swapChain, 0);
surface = backBuffer.QueryInterface<Surface>();
RenderTarget = new RenderTarget(direct2DFactory, surface, defaultRenderTargetProperties);
Screen = new ScreenSpace(newSizeInPixel);
}
示例6: 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;
}