本文整理汇总了C#中Device.GetRenderTargetData方法的典型用法代码示例。如果您正苦于以下问题:C# Device.GetRenderTargetData方法的具体用法?C# Device.GetRenderTargetData怎么用?C# Device.GetRenderTargetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.GetRenderTargetData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: copyBuffer
private void copyBuffer(Device device, Surface bb)
{
device.StretchRectangle(bb, _renderTarget0, TextureFilter.Point);
device.GetRenderTargetData(_renderTarget0, _renderTarget);
}
示例3: Screenshot
public void Screenshot(Device device, string filename, int primCount, int numVertices)
{
Surface surf;
using (Surface backbuffer = device.GetBackBuffer(0, 0))
{
using (SwapChain sc = device.GetSwapChain(0))
{
surf = Surface.CreateOffscreenPlain(device, sc.PresentParameters.BackBufferWidth, sc.PresentParameters.BackBufferHeight, sc.PresentParameters.BackBufferFormat, Pool.SystemMemory);
}
try
{
device.GetRenderTargetData(backbuffer, surf);
if(!Directory.Exists(filename + "Output"))
Directory.CreateDirectory(filename + "Output");
if (!Directory.Exists(filename + "Output\\"+ Interface.exe))
Directory.CreateDirectory(filename + "Output\\" + Interface.exe);
Surface.ToFile(surf, filename + "Output\\" + Interface.exe + "\\" + primCount + "x" + numVertices + ".bmp", ImageFileFormat.Bmp);
surf.Dispose();
}
catch (Exception e)
{
Interface.ReportException(e);
}
}
}