Beispiel #1
0
        public Presenter(Context glContext)
        {
            this.glContext = glContext;
            glPipeline = glContext.Pipeline;

            sourceFramebuffer = new Framebuffer(glContext);
            destinationFramebuffer = new Framebuffer(glContext);

            vertices = new Buffer(glContext, BufferTarget.ArrayBuffer, 4 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new Data(new[]
            {
                new Vertex(-1f, -1f),
                new Vertex(-1f, 1f),
                new Vertex(1f, 1f),
                new Vertex(1f, -1f)
            }));

            indices = new Buffer(glContext, BufferTarget.ElementArrayBuffer, 6 * sizeof(ushort), BufferUsageHint.StaticDraw, new Data(new ushort[]
            {
                0, 1, 2, 0, 2, 3
            }));

            sampler = new Sampler();
            sampler.SetMagFilter(TextureMagFilter.Nearest);
            sampler.SetMinFilter(TextureMinFilter.Nearest);

            string shaderErrors;
            if (!VertexShader.TryCompile(VertexShaderText, out vertexShader, out shaderErrors) ||
                !FragmentShader.TryCompile(FragmentShaderText, out fragmentShader, out shaderErrors) ||
                !ShaderProgram.TryLink(glContext, new ShaderProgramDescription
                    {
                        VertexShaders = vertexShader,
                        FragmentShaders = fragmentShader,
                        VertexAttributeNames = new[] { "in_position" },
                        SamplerNames = new[] { "Image" }
                    },
                    out program, out shaderErrors))
                throw new ArgumentException("Program errors:\n\n" + shaderErrors);

            vertexArray = new VertexArray(glContext);
            vertexArray.SetElementArrayBuffer(glContext, indices);
            vertexArray.SetVertexAttributeF(glContext, 0, vertices, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, 8, 0);
        }