示例#1
0
        public void RenderInterleavedVertexBuffer()
        {
            string vs =
                @"#version 330

                  layout(location = og_positionVertexLocation) in vec4 position;               
                  layout(location = og_colorVertexLocation) in vec4 color;

                  out vec4 fsColor;

                  void main()                     
                  {
                      gl_Position = position; 
                      fsColor = color;
                  }";
            string fs = 
                @"#version 330
                 
                  in vec4 fsColor;
                  out vec4 FragColor;

                  void main()
                  {
                      FragColor = fsColor;
                  }";

            InterleavedVertex[] vertices = new InterleavedVertex[]
            {
                new InterleavedVertex()
                {
                    Position = new Vector4F(0, 0, 0, 1),
                    Color = new BlittableRGBA(Color.Red)
                },
                new InterleavedVertex()
                {
                    Position = new Vector4F(0, 0, 0, 1),
                    Color = new BlittableRGBA(Color.FromArgb(255, 0, 255, 0))
                }
            };

            GraphicsWindow window = Device.CreateWindow(1, 1);
            Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context);
            ShaderProgram sp = Device.CreateShaderProgram(vs, fs);
            VertexBuffer vertexBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, ArraySizeInBytes.Size(vertices));
            VertexArray va = window.Context.CreateVertexArray();
            {
                int colorOffset = SizeInBytes<Vector4F>.Value;
                vertexBuffer.CopyFromSystemMemory(vertices);

                va.Attributes[sp.VertexAttributes["position"].Location] =
                    new VertexBufferAttribute(vertexBuffer, ComponentDatatype.Float, 4, false, 0, SizeInBytes<InterleavedVertex>.Value);
                va.Attributes[sp.VertexAttributes["color"].Location] =
                    new VertexBufferAttribute(vertexBuffer, ComponentDatatype.UnsignedByte, 4, true, colorOffset, SizeInBytes<InterleavedVertex>.Value);

                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);

                window.Context.Draw(PrimitiveType.Points, 1, 1, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), new SceneState());
                TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 0, 255, 0);
            }
        }
示例#2
0
        public void RenderInterleavedVertexBuffer()
        {
            string vs =
                @"#version 330

                  layout(location = og_positionVertexLocation) in vec4 position;               
                  layout(location = og_colorVertexLocation) in vec4 color;

                  out vec4 fsColor;

                  void main()                     
                  {
                      gl_Position = position; 
                      fsColor = color;
                  }";
            string fs =
                @"#version 330
                 
                  in vec4 fsColor;
                  out vec4 FragColor;

                  void main()
                  {
                      FragColor = fsColor;
                  }";

            InterleavedVertex[] vertices = new InterleavedVertex[]
            {
                new InterleavedVertex()
                {
                    Position = new Vector4F(0, 0, 0, 1),
                    Color    = new BlittableRGBA(Color.Red)
                },
                new InterleavedVertex()
                {
                    Position = new Vector4F(0, 0, 0, 1),
                    Color    = new BlittableRGBA(Color.FromArgb(255, 0, 255, 0))
                }
            };

            GraphicsWindow window       = Device.CreateWindow(1, 1);
            Framebuffer    framebuffer  = TestUtility.CreateFramebuffer(window.Context);
            ShaderProgram  sp           = Device.CreateShaderProgram(vs, fs);
            VertexBuffer   vertexBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, ArraySizeInBytes.Size(vertices));
            VertexArray    va           = window.Context.CreateVertexArray();
            {
                int colorOffset = SizeInBytes <Vector4F> .Value;
                vertexBuffer.CopyFromSystemMemory(vertices);

                va.Attributes[sp.VertexAttributes["position"].Location] =
                    new VertexBufferAttribute(vertexBuffer, ComponentDatatype.Float, 4, false, 0, SizeInBytes <InterleavedVertex> .Value);
                va.Attributes[sp.VertexAttributes["color"].Location] =
                    new VertexBufferAttribute(vertexBuffer, ComponentDatatype.UnsignedByte, 4, true, colorOffset, SizeInBytes <InterleavedVertex> .Value);

                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);

                window.Context.Draw(PrimitiveType.Points, 1, 1, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), new SceneState());
                TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 0, 255, 0);
            }
        }