Exemplo n.º 1
0
        private void BindMaterial(Material mat)
        {
            Ogl.BindVertexArray(vertexArrayHandle);

            Ogl.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
            Ogl.BufferData(BufferTarget.ArrayBuffer, packedData.Length * sizeof(float), packedData, BufferUsageHint.StaticDraw);

            Ogl.BindBuffer(BufferTarget.ElementArrayBuffer, trisBuffer);
            Ogl.BufferData(BufferTarget.ElementArrayBuffer, tris.Length * sizeof(uint), tris, BufferUsageHint.StaticDraw);

            VertexBufferLayout[] layouts = GetVertexLayout();
            int layoutSize   = GetVertexLayoutSize();
            int layoutOffset = 0;

            for (int l = 0; l < layouts.Length; l++)
            {
                VertexBufferLayout layout = layouts[l];
                int location = layout.Attribute.GetAttributeLocation(mat);

                if (location == -1)
                {
                    continue;
                }

                int stride = layoutSize * layout.Format.ByteSize();
                Ogl.EnableVertexAttribArray(location);
                Ogl.VertexAttribPointer(location, layout.Size, layout.Format.ToOpenGlAttribType(), false, stride, layoutOffset);

                layoutOffset += layout.Size * layout.Format.ByteSize();
            }

            Ogl.BindVertexArray(0);
        }