Esempio n. 1
0
        public Mesh(MeshVertex[] vertices, ushort[] indices)
        {
            this.Vertices = vertices;
            this.Indices  = indices;

            VA = new VertexArray();
            VA.Bind();

            VertexBuffer vb = new VertexBuffer();

            vb.SetData((uint)(System.Runtime.InteropServices.Marshal.SizeOf(typeof(MeshVertex)) * vertices.Length), vertices);

            BufferLayout layout = new BufferLayout();

            layout.Push <Vector3>("POSITION");
            layout.Push <Vector2>("TEXCOORD");
            layout.Push <Vector3>("NORMAL");
            layout.Push <Vector3>("BITANGENT");
            layout.Push <Vector3>("TANGENT");
            layout.Push <Vector4>("COLOR");

            vb.SetLayout(layout);

            VA.PushBuffer(vb);

            IB = new IndexBuffer(indices, (uint)indices.Length);

            VA.Unbind();
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the layout of the vertex buffer
        /// </summary>
        /// <param name="layout">New layout of the vertex buffer</param>
        public void SetLayout(BufferLayout layout)
        {
            this._layout = layout;

            for (int i = 0; i < layout.GetLayout().Count; i++)
            {
                BufferElement element = layout.GetLayout()[i];
                GL.EnableVertexAttribArray(i);
                GL.VertexAttribPointer(i, (int)element.Count, element.AttribType, element.Normalized, (int)layout.GetStride(), new IntPtr(element.Offset));
            }
        }