本文整理汇总了C#中Device.GetRenderTarget方法的典型用法代码示例。如果您正苦于以下问题:C# Device.GetRenderTarget方法的具体用法?C# Device.GetRenderTarget怎么用?C# Device.GetRenderTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.GetRenderTarget方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderBloom
public void RenderBloom(Device device, Effect effect)
{
BrightPassFilter(device, effect);
Surface orgTarget = device.GetRenderTarget(0);
Vector2[] sampleOffsets = new Vector2[16];
Vector4[] sampleWeights = new Vector4[16];
float[] afSampleOffsets = new float[16];
Surface surfDest = BloomTex[1].GetSurfaceLevel(0);
SurfaceDescription desc = BrightPassTex.GetSurfaceLevel(0).Description;
Surface OriginalDS = device.DepthStencilSurface;
device.DepthStencilSurface = Renderer.Instance.RenderDepthSurface;
GetSampleOffsets_Bloom(desc.Width, afSampleOffsets, ref sampleWeights, 3.0f, 1.25f);
for (int i = 0; i < 16; i++)
{
sampleOffsets[i] = new Vector2(afSampleOffsets[i], 0f);
}
effect.Technique = "Bloom";
effect.SetValue("g_avSampleWeights", sampleWeights);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
device.SetRenderTarget(0, surfDest);
device.SetTexture(0, BrightPassTex);
device.SetSamplerState(0, SamplerState.MinFilter, (int)TextureFilter.Point);
device.SetSamplerState(0, SamplerState.MagFilter, (int)TextureFilter.Point);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
surfDest.Dispose();
surfDest = BloomTex[0].GetSurfaceLevel(0);
GetSampleOffsets_Bloom(desc.Height, afSampleOffsets, ref sampleWeights, 3.0f, 1.25f);
for (int i = 0; i < 16; i++)
{
sampleOffsets[i] = new Vector2(0f, afSampleOffsets[i]);
}
effect.Technique = "Bloom";
effect.SetValue("g_avSampleWeights", sampleWeights);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
device.SetRenderTarget(0, surfDest);
device.SetTexture(0, BloomTex[1]);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
device.SetRenderTarget(0, orgTarget);
device.DepthStencilSurface = OriginalDS;
}
示例2: Scene
public Scene(Control _control, Device _device)
{
m_Control = _control;
m_Device = _device;
if (m_Device == null)
{
Direct3DEx _d3d = new Direct3DEx();
DisplayMode _mode = _d3d.GetAdapterDisplayMode(0);
PresentParameters _parameters = new PresentParameters();
_parameters.BackBufferFormat = _mode.Format;
_parameters.BackBufferCount = 1;
_parameters.BackBufferWidth = m_Control.Width;
_parameters.BackBufferHeight = m_Control.Height;
_parameters.Multisample = MultisampleType.None;
_parameters.SwapEffect = SwapEffect.Discard;
_parameters.PresentationInterval = PresentInterval.Default;
_parameters.Windowed = true;
_parameters.DeviceWindowHandle = m_Control.Handle;
_parameters.PresentFlags = PresentFlags.DeviceClip | PresentFlags.Video;
m_Device = new DeviceEx(_d3d, 0, DeviceType.Hardware, m_Control.Handle, CreateFlags.Multithreaded | CreateFlags.HardwareVertexProcessing, _parameters);
m_RenderTarget = m_Device.GetRenderTarget(0);
}
}
示例3: GetSurface
protected override sealed void GetSurface(Device device)
{
Surface = device.GetRenderTarget(_index);
}
示例4: CreateDevice
private void CreateDevice()
{
adapterInfo = Manager.Adapters.Default;
presentParam = new PresentParameters();
presentParam.Windowed = true;
presentParam.PresentFlag = PresentFlag.Video;
presentParam.SwapEffect = SwapEffect.Copy;
presentParam.BackBufferFormat = adapterInfo.CurrentDisplayMode.Format;
device = new Device(
0,
DeviceType.Hardware,
parentControl,
CreateFlags.SoftwareVertexProcessing | CreateFlags.MultiThreaded,
presentParam
);
renderTarget = device.GetRenderTarget(0);
}
示例5: CreateDevice
public static void CreateDevice(Control window)
{
CloseDevice();
device = new Device(adapter, DeviceType.Hardware, window, CreateFlags.FpuPreserve|CreateFlags.MultiThreaded|CreateFlags.HardwareVertexProcessing, devParams);
//BackBuffer=device.GetBackBuffer(0, 0, BackBufferType.Mono);
BackBuffer=device.GetRenderTarget(0);
device.RenderState.Lighting = false;
device.RenderState.ZBufferEnable = false;
device.RenderState.StencilEnable = false;
device.RenderState.AmbientColor = int.MinValue;
}
示例6: RenderDatabaseTree
public static TextureMatrixLayer[] RenderDatabaseTree(RasterDatabase.RasterDatabase db, Device device)
{
// setup device
device.RenderState.ZBufferEnable = false;
device.Indices = null;
device.VertexFormat = CustomVertex.TransformedTextured.Format;
//device.Transform.World = Matrix.Identity;
Surface rt0 = device.GetRenderTarget(0);
// setup template quad
CustomVertex.TransformedTextured[] tQuad = new CustomVertex.TransformedTextured[4];
foreach(DataLayer layer in db.Layers)
{
RectangleGroupQuadTree tree = db.ProduceLayerMipMap(layer, 2048);
Texture[][] textures = new Texture[tree.Depth][];
for (int i = 1; i <= tree.Depth; i++)
{
RectangleGroupQuadTree.GroupNode[] nodes;
tree.GetNodes(i, out nodes);
textures[i] = new Texture[nodes.Length];
// render each node to texture
int texIdx = 0;
foreach (RectangleGroupQuadTree.GroupNode node in nodes)
{
Texture texture = textures[i][texIdx++] = new Texture(device, node.NodeArea.Width,
node.NodeArea.Height, 0,
Usage.WriteOnly, Format.X8R8G8B8,
Pool.Managed);
device.SetRenderTarget(0, texture.GetSurfaceLevel(0));
device.Clear(ClearFlags.Target, Color.Black, 1, 0);
device.BeginScene();
// draw each rectangle quad
foreach (DataArea area in node.Rectangles)
{
// setup quad
tQuad[0] = new CustomVertex.TransformedTextured(area.Area.Left, area.Area.Top, 1, 1,
area.TexCoords.Left, area.TexCoords.Top);
tQuad[1] = new CustomVertex.TransformedTextured(area.Area.Right, area.Area.Top, 1, 1,
area.TexCoords.Right, area.TexCoords.Top);
tQuad[2] = new CustomVertex.TransformedTextured(area.Area.Left, area.Area.Bottom, 1, 1,
area.TexCoords.Left, area.TexCoords.Bottom);
tQuad[3] = new CustomVertex.TransformedTextured(area.Area.Right, area.Area.Bottom, 1, 1,
area.TexCoords.Right, area.TexCoords.Bottom);
// render quad
device.SetTexture(0, (Texture)area.Data);
device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, tQuad);
}
device.EndScene();
}
}
}
device.SetRenderTarget(0, rt0);
device.RenderState.ZBufferEnable = true;
return null;
}
示例7: CreateDevice
public static void CreateDevice(Control window)
{
CloseDevice();
device = new Device(d3d, adapter, DeviceType.Hardware, window.Handle, CreateFlags.FpuPreserve|CreateFlags.Multithreaded|CreateFlags.HardwareVertexProcessing, devParams);
//BackBuffer=device.GetBackBuffer(0, 0, BackBufferType.Mono);
BackBuffer=device.GetRenderTarget(0);
device.SetRenderState(RenderState.Lighting, false);
device.SetRenderState(RenderState.ZEnable, false);
device.SetRenderState(RenderState.StencilEnable, false);
device.SetRenderState(RenderState.Ambient, int.MinValue);
}
示例8: BrightPassFilter
private void BrightPassFilter(Device device, Effect effect)
{
Surface OriginalDS = device.DepthStencilSurface;
device.DepthStencilSurface = Renderer.Instance.RenderDepthSurface;
Vector2[] sampleOffsets = new Vector2[16];
Surface brightPassSurface = BrightPassTex.GetSurfaceLevel(0);
SurfaceDescription backbufDescr = Renderer.Instance.RenderSurface.Description;
GetSampleOffsetsets_DownScale3x3(backbufDescr.Width / 2, backbufDescr.Height / 2, ref sampleOffsets);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
effect.Technique = "DownScale3x3_BrightPass_RGBE8";
Surface orgTarget = device.GetRenderTarget(0);
device.SetRenderTarget(0, brightPassSurface);
device.SetTexture(0, Renderer.Instance.RenderTexture);
device.SetTexture(1, Renderer.Instance.AvgLum);
device.SetSamplerState(0, SamplerState.MagFilter, (int)TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MinFilter, (int)TextureFilter.Linear);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
device.SetTexture(1, null);
device.SetRenderTarget(0, orgTarget);
device.DepthStencilSurface = OriginalDS;
}
示例9: MeasureLuminance
public void MeasureLuminance(Effect effect, Device device)
{
Surface OriginalRenderTarget = device.GetRenderTarget(0);
Vector2[] sampleOffsets = new Vector2[16];
Texture dest = ToneMapTex[nToneMapTex - 1];
SurfaceDescription destDescr = dest.GetLevelDescription(0);
SurfaceDescription sourceDescr = Renderer.Instance.RenderSurface.Description;
GetSampleOffsets_DownScale2x2_Lum(sourceDescr.Width, sourceDescr.Height, destDescr.Width, destDescr.Height, ref sampleOffsets);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
effect.Technique = "DownScale2x2_Lum_RGBE8";
Surface destSurface = dest.GetSurfaceLevel(0);
device.SetRenderTarget(0, destSurface);
Surface OriginalDS = device.DepthStencilSurface;
device.DepthStencilSurface = Renderer.Instance.RenderDepthSurface;
device.SetSamplerState(0, SamplerState.MagFilter, (int)TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MinFilter, (int)TextureFilter.Linear);
device.SetTexture(0, Renderer.Instance.RenderTexture);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
effect.Technique = "DownScale3x3_RGBE8";
for (int i = nToneMapTex - 1; i > 0; i--)
{
Surface source = ToneMapTex[i].GetSurfaceLevel(0);
dest = ToneMapTex[i - 1];
destSurface = dest.GetSurfaceLevel(0);
GetSampleOffsetsets_DownScale3x3(destSurface.Description.Width, destSurface.Description.Height, ref sampleOffsets);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
device.SetRenderTarget(0, destSurface);
device.SetTexture(0, ToneMapTex[i]);
//device.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point);
//device.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
}
// Add calculated luminance to average
if (CurrentAvgToneMap == -1)
{
Rectangle avgrect = new Rectangle(new Point(), new Size(1, 1));
device.StretchRectangle(ToneMapTex[0].GetSurfaceLevel(0), avgrect, avgToneMap[0].GetSurfaceLevel(0), avgrect, TextureFilter.Point);
CurrentAvgToneMap = 0;
}
else
{
effect.Technique = "CalcAvgLum_RGBE8";
device.SetTexture(0, avgToneMap[CurrentAvgToneMap]); // "main" average
int other = (CurrentAvgToneMap == 0 ? 1 : 0);
device.SetTexture(1, ToneMapTex[0]); // new average to be added
Surface surf = avgToneMap[other].GetSurfaceLevel(0);
device.SetRenderTarget(0, surf); // unused "main" average texture used as rendertarget
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
device.SetTexture(1, null);
CurrentAvgToneMap = other; // swap avgTonemap usage next frame
}
device.SetRenderTarget(0, OriginalRenderTarget);
device.DepthStencilSurface = OriginalDS;
// Read result
device.GetRenderTargetData(AverageLum.GetSurfaceLevel(0), LockableAverage.GetSurfaceLevel(0));
DataRectangle rect = LockableAverage.LockRectangle(0, LockFlags.ReadOnly);
Color4 color = new Color4(rect.Data.Read<int>());
LockableAverage.UnlockRectangle(0);
// Revert LogLum encoding
float invLogLumRange = 1.0f / (MaxLogLum + MinLogLum);
float logLumOffset = MinLogLum * invLogLumRange;
double avgLum = Math.Exp((color.Alpha) / (invLogLumRange + logLumOffset));
effect.SetValue("avgLogLum", avgLum);
//System.Console.WriteLine(avgLum);
}