Example #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);
        }
Example #2
0
        public void CalculatePackedData()
        {
            int layoutSize = GetVertexLayoutSize();

            packedData = new float[verts.Length * layoutSize];
            for (int i = 0, v = -1; i < verts.Length; i++)
            {
                for (int l = 0; l < layouts.Length; l++)
                {
                    VertexBufferLayout layout = layouts[l];
                    switch (layout.Attribute)
                    {
                    case VertexAttribute.Position:
                        for (int s = 0; s < layout.Size; s++)
                        {
                            packedData[++v] = verts[i][s];
                        }
                        break;

                    case VertexAttribute.Normal:
                        for (int s = 0; s < layout.Size; s++)
                        {
                            packedData[++v] = normals[i][s];
                        }
                        break;

                    case VertexAttribute.Tangent:
                        break;

                    case VertexAttribute.Color:
                        break;

                    case VertexAttribute.Uv0:
                        for (int s = 0; s < layout.Size; s++)
                        {
                            packedData[++v] = uvs[i][s];
                        }
                        break;

                    case VertexAttribute.Uv1:
                        break;

                    case VertexAttribute.Uv2:
                        break;

                    case VertexAttribute.Uv3:
                        break;

                    case VertexAttribute.Uv4:
                        break;

                    case VertexAttribute.Uv5:
                        break;

                    case VertexAttribute.Uv6:
                        break;

                    case VertexAttribute.Uv7:
                        break;
                    }
                }
            }
        }