本文整理汇总了C#中GraphicsDevice.GetRenderTargets方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsDevice.GetRenderTargets方法的具体用法?C# GraphicsDevice.GetRenderTargets怎么用?C# GraphicsDevice.GetRenderTargets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphicsDevice
的用法示例。
在下文中一共展示了GraphicsDevice.GetRenderTargets方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(GraphicsDevice device)
{
var oldTargets = device.GetRenderTargets();
device.SetRenderTarget(Target);
device.Clear(Color.Transparent);
device.DepthStencilState = DepthStencilState.Default;
Camera.ProjectionDirty();
base.Draw(device);
device.SetRenderTargets(oldTargets);
}
示例2: Draw
public void Draw(GraphicsDevice device, GameTime gameTime, Vector4? clipPlane = null, float? alpha = null)
{
terrainWater.Time = (float)(gameTime.TotalGameTime.TotalMilliseconds) / 2000000.0f;
RenderTargetBinding[] renderTargetBindings = device.GetRenderTargets();
terrainWater.Board.UseLessVertices = true;
DrawRefractionMap(device, gameTime);
DrawReflectionMap(device, gameTime);
terrainWater.Board.UseLessVertices = false;
device.SetRenderTargets(renderTargetBindings);
DrawWater(device);
}
示例3: DeviceState
internal DeviceState(GraphicsDevice device)
{
Device = device;
BlendFactor = device.BlendFactor;
BlendState = device.BlendState;
DepthStencilState = device.DepthStencilState;
Indices = device.Indices;
RasterizerState = device.RasterizerState;
RenderTargets = device.GetRenderTargets();
ScissorRectangle = device.ScissorRectangle;
Viewport = device.Viewport;
VertexBuffers = device.GetVertexBuffers();
MultisampleMask = device.MultiSampleMask;
ReferenceStencil = device.ReferenceStencil;
}
示例4: StateManager
public StateManager(ContentManager content, GraphicsDevice pGraphics)
{
///centerCoordParam = blurEffect.Parameters["fCenter"];
mCurrentState = mNextState = SCREEN_STATES.SPLASH_SCREEN;
changeScreen = false;
mContent = content;
mGraphics = pGraphics;
mInputManagerPlayerOne = new InputManager(PlayerIndex.One);
//intantiate screens
mSplashScreen = new SplashScreen(new EventHandler(SplashScreenEvent), pGraphics);
mGameScreen = new GameScreen(new EventHandler(GameScreenEvent), pGraphics);
mMenuScreen = new MainMenuScreen(new EventHandler(MenuScreenEvent), pGraphics);
//mCurrentScreen = mGameScreen
tempRenderTargetOne = new RenderTarget2D(mGraphics, screenWidth, screenHeight);
tempRenderTargetTwo = new RenderTarget2D(mGraphics, screenWidth, screenHeight);
tempBinding = mGraphics.GetRenderTargets();
mGraphics.SetRenderTarget(tempRenderTargetOne);
//effects
noiseEffect = content.Load<Effect>("Noise");
SepiaEffect = content.Load<Effect>("Sepia");
noiseFilter = noiseEffect.Parameters["noisefilter"];
blackLine = noiseEffect.Parameters["blkLine"];
TempNoise = new Texture2D[3];
TempNoise[0] = content.Load<Texture2D>("NOISE/noise1");
TempNoise[1] = content.Load<Texture2D>("NOISE/noise2");
TempNoise[2] = content.Load<Texture2D>("NOISE/noise3");
rand = new Random();
noise = 0;
}
示例5: GenerateMaxMap
private void GenerateMaxMap(RenderTarget2D texture, GraphicsDevice graphicsDevice)
{
// Save old render setup to restore later.
SharpDX.Direct3D11.DepthStencilView depthStencilBefore;
var renderTargetsBefore = graphicsDevice.GetRenderTargets(out depthStencilBefore);
ViewportF oldViewport = graphicsDevice.GetViewport(0);
numHeightmapMipLevels = 0;
var currentWidth = texture.Width / 2;
var currentHeight = texture.Height / 2;
for (var mipLevel = 1; currentWidth > 0 && currentHeight > 0; ++mipLevel, currentWidth /= 2, currentHeight /= 2)
{
// Generate sampler on-the-fly.
var samplerStateDesc = SharpDX.Direct3D11.SamplerStateDescription.Default();
samplerStateDesc.AddressV = SharpDX.Direct3D11.TextureAddressMode.Clamp;
samplerStateDesc.AddressU = SharpDX.Direct3D11.TextureAddressMode.Clamp;
samplerStateDesc.Filter = SharpDX.Direct3D11.Filter.MinMagMipPoint;
samplerStateDesc.MinimumLod = mipLevel-1;
samplerStateDesc.MaximumLod = mipLevel-1;
samplerStateDesc.MipLodBias = mipLevel-1;
var mipLevelSamplerState = SamplerState.New(graphicsDevice, "MipLevelSampler_" + mipLevel, samplerStateDesc);
// Draw.
maxmapGenShader.Effect.Parameters["NearestSampler"].SetResource(mipLevelSamplerState);
maxmapGenShader.Effect.Parameters["InputTexture"].SetResource(texture.ShaderResourceView[ViewType.Single, 0, mipLevel-1]);
graphicsDevice.SetRenderTargets(texture.RenderTargetView[ViewType.Single, 0, mipLevel]);
graphicsDevice.SetViewport(0, 0, currentWidth, currentHeight);
maxmapGenShader.Effect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.Draw(PrimitiveType.PointList, 1);
maxmapGenShader.Effect.CurrentTechnique.Passes[0].UnApply();
++numHeightmapMipLevels;
}
graphicsDevice.SetRenderTargets(depthStencilBefore, renderTargetsBefore);
graphicsDevice.SetViewport(oldViewport);
}
示例6: MotionBlur
private void MotionBlur(SpriteBatch spritebatch, GraphicsDevice graphics)
{
//3_1
//graphics.ResolveBackBuffer(resolvedtexture);
//tex = resolvedtexture;
RenderTargetBinding[] targets = graphics.GetRenderTargets();
tex = (RenderTarget2D)targets[0].RenderTarget;
graphics.SetRenderTarget(target);
float speedx;
if (player.speed.X < 0)
{
speedx = MathHelper.Clamp(camera.CamOffset.X, -Player.MAX_SPEED, -60);
speedx += 60;
}
else
{
speedx = MathHelper.Clamp(camera.CamOffset.X, 60, Player.MAX_SPEED);
speedx -= 60;
}
speedx /= 600;
motionblur.Parameters["speed"].SetValue(
new Vector2(speedx, camera.CamOffset.Y / 5000));
//graphics.Clear(Color.Black);
//3_1
//spritebatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
//motionblur.Begin();
//foreach (EffectPass pass in motionblur.CurrentTechnique.Passes)
//{
// pass.Begin();
spritebatch.Begin(SpriteSortMode.Immediate, null, null, null, null, motionblur);
spritebatch.Draw(tex, Vector2.Zero, Color.White);
// pass.End();
//}
//motionblur.End();
spritebatch.End();
graphics.SetRenderTarget((RenderTarget2D)targets[0].RenderTarget);
spritebatch.Begin();
spritebatch.Draw(target, Vector2.Zero, Color.White);
spritebatch.End();
}
示例7: Blur
private void Blur(SpriteBatch spriteBatch, GraphicsDevice device)
{
RenderTargetBinding[] targets = device.GetRenderTargets();
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, blur);
spriteBatch.Draw((RenderTarget2D)targets[0].RenderTarget, Vector2.Zero, Color.White);
spriteBatch.End();
}
示例8: Draw
/// <summary>
/// Render the terrain
/// </summary>
/// <param name="device"></param>
/// <param name="world"></param>
public override void Draw(GraphicsDevice device, WorldState world)
{
if (VertexBuffer == null) return;
PPXDepthEngine.RenderPPXDepth(Effect, true, (depthMode) =>
{
Effect.Parameters["LightGreen"].SetValue(LightGreen.ToVector4());
Effect.Parameters["DarkGreen"].SetValue(DarkGreen.ToVector4());
Effect.Parameters["DarkBrown"].SetValue(DarkBrown.ToVector4());
Effect.Parameters["LightBrown"].SetValue(LightBrown.ToVector4());
Effect.Parameters["ScreenSize"].SetValue(new Vector2(device.Viewport.Width, device.Viewport.Height));
//Effect.Parameters["depthOutMode"].SetValue(DepthMode && (!FSOEnvironment.UseMRT));
var offset = -world.WorldSpace.GetScreenOffset();
world._3D.ApplyCamera(Effect);
var worldmat = Matrix.Identity * Matrix.CreateTranslation(0, ((world.Zoom == WorldZoom.Far) ? -5 : ((world.Zoom == WorldZoom.Medium) ? -4 : -3)) * (20 / 522f), 0);
Effect.Parameters["World"].SetValue(worldmat);
Effect.Parameters["DiffuseColor"].SetValue(new Vector4(world.OutsideColor.R / 255f, world.OutsideColor.G / 255f, world.OutsideColor.B / 255f, 1.0f));
device.SetVertexBuffer(VertexBuffer);
device.Indices = IndexBuffer;
Effect.CurrentTechnique = Effect.Techniques["DrawBase"];
foreach (var pass in Effect.CurrentTechnique.Passes)
{
pass.Apply();
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, NumPrimitives);
}
int grassScale;
float grassDensity;
switch (world.Zoom)
{
case WorldZoom.Far:
grassScale = 4;
grassDensity = 0.56f;
break;
case WorldZoom.Medium:
grassScale = 2;
grassDensity = 0.50f;
break;
default:
grassScale = 1;
grassDensity = 0.43f;
break;
}
grassDensity *= GrassDensityScale;
if (BladePrimitives > 0)
{
Effect.CurrentTechnique = Effect.Techniques["DrawBlades"];
int grassNum = (int)Math.Ceiling(GrassHeight / (float)grassScale);
//if (depthMode && (!FSOEnvironment.UseMRT)) return;
RenderTargetBinding[] rts = null;
if (FSOEnvironment.UseMRT)
{
rts = device.GetRenderTargets();
if (rts.Length > 1)
{
device.SetRenderTarget((RenderTarget2D)rts[0].RenderTarget);
}
}
device.Indices = BladeIndexBuffer;
for (int i = 0; i < grassNum; i++)
{
Effect.Parameters["World"].SetValue(Matrix.Identity * Matrix.CreateTranslation(0, i * (20 / 522f) * grassScale, 0));
Effect.Parameters["GrassProb"].SetValue(grassDensity * ((grassNum - (i / (2f * grassNum))) / (float)grassNum));
offset += new Vector2(0, 1);
Effect.Parameters["ScreenOffset"].SetValue(offset);
foreach (var pass in Effect.CurrentTechnique.Passes)
{
pass.Apply();
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, BladePrimitives);
}
}
if (FSOEnvironment.UseMRT)
{
device.SetRenderTargets(rts);
}
}
});
}
示例9: init
public override void init()
{
//Shader stuff
mDevice = mManager.mGraphicsDevice;
tempBinding = mDevice.GetRenderTargets();
tempRenderTarget = new RenderTarget2D(mDevice, 1280, 720);
blurShader = new BlurFocusShader(mDevice, tempRenderTarget, mManager.blur);
//rippleShader = new RippleShader(mDevice, tempRenderTarget, mManager.ripple);
//Shader stuff ends
//Map stuff
map = mManager.mGame.Content.Load<Map>("maps\\" + mManager.mLevelName);
mapDisplayDevice = new XnaDisplayDevice(mManager.mGame.Content, mDevice);
map.LoadTileSheets(mapDisplayDevice);
viewport = new xTile.Dimensions.Rectangle(new Size(1280, 720));
//Map stuff done
scoreCounter = new ScoreCounter();
camera = new Camera();
runEffect = new ParticleEffect(mManager.particleEffect, ParticleEffect.ParticleType.Dust, BlendState.AlphaBlend, camera);
explosion = new ParticleEffect(mManager.particleEffect, ParticleEffect.ParticleType.Explosion, BlendState.Additive, camera);
input = new GetInput(PlayerIndex.One);
player = new Hero(mManager.heroSprites);
shotList = new List<Shot>();
puncheeList = new List<Punchee>();
scoreAreaList = new List<ScoreArea>();
chargingSoundEffect = mManager.chargingSound.CreateInstance();
chargingSoundEffect.Pitch = 0.2f;
attachEventListener();
for (int i = 0; i < map.Layers[0].LayerWidth; i++)
{
for (int j = 0; j < map.Layers[0].LayerHeight; j++)
{
Layer collision = map.Layers[0];
Location tileLocation = new Location(i, j);
Tile tile = collision.Tiles[tileLocation];
if (tile.TileIndex == 90)
{
ParticleEffect trail = new ParticleEffect(mManager.particleEffect, ParticleEffect.ParticleType.Knockback, BlendState.AlphaBlend, camera);
Punchee punched = new Punchee(mManager.startScreen, trail);
FollowAI followAI = new FollowAI(punched, player);
punched.addAI(followAI);
punched.mPosition.X = 32 * i;
punched.mPosition.Y = 32 * j;
puncheeList.Add(punched);
}
if (tile.TileIndex == 77)
{
int posX = i * 32;
int posY = j * 32;
ScoreArea scoreArea = new ScoreArea(posX, posY);
scoreAreaList.Add(scoreArea);
}
}
}
}
示例10: RenderTargetState
public RenderTargetState(GraphicsDevice GraphicsDevice,
int renderTargetIndex)
{
this.GraphicsDevice = GraphicsDevice;
//RenderTarget = (RenderTarget2D)GraphicsDevice.GetRenderTarget(renderTargetIndex);
RenderTargetBinding[] rents = GraphicsDevice.GetRenderTargets();
if (rents.Length > 0) RenderTarget = (RenderTarget2D)rents[0].RenderTarget;
//DepthBuffer = GraphicsDevice.DepthStencilBuffer;
CreatedBuffers = false;
}
示例11: UpdateNormalMapTexture
private void UpdateNormalMapTexture(GraphicsDevice pGraphicsDevice)
{
RenderTargetBinding[] pSavedSurfaces = pGraphicsDevice.GetRenderTargets();
pGraphicsDevice.SetRenderTarget(m_pNormalMapTexture);
pGraphicsDevice.Clear(Color.Black);
Matrix tWorld = Matrix.Identity;
Matrix tView = Matrix.Identity;
Matrix tProjection = Matrix.CreateOrthographicOffCenter(0, Settings.NORMAL_MAP_TEXTURE_SIZE,
Settings.NORMAL_MAP_TEXTURE_SIZE, 0, 0.0f, 1.0f);
m_pNormalMapUpdateEffect.SetValue("WorldViewProjection", Matrix.Transpose(tProjection));
// render to texture here
m_pNormalMapUpdateEffect.SetValue("ElevationTexture", m_pElevationTexture);
m_pNormalMapUpdateEffect.SetValue("ElevationTextureSizeInverse", Settings.ELEVATION_TEXTURE_SIZE_INVERSE);
m_pNormalMapUpdateEffect.SetValue("NormalScaleFactor", new Vector2(0.5f / (float)m_nGridSpacing));
m_pNormalMapUpdateEffect.Render(new RenderCallback(RenderNormalMapTexture));
pGraphicsDevice.SetRenderTargets(pSavedSurfaces);
//m_pNormalMapTexture.GetTexture().Save("NormalMap " + m_nGridSpacing + ".dds", ImageFileFormat.Dds);
}
示例12: UpdateElevationTexture
private void UpdateElevationTexture(GraphicsDevice pGraphicsDevice)
{
// TODO: currently we just update the whole texture. we need to do this toroidally
RenderTargetBinding[] pSavedSurfaces = pGraphicsDevice.GetRenderTargets();
pGraphicsDevice.SetRenderTarget(m_pElevationTexture);
Matrix tWorld = Matrix.Identity;
Matrix tView = Matrix.Identity;
Matrix tProjection = Matrix.CreateOrthographicOffCenter(0, Settings.ELEVATION_TEXTURE_SIZE,
Settings.ELEVATION_TEXTURE_SIZE, 0, 0.0f, 1.0f);
m_pElevationUpdateEffect.SetValue("WorldViewProjection", Matrix.Transpose(tProjection));
// render to texture here
m_pElevationUpdateEffect.SetValue("HeightMapTexture", m_pParentTerrain.HeightMapTexture);
m_pElevationUpdateEffect.SetValue("HeightMapSizeInverse", 1.0f / (float) m_pParentTerrain.HeightMapTexture.Width);
m_pElevationUpdateEffect.SetValue("GridSpacing", (float) m_nGridSpacing);
m_pElevationUpdateEffect.SetValue("WorldPosMin", (Vector2) m_tPositionMin);
m_pElevationUpdateEffect.SetValue("ToroidalOrigin", m_tToroidalOrigin);
m_pElevationUpdateEffect.SetValue("ElevationTextureSize", Settings.ELEVATION_TEXTURE_SIZE);
m_pElevationUpdateEffect.Render(RenderElevationTexture);
pGraphicsDevice.SetRenderTargets(pSavedSurfaces);
/*using (Stream pFileStream = File.OpenWrite("Level " + m_nGridSpacing + ".png"))
{
m_pElevationTexture.SaveAsPng(pFileStream,
Settings.ELEVATION_TEXTURE_SIZE,
Settings.ELEVATION_TEXTURE_SIZE);
}*/
}
示例13: RenderTargetSwitchContext
public RenderTargetSwitchContext(GraphicsDevice graphicsDevice, RenderTarget2D target) {
this.graphicsDevice = graphicsDevice;
this.target = target;
oldRenderTargets = graphicsDevice.GetRenderTargets(out oldDepthStencil);
graphicsDevice.SetRenderTargets(target);
}