Beispiel #1
0
        public void RenderPointWithStencil()
        {
            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
                    using (Texture2D depthStencilTexture = Device.CreateTexture2D(new Texture2DDescription(1, 1, TextureFormat.Depth24Stencil8, false)))
                        using (ShaderProgram sp = Device.CreateShaderProgram(ShaderSources.PassThroughVertexShader(), ShaderSources.PassThroughFragmentShader()))
                            using (VertexArray va = TestUtility.CreateVertexArray(window.Context, sp.VertexAttributes["position"].Location))
                            {
                                framebuffer.DepthStencilAttachment = depthStencilTexture;

                                StencilTest stencilTest = new StencilTest();
                                stencilTest.Enabled = true;
                                stencilTest.FrontFace.DepthFailStencilPassOperation = StencilOperation.Replace;
                                stencilTest.FrontFace.DepthPassStencilPassOperation = StencilOperation.Replace;
                                stencilTest.FrontFace.StencilFailOperation          = StencilOperation.Replace;
                                stencilTest.FrontFace.ReferenceValue = 2;

                                RenderState renderState = new RenderState();
                                renderState.StencilTest = stencilTest;

                                window.Context.Framebuffer = framebuffer;
                                window.Context.Clear(new ClearState());
                                window.Context.Draw(PrimitiveType.Points, 0, 1, new DrawState(renderState, sp, va), new SceneState());

                                TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);

                                using (ReadPixelBuffer readPixelBuffer = depthStencilTexture.CopyToBuffer(ImageFormat.DepthStencil, ImageDatatype.UnsignedInt248, 1))
                                {
                                    byte[] depthStencil = readPixelBuffer.CopyToSystemMemory <byte>();
                                    Assert.AreEqual(stencilTest.FrontFace.ReferenceValue, depthStencil[0]);
                                }
                            }
        }
Beispiel #2
0
 public RenderState()
 {
     PrimitiveRestart = new PrimitiveRestart();
     FacetCulling = new FacetCulling();
     ProgramPointSize = ProgramPointSize.Disabled;
     RasterizationMode = RasterizationMode.Fill;
     ScissorTest = new ScissorTest();
     StencilTest = new StencilTest();
     DepthTest = new DepthTest();
     DepthRange = new DepthRange();
     Blending = new Blending();
     ColorMask = new ColorMask(true, true, true, true);
     DepthMask = true;
 }
Beispiel #3
0
 public RenderState()
 {
     PrimitiveRestart  = new PrimitiveRestart();
     FacetCulling      = new FacetCulling();
     ProgramPointSize  = ProgramPointSize.Disabled;
     RasterizationMode = RasterizationMode.Fill;
     ScissorTest       = new ScissorTest();
     StencilTest       = new StencilTest();
     DepthTest         = new DepthTest();
     DepthRange        = new DepthRange();
     Blending          = new Blending();
     ColorMask         = new ColorMask(true, true, true, true);
     DepthMask         = true;
 }
        public void StencilTest()
        {
            StencilTest     stencilTest  = new StencilTest();
            StencilTestFace frontStencil = stencilTest.FrontFace;
            StencilTestFace backStencil  = stencilTest.BackFace;

            stencilTest.Enabled = true;

            frontStencil.StencilFailOperation          = StencilOperation.Keep;
            frontStencil.DepthFailStencilPassOperation = StencilOperation.Keep;
            frontStencil.DepthPassStencilPassOperation = StencilOperation.Increment;
            frontStencil.Function       = StencilTestFunction.Always;
            frontStencil.ReferenceValue = 0;
            frontStencil.Mask           = 0xFF;

            backStencil.StencilFailOperation          = StencilOperation.Zero;
            backStencil.DepthFailStencilPassOperation = StencilOperation.Zero;
            backStencil.DepthPassStencilPassOperation = StencilOperation.Decrement;
            backStencil.Function       = StencilTestFunction.Equal;
            backStencil.ReferenceValue = 1;
            backStencil.Mask           = 0x03;

            Assert.IsTrue(stencilTest.Enabled);

            Assert.AreEqual(StencilOperation.Keep, frontStencil.StencilFailOperation);
            Assert.AreEqual(StencilOperation.Keep, frontStencil.DepthFailStencilPassOperation);
            Assert.AreEqual(StencilOperation.Increment, frontStencil.DepthPassStencilPassOperation);
            Assert.AreEqual(StencilTestFunction.Always, frontStencil.Function);
            Assert.AreEqual(0, frontStencil.ReferenceValue);
            Assert.AreEqual(0xFF, frontStencil.Mask);

            Assert.AreEqual(StencilOperation.Zero, backStencil.StencilFailOperation);
            Assert.AreEqual(StencilOperation.Zero, backStencil.DepthFailStencilPassOperation);
            Assert.AreEqual(StencilOperation.Decrement, backStencil.DepthPassStencilPassOperation);
            Assert.AreEqual(StencilTestFunction.Equal, backStencil.Function);
            Assert.AreEqual(1, backStencil.ReferenceValue);
            Assert.AreEqual(0x03, backStencil.Mask);
        }
        public void StencilTest()
        {
            StencilTest stencilTest = new StencilTest();
            StencilTestFace frontStencil = stencilTest.FrontFace;
            StencilTestFace backStencil = stencilTest.BackFace;

            stencilTest.Enabled = true;

            frontStencil.StencilFailOperation = StencilOperation.Keep;
            frontStencil.DepthFailStencilPassOperation = StencilOperation.Keep;
            frontStencil.DepthPassStencilPassOperation = StencilOperation.Increment;
            frontStencil.Function = StencilTestFunction.Always;
            frontStencil.ReferenceValue = 0;
            frontStencil.Mask = 0xFF;

            backStencil.StencilFailOperation = StencilOperation.Zero;
            backStencil.DepthFailStencilPassOperation = StencilOperation.Zero;
            backStencil.DepthPassStencilPassOperation = StencilOperation.Decrement;
            backStencil.Function = StencilTestFunction.Equal;
            backStencil.ReferenceValue = 1;
            backStencil.Mask = 0x03;

            Assert.IsTrue(stencilTest.Enabled);

            Assert.AreEqual(StencilOperation.Keep, frontStencil.StencilFailOperation);
            Assert.AreEqual(StencilOperation.Keep, frontStencil.DepthFailStencilPassOperation);
            Assert.AreEqual(StencilOperation.Increment, frontStencil.DepthPassStencilPassOperation);
            Assert.AreEqual(StencilTestFunction.Always, frontStencil.Function);
            Assert.AreEqual(0, frontStencil.ReferenceValue);
            Assert.AreEqual(0xFF, frontStencil.Mask);

            Assert.AreEqual(StencilOperation.Zero, backStencil.StencilFailOperation);
            Assert.AreEqual(StencilOperation.Zero, backStencil.DepthFailStencilPassOperation);
            Assert.AreEqual(StencilOperation.Decrement, backStencil.DepthPassStencilPassOperation);
            Assert.AreEqual(StencilTestFunction.Equal, backStencil.Function);
            Assert.AreEqual(1, backStencil.ReferenceValue);
            Assert.AreEqual(0x03, backStencil.Mask);
        }
Beispiel #6
0
        public void RenderPointWithStencil()
        {
            using (GraphicsWindow window = Device.CreateWindow(1, 1))
            using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
            using (Texture2D depthStencilTexture = Device.CreateTexture2D(new Texture2DDescription(1, 1, TextureFormat.Depth24Stencil8, false)))
            using (ShaderProgram sp = Device.CreateShaderProgram(ShaderSources.PassThroughVertexShader(), ShaderSources.PassThroughFragmentShader()))
            using (VertexArray va = TestUtility.CreateVertexArray(window.Context, sp.VertexAttributes["position"].Location))
            {
                framebuffer.DepthStencilAttachment = depthStencilTexture;

                StencilTest stencilTest = new StencilTest();
                stencilTest.Enabled = true;
                stencilTest.FrontFace.DepthFailStencilPassOperation = StencilOperation.Replace;
                stencilTest.FrontFace.DepthPassStencilPassOperation = StencilOperation.Replace;
                stencilTest.FrontFace.StencilFailOperation = StencilOperation.Replace;
                stencilTest.FrontFace.ReferenceValue = 2;

                RenderState renderState = new RenderState();
                renderState.StencilTest = stencilTest;

                window.Context.Framebuffer = framebuffer;
                window.Context.Clear(new ClearState());
                window.Context.Draw(PrimitiveType.Points, 0, 1, new DrawState(renderState, sp, va), new SceneState());

                TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);

                using (ReadPixelBuffer readPixelBuffer = depthStencilTexture.CopyToBuffer(ImageFormat.DepthStencil, ImageDatatype.UnsignedInt248, 1))
                {
                    byte[] depthStencil = readPixelBuffer.CopyToSystemMemory<byte>();
                    Assert.AreEqual(stencilTest.FrontFace.ReferenceValue, depthStencil[0]);
                }
            }
        }