public void AddVertexBufferWithNullLayout()
        {
            IVertexArray  vertexArray  = new OpenGLVertexArray();
            IVertexBuffer vertexBuffer = new OpenGLVertexBuffer(new float[0]);

            Assert.Throws <ArgumentNullException>(() =>
                                                  vertexArray.Add(vertexBuffer));
        }
        public void AddVertexBuffer(int count)
        {
            IVertexArray vertexArray = new OpenGLVertexArray();

            for (int i = 0; i < count; i++)
            {
                IVertexBuffer vertexBuffer = new OpenGLVertexBuffer(new float[] { 0, 0 })
                {
                    Layout = new OpenGLBufferLayout(
                        new BufferElement(ShaderDataType.Float2, "TestsBuffer")
                        )
                };
                vertexArray.Add(vertexBuffer);
            }

            Assert.NotNull(vertexArray.VertexBuffers);
            Assert.Equal(count, vertexArray.VertexBuffers.Count());
        }
        /// <summary>
        /// Binds the specified buffer's vertex attributes to the currently cached program.
        /// </summary>
        private void BindVertexAttributesForBuffer(OpenGLVertexBuffer vbuffer, Int32 instanceFrequency)
        {
            gl.BindBuffer(gl.GL_ARRAY_BUFFER, vbuffer.OpenGLName);
            gl.ThrowIfError();

            var position = 0u;

            foreach (var element in vbuffer.VertexDeclaration)
            {
                var name = GetVertexAttributeNameFromUsage(element.Usage, element.Index);
                var size = 0;
                var stride = 0;
                var normalize = false;
                var integer = false;
                var type = GetVertexFormatGL(element.Format, out size, out stride, out normalize, out integer);

                var location = gl.GetAttribLocation(program, name);
                if (location >= 0)
                {
                    gl.VertexAttribDivisor((uint)location, (uint)instanceFrequency);
                    gl.ThrowIfError();

                    unsafe
                    {
                        if (integer && !gl.IsGLES2)
                        {
                            gl.VertexAttribIPointer((uint)location, size, type, vbuffer.VertexDeclaration.VertexStride, (void*)(position));
                            gl.ThrowIfError();
                        }
                        else
                        {
                            gl.VertexAttribPointer((uint)location, size, type, normalize, vbuffer.VertexDeclaration.VertexStride, (void*)(position));
                            gl.ThrowIfError();
                        }
                    }

                    gl.EnableVertexAttribArray((uint)location);
                    gl.ThrowIfError();
                }

                position += (uint)stride;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="VertexBufferBinding"/> structure.
 /// </summary>
 /// <param name="vbuffer">The vertex buffer which is bound to the geometry stream.</param>
 /// <param name="instanceFrequency">The number of instances which are drawn for each
 /// set of data in the vertex buffer.</param>
 public VertexBufferBinding(OpenGLVertexBuffer vbuffer, Int32 instanceFrequency)
 {
     this.VertexBuffer = vbuffer;
     this.InstanceFrequency = instanceFrequency;
 }
        /// <summary>
        /// Binds the specified buffer's vertex attributes to the currently cached program.
        /// </summary>
        /// <param name="vbuffer">The vertex buffer to bind to the cached program.</param>
        private void BindVertexAttributesForBuffer(OpenGLVertexBuffer vbuffer)
        {
            gl.BindBuffer(gl.GL_ARRAY_BUFFER, vbuffer.OpenGLName);
            gl.ThrowIfError();

            var position = 0u;

            foreach (var element in vbuffer.VertexDeclaration)
            {
                var name = GetVertexAttributeNameFromUsage(element.Usage, element.Index);
                var size = 0;
                var stride = 0;
                var type = GetVertexFormatGL(element.Format, out size, out stride);

                var location = gl.GetAttribLocation(program, name);
                if (location >= 0)
                {
                    unsafe
                    {
                        gl.VertexAttribPointer((uint)location, size, type, true, vbuffer.VertexDeclaration.VertexStride, (void*)(position));
                        gl.ThrowIfError();
                    }

                    gl.EnableVertexAttribArray((uint)location);
                    gl.ThrowIfError();
                }

                position += (uint)stride;
            }
        }