本文整理汇总了C#中IRenderContext.PushRenderTarget方法的典型用法代码示例。如果您正苦于以下问题:C# IRenderContext.PushRenderTarget方法的具体用法?C# IRenderContext.PushRenderTarget怎么用?C# IRenderContext.PushRenderTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRenderContext
的用法示例。
在下文中一共展示了IRenderContext.PushRenderTarget方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public virtual void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
{
var layoutWidth = layout.Width - skinLayout.HorizontalScrollBarHeight;
var layoutHeight = layout.Height - skinLayout.VerticalScrollBarWidth;
int childWidth, childHeight;
if (!(_child is IHasDesiredSize))
{
childWidth = layoutWidth;
childHeight = layoutHeight;
}
else
{
var hasDesiredSize = (IHasDesiredSize) _child;
childWidth = hasDesiredSize.GetDesiredWidth(skinLayout) ?? layoutWidth;
childHeight = hasDesiredSize.GetDesiredHeight(skinLayout) ?? layoutHeight;
if (childWidth < layoutWidth)
{
childWidth = layoutWidth;
}
if (childHeight < layoutHeight)
{
childHeight = layoutHeight;
}
}
if (_renderTarget == null || _renderTarget.Width != childWidth ||
_renderTarget.Height != childHeight)
{
_renderTarget?.Dispose();
_renderTarget = new RenderTarget2D(
context.GraphicsDevice,
Math.Max(1, childWidth),
Math.Max(1, childHeight));
}
context.SpriteBatch.End();
context.PushRenderTarget(_renderTarget);
context.GraphicsDevice.Clear(Color.Transparent);
context.SpriteBatch.Begin();
try
{
_child?.Render(
context,
skinLayout,
skinDelegator,
new Rectangle(0, 0, childWidth, childHeight));
}
finally
{
context.SpriteBatch.End();
context.PopRenderTarget();
context.SpriteBatch.Begin();
}
skinDelegator.Render(context, layout, this);
}
示例2: Render
public void Render(IGameContext gameContext, IRenderContext renderContext, ILightContext lightContext)
{
var oldRasterizerState = renderContext.GraphicsDevice.RasterizerState;
var oldWorld = renderContext.World;
_parameterSet.Unlock();
_parameterSet["Color"]?.SetValue(lightContext.DeferredColorMap);
_parameterSet["Normal"]?.SetValue(lightContext.DeferredNormalMap);
_parameterSet["Depth"]?.SetValue(lightContext.DeferredDepthMap);
_parameterSet["Specular"]?.SetValue(lightContext.DeferredSpecularMap);
_parameterSet["CameraPosition"]?.SetValue(renderContext.CameraPosition);
_parameterSet["LightPosition"]?.SetValue(LightPosition);
_parameterSet["LightColor"]?.SetValue(LightColor.ToVector3());
_parameterSet["LightRadius"]?.SetValue(LightRadius);
_parameterSet["LightIntensity"]?.SetValue(LightIntensity);
_parameterSet["LightInvertViewProjection"]?.SetValue(Matrix.Invert(renderContext.View * renderContext.Projection));
_parameterSet["World"]?.SetValue(renderContext.World);
_parameterSet["View"]?.SetValue(renderContext.View);
_parameterSet["Projection"]?.SetValue(renderContext.Projection);
// If we are inside the lighting sphere, we need to invert the culling mode so
// that we see the inside faces of the model.
float cameraToCenter = Vector3.Distance(renderContext.CameraPosition, LightPosition);
if (cameraToCenter < LightRadius)
{
renderContext.GraphicsDevice.RasterizerState = lightContext.RasterizerStateCullClockwiseFace;
}
else
{
renderContext.GraphicsDevice.RasterizerState = lightContext.RasterizerStateCullCounterClockwiseFace;
}
renderContext.World = Matrix.CreateScale(LightRadius) * Matrix.CreateTranslation(LightPosition);
if (lightContext.DiffuseLightRenderTarget != null && lightContext.SpecularLightRenderTarget != null)
{
renderContext.PushRenderTarget(lightContext.DiffuseLightRenderTarget, lightContext.SpecularLightRenderTarget);
}
_pointLightSphereModel.Render(renderContext, _pointLightEffect.Effect, _parameterSet, Matrix.Identity);
if (lightContext.DiffuseLightRenderTarget != null && lightContext.SpecularLightRenderTarget != null)
{
renderContext.PopRenderTarget();
}
renderContext.World = oldWorld;
renderContext.GraphicsDevice.RasterizerState = oldRasterizerState;
}
示例3: BeginRenderPass
public void BeginRenderPass(
IGameContext gameContext,
IRenderContext renderContext,
IRenderPass previousPass,
RenderTarget2D postProcessingSource)
{
_colorRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_colorRenderTarget, gameContext, SurfaceFormat.Color, DepthFormat.Depth24, null);
_normalRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_normalRenderTarget, gameContext, SurfaceFormat.Color, DepthFormat.None, null);
_depthRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_depthRenderTarget, gameContext, SurfaceFormat.Single, DepthFormat.None, null);
_specularRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_specularRenderTarget, gameContext, SurfaceFormat.Color, DepthFormat.None, null);
_diffuseLightRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_diffuseLightRenderTarget, gameContext, null, DepthFormat.None, null);
_specularLightRenderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_specularLightRenderTarget, gameContext, null, DepthFormat.None, null);
if (_rasterizerStateCullNone == null)
{
_rasterizerStateCullNone = new RasterizerState();
_rasterizerStateCullNone.CullMode = CullMode.None;
_rasterizerStateCullNone.FillMode = FillMode.Solid;
_rasterizerStateCullNone.DepthBias = 0;
_rasterizerStateCullNone.MultiSampleAntiAlias = true;
_rasterizerStateCullNone.ScissorTestEnable = false;
_rasterizerStateCullNone.SlopeScaleDepthBias = 0;
_rasterizerStateCullNone.DepthClipEnable = true;
}
if (_rasterizerStateCullClockwiseFace == null)
{
_rasterizerStateCullClockwiseFace = new RasterizerState();
_rasterizerStateCullClockwiseFace.CullMode = CullMode.CullClockwiseFace;
_rasterizerStateCullClockwiseFace.FillMode = FillMode.Solid;
_rasterizerStateCullClockwiseFace.DepthBias = 0;
_rasterizerStateCullClockwiseFace.MultiSampleAntiAlias = true;
_rasterizerStateCullClockwiseFace.ScissorTestEnable = false;
_rasterizerStateCullClockwiseFace.SlopeScaleDepthBias = 0;
_rasterizerStateCullClockwiseFace.DepthClipEnable = true;
}
if (_rasterizerStateCullCounterClockwiseFace == null)
{
_rasterizerStateCullCounterClockwiseFace = new RasterizerState();
_rasterizerStateCullCounterClockwiseFace.CullMode = CullMode.CullCounterClockwiseFace;
_rasterizerStateCullCounterClockwiseFace.FillMode = FillMode.Solid;
_rasterizerStateCullCounterClockwiseFace.DepthBias = 0;
_rasterizerStateCullCounterClockwiseFace.MultiSampleAntiAlias = true;
_rasterizerStateCullCounterClockwiseFace.ScissorTestEnable = false;
_rasterizerStateCullCounterClockwiseFace.SlopeScaleDepthBias = 0;
_rasterizerStateCullCounterClockwiseFace.DepthClipEnable = true;
}
if (_depthStencilState == null)
{
_depthStencilState = DepthStencilState.Default;
}
if (_lightDepthStencilState == null)
{
_lightDepthStencilState = DepthStencilState.None;
}
if (_blendState == null)
{
_blendState = BlendState.Opaque;
}
if (_lightBlendState == null)
{
_lightBlendState = BlendState.AlphaBlend;
}
renderContext.PushRenderTarget(
_colorRenderTarget,
_normalRenderTarget,
_depthRenderTarget,
_specularRenderTarget);
// Clear the geometry buffer before moving into main rendering.
_graphicsBlit.Blit(
renderContext,
null,
null,
_gbufferClearEffect.Effect);
_previousDepthStencilState = renderContext.GraphicsDevice.DepthStencilState;
_previousRasterizerState = renderContext.GraphicsDevice.RasterizerState;
_previousBlendState = renderContext.GraphicsDevice.BlendState;
renderContext.GraphicsDevice.DepthStencilState = _depthStencilState;
renderContext.GraphicsDevice.RasterizerState = _rasterizerStateCullCounterClockwiseFace;
renderContext.GraphicsDevice.BlendState = _blendState;
}
示例4: EndRenderPass
public void EndRenderPass(
IGameContext gameContext,
IRenderContext renderContext,
IRenderPass nextPass)
{
_renderBatcher.FlushRequests(gameContext, renderContext);
renderContext.PopRenderTarget();
renderContext.GraphicsDevice.DepthStencilState = _previousDepthStencilState;
renderContext.GraphicsDevice.RasterizerState = _previousRasterizerState;
renderContext.GraphicsDevice.BlendState = _previousBlendState;
renderContext.PushRenderTarget(_diffuseLightRenderTarget);
renderContext.GraphicsDevice.Clear(Color.Transparent);
renderContext.PopRenderTarget();
renderContext.PushRenderTarget(_specularLightRenderTarget);
renderContext.GraphicsDevice.Clear(Color.Transparent);
renderContext.PopRenderTarget();
var lightContext = new DefaultLightContext(
_colorRenderTarget,
_normalRenderTarget,
_depthRenderTarget,
_specularRenderTarget,
_diffuseLightRenderTarget,
_specularLightRenderTarget,
_lightBlendState,
_rasterizerStateCullNone,
_rasterizerStateCullClockwiseFace,
_rasterizerStateCullCounterClockwiseFace,
new Vector2(
0.5f/renderContext.GraphicsDevice.PresentationParameters.BackBufferWidth,
0.5f/renderContext.GraphicsDevice.PresentationParameters.BackBufferHeight));
var lights = new List<ILight>();
foreach (var l in _hierarchy.Lookup(gameContext.World).Children.Select(x => x.UntypedValue).OfType<IHasLights>())
{
lights.AddRange(l.GetLights());
}
renderContext.GraphicsDevice.BlendState = _lightBlendState;
renderContext.GraphicsDevice.DepthStencilState = _lightDepthStencilState;
foreach (var light in lights)
{
light.Render(gameContext, renderContext, lightContext);
}
renderContext.GraphicsDevice.BlendState = _previousBlendState;
renderContext.GraphicsDevice.DepthStencilState = _previousDepthStencilState;
if (DebugGBuffer)
{
// Render the G buffer into 4 quadrants on the current render target.
renderContext.GraphicsDevice.Clear(Color.Purple);
_graphicsBlit.Blit(
renderContext,
_colorRenderTarget,
null,
null,
null,
null,
new Vector2(0, 0),
new Vector2(0.33f, 0.5f));
_graphicsBlit.Blit(
renderContext,
_normalRenderTarget,
null,
null,
null,
null,
new Vector2(0.33f, 0),
new Vector2(0.34f, 0.5f));
_graphicsBlit.Blit(
renderContext,
_depthRenderTarget,
null,
null,
null,
null,
new Vector2(0.67f, 0f),
new Vector2(0.33f, 0.5f));
_graphicsBlit.Blit(
renderContext,
_specularRenderTarget,
null,
null,
null,
null,
new Vector2(0.0f, 0.5f),
new Vector2(0.33f, 0.5f));
_graphicsBlit.Blit(
renderContext,
_diffuseLightRenderTarget,
null,
null,
null,
//.........这里部分代码省略.........
示例5: Render
public void Render(IGameContext gameContext, IRenderContext renderContext)
{
try
{
renderContext.Render(gameContext);
_primary = _renderTargetBackBufferUtilities.UpdateRenderTarget(_primary, gameContext);
_secondary = _renderTargetBackBufferUtilities.UpdateRenderTarget(_secondary, gameContext);
var standardRenderPasses = _standardRenderPasses.ToArray();
var postProcessingRenderPasses = _postProcessingRenderPasses.ToArray();
//IRenderPass[] transientStandardRenderPasses;
//IRenderPass[] transientPostProcessingRenderPasses;
IRenderPass previousPass = null;
IRenderPass nextPass = null;
var entities = gameContext.World.Entities.ToArray();
#if !DISABLE_PIPELINE_TARGETS
renderContext.PushRenderTarget(_primary);
#endif
for (var i = 0; i < standardRenderPasses.Length; i++)
{
var pass = standardRenderPasses[i];
_isFirstRenderPass = previousPass == null;
_renderPass = pass;
pass.BeginRenderPass(gameContext, renderContext, previousPass, null);
previousPass = pass;
RenderPass(gameContext, renderContext, entities);
if (i < standardRenderPasses.Length - 1)
{
nextPass = standardRenderPasses[i + 1];
}
else if (_transientStandardRenderPasses.Count > 0)
{
nextPass = _transientStandardRenderPasses[0];
}
else if (postProcessingRenderPasses.Length > 0)
{
nextPass = postProcessingRenderPasses[0];
}
else if (_transientPostProcessingRenderPasses.Count > 0)
{
nextPass = _transientPostProcessingRenderPasses[0];
}
else
{
nextPass = null;
}
pass.EndRenderPass(gameContext, renderContext, nextPass);
}
var loop = 100;
while (_transientStandardRenderPasses.Count > 0 && loop-- >= 0)
{
var transientStandardRenderPasses = _transientStandardRenderPasses.ToArray();
_transientStandardRenderPasses.Clear();
for (var i = 0; i < transientStandardRenderPasses.Length; i++)
{
var pass = transientStandardRenderPasses[i];
_isFirstRenderPass = previousPass == null;
_renderPass = pass;
pass.BeginRenderPass(gameContext, renderContext, previousPass, null);
previousPass = pass;
RenderPass(gameContext, renderContext, entities);
if (i < transientStandardRenderPasses.Length - 1)
{
nextPass = transientStandardRenderPasses[i + 1];
}
else if (_transientStandardRenderPasses.Count > 0)
{
nextPass = _transientStandardRenderPasses[0];
}
else if (postProcessingRenderPasses.Length > 0)
{
nextPass = postProcessingRenderPasses[0];
}
else if (_transientPostProcessingRenderPasses.Count > 0)
{
nextPass = _transientPostProcessingRenderPasses[0];
}
else
{
nextPass = null;
}
pass.EndRenderPass(gameContext, renderContext, nextPass);
}
}
if (loop < 0)
{
throw new InvalidOperationException(
"Exceeded the number of AppendTransientRenderPass iterations (100). Ensure you " +
"are not unconditionally calling AppendTransientRenderPass within another render pass.");
}
#if !DISABLE_PIPELINE_TARGETS
renderContext.PopRenderTarget();
#endif
//.........这里部分代码省略.........
示例6: Render
public override void Render(IGameContext gameContext, IRenderContext renderContext)
{
// Render the LEM1802 to a texture
if (this.m_LEM1802 != null)
{
this.RenderDCPU(renderContext);
}
else
{
if (this.m_RenderTarget == null)
{
this.m_RenderTarget = new RenderTarget2D(renderContext.GraphicsDevice, LEM1802.Width, LEM1802.Height);
}
renderContext.PushRenderTarget(this.m_RenderTarget);
renderContext.GraphicsDevice.Clear(Color.Black);
renderContext.PopRenderTarget();
}
if (this.m_PendRecalculation)
{
this.RecalculateObject(gameContext, renderContext);
}
renderContext.GraphicsDevice.Indices = this.m_IndexBuffer;
renderContext.GraphicsDevice.SetVertexBuffer(this.m_VertexBuffer);
renderContext.SetActiveTexture(this.m_RenderTarget);
renderContext.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
0,
0,
this.m_VertexBuffer.VertexCount,
0,
this.m_IndexBuffer.IndexCount / 3);
renderContext.SetActiveTexture(this.m_ShipTextureAsset.Texture);
this.m_TouchAnimIndex++;
if (this.m_TouchAnimIndex >= this.m_TouchAnim.Length * 3)
{
this.m_TouchAnimIndex = 0;
}
}
示例7: Render
public void Render(IGameContext gameContext, IRenderContext renderContext)
{
try
{
renderContext.Render(gameContext);
// NOTE: We MUST clear the depth buffer because OpenGL will not do it for us.
renderContext.GraphicsDevice.Clear(
ClearOptions.DepthBuffer,
Microsoft.Xna.Framework.Color.Transparent,
renderContext.GraphicsDevice.Viewport.MaxDepth,
0);
_primary = _renderTargetBackBufferUtilities.UpdateRenderTarget(_primary, gameContext);
_secondary = _renderTargetBackBufferUtilities.UpdateRenderTarget(_secondary, gameContext);
if (_primary == null || _secondary == null)
{
// These are null if the window is minimized or invalid, in which case we don't
// render anything anyway.
return;
}
var standardRenderPasses = _standardRenderPasses.ToArray();
var postProcessingRenderPasses = _postProcessingRenderPasses.ToArray();
IRenderPass previousPass = null;
IRenderPass nextPass = null;
var entities = gameContext.World.GetEntitiesForWorld(gameContext.Hierarchy).ToArray();
#if !DISABLE_PIPELINE_TARGETS
renderContext.PushRenderTarget(_primary);
#endif
for (var i = 0; i < standardRenderPasses.Length; i++)
{
var pass = standardRenderPasses[i];
using (_profiler.Measure("r-" + pass.GetType().Name))
{
_isFirstRenderPass = previousPass == null;
_renderPass = pass;
SetupRenderPassViewport(renderContext, pass);
pass.BeginRenderPass(gameContext, renderContext, previousPass, null);
previousPass = pass;
RenderPass(gameContext, renderContext, pass, entities);
if (i < standardRenderPasses.Length - 1)
{
nextPass = standardRenderPasses[i + 1];
}
else if (_transientStandardRenderPasses.Count > 0)
{
nextPass = _transientStandardRenderPasses[0];
}
else if (postProcessingRenderPasses.Length > 0)
{
nextPass = postProcessingRenderPasses[0];
}
else if (_transientPostProcessingRenderPasses.Count > 0)
{
nextPass = _transientPostProcessingRenderPasses[0];
}
else
{
nextPass = null;
}
pass.EndRenderPass(gameContext, renderContext, nextPass);
}
}
var loop = 100;
while (_transientStandardRenderPasses.Count > 0 && loop-- >= 0)
{
var transientStandardRenderPasses = _transientStandardRenderPasses.ToArray();
_transientStandardRenderPasses.Clear();
for (var i = 0; i < transientStandardRenderPasses.Length; i++)
{
var pass = transientStandardRenderPasses[i];
using (_profiler.Measure("r-" + pass.GetType().Name))
{
_isFirstRenderPass = previousPass == null;
_renderPass = pass;
SetupRenderPassViewport(renderContext, pass);
pass.BeginRenderPass(gameContext, renderContext, previousPass, null);
previousPass = pass;
RenderPass(gameContext, renderContext, pass, entities);
if (i < transientStandardRenderPasses.Length - 1)
{
nextPass = transientStandardRenderPasses[i + 1];
}
else if (_transientStandardRenderPasses.Count > 0)
{
nextPass = _transientStandardRenderPasses[0];
}
else if (postProcessingRenderPasses.Length > 0)
{
nextPass = postProcessingRenderPasses[0];
}
else if (_transientPostProcessingRenderPasses.Count > 0)
{
//.........这里部分代码省略.........
示例8: Blit
public void Blit(IRenderContext renderContext, RenderTarget2D source, RenderTarget2D destination = null, Effect shader = null)
{
float destWidth, destHeight;
if (destination != null)
{
renderContext.PushRenderTarget(destination);
destWidth = destination.Width;
destHeight = destination.Height;
}
else
{
// TODO: renderContext.GraphicsDevice.GetRenderTargets();
destWidth = renderContext.GraphicsDevice.PresentationParameters.BackBufferWidth;
destHeight = renderContext.GraphicsDevice.PresentationParameters.BackBufferHeight;
}
if (shader == null)
{
shader = _blitEffect;
}
if (_vertexBuffer == null)
{
_vertexBuffer = new VertexBuffer(renderContext.GraphicsDevice, typeof (VertexPositionTexture),
_vertexes.Length, BufferUsage.WriteOnly);
_vertexBuffer.SetData(_vertexes);
}
if (_indexBuffer == null)
{
_indexBuffer = new IndexBuffer(renderContext.GraphicsDevice, typeof (short), _indicies.Length,
BufferUsage.WriteOnly);
_indexBuffer.SetData(_indicies);
}
var oldWorld = renderContext.World;
var oldProjection = renderContext.Projection;
var oldView = renderContext.View;
renderContext.GraphicsDevice.BlendState = BlendState.Opaque;
renderContext.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
renderContext.GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
renderContext.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
renderContext.World = Matrix.CreateScale(destWidth, destHeight, 1);
#if PLATFORM_WINDOWS
renderContext.Projection = Matrix.CreateOrthographicOffCenter(0, destWidth, destHeight, 0, 0, 1);
#else
renderContext.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
Matrix.CreateOrthographicOffCenter(0, destWidth, destHeight, 0, 0, 1);
#endif
renderContext.View = Matrix.Identity;
renderContext.PushEffect(shader);
renderContext.EnableTextures();
renderContext.SetActiveTexture(source);
renderContext.GraphicsDevice.SetVertexBuffer(_vertexBuffer);
renderContext.GraphicsDevice.Indices = _indexBuffer;
foreach (var pass in shader.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleStrip,
0,
0,
4,
0,
2);
}
renderContext.PopEffect();
renderContext.World = oldWorld;
renderContext.Projection = oldProjection;
renderContext.View = oldView;
if (destination != null)
{
renderContext.PopRenderTarget();
}
}
示例9: BlitInternal
private void BlitInternal(
IRenderContext renderContext,
Texture2D source,
RenderTarget2D[] destinations = null,
IEffect shader = null,
IEffectParameterSet effectParameterSet = null,
BlendState blendState = null,
Vector2? offset = null,
Vector2? size = null)
{
float destWidth, destHeight;
if (destinations != null)
{
var destinationsBound = new RenderTargetBinding[destinations.Length];
for (var i = 0; i < destinations.Length; i++)
{
// Implicit cast.
destinationsBound[i] = destinations[i];
}
renderContext.PushRenderTarget(destinationsBound);
destWidth = destinations[0].Width;
destHeight = destinations[0].Height;
}
else
{
// TODO: renderContext.GraphicsDevice.GetRenderTargets();
destWidth = renderContext.GraphicsDevice.PresentationParameters.BackBufferWidth;
destHeight = renderContext.GraphicsDevice.PresentationParameters.BackBufferHeight;
}
offset = offset ?? new Vector2(0, 0);
size = size ?? new Vector2(1 - offset.Value.X, 1 - offset.Value.Y);
if (blendState == null)
{
blendState = BlendState.Opaque;
}
if (shader == null)
{
shader = _blitEffect;
}
if (effectParameterSet == null)
{
effectParameterSet = shader.CreateParameterSet();
}
if (_vertexBuffer == null)
{
_vertexBuffer = new VertexBuffer(renderContext.GraphicsDevice, typeof (VertexPositionNormalTexture),
_vertexes.Length, BufferUsage.WriteOnly);
_vertexBuffer.SetData(_vertexes);
}
if (_indexBuffer == null)
{
_indexBuffer = new IndexBuffer(renderContext.GraphicsDevice, typeof (short), _indicies.Length,
BufferUsage.WriteOnly);
_indexBuffer.SetData(_indicies);
}
var oldWorld = renderContext.World;
var oldProjection = renderContext.Projection;
var oldView = renderContext.View;
renderContext.GraphicsDevice.BlendState = blendState;
renderContext.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
renderContext.GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
renderContext.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
renderContext.World = Matrix.CreateScale(destWidth, destHeight, 1);
renderContext.Projection =
#if !PLATFORM_WINDOWS
Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
#endif
Matrix.CreateOrthographicOffCenter(
destWidth * (-offset.Value.X / size.Value.X),
destWidth * (-offset.Value.X / size.Value.X) + destWidth / size.Value.X,
destHeight * (-offset.Value.Y / size.Value.Y) + destHeight / size.Value.Y,
destHeight * (-offset.Value.Y / size.Value.Y),
0,
1);
renderContext.View = Matrix.Identity;
if (source != null && effectParameterSet != null)
{
var semantic = effectParameterSet.GetSemantic<ITextureEffectSemantic>();
if (semantic.Texture != source)
{
semantic.Texture = source;
}
}
renderContext.GraphicsDevice.SetVertexBuffer(_vertexBuffer);
renderContext.GraphicsDevice.Indices = _indexBuffer;
shader.LoadParameterSet(renderContext, effectParameterSet);
foreach (var pass in shader.NativeEffect.CurrentTechnique.Passes)
//.........这里部分代码省略.........
示例10: Render
public void Render(IGameContext gameContext, IRenderContext renderContext)
{
if (this.m_PreviewTarget == null)
{
this.m_PreviewTarget = new RenderTarget2D(
renderContext.GraphicsDevice,
400,
240,
false,
gameContext.Graphics.PreferredBackBufferFormat,
gameContext.Graphics.PreferredDepthStencilFormat,
0,
RenderTargetUsage.PlatformContents);
}
if (renderContext.Is3DContext)
{
this.SetCamera(renderContext, this.m_CameraRotation);
this.m_GridRenderer.Render(
renderContext,
this.GridX,
this.GridY,
this.GridZ,
this.HorizontalRange,
this.VerticalRange,
this.VerticalSelection,
new Color(31, 31, 31),
new Color(95, 31, 31));
this.m_Ship.Render(gameContext, renderContext);
var point = this.GetMouseIntersectionPoint(gameContext);
if (point != null)
{
this.m_3DRenderUtilities.RenderCube(
renderContext,
Matrix.CreateScale(1, this.VerticalSelection + 0.1f, 1)
* Matrix.CreateTranslation(point.Value.X, this.GridY, point.Value.Y),
Color.Green);
}
var world = (ShipEditorWorld)gameContext.World;
if (this.m_ToolIsActive)
{
if (world.ActiveShipTool is RectangleFillShipTool || world.ActiveShipTool is RectangleClearShipTool
|| world.ActiveShipTool is CreateRoomShipTool)
{
if (point != null)
{
this.m_3DRenderUtilities.RenderCube(
renderContext,
Matrix.CreateScale(
Math.Max(point.Value.X + 1, this.m_StartGridX)
- Math.Min(point.Value.X + 1, this.m_StartGridX),
this.VerticalSelection + 0.1f,
Math.Max(point.Value.Y + 1, this.m_StartGridZ)
- Math.Min(point.Value.Y + 1, this.m_StartGridZ))
* Matrix.CreateTranslation(
Math.Min(point.Value.X + 1, this.m_StartGridX),
this.GridY,
Math.Min(point.Value.Y + 1, this.m_StartGridZ)),
Color.Green);
}
}
}
if (world.ActiveShipTool is EnterRoomShipTool || world.ActiveShipTool is DeleteRoomShipTool)
{
if (point != null)
{
var cell =
this.m_Ship.Cells.FirstOrDefault(
a =>
a.X == (int)point.Value.X && a.Y == this.GridY && a.Z == (int)point.Value.Y
&& a.Room != null);
if (cell != null)
{
this.m_3DRenderUtilities.RenderCube(
renderContext,
Matrix.CreateScale(cell.Room.Width / 10, cell.Room.Height / 10 + 0.1f, cell.Room.Depth / 10)
* Matrix.CreateTranslation(cell.Room.X / 10, cell.Room.Y / 10, cell.Room.Z / 10),
world.ActiveShipTool is EnterRoomShipTool ? Color.GreenYellow : Color.Red);
}
}
}
renderContext.PushRenderTarget(this.m_PreviewTarget);
renderContext.GraphicsDevice.Clear(Color.Black);
this.SetCamera(renderContext, this.m_PreviewRotation, true);
this.m_Ship.Render(gameContext, renderContext, true);
renderContext.PopRenderTarget();
this.SetCamera(renderContext, this.m_CameraRotation);
//.........这里部分代码省略.........