示例#1
0
        public VertexArray(Shader shader,
                           VertexList vertexes,
                           IList <uint> idxs     = null,
                           PrimitiveType prim    = PrimitiveType.Triangles,
                           BufferUsageHint usage = BufferUsageHint.StaticDraw)
        {
            Log.Assert(shader != null);
            Log.Assert(vertexes != null);

            //Vertexes = vertexes;
            Layout          = vertexes.Layout;
            indices         = idxs;
            usageHint       = usage;
            primitive       = prim;
            NumberOfIndices = indices.Count;


            vao = GL.GenVertexArray();
            GL.BindVertexArray(vao);
            buffer = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
            indexBuffer = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);
            AddVertexesToBuffer(vertexes);
            AddIndicesToBuffer(indices);
            SetupVertexPointers(shader, vertexes);
            // Unbinding the buffer *does not* alter the state of the vertex array object.
            // The association between buffer and vao is made on the GL.VertexAttribPointer() call.
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            // Except for ElementArrayBuffer's, OF COURSE.(?)
            //GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            GL.BindVertexArray(0);
        }
示例#2
0
        public GlowFilter(int screenw, int screenh)
        {
            Log.Assert(Util.IsPowerOf2(screenw));
            Log.Assert(Util.IsPowerOf2(screenh));
            width         = screenw;
            height        = screenh;
            hGlowShader   = Resources.TheResources.GetShader("glow1");
            vGlowShader   = Resources.TheResources.GetShader("glow2");
            combineShader = Resources.TheResources.GetShader("glow3");
            // XXX: This could be more efficient somehow...
            matrix = Matrix4.CreateOrthographic(1, 1, 0, 10f);

            // Create back-buffer
            DestTexture1 = new Texture(width, height);
            DestTexture2 = new Texture(width, height);

            // Create framebuffer
            fbo1 = new FramebufferObject(DestTexture1);
            fbo2 = new FramebufferObject(DestTexture2);
            //this.bb = Starmaze.Content.Images.Billboard();

            // Make a billboard to render to.
            // XXX: Aspect ratio...
            var aspectRatio = 4.0f / 3.0f;
            var bb          = new VertexList(VertexLayout.TextureVertex);

            var halfHeight = 1.0f / 2;
            var halfWidth  = 1.0f / 2;

            bb.AddTextureVertex(
                new Vector2(-halfWidth, -halfHeight),
                Color4.White,
                new Vector2(0, 0)
                );
            bb.AddTextureVertex(
                new Vector2(-halfWidth, halfHeight),
                Color4.White,
                new Vector2(0, (1.0f / aspectRatio))
                );
            bb.AddTextureVertex(
                new Vector2(halfWidth, halfHeight),
                Color4.White,
                new Vector2(1, (1.0f / aspectRatio))
                );
            bb.AddTextureVertex(
                new Vector2(halfWidth, -halfHeight),
                Color4.White,
                new Vector2(1, 0)
                );
            var indices = new uint[] {
                0, 1, 2,
                0, 2, 3,
            };

            bb1 = new VertexArray(hGlowShader, bb, idxs: indices);
            bb2 = new VertexArray(vGlowShader, bb, idxs: indices);
            bb3 = new VertexArray(combineShader, bb, idxs: indices);
        }
示例#3
0
        void AddVertexesToBuffer(VertexList verts)
        {
            Log.Assert(verts != null);
            // Not the fastest way, but the easiest.
            var vertexData = verts.ToArray();

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.LengthInBytes),
                          vertexData, usageHint);
        }
示例#4
0
        public PostprocStep(Shader shader, int screenw, int screenh)
        {
            Log.Assert(Util.IsPowerOf2(screenw));
            Log.Assert(Util.IsPowerOf2(screenh));
            width       = screenw;
            height      = screenh;
            this.shader = shader;
            // XXX: This could be more efficient somehow...
            matrix = Matrix4.CreateOrthographic(1, 1, 0, 10f);

            // Create back-buffer
            // XXX: Is ActiveTexture needed?  I THINK so...
            //GL.ActiveTexture(TextureUnit.Texture0);
            DestTexture = new Texture(width, height);

            // Create framebuffer
            fbo = new FramebufferObject(DestTexture);
            //this.bb = Starmaze.Content.Images.Billboard();

            // Make a billboard to render to.
            // XXX: Aspect ratio...
            var aspectRatio = 4.0f / 3.0f;
            var bb          = new VertexList(VertexLayout.TextureVertex);

            var halfHeight = 1.0f / 2;
            var halfWidth  = 1.0f / 2;

            bb.AddTextureVertex(
                new Vector2(-halfWidth, -halfHeight),
                Color4.White,
                new Vector2(0, 0)
                );
            bb.AddTextureVertex(
                new Vector2(-halfWidth, halfHeight),
                Color4.White,
                new Vector2(0, (1.0f / aspectRatio))
                );
            bb.AddTextureVertex(
                new Vector2(halfWidth, halfHeight),
                Color4.White,
                new Vector2(1, (1.0f / aspectRatio))
                );
            bb.AddTextureVertex(
                new Vector2(halfWidth, -halfHeight),
                Color4.White,
                new Vector2(1, 0)
                );
            var indices = new uint[] {
                0, 1, 2,
                0, 2, 3,
            };

            this.bb = new VertexArray(shader, bb, idxs: indices);
        }
示例#5
0
        /// <summary>
        /// Returns a new vertex array containing the data in the VertexModel.
        /// Makes some assumptions about what you're going to be drawing.
        /// </summary>
        /// <returns>The vertex array.</returns>
        public VertexArray ToVertexArray(Shader s)
        {
            var verts = new VertexList(VertexLayout.ColorVertex);

            for (int i = 0; i < positions.Count; i++)
            {
                verts.AddColorVertex(positions[i], colors[i]);
            }
            var vertArray = new VertexArray(s, verts, indices,
                                            prim: PrimitiveType.Triangles, usage: BufferUsageHint.StaticDraw);

            return(vertArray);
        }
示例#6
0
        void SetupVertexPointers(Shader shader, VertexList vertexes)
        {
            Log.Assert(shader != null);
            Log.Assert(vertexes != null);

            var byteOffset = 0;

            foreach (var vertexMember in Layout.Members)
            {
                var location = shader.VertexAttributeLocation(vertexMember.Name);
                GL.EnableVertexAttribArray(location);
                GL.VertexAttribPointer(location, vertexMember.Count, VertexAttribPointerType.Float,
                                       false, Layout.ByteCount, byteOffset);
                byteOffset += vertexMember.Count * VertexMember.ElementBytes;
            }
        }