Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// Initalises the Vertex Array Object without seting any vertex or index data
        /// </summary>
        public unsafe void InitElementsArrayBuffer <T>(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.GenBuffers(1, out m_IndexBufferId);

            GlBindings.BindVertexArray(m_VaoId);

            GlBindings.BindBuffer(BufferTarget.GL_ARRAY_BUFFER, m_VertexArrayBufferId);

            GlBindings.BindBuffer(BufferTarget.GL_ELEMENT_ARRAY_BUFFER, m_IndexBufferId);


            // 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 = indicies.Length;
            m_Stride      = stride;
            m_BufferUsage = hint;

            GlBindings.BindBuffer(BufferTarget.GL_ARRAY_BUFFER, 0);
            GlBindings.BindVertexArray(0);
        }
Beispiel #3
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();
        }
Beispiel #4
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;
        }
Beispiel #5
0
        public unsafe void UpdateVertexData <T>(T[] verts, int offset, int vertexCount)
        {
            GCHandle handleVerticies = GCHandle.Alloc(verts, GCHandleType.Pinned);

            IntPtr ptrVerticies = handleVerticies.AddrOfPinnedObject();


            GlBindings.BindBuffer(BufferTarget.GL_ARRAY_BUFFER, m_VertexArrayBufferId);
            GlBindings.BufferSubData(BufferTarget.GL_ARRAY_BUFFER, (IntPtr)0, (IntPtr)(m_Stride * vertexCount), ptrVerticies);

            handleVerticies.Free();
        }
Beispiel #6
0
        public unsafe void UpdateIndexData32(uint[] indicies)
        {
            GCHandle handleIndicies = GCHandle.Alloc(indicies, GCHandleType.Pinned);

            IntPtr ptrIndicies = handleIndicies.AddrOfPinnedObject();

            GlBindings.BindBuffer(BufferTarget.GL_ELEMENT_ARRAY_BUFFER, m_IndexBufferId);
            GlBindings.BufferSubData(BufferTarget.GL_ELEMENT_ARRAY_BUFFER, (IntPtr)0, (IntPtr)(4 * indicies.Length), ptrIndicies);
            handleIndicies.Free();

            m_VertexCount = indicies.Length;
        }