Exemple #1
0
        private unsafe void GenerateVao()
        {
            fixed(uint *address = &vao)
            {
                glGenVertexArrays(1, address);
            }

            glBindVertexArray(vao);
            glBindBuffer(GL_ARRAY_BUFFER, bufferId);

            if (indexId > 0)
            {
                glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId);
            }

            for (int i = 0; i < attributes.Count; i++)
            {
                ShaderAttribute attribute = attributes[i];

                uint index = (uint)i;

                if (attribute.IsInteger)
                {
                    glVertexAttribIPointer(index, (int)attribute.Count, attribute.Type, Stride,
                                           (void *)attribute.Offset);
                }
                else
                {
                    glVertexAttribPointer(index, (int)attribute.Count, attribute.Type, attribute.IsNormalized, Stride,
                                          (void *)attribute.Offset);
                }

                glEnableVertexAttribArray(index);
            }

            // This assumes that shaders won't be bound twice.
            attributes        = null;
            IsBindingComplete = true;
        }
Exemple #2
0
        public unsafe void Bind(uint bufferId, uint indexBufferId)
        {
            this.bufferId      = bufferId;
            this.indexBufferId = indexBufferId;

            glBindVertexArray(vao);

            // The index buffer ID can be zero when array rendering is being used.
            if (indexBufferId != 0)
            {
                glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferId);
            }

            glBindBuffer(GL_ARRAY_BUFFER, bufferId);

            for (int i = 0; i < attributes.Count; i++)
            {
                ShaderAttribute attribute = attributes[i];

                uint index = (uint)i;

                if (attribute.IsInteger)
                {
                    glVertexAttribIPointer(index, (int)attribute.Count, attribute.Type, Stride,
                                           (void *)attribute.Offset);
                }
                else
                {
                    glVertexAttribPointer(index, (int)attribute.Count, attribute.Type, attribute.IsNormalized, Stride,
                                          (void *)attribute.Offset);
                }

                glEnableVertexAttribArray(index);
            }

            // This assumes that shaders won't be bound twice.
            attributes      = null;
            BindingComplete = true;
        }