本文整理汇总了C#中SharpDX.Direct3D11.DepthStencilView类的典型用法代码示例。如果您正苦于以下问题:C# DepthStencilView类的具体用法?C# DepthStencilView怎么用?C# DepthStencilView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DepthStencilView类属于SharpDX.Direct3D11命名空间,在下文中一共展示了DepthStencilView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PlatformConstruct
private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap,
SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
{
// Setup the multisampling description.
var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0);
if (preferredMultiSampleCount > 1)
{
multisampleDesc.Count = preferredMultiSampleCount;
multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern;
}
// Create a descriptor for the depth/stencil buffer.
// Allocate a 2-D surface as the depth/stencil buffer.
// Create a DepthStencil view on this surface to use on bind.
using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription
{
Format = SharpDXHelper.ToFormat(preferredDepthFormat),
ArraySize = 1,
MipLevels = 1,
Width = width,
Height = height,
SampleDescription = multisampleDesc,
BindFlags = BindFlags.DepthStencil,
}))
{
// Create the view for binding to the device.
_depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription()
{
Format = SharpDXHelper.ToFormat(preferredDepthFormat),
Dimension = DepthStencilViewDimension.Texture2D
});
}
}
示例2: DepthBuffer
public DepthBuffer(Dx11ChainedDevice device, int width, int height)
{
try
{
_device = device;
_depthBuffer = new Texture2D(_device.Device, new Texture2DDescription
{
Format = Format.D32_Float_S8X24_UInt,
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
});
_depthView = new DepthStencilView(device.Device, _depthBuffer);
}
catch
{
Dispose();
throw;
}
}
示例3: DepthStencilSurface
/// <summary>
///
/// </summary>
/// <param name="dsv"></param>
internal DepthStencilSurface ( DepthStencilView dsv, DepthFormat format, int width, int height, int sampleCount )
{
Width = width;
Height = height;
Format = format;
SampleCount = sampleCount;
DSV = dsv;
}
示例4: RenderTexture
public RenderTexture(Device device, Vector2I size)
{
var textureDesc = new Texture2DDescription
{
Width = size.X,
Height = size.Y,
MipLevels = 1,
ArraySize = 1,
Format = Format.R32G32B32A32_Float,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
};
_renderTargetTexture = new Texture2D(device, textureDesc);
_renderTargetView = new RenderTargetView(device, _renderTargetTexture,
new RenderTargetViewDescription
{
Format = textureDesc.Format,
Dimension = RenderTargetViewDimension.Texture2D,
Texture2D = { MipSlice = 0 },
});
// Create the render target view.
ShaderResourceView = new ShaderResourceView(device, _renderTargetTexture,
new ShaderResourceViewDescription
{
Format = textureDesc.Format,
Dimension = ShaderResourceViewDimension.Texture2D,
Texture2D = { MipLevels = 1, MostDetailedMip = 0 },
});
_depthStencilView = new DepthStencilView(device, new Texture2D(device, new Texture2DDescription
{
Width = size.X,
Height = size.Y,
MipLevels = 1,
ArraySize = 1,
Format = Format.D24_UNorm_S8_UInt,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
}), new DepthStencilViewDescription
{
Format = Format.D24_UNorm_S8_UInt,
Dimension = DepthStencilViewDimension.Texture2D,
Texture2D = new DepthStencilViewDescription.Texture2DResource { MipSlice = 0 }
});
}
示例5: ClearRenderTarget
public void ClearRenderTarget(DeviceContext context, DepthStencilView depthStencilView, float red, float green, float blue, float alpha)
{
// Setup the color the buffer to.
var color = new Color4(red, green, blue, alpha);
// Clear the back buffer.
context.ClearRenderTargetView(RenderTargetView, color);
// Clear the depth buffer.
context.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);
}
示例6: ShadowMap
public ShadowMap(Device device, int width, int height) {
_width = width;
_height = height;
_viewport = new Viewport(0, 0, _width, _height, 0, 1.0f);
var texDesc = new Texture2DDescription {
Width = _width,
Height = _height,
MipLevels = 1,
ArraySize = 1,
Format = Format.R24G8_Typeless,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
};
var depthMap = new Texture2D(device, texDesc) {
DebugName = "shadowmap depthmap"
};
var dsvDesc = new DepthStencilViewDescription {
Flags = DepthStencilViewFlags.None,
Format = Format.D24_UNorm_S8_UInt,
Dimension = DepthStencilViewDimension.Texture2D,
Texture2D = new DepthStencilViewDescription.Texture2DResource() {
MipSlice = 0
}
};
_depthMapDSV = new DepthStencilView(device, depthMap, dsvDesc);
var srvDesc = new ShaderResourceViewDescription {
Format = Format.R24_UNorm_X8_Typeless,
Dimension = ShaderResourceViewDimension.Texture2D,
Texture2D = new ShaderResourceViewDescription.Texture2DResource() {
MipLevels = texDesc.MipLevels,
MostDetailedMip = 0
}
};
DepthMapSRV = new ShaderResourceView(device, depthMap, srvDesc);
Utilities.Dispose(ref depthMap);
}
示例7: RenderTarget3D
public RenderTarget3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
:base (graphicsDevice, width, height, depth, mipMap, preferredFormat, true)
{
DepthStencilFormat = preferredDepthFormat;
MultiSampleCount = preferredMultiSampleCount;
RenderTargetUsage = usage;
// If we don't need a depth buffer then we're done.
if (preferredDepthFormat == DepthFormat.None)
return;
#if DIRECTX
// Setup the multisampling description.
var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0);
if ( preferredMultiSampleCount > 1 )
{
multisampleDesc.Count = preferredMultiSampleCount;
multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern;
}
// Create a descriptor for the depth/stencil buffer.
// Allocate a 2-D surface as the depth/stencil buffer.
// Create a DepthStencil view on this surface to use on bind.
using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription
{
Format = SharpDXHelper.ToFormat(preferredDepthFormat),
ArraySize = 1,
MipLevels = 1,
Width = width,
Height = height,
SampleDescription = multisampleDesc,
BindFlags = BindFlags.DepthStencil,
}))
{
// Create the view for binding to the device.
_depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription()
{
Format = SharpDXHelper.ToFormat(preferredDepthFormat),
Dimension = DepthStencilViewDimension.Texture2D
});
}
#endif // DIRECTX
}
示例8: OnLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (DesignMode)
return;
// create swap chain, rendertarget
var swapChainDesc = new SwapChainDescription()
{
BufferCount = 1,
Usage = Usage.RenderTargetOutput,
OutputHandle = videoPanel1.Handle,
IsWindowed = true,
ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
Flags = SwapChainFlags.AllowModeSwitch,
SwapEffect = SwapEffect.Discard,
SampleDescription = new SampleDescription(1, 0),
};
swapChain = new SwapChain(factory, device, swapChainDesc);
// render target
renderTarget = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
renderTargetView = new RenderTargetView(device, renderTarget);
// depth buffer
var depthBufferDesc = new Texture2DDescription()
{
Width = videoPanel1.Width,
Height = videoPanel1.Height,
MipLevels = 1,
ArraySize = 1,
Format = Format.D32_Float, // necessary?
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None
};
depthStencil = new Texture2D(device, depthBufferDesc);
depthStencilView = new DepthStencilView(device, depthStencil);
// viewport
viewport = new Viewport(0, 0, videoPanel1.Width, videoPanel1.Height, 0f, 1f);
}
示例9: DXImageSource
public DXImageSource(GraphicsDevice graphics, int width, int height)
{
if (width < 10) width = 10;
if (height < 10) height = 10;
_renderTarget = RenderTarget2D.New(graphics, width, height, SharpDX.Toolkit.Graphics.PixelFormat.B8G8R8A8.UNorm);
_renderTargetView = new RenderTargetView(graphics, (SharpDX.Toolkit.Graphics.GraphicsResource)_renderTarget);
SharpDX.Direct3D11.Texture2D depthBuffer = new SharpDX.Direct3D11.Texture2D(graphics, new Texture2DDescription()
{
Format = SharpDX.DXGI.Format.D24_UNorm_S8_UInt,
ArraySize=1,
MipLevels=0,
Width = width,
Height = height,
SampleDescription = new SharpDX.DXGI.SampleDescription(1,0),
BindFlags = SharpDX.Direct3D11.BindFlags.DepthStencil
});
//_depthStencilBuffer = DepthStencilBuffer.New(graphics,width,height,DepthFormat.Depth24Stencil8);
_depthStencilView = new DepthStencilView(graphics, depthBuffer);
Texture2DDescription description = new Texture2DDescription()
{
Width = width,
Height = height,
MipLevels = 1,
ArraySize = 1,
Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
BindFlags = BindFlags.None,
CpuAccessFlags = CpuAccessFlags.Read,
SampleDescription = new SharpDX.DXGI.SampleDescription()
{
Count = 1,
Quality = 0
},
Usage = ResourceUsage.Staging,
OptionFlags = ResourceOptionFlags.None
};
_stagingTexture = SharpDX.Toolkit.Graphics.Texture2D.New(graphics, description);
_buffer = new byte[width * height * 4];
_writeableBitmap = new WriteableBitmap(
width, height, 96, 96, PixelFormats.Bgr32, null);
}
示例10: OnSurfaceInvalidated
protected override void OnSurfaceInvalidated(object sender, EventArgs e) {
var swapChain = D3DApp11.I.SwapChain;
var clientSize = D3DApp11.I.ControlWindow.ClientSize;
var device = D3DApp11.I.D3DDevice;
var immediateContext = D3DApp11.I.ImmediateContext;
// Dispose all previous allocated resources
Utilities.Dispose(ref _backBuffer);
Utilities.Dispose(ref _renderView);
Utilities.Dispose(ref _depthBuffer);
Utilities.Dispose(ref _depthView);
// Resize the backbuffer
swapChain.ResizeBuffers(_swapChainDescription.BufferCount, clientSize.Width, clientSize.Height, Format.Unknown, SwapChainFlags.None);
// Get the backbuffer from the swapchain
_backBuffer = Resource.FromSwapChain<Texture2D>(swapChain, 0);
// Renderview on the backbuffer
_renderView = new RenderTargetView(device, _backBuffer);
// Create the depth buffer
_depthBuffer = new Texture2D(device, new Texture2DDescription() {
Format = Format.D32_Float_S8X24_UInt,
ArraySize = 1,
MipLevels = 1,
Width = clientSize.Width,
Height = clientSize.Height,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
// Create the depth buffer view
_depthView = new DepthStencilView(device, _depthBuffer);
// Setup targets and viewport for rendering
_viewport = new Viewport(0, 0, clientSize.Width, clientSize.Height, 0.0f, 1.0f);
immediateContext.Rasterizer.SetViewport(_viewport);
immediateContext.OutputMerger.SetTargets(_depthView, _renderView);
base.OnSurfaceInvalidated(sender, e);
}
示例11: SharpCubeTarget
/// <summary>
/// Constructor
/// </summary>
/// <param name="device">Device</param>
/// <param name="size">Cube Size</param>
/// <param name="format">Color Format</param>
public SharpCubeTarget(SharpDevice device, int size, Format format)
{
Device = device;
Size = size;
Texture2D target = new Texture2D(device.Device, new Texture2DDescription()
{
Format = format,
Width = size,
Height = size,
ArraySize = 6,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.TextureCube,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
});
_target = new RenderTargetView(device.Device, target);
_resource = new ShaderResourceView(device.Device, target);
ComObject.Dispose(ref target);
var _zbufferTexture = new Texture2D(Device.Device, new Texture2DDescription()
{
Format = Format.D16_UNorm,
ArraySize = 6,
MipLevels = 1,
Width = size,
Height = size,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.TextureCube
});
// Create the depth buffer view
_zbuffer = new DepthStencilView(Device.Device, _zbufferTexture);
ComObject.Dispose(ref _zbufferTexture);
}
示例12: GenerateIfRequired
private void GenerateIfRequired()
{
if (_renderTargetView != null)
return;
// Create a view interface on the rendertarget to use on bind.
_renderTargetView = new RenderTargetView(GraphicsDevice._d3dDevice, GetTexture());
// If we don't need a depth buffer then we're done.
if (DepthStencilFormat == DepthFormat.None)
return;
// Setup the multisampling description.
var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0);
if (MultiSampleCount > 1)
{
multisampleDesc.Count = MultiSampleCount;
multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern;
}
// Create a descriptor for the depth/stencil buffer.
// Allocate a 2-D surface as the depth/stencil buffer.
// Create a DepthStencil view on this surface to use on bind.
using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, new Texture2DDescription
{
Format = SharpDXHelper.ToFormat(DepthStencilFormat),
ArraySize = 1,
MipLevels = 1,
Width = width,
Height = height,
SampleDescription = multisampleDesc,
BindFlags = BindFlags.DepthStencil,
}))
{
// Create the view for binding to the device.
_depthStencilView = new DepthStencilView(GraphicsDevice._d3dDevice, depthBuffer,
new DepthStencilViewDescription()
{
Format = SharpDXHelper.ToFormat(DepthStencilFormat),
Dimension = DepthStencilViewDimension.Texture2D
});
}
}
示例13: SharpRenderTarget
/// <summary>
/// Constructor
/// </summary>
/// <param name="device">Device</param>
/// <param name="width">Width</param>
/// <param name="height">Height</param>
/// <param name="format">Format</param>
public SharpRenderTarget(SharpDevice device, int width, int height, Format format)
{
Device = device;
Height = height;
Width = width;
Texture2D target = new Texture2D(device.Device, new Texture2DDescription()
{
Format = format,
Width = width,
Height = height,
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
});
_target = new RenderTargetView(device.Device, target);
_resource = new ShaderResourceView(device.Device, target);
target.Dispose();
var _zbufferTexture = new Texture2D(Device.Device, 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
});
// Create the depth buffer view
_zbuffer = new DepthStencilView(Device.Device, _zbufferTexture);
_zbufferTexture.Dispose();
}
示例14: Dispose
/// <summary>
/// Dispose contained fields.
/// </summary>
public void Dispose()
{
if (SwapTextureSet != null)
{
SwapTextureSet.Dispose();
SwapTextureSet = null;
}
if (Textures != null)
{
foreach (Texture2D texture in Textures)
texture.Dispose();
Textures = null;
}
if (RenderTargetViews != null)
{
foreach (RenderTargetView renderTargetView in RenderTargetViews)
renderTargetView.Dispose();
RenderTargetViews = null;
}
if (DepthBuffer != null)
{
DepthBuffer.Dispose();
DepthBuffer = null;
}
if (DepthStencilView != null)
{
DepthStencilView.Dispose();
DepthStencilView = null;
}
}
示例15: Resize
// ReSharper disable once FunctionComplexityOverflow
public void Resize(int width, int height, bool bgra)
{
if (Texture != null)
Texture.Dispose();
if (Native != null)
Native.Dispose();
var texDesc = new Texture2DDescription
{
ArraySize = 1,
BindFlags = BindFlags.RenderTarget,
CpuAccessFlags = CpuAccessFlags.None,
Format = bgra ? SharpDX.DXGI.Format.B8G8R8A8_UNorm : SharpDX.DXGI.Format.R8G8B8A8_UNorm,
Height = height,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = mContext.Multisampling,
Usage = ResourceUsage.Default,
Width = width
};
Texture = new Texture2D(mContext.Device, texDesc);
var rtvd = new RenderTargetViewDescription
{
Dimension = RenderTargetViewDimension.Texture2DMultisampled,
Format = texDesc.Format,
Texture2DMS = new RenderTargetViewDescription.Texture2DMultisampledResource()
};
Native = new RenderTargetView(mContext.Device, Texture, rtvd);
if (mDepthTexture != null)
mDepthTexture.Dispose();
if (mDepthView != null)
mDepthView.Dispose();
texDesc = new Texture2DDescription
{
ArraySize = 1,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
Format = SharpDX.DXGI.Format.D24_UNorm_S8_UInt,
Height = height,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = mContext.Multisampling,
Usage = ResourceUsage.Default,
Width = width
};
mDepthTexture = new Texture2D(mContext.Device, texDesc);
var dsvd = new DepthStencilViewDescription
{
Dimension = DepthStencilViewDimension.Texture2DMultisampled,
Flags = DepthStencilViewFlags.None,
Format = SharpDX.DXGI.Format.D24_UNorm_S8_UInt,
Texture2DMS = new DepthStencilViewDescription.Texture2DMultisampledResource()
};
mDepthView = new DepthStencilView(mContext.Device, mDepthTexture, dsvd);
}