Exemplo n.º 1
0
        public void Find()
        {
            using (GraphicsWindow window = Device.CreateWindow(1, 1))
            {
                ShaderCache cache = new ShaderCache();

                ShaderProgram sp = cache.FindOrAdd("PassThrough",
                                                   ShaderSources.PassThroughVertexShader(),
                                                   ShaderSources.PassThroughFragmentShader());
                ShaderProgram sp2 = cache.Find("PassThrough");

                Assert.AreEqual(sp, sp2);

                cache.Release("PassThrough");
                cache.Release("PassThrough");
            }
        }
Exemplo n.º 2
0
        private void RenderPoint(string vs)
        {
            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
                    using (ShaderProgram sp = Device.CreateShaderProgram(vs, ShaderSources.PassThroughFragmentShader()))
                        using (VertexArray va = TestUtility.CreateVertexArray(window.Context, sp.VertexAttributes["position"].Location))
                        {
                            SceneState sceneState = new SceneState();
                            sceneState.Camera.Eye    = 2 * Vector3D.UnitX;
                            sceneState.Camera.Target = Vector3D.Zero;
                            sceneState.Camera.Up     = Vector3D.UnitZ;

                            window.Context.Framebuffer = framebuffer;
                            window.Context.Draw(PrimitiveType.Points, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), sceneState);
                            TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);
                        }
        }
Exemplo n.º 3
0
        public void PassThrough()
        {
            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (ShaderProgram sp = Device.CreateShaderProgram(
                           ShaderSources.PassThroughVertexShader(),
                           ShaderSources.PassThroughFragmentShader()))
                {
                    Assert.IsFalse(sp.Log.Contains("warning"));
                    Assert.IsEmpty(sp.Uniforms);
                    Assert.IsEmpty(sp.UniformBlocks);

                    Assert.AreEqual(1, sp.VertexAttributes.Count);
                    Assert.IsTrue(sp.VertexAttributes.Contains("position"));

                    ShaderVertexAttribute attribute = sp.VertexAttributes["position"];
                    Assert.AreEqual("position", attribute.Name);
                    Assert.AreEqual(ShaderVertexAttributeType.FloatVector4, attribute.Datatype);
                    Assert.AreEqual(1, attribute.Length);
                }
        }
Exemplo n.º 4
0
        public void RenderTriangle()
        {
            Vector4F[] positions = new[]
            {
                new Vector4F(-0.5f, -0.5f, 0, 1),
                new Vector4F(0.5f, -0.5f, 0, 1),
                new Vector4F(0.5f, 0.5f, 0, 1)
            };

            ushort[] indices = new ushort[]
            {
                0, 1, 2
            };

            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
                    using (ShaderProgram sp = Device.CreateShaderProgram(ShaderSources.PassThroughVertexShader(), ShaderSources.PassThroughFragmentShader()))
                        using (VertexBuffer positionsBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, ArraySizeInBytes.Size(positions)))
                            using (IndexBuffer indexBuffer = Device.CreateIndexBuffer(BufferHint.StaticDraw, indices.Length * sizeof(ushort)))
                                using (VertexArray va = window.Context.CreateVertexArray())
                                {
                                    positionsBuffer.CopyFromSystemMemory(positions);
                                    indexBuffer.CopyFromSystemMemory(indices);

                                    va.Attributes[sp.VertexAttributes["position"].Location] =
                                        new VertexBufferAttribute(positionsBuffer, ComponentDatatype.Float, 4);
                                    va.IndexBuffer = indexBuffer;

                                    window.Context.Framebuffer = framebuffer;
                                    window.Context.Draw(PrimitiveType.Triangles, 0, 3, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), new SceneState());
                                    TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);

                                    //
                                    // Verify detach
                                    //
                                    window.Context.Clear(new ClearState()
                                    {
                                        Buffers = ClearBuffers.ColorBuffer, Color = Color.FromArgb(0, 255, 0)
                                    });
                                    va.Attributes[sp.VertexAttributes["position"].Location] = null;
                                    va.IndexBuffer = null;
                                    window.Context.Draw(PrimitiveType.Triangles, 0, 0, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), new SceneState());
                                    TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 0, 255, 0);

                                    //
                                    // Verify rendering without indices
                                    //
                                    va.Attributes[sp.VertexAttributes["position"].Location] =
                                        new VertexBufferAttribute(positionsBuffer, ComponentDatatype.Float, 4);
                                    window.Context.Draw(PrimitiveType.Triangles, 0, 3, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), new SceneState());
                                    TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);
                                }
        }
Exemplo n.º 5
0
 public void RenderPoint()
 {
     using (GraphicsWindow window = Device.CreateWindow(1, 1))
         using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
             using (ShaderProgram sp = Device.CreateShaderProgram(ShaderSources.PassThroughVertexShader(), ShaderSources.PassThroughFragmentShader()))
                 using (VertexArray va = TestUtility.CreateVertexArray(window.Context, sp.VertexAttributes["position"].Location))
                 {
                     window.Context.Framebuffer = framebuffer;
                     window.Context.Draw(PrimitiveType.Points, 0, 1, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), new SceneState());
                     TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);
                 }
 }
Exemplo n.º 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]);
                                }
                            }
        }