示例#1
0
        public VAO CreateString(ShaderProgram Program, string Text)
        {
            Vector3[] vertices = new Vector3[Text.Length * 4];
            Vector2[] uvs      = new Vector2[Text.Length * 4];
            int[]     indices  = new int[Text.Length * 6];

            for (int i = 0; i < Text.Length; i++)
            {
                // Note: These are fixed width fonts so just use 2x2 quads (-1..1)
                vertices[i * 4 + 0] = new Vector3(-1 + i * 2, 1, 0);
                vertices[i * 4 + 1] = new Vector3(-1 + i * 2, -1, 0);
                vertices[i * 4 + 2] = new Vector3(1 + i * 2, 1, 0);
                vertices[i * 4 + 3] = new Vector3(1 + i * 2, -1, 0);

                UVPair ch = Character[Text[i] > 256 ? ' ' : Text[i]];
                uvs[i * 4 + 0] = new Vector2(ch.Topleft.x, ch.BottomRight.y);
                uvs[i * 4 + 1] = ch.Topleft;
                uvs[i * 4 + 2] = ch.BottomRight;
                uvs[i * 4 + 3] = new Vector2(ch.BottomRight.x, ch.Topleft.y);

                indices[i * 6 + 0] = i * 4 + 1;
                indices[i * 6 + 1] = i * 4 + 0;
                indices[i * 6 + 2] = i * 4 + 2;
                indices[i * 6 + 3] = i * 4 + 1;
                indices[i * 6 + 4] = i * 4 + 2;
                indices[i * 6 + 5] = i * 4 + 3;
            }

            // Create the vertex buffer objects and then create the array object
            VBO <Vector3> vertexArray  = new VBO <Vector3>(vertices, BufferTarget.ArrayBuffer, BufferUsageHint.StaticRead);
            VBO <Vector2> uvArray      = new VBO <Vector2>(uvs, BufferTarget.ArrayBuffer, BufferUsageHint.StaticRead);
            VBO <int>     elementArray = new VBO <int>(indices, BufferTarget.ElementArrayBuffer, BufferUsageHint.StaticRead);

            return(new VAO(Program, vertexArray, uvArray, elementArray));
        }
示例#2
0
        /// <summary>
        /// Binds a VBO to a shader attribute.
        /// </summary>
        /// <param name="buffer">The VBO to bind to the shader attribute.</param>
        /// <param name="program">The shader program whose attribute will be bound to.</param>
        /// <param name="attributeName">The name of the shader attribute to be bound to.</param>
        public static void BindBufferToShaderAttribute <T>(VBO <T> buffer, ShaderProgram program, string attributeName)
            where T : struct
        {
            uint location = (uint)Gl.GetAttribLocation(program.ProgramID, attributeName);

            Gl.EnableVertexAttribArray(location);
            Gl.BindBuffer(buffer);
            Gl.VertexAttribPointer(location, buffer.Size, buffer.PointerType, true, Marshal.SizeOf(typeof(T)), IntPtr.Zero);
        }
示例#3
0
        public VAO(ShaderProgram program, VBO <T1> vbo1, string attribName, VBO <int> elementArray)
            : base(program)
        {
            GenericVAO.GenericVBO[] vbos = new GenericVBO[2];
            vbos[0] = new GenericVBO(vbo1.vboID, attribName, vbo1.Count, vbo1.Size, vbo1.PointerType, vbo1.BufferTarget);
            vbos[1] = new GenericVBO(elementArray.vboID, "", elementArray.Count, elementArray.Size, elementArray.PointerType, elementArray.BufferTarget);

            Init(vbos);
        }
示例#4
0
        public VAO(ShaderProgram program, VBO <T1> vbo1, string attribName, VBO <int> elementArray)
            : base(program)
        {
            IGenericVBO[] vbos = new IGenericVBO[2];
            vbos[0] = new GenericVBO <T1>(vbo1, attribName);
            vbos[1] = new GenericVBO <int>(elementArray);

            Init(vbos);
        }
示例#5
0
        public VAO(ShaderProgram program, VBO <T1> vbo1, string[] attribNames, VBO <int> elementArray)
            : base(program)
        {
            if (attribNames.Length != 1)
            {
                throw new Exception(string.Format("Expected an array of 1 name, but instead got {0}.", attribNames.Length));
            }

            GenericVAO.GenericVBO[] vbos = new GenericVBO[2];
            vbos[0] = new GenericVBO(vbo1.vboID, attribNames[0], vbo1.Count, vbo1.Size, vbo1.PointerType, vbo1.BufferTarget);
            vbos[1] = new GenericVBO(elementArray.vboID, "", elementArray.Count, elementArray.Size, elementArray.PointerType, elementArray.BufferTarget);

            Init(vbos);
        }
示例#6
0
        public VAO(ShaderProgram program, VBO <T1> vbo1, string[] attribNames, VBO <int> elementArray)
            : base(program)
        {
            if (attribNames.Length != 1)
            {
                throw new Exception(string.Format("Expected an array of 1 name, but instead got {0}.", attribNames.Length));
            }

            IGenericVBO[] vbos = new IGenericVBO[2];
            vbos[0] = new GenericVBO <T1>(vbo1, attribNames[0]);
            vbos[1] = new GenericVBO <int>(elementArray);

            Init(vbos);
        }
示例#7
0
        /// <summary>
        /// Deletes the vertex array from the GPU and will also dispose of any child VBOs if (DisposeChildren == true).
        /// </summary>
        public void Dispose()
        {
            // first try to dispose of the vertex array
            if (vaoID != 0)
            {
                Gl.DeleteVertexArrays(1, new uint[] { vaoID });

                vaoID = 0;
            }

            // children must be disposed of separately since OpenGL 2.1 will not have a vertex array
            if (DisposeChildren)
            {
                if (vertex != null)
                {
                    vertex.Dispose();
                }
                if (normal != null)
                {
                    normal.Dispose();
                }
                if (tangent != null)
                {
                    tangent.Dispose();
                }
                if (uv != null)
                {
                    uv.Dispose();
                }
                if (element != null)
                {
                    element.Dispose();
                }

                vertex  = null;
                normal  = null;
                tangent = null;
                uv      = null;
                element = null;
            }
        }
示例#8
0
 /// <summary>
 /// Binds a VBO based on the buffer target.
 /// </summary>
 /// <param name="buffer">The VBO to bind.</param>
 public static void BindBuffer <T>(VBO <T> buffer)
     where T : struct
 {
     Gl.BindBuffer(buffer.BufferTarget, buffer.vboID);
 }
示例#9
0
        public VAO(ShaderProgram program, VBO <Vector3> vertex, VBO <Vector3> normal, VBO <Vector3> tangent, VBO <Vector2> uv, VBO <int> element)
        {
            this.Program     = program;
            this.VertexCount = element.Count;
            this.DrawMode    = BeginMode.Triangles;
            this.vertex      = vertex;
            this.normal      = normal;
            this.tangent     = tangent;
            this.uv          = uv;
            this.element     = element;

            if (Gl.Version() >= 3)
            {
                vaoID = Gl.GenVertexArray();
                if (vaoID != 0)
                {
                    Gl.BindVertexArray(vaoID);
                    BindAttributes(this.Program);
                }
                Gl.BindVertexArray(0);

                Draw = DrawOGL3;
            }
            else
            {
                Draw = DrawOGL2;
            }
        }
示例#10
0
 public VAO(ShaderProgram program, VBO <Vector3> vertex, VBO <Vector3> normal, VBO <Vector2> uv, VBO <int> element)
     : this(program, vertex, normal, null, uv, element)
 {
 }
示例#11
0
 public GenericVBO(VBO <T> vbo, string name)
 {
     this.vbo  = vbo;
     this.name = name;
 }
示例#12
0
 public GenericVBO(VBO <T> vbo) : this(vbo, string.Empty)
 {
 }