本文整理汇总了C#中RenderTargetView类的典型用法代码示例。如果您正苦于以下问题:C# RenderTargetView类的具体用法?C# RenderTargetView怎么用?C# RenderTargetView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RenderTargetView类属于命名空间,在下文中一共展示了RenderTargetView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
SwapChainDescription desc=new SwapChainDescription()
{
BufferCount = 2,
Flags = SwapChainFlags.AllowModeSwitch,
IsWindowed = true,
ModeDescription = new ModeDescription()
{
Format = Format.R8G8B8A8_UNorm,
Height = Height,
Width = Width,
RefreshRate = new Rational(1,60),
Scaling = DisplayModeScaling.Centered,
ScanlineOrdering = DisplayModeScanlineOrdering.Progressive
},
OutputHandle = Handle,
SampleDescription = new SampleDescription(1,0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None,
new FeatureLevel[1] {FeatureLevel.Level_11_0}, desc, out device, out swapChain);
using (Texture2D tex=Texture2D.FromSwapChain<Texture2D>(swapChain,0))
{
renderTarget=new RenderTargetView(device,tex);
}
}
示例2: InitializeD3D
public void InitializeD3D()
{
var description = new SwapChainDescription()
{
BufferCount = 2,
Usage = Usage.RenderTargetOutput,
OutputHandle = form.Handle,
IsWindowed = true,
ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
SampleDescription = new SampleDescription(1, 0),
Flags = SwapChainFlags.AllowModeSwitch,
SwapEffect = SwapEffect.Discard
};
//Create swap chain
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out this.device, out swapChain);
// create a view of our render target, which is the backbuffer of the swap chain we just created
// setting a viewport is required if you want to actually see anything
var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0);
renderTarget = new RenderTargetView(device, resource);
var context = device.ImmediateContext;
var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
context.OutputMerger.SetTargets(renderTarget);
context.Rasterizer.SetViewports(viewport);
}
示例3: InitDevice
/// <summary>
/// Create Direct3D device and swap chain
/// </summary>
protected void InitDevice()
{
device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain);
// Create a render target view
using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
{
renderTargetView = device.CreateRenderTargetView(pBuffer);
}
device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView });
// Setup the viewport
Viewport vp = new Viewport()
{
Width = (uint)directControl.ClientSize.Width,
Height = (uint)directControl.ClientSize.Height,
MinDepth = 0.0f,
MaxDepth = 1.0f,
TopLeftX = 0,
TopLeftY = 0
};
device.RS.SetViewports(new Viewport[] { vp });
}
示例4: D3DApp
protected D3DApp(IntPtr hInstance)
{
AppInst = hInstance;
MainWindowCaption = "D3D11 Application";
DriverType = DriverType.Hardware;
ClientWidth = 800;
ClientHeight = 600;
Enable4XMsaa = false;
Window = null;
AppPaused = false;
Minimized = false;
Maximized = false;
Resizing = false;
Msaa4XQuality = 0;
Device = null;
ImmediateContext = null;
SwapChain = null;
DepthStencilBuffer = null;
RenderTargetView = null;
DepthStencilView = null;
Viewport = new Viewport();
Timer = new GameTimer();
GD3DApp = this;
}
示例5: RenderTexture
/// <summary>
/// Constructor
/// Creates the texture we will render to based on the supplied width and height
/// </summary>
/// <param name="device">The device we will create the texture with</param>
/// <param name="texWidth"></param>
/// <param name="texHeight"></param>
public RenderTexture(Device device, int texWidth, int texHeight)
{
Texture2DDescription textureDescription = new Texture2DDescription()
{
Width = texWidth,
Height = texHeight,
MipLevels = 1,
ArraySize = 1,
Format = SlimDX.DXGI.Format.R32G32B32A32_Float,
SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0),
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default,
};
Texture = new Texture2D(device, textureDescription);
RenderTargetViewDescription renderTargetViewDescription = new RenderTargetViewDescription()
{
Format = textureDescription.Format,
Dimension = RenderTargetViewDimension.Texture2D,
MipSlice = 0,
};
renderTargetView = new RenderTargetView(device, Texture, renderTargetViewDescription);
ShaderResourceViewDescription shaderResourceViewDescription = new ShaderResourceViewDescription()
{
Format = textureDescription.Format,
Dimension = ShaderResourceViewDimension.Texture2D,
MostDetailedMip = 0,
MipLevels = 1
};
shaderResourceView = new ShaderResourceView(device, Texture, shaderResourceViewDescription);
}
示例6: InitalizeGraphics
private void InitalizeGraphics()
{
if (Window.RenderCanvasHandle == IntPtr.Zero)
throw new InvalidOperationException("Window handle cannot be zero");
SwapChainDescription swapChainDesc = new SwapChainDescription()
{
BufferCount = 1,
Flags = SwapChainFlags.None,
IsWindowed = true,
OutputHandle = Window.RenderCanvasHandle,
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput,
ModeDescription = new ModeDescription()
{
Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
//Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
Width = Window.ClientSize.Width,
Height = Window.ClientSize.Height,
RefreshRate = new Rational(60, 1),
Scaling = DisplayModeScaling.Unspecified,
ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified
},
SampleDescription = new SampleDescription(1, 0)
};
var giFactory = new SlimDX.DXGI.Factory();
var adapter = giFactory.GetAdapter(0);
Device device;
SwapChain swapChain;
Device.CreateWithSwapChain(adapter, DriverType.Hardware, DeviceCreationFlags.None, swapChainDesc, out device, out swapChain);
_swapChain = swapChain;
GraphicsDevice = device;
// create a view of our render target, which is the backbuffer of the swap chain we just created
using (var resource = SlimDX.Direct3D10.Resource.FromSwapChain<Texture2D>(swapChain, 0))
{
_backBuffer = new RenderTargetView(device, resource);
}
// setting a viewport is required if you want to actually see anything
var viewport = new Viewport(0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
device.OutputMerger.SetTargets(_backBuffer);
device.Rasterizer.SetViewports(viewport);
CreateDepthStencil();
LoadVisualizationEffect();
// Allocate a large buffer to write the PhysX visualization vertices into
// There's more optimized ways of doing this, but for this sample a large buffer will do
_userPrimitivesBuffer = new SlimDX.Direct3D10.Buffer(GraphicsDevice, VertexPositionColor.SizeInBytes * 50000, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None);
var elements = new[]
{
new InputElement("Position", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("Color", 0, Format.R32G32B32A32_Float, 16, 0)
};
_inputLayout = new InputLayout(GraphicsDevice, _visualizationEffect.RenderScenePass0.Description.Signature, elements);
}
示例7: Execute
//void Update()
//{
// stereoCamera.Update();
// SceneTree.Update();
// isDirty = false;
//}
public override void Execute()
{
//Game.RenderEvent.Wait();
//if (isDirty)
// Update();
//stereoCamera.Update();
//SceneTree.Update();
lTexture = new Texture2D(Game.Context.Device, RenderTextureDesc);
rTexture = new Texture2D(Game.Context.Device, RenderTextureDesc);
rTargetViewLeft = new SlimDX.Direct3D11.RenderTargetView(Game.Context.Device, lTexture);
rTargetViewRight = new SlimDX.Direct3D11.RenderTargetView(Game.Context.Device, rTexture);
stereoCamera.EnableLeftStereoProjection();
RenderSceneImage(lTexture, rTargetViewLeft);
stereoCamera.EnableRightStereoProjection();
RenderSceneImage(rTexture, rTargetViewRight);
Texture2D newTexture = Stereo.Make3D(lTexture, rTexture);
FreeResources();
Texture = newTexture;
}
示例8: LoadResources
public void LoadResources()
{
if (m_Disposed == true)
{
Buffer = new Texture2D(GameEnvironment.Device, new Texture2DDescription()
{
Format = m_Format,
Width = m_Width,
Height = m_Height,
OptionFlags = ResourceOptionFlags.None,
MipLevels = 1,
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default
});
View = new RenderTargetView(GameEnvironment.Device, Buffer);
ResourceView = new ShaderResourceView(GameEnvironment.Device, Buffer);
Viewport = new Viewport(0, 0, Buffer.Description.Width, Buffer.Description.Height);
m_Disposed = false;
}
}
示例9: Resize
public override void Resize(DeviceContextHolder holder, int width, int height) {
if (width == Width && height == Height) return;
base.Resize(holder, width, height);
TargetView = new RenderTargetView(holder.Device, Texture);
View = new ShaderResourceView(holder.Device, Texture);
}
示例10: InitDevice
/// <summary>
/// Create Direct3D device and swap chain
/// </summary>
public void InitDevice()
{
device = D3DDevice.CreateDeviceAndSwapChain(host.Handle, out swapChain);
// Create a render target view
using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
{
renderTargetView = device.CreateRenderTargetView(pBuffer);
}
device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView }, null);
// Setup the viewport
Viewport vp = new Viewport()
{
Width = (uint)host.ActualWidth,
Height = (uint)host.ActualHeight,
MinDepth = 0.0f,
MaxDepth = 1.0f,
TopLeftX = 0,
TopLeftY = 0
};
device.RS.SetViewports(new Viewport[] { vp });
}
示例11: CreateDeviceSwapChainAndRenderTarget
public static void CreateDeviceSwapChainAndRenderTarget(Form form,
out Device device, out SwapChain swapChain, out RenderTargetView renderTarget)
{
try
{
// the debug mode requires the sdk to be installed otherwise an exception is thrown
device = new Device(DeviceCreationFlags.Debug);
}
catch (Direct3D10Exception)
{
device = new Device(DeviceCreationFlags.None);
}
var swapChainDescription = new SwapChainDescription();
var modeDescription = new ModeDescription();
var sampleDescription = new SampleDescription();
modeDescription.Format = Format.R8G8B8A8_UNorm;
modeDescription.RefreshRate = new Rational(60, 1);
modeDescription.Scaling = DisplayModeScaling.Unspecified;
modeDescription.ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified;
modeDescription.Width = WIDTH;
modeDescription.Height = HEIGHT;
sampleDescription.Count = 1;
sampleDescription.Quality = 0;
swapChainDescription.ModeDescription = modeDescription;
swapChainDescription.SampleDescription = sampleDescription;
swapChainDescription.BufferCount = 1;
swapChainDescription.Flags = SwapChainFlags.None;
swapChainDescription.IsWindowed = true;
swapChainDescription.OutputHandle = form.Handle;
swapChainDescription.SwapEffect = SwapEffect.Discard;
swapChainDescription.Usage = Usage.RenderTargetOutput;
using (var factory = new Factory())
{
swapChain = new SwapChain(factory, device, swapChainDescription);
}
using (var resource = swapChain.GetBuffer<Texture2D>(0))
{
renderTarget = new RenderTargetView(device, resource);
}
var viewport = new Viewport
{
X = 0,
Y = 0,
Width = WIDTH,
Height = HEIGHT,
MinZ = 0.0f,
MaxZ = 1.0f
};
device.Rasterizer.SetViewports(viewport);
device.OutputMerger.SetTargets(renderTarget);
}
示例12: DX11RenderTexture3D
public DX11RenderTexture3D(DX11RenderContext context, int w, int h, int d, Format format)
: base(context)
{
Texture3DDescription desc = new Texture3DDescription()
{
BindFlags = BindFlags.UnorderedAccess | BindFlags.ShaderResource | BindFlags.RenderTarget,
CpuAccessFlags = CpuAccessFlags.None,
Depth = d,
Format = format,
Height = h,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default,
Width = w
};
RenderTargetViewDescription rtvd = new RenderTargetViewDescription();
rtvd.Format = format;
rtvd.Dimension = RenderTargetViewDimension.Texture3D;
rtvd.MipSlice = 0;
rtvd.FirstDepthSlice = 0;
rtvd.DepthSliceCount = d;
this.Resource = new Texture3D(context.Device, desc);
this.SRV = new ShaderResourceView(context.Device, this.Resource);
this.UAV = new UnorderedAccessView(context.Device, this.Resource);
this.RTV = new RenderTargetView(context.Device, this.Resource, rtvd);
this.Width = desc.Width;
this.Height = desc.Height;
this.Format = desc.Format;
this.Depth = desc.Depth;
}
示例13: Draw
public void Draw(DeviceContextHolder holder, ShaderResourceView view, RenderTargetView target,
TargetResourceTexture temporaryEdges, TargetResourceTexture temporaryBlending) {
holder.PrepareQuad(_effect.LayoutPT);
holder.DeviceContext.OutputMerger.BlendState = null;
// edges
holder.DeviceContext.OutputMerger.SetTargets(temporaryEdges.TargetView);
holder.DeviceContext.ClearRenderTargetView(temporaryEdges.TargetView, new Color4(0f, 0f, 0f, 0f));
_effect.FxScreenSizeSpec.Set(new Vector4(1f / holder.Width, 1f / holder.Height, holder.Width, holder.Height));
_effect.FxInputMap.SetResource(view);
_effect.TechSmaa.DrawAllPasses(holder.DeviceContext, 6);
// blending
holder.DeviceContext.OutputMerger.SetTargets(temporaryBlending.TargetView);
holder.DeviceContext.ClearRenderTargetView(temporaryBlending.TargetView, new Color4(0f, 0f, 0f, 0f));
_effect.FxEdgesMap.SetResource(temporaryEdges.View);
_effect.FxAreaTexMap.SetResource(_areasTexMap);
_effect.FxSearchTexMap.SetResource(_searchTexMap);
_effect.TechSmaaB.DrawAllPasses(holder.DeviceContext, 6);
// final part
holder.DeviceContext.OutputMerger.SetTargets(target);
_effect.FxBlendMap.SetResource(temporaryBlending.View);
_effect.TechSmaaN.DrawAllPasses(holder.DeviceContext, 6);
}
示例14: OnResourceLoad
protected override void OnResourceLoad()
{
using (Texture2D texture = Texture2D.FromSwapChain<Texture2D>(Context10.SwapChain, 0))
{
renderTargetView = new RenderTargetView(Context10.Device, texture);
}
effect = Effect.FromFile(Context10.Device, "SimpleTriangle10.fx", "fx_4_0");
technique = effect.GetTechniqueByIndex(0);
pass = technique.GetPassByIndex(0);
ShaderSignature signature = pass.Description.Signature;
inputLayout = new InputLayout(Context10.Device, signature, new[] {
new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
new InputElement("COLOR", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 16, 0)
});
vertexBuffer = new Buffer(
Context10.Device,
3 * 32,
ResourceUsage.Dynamic,
BindFlags.VertexBuffer,
CpuAccessFlags.Write,
ResourceOptionFlags.None
);
DataStream stream = vertexBuffer.Map(MapMode.WriteDiscard, MapFlags.None);
stream.WriteRange(new[] {
new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
});
vertexBuffer.Unmap();
}
示例15: Draw
public void Draw(DeviceContextHolder holder, ShaderResourceView view, RenderTargetView target) {
holder.DeviceContext.OutputMerger.SetTargets(target);
holder.QuadBuffers.Prepare(holder.DeviceContext, _effect.LayoutPT);
_effect.FxScreenSize.Set(new Vector4(holder.Width, holder.Height, 1f / holder.Width, 1f / holder.Height));
_effect.FxInputMap.SetResource(view);
_effect.TechFxaa.DrawAllPasses(holder.DeviceContext, 6);
}