本文整理汇总了C#中Texture2D.QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.QueryInterface方法的具体用法?C# Texture2D.QueryInterface怎么用?C# Texture2D.QueryInterface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture2D
的用法示例。
在下文中一共展示了Texture2D.QueryInterface方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: D3D11Image
/// <summary>
/// Initializes a new instance of the <see cref="D3D11Image"/> class. Associates an D3D11 render target with the current instance.
/// </summary>
/// <param name="device">A valid D3D9 DeviceEx.</param>
/// <param name="renderTarget">A valid D3D11 render target. It must be created with the "Shared" flag.</param>
public D3D11Image(DeviceEx device, Texture2D renderTarget)
{
using (var resource = renderTarget.QueryInterface<DXGIResource>())
{
var handle = resource.SharedHandle;
this.texture = new Texture(
device,
renderTarget.Description.Width,
renderTarget.Description.Height,
1,
Usage.RenderTarget,
Format.A8R8G8B8,
Pool.Default,
ref handle);
}
using (var surface = this.texture.GetSurfaceLevel(0))
{
this.textureSurfaceHandle = surface.NativePointer;
this.TrySetBackbufferPointer(this.textureSurfaceHandle);
}
this.IsFrontBufferAvailableChanged += this.HandleIsFrontBufferAvailableChanged;
}
示例2: GetSharedHandle
private static IntPtr GetSharedHandle(Texture2D sharedTexture)
{
using (var resource = sharedTexture.QueryInterface<global::SharpDX.DXGI.Resource>())
{
IntPtr result = resource.SharedHandle;
return result;
}
}
示例3: InitRendering
/// <summary>
/// Initializes DirectX rendering resources.
/// </summary>
private void InitRendering()
{
double dpiScale = 1.0; // default value for 96 dpi
var hwndTarget = PresentationSource.FromVisual(this).CompositionTarget as HwndTarget;
if (hwndTarget != null)
{
dpiScale = hwndTarget.TransformToDevice.M11;
}
int surfWidth = (int)(this.viewport.Width < 0 ? 0 : Math.Ceiling(this.viewport.Width * dpiScale));
int surfHeight = (int)(this.viewport.Height < 0 ? 0 : Math.Ceiling(this.viewport.Height * dpiScale));
var windowHandle = (new System.Windows.Interop.WindowInteropHelper(System.Windows.Window.GetWindow(this))).Handle;
this.d3d11Device = new D3D11Device(
DriverType.Hardware,
DeviceCreationFlags.BgraSupport,
FeatureLevel.Level_11_0,
FeatureLevel.Level_10_1,
FeatureLevel.Level_10_0,
FeatureLevel.Level_9_3,
FeatureLevel.Level_9_2,
FeatureLevel.Level_9_1);
var backBuffer = new Texture2D(
this.d3d11Device,
new Texture2DDescription
{
Height = surfHeight,
Width = surfWidth,
ArraySize = 1,
MipLevels = 1,
Format = Format.B8G8R8A8_UNorm,
SampleDescription = { Count = 1, Quality = 0 },
Usage = ResourceUsage.Default,
OptionFlags = ResourceOptionFlags.Shared,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = 0
});
var surface = backBuffer.QueryInterface<Surface>();
this.renderTarget = new RenderTarget(
this.oxyRenderContext.D2DFactory,
surface,
new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
this.d3d9Device = new D3D9Device(
new Direct3D(),
0,
D3D9DeviceType.Hardware,
windowHandle,
D3D9CreateFlags.HardwareVertexProcessing | D3D9CreateFlags.Multithreaded | D3D9CreateFlags.FpuPreserve,
new D3D9PresentParameters(surfWidth, surfHeight)
{
PresentationInterval = D3D9PresentInterval.Immediate,
DeviceWindowHandle = windowHandle,
SwapEffect = D3D9SwapEffect.Discard,
Windowed = true
});
this.imageSource = new D3D11Image(this.d3d9Device, backBuffer);
this.oxyRenderContext.ResetRenderTarget(this.renderTarget);
}