Esempio n. 1
0
        public Mesh(GeometryData data)
        {
            VertexCount = data.VertexCount;

            VertexArrayObject = GL.GenVertexArray();

            GL.BindVertexArray(VertexArrayObject);

            Buffer = GL.GenBuffer();

            GL.BindBuffer(BufferTarget.ArrayBuffer, Buffer);
            GL.BufferData(BufferTarget.ArrayBuffer, data.Data.Length, data.Data, BufferUsageHint.StaticDraw);

            ElementBuffer = GL.GenBuffer();

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBuffer);
            GL.BufferData(BufferTarget.ElementArrayBuffer, data.Indices.Length * 4, data.Indices, BufferUsageHint.StaticDraw);

            MeshHelper.ApplyVertexAttribs(data.Attribs);

            ElementBufferSize = data.Indices.Length;

            GL.BindVertexArray(0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
        }
Esempio n. 2
0
        public Mesh(GeometryData data)
        {
            VertexCount = data.VertexCount;

            VertexArrayObject = GL.GenVertexArray();

            if (VertexArrayObject == 0)
            {
                throw new Exception(GL.GetError().ToString());
            }

            GL.BindVertexArray(VertexArrayObject);

            Buffer = GL.GenBuffer();

            if (Buffer == 0)
            {
                throw new Exception(GL.GetError().ToString());
            }

            GL.BindBuffer(BufferTarget.ArrayBuffer, Buffer);
            GL.BufferData(BufferTarget.ArrayBuffer, data.Data.Length, data.Data, BufferUsageHint.StaticDraw);

            ElementBuffer = GL.GenBuffer();

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBuffer);
            GL.BufferData(BufferTarget.ElementArrayBuffer, data.Indices.Length * 4, data.Indices, BufferUsageHint.StaticDraw);

            MeshHelper.ApplyVertexAttribs(data.Attribs, InstanceBuffer);

            ElementBufferSize = data.Indices.Length;

            GL.BindVertexArray(0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
        }