예제 #1
0
        /// <summary>
        /// Creates a vertex array object based on a series of attribute arrays and and attribute names.
        /// </summary>
        /// <param name="program">The shader program that contains the attributes to be bound to.</param>
        /// <param name="vbo">The VBO containing all of the attribute data.</param>
        /// <param name="sizes">An array of sizes which correspond to the size of each attribute.</param>
        /// <param name="types">An array of the attribute pointer types.</param>
        /// <param name="targets">An array of the buffer targets.</param>
        /// <param name="names">An array of the attribute names.</param>
        /// <param name="stride">The stride of the VBO.</param>
        /// <param name="eboHandle">The element buffer handle.</param>
        /// <returns>The vertex array object (VAO) ID.</returns>
        public static uint CreateVAO(ShaderProgram program, uint vbo, int[] sizes, VertexAttribPointerType[] types, BufferTarget[] targets, string[] names, int stride, uint eboHandle)
        {
            uint vaoHandle = Gl.GenVertexArray();
            Gl.BindVertexArray(vaoHandle);

            int offset = 0;

            for (uint i = 0; i < names.Length; i++)
            {
                Gl.EnableVertexAttribArray(i);
                Gl.BindBuffer(targets[i], vbo);
                Gl.VertexAttribPointer(i, sizes[i], types[i], true, stride, new IntPtr(offset));
                Gl.BindAttribLocation(program.ProgramID, i, names[i]);
            }

            Gl.BindBuffer(BufferTarget.ElementArrayBuffer, eboHandle);
            Gl.BindVertexArray(0);

            return vaoHandle;
        }