Exemplo n.º 1
0
        private void MakeVAO()
        {
            vbo_xy = new BufferObject <float>(quad_xy, BufferTarget.ArrayBuffer);
            ebo_ix = new BufferObject <byte>(quad_el, BufferTarget.ElementArrayBuffer);
            vao    = new VertexArrayObject();

            vao.Bind();
            vbo_xy.Bind();
            vao.SetAttrib(0, 2, VertexAttribPointerType.Float);

            int stride = this.InstanceStride;
            var vbo    = this.VBO;

            vbo.Bind();
            vao.SetAttrib(1, 4, VertexAttribPointerType.Float, false, stride, 0, 1);
            vao.SetAttrib(2, 4, VertexAttribPointerType.Float, false, stride, 16, 1);
            vao.SetAttrib(3, 4, VertexAttribPointerType.Float, false, stride, 32, 1);
            vao.SetAttrib(4, 4, VertexAttribPointerType.Float, false, stride, 48, 1);
            vao.SetAttrib(5, 4, VertexAttribPointerType.UnsignedByte, true, stride, 64, 1);
            vbo.Unbind();
            vao.Enable(0);
            vao.Enable(1);
            vao.Enable(2);
            vao.Enable(3);
            vao.Enable(4);
            vao.Enable(5);
            vao.Unbind();
        }
Exemplo n.º 2
0
        protected override void BeginSubmit(FrameBuffer renderTarget)
        {
            var projection = renderTarget.Projection;

            program.Bind();
            GL.UniformMatrix4(program["projection"], false, ref projection);

            vao.Bind();
            ebo_ix.Bind();
        }
Exemplo n.º 3
0
        private void Blit(FrameBuffer src, FrameBuffer dst)
        {
            dst.SetViewport();
            dst.Bind();

            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.ActiveTexture(TextureUnit.Texture0);
            src.ColorAttachment.Bind();

            ppVao.Bind();
            ppEbo.Bind();
            GL.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedByte, 0);
            ppEbo.Unbind();
            ppVao.Unbind();
            src.ColorAttachment.Unbind();
        }
Exemplo n.º 4
0
        protected override void BeginSubmit(FrameBuffer renderTarget)
        {
            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, paletteTexture.Handle);

            // prepare the program
            var projection = renderTarget.Projection;

            program.Bind();
            GL.UniformMatrix4(program["projection"], false, ref projection);
            // tell the program on which texture units the textures are
            GL.Uniform1(program["sprite"], 0);
            GL.Uniform1(program["palette"], 1);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);
            vao.Bind();
            ebo_ix.Bind();
        }
Exemplo n.º 5
0
        /// Constructor.
        public Renderer(Display display)
        {
            this.display     = display;
            this.spriteBatch = new SpriteBatch(
                LoadShaderProgram("vert.glsl", "frag.glsl"),
                2048
                );
            this.rectangleBatch = new RectangleBatch(
                LoadShaderProgram("rect.v.glsl", "rect.f.glsl"),
                256
                );

            vboQuadPosition = new BufferObject <float>(quad_xy, BufferTarget.ArrayBuffer);
            vboQuadTexcoord = new BufferObject <float>(quad_uv, BufferTarget.ArrayBuffer);
            ppVao           = new VertexArrayObject();
            ppVao.Bind();
            vboQuadPosition.Bind();
            ppVao.SetAttrib(0, 2, VertexAttribPointerType.Float);
            vboQuadTexcoord.Bind();
            ppVao.SetAttrib(1, 2, VertexAttribPointerType.Float);
            ppVao.Enable(0);
            ppVao.Enable(1);
            ppVao.Unbind();
            ppEbo = new BufferObject <byte>(quad_ix, BufferTarget.ElementArrayBuffer);

            frameBuffers      = new FrameBuffer[2];
            frameBuffers[0]   = new FrameBuffer(display.Resolution, PixelFormat.Rgba);
            frameBuffers[1]   = new FrameBuffer(display.Resolution, PixelFormat.Rgba);
            activeFramebuffer = 0;

            this.screenBuffer = new FrameBuffer(display.Viewport);

            this.blit = LoadShaderProgram("blit.v.glsl", "blit.f.glsl");
            this.gray = LoadShaderProgram("blit.v.glsl", "gray.f.glsl");

            screenBuffer.SetViewport();
        }