From 05112d1e757ac097f5312c297d47a055063029c8 Mon Sep 17 00:00:00 2001 From: Glatzemann Date: Wed, 30 Nov 2011 06:59:32 +0000 Subject: [PATCH] fixed issue #468 finished issue #465 --- .../FormatConverter.cs | 37 +++++++++++++------ Samples/StencilBuffer/Game1.cs | 32 ++++++++++------ 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/RenderSystems/ANX.Framework.Windows.DX10/FormatConverter.cs b/RenderSystems/ANX.Framework.Windows.DX10/FormatConverter.cs index 18469531..d29ee791 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/FormatConverter.cs +++ b/RenderSystems/ANX.Framework.Windows.DX10/FormatConverter.cs @@ -275,21 +275,34 @@ namespace ANX.Framework.Windows.DX10 public static ColorWriteMaskFlags Translate(ColorWriteChannels colorWriteChannels) { - switch (colorWriteChannels) + ColorWriteMaskFlags mask = 0; + + if ((colorWriteChannels & ColorWriteChannels.All) == ColorWriteChannels.All) { - case ColorWriteChannels.All: - return ColorWriteMaskFlags.All; - case ColorWriteChannels.Alpha: - return ColorWriteMaskFlags.Alpha; - case ColorWriteChannels.Blue: - return ColorWriteMaskFlags.Blue; - case ColorWriteChannels.Green: - return ColorWriteMaskFlags.Green; - case ColorWriteChannels.Red: - return ColorWriteMaskFlags.Red; + mask |= ColorWriteMaskFlags.All; } - throw new NotImplementedException(); + if ((colorWriteChannels & ColorWriteChannels.Alpha) == ColorWriteChannels.Alpha) + { + mask |= ColorWriteMaskFlags.Alpha; + } + + if ((colorWriteChannels & ColorWriteChannels.Blue) == ColorWriteChannels.Blue) + { + mask |= ColorWriteMaskFlags.Blue; + } + + if ((colorWriteChannels & ColorWriteChannels.Green) == ColorWriteChannels.Green) + { + mask |= ColorWriteMaskFlags.Green; + } + + if ((colorWriteChannels & ColorWriteChannels.Red) == ColorWriteChannels.Red) + { + mask |= ColorWriteMaskFlags.Red; + } + + return mask; } public static SharpDX.Direct3D10.StencilOperation Translate(ANX.Framework.Graphics.StencilOperation stencilOperation) diff --git a/Samples/StencilBuffer/Game1.cs b/Samples/StencilBuffer/Game1.cs index a5523fef..8f736963 100644 --- a/Samples/StencilBuffer/Game1.cs +++ b/Samples/StencilBuffer/Game1.cs @@ -15,6 +15,7 @@ namespace StencilBuffer private Texture2D ground; private SamplerState SamplerState; + private DepthStencilState RenderGroundStencilState; private DepthStencilState RenderObjectsStencilState; private DepthStencilState StencilStateRenderShadows; @@ -75,24 +76,33 @@ namespace StencilBuffer Filter = TextureFilter.Linear, }; + this.RenderGroundStencilState = new DepthStencilState() + { + DepthBufferEnable = false, + DepthBufferWriteEnable = false, + StencilEnable = true, + ReferenceStencil = 1, + StencilPass = StencilOperation.Replace, + StencilFunction = CompareFunction.Always, + }; + this.RenderObjectsStencilState = new DepthStencilState() { DepthBufferEnable = true, DepthBufferWriteEnable = true, DepthBufferFunction = CompareFunction.Always, - ReferenceStencil = 2, - StencilEnable = true, - StencilPass = StencilOperation.Increment, + ReferenceStencil = 1, + StencilEnable = false, + StencilPass = StencilOperation.Replace, }; this.StencilStateRenderShadows = new DepthStencilState { - DepthBufferEnable = true, - DepthBufferWriteEnable = true, - DepthBufferFunction = CompareFunction.LessEqual, - ReferenceStencil = 1, + DepthBufferEnable = false, StencilEnable = true, - StencilPass = StencilOperation.Keep, + ReferenceStencil = 1, + StencilPass = StencilOperation.Increment, + StencilFunction = CompareFunction.LessEqual, }; } @@ -107,7 +117,7 @@ namespace StencilBuffer private void RenderGround() { - spriteBatch.Begin(SpriteSortMode.Texture, null, SamplerState, RenderObjectsStencilState, null); + spriteBatch.Begin(SpriteSortMode.Texture, null, SamplerState, RenderGroundStencilState, null); for (int y = 0; y < 2; y++) { for (int x = 0; x < 4; x++) @@ -122,13 +132,13 @@ namespace StencilBuffer { spriteBatch.Begin(SpriteSortMode.Texture, null, SamplerState, StencilStateRenderShadows, null); spriteBatch.Draw(crate, new Vector2(125, 125), new Color(0, 0, 0, 0.5f)); - spriteBatch.Draw(crate, new Vector2(10, 10), new Color(0, 0, 0, 0.5f)); + spriteBatch.Draw(crate, new Vector2(20, 20), new Color(0, 0, 0, 0.5f)); spriteBatch.End(); } protected override void Draw(GameTime gameTime) { - GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.Stencil, Color.CornflowerBlue, 1.0f, 2); + GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.Stencil, Color.CornflowerBlue, 1.0f, 0); RenderGround(); RenderShadows();