Exemplo n.º 1
0
        public unsafe void BindArrayBuffer <T>(T[] verts, int stride, int[] attributeLengths, int[] attributeOffsets, BufferUsageHint hint = BufferUsageHint.GL_STATIC_DRAW) where T : IInterleavedVertex
        {
            GlBindings.GenVertexArrays(1, out m_VaoId);

            GlBindings.GenBuffers(1, out m_VertexArrayBufferId);
            GlBindings.BindVertexArray(m_VaoId);

            GCHandle handle       = GCHandle.Alloc(verts, GCHandleType.Pinned);
            IntPtr   ptrVerticies = handle.AddrOfPinnedObject();

            GlBindings.BindBuffer(BufferTarget.GL_ARRAY_BUFFER, m_VertexArrayBufferId);
            GlBindings.BufferData(BufferTarget.GL_ARRAY_BUFFER, stride * verts.Length, ptrVerticies, hint);
            handle.Free();

            // Setup Attributes
            for (int i = 0; i < attributeLengths.Length; i++)
            {
                GlBindings.VertexAttribPointer(i, attributeLengths[i], VertexAttribPointerType.Float, 0, stride, attributeOffsets[i]);
                GlBindings.EnableVertexAttribArray(i);
            }

            m_VertexCount = verts.Length;

            GlBindings.BindBuffer(BufferTarget.GL_ARRAY_BUFFER, 0);
            GlBindings.BindVertexArray(0);
        }
Exemplo n.º 2
0
        public unsafe void SetVertexData <T>(T[] verts)
        {
            GCHandle handleVerticies = GCHandle.Alloc(verts, GCHandleType.Pinned);

            IntPtr ptrVerticies = handleVerticies.AddrOfPinnedObject();

            GlBindings.BindBuffer(BufferTarget.GL_ARRAY_BUFFER, m_VertexArrayBufferId);
            GlBindings.BufferData(BufferTarget.GL_ARRAY_BUFFER, m_Stride * verts.Length, ptrVerticies, m_BufferUsage);

            handleVerticies.Free();
        }
Exemplo n.º 3
0
        public unsafe void SetIndexData32(uint[] indicies)
        {
            GCHandle handleIndicies = GCHandle.Alloc(indicies, GCHandleType.Pinned);

            IntPtr ptrIndicies = handleIndicies.AddrOfPinnedObject();

            GlBindings.BindBuffer(BufferTarget.GL_ELEMENT_ARRAY_BUFFER, m_IndexBufferId);
            GlBindings.BufferData(BufferTarget.GL_ELEMENT_ARRAY_BUFFER, indicies.Length * 4, ptrIndicies, m_BufferUsage);   // TODO Support UnsignedInt and UnsignedShort
            handleIndicies.Free();

            m_VertexCount = indicies.Length;
        }