Пример #1
0
 /// <summary>
 /// Initializes a new <see cref="VertexArrayObject"/> drawing triangles using <see cref="UInt16"/> indices.
 /// </summary>
 /// <param name="indexBuffer">The <see cref="IBuffer"/> containing the index data.</param>
 /// <param name="buffers">The buffers containing the actual vertex data.</param>
 public VertexArrayObject(IReadOnlyBuffer indexBuffer, params BufferDescription[] buffers)
     : this(indexBuffer, BeginMode.Triangles, DrawElementsType.UnsignedShort, buffers)
 {
     Contract.Requires<ArgumentNullException>(buffers != null);
     Contract.Requires<ArgumentNullException>(indexBuffer != null);
     Contract.Requires<ArgumentException>(indexBuffer.Target == BufferTarget.ElementArrayBuffer);
 }
Пример #2
0
        /// <summary>
        /// Initializes a new <see cref="BufferDescription"/> setting the buffer and the attribute pointers.
        /// </summary>
        /// <param name="vertexBuffer">The data buffer.</param>
        /// <param name="vertexAttributePointers">
        /// The <see cref="VertexAttributePointer"/>s describing the layout of the data in memory.
        /// </param>
        public BufferDescription(IReadOnlyBuffer vertexBuffer, params VertexAttributePointer[] vertexAttributePointers)
            : this()
        {
            Contract.Requires<ArgumentNullException>(vertexAttributePointers != null);

            this.Buffer = vertexBuffer;
            this.VertexAttributePointers = vertexAttributePointers.FilterNull().ToImmutableArray();
        }
Пример #3
0
        /// <summary>
        /// Initializes a new <see cref="VertexArrayObject"/>.
        /// </summary>
        /// <param name="indexBuffer">The <see cref="IBuffer"/> containing the index data.</param>
        /// <param name="drawMode">The <see cref="BeginMode"/>.</param>
        /// <param name="indexBufferType">The type of the indices.</param>
        /// <param name="buffers">The buffers containing the actual vertex data.</param>
        public VertexArrayObject(IReadOnlyBuffer indexBuffer, BeginMode drawMode, DrawElementsType indexBufferType, params BufferDescription[] buffers)
        {
            Contract.Requires<ArgumentNullException>(buffers != null);
            Contract.Requires<ArgumentNullException>(indexBuffer != null);
            Contract.Requires<ArgumentException>(indexBuffer.Target == BufferTarget.ElementArrayBuffer);

            this.VerifyAccess();

            this.DrawMode = drawMode;
            this.IndexBuffer = indexBuffer;
            this.IndexType = indexBufferType;
            this.VertexBuffers = buffers.ToImmutableArray();

            this.Handle = GL.GenVertexArray();

            // Can't use Binding and using clause here because it causes a stack overflow (Bindable.Bind -> Initialize)
            try
            {
                GL.BindVertexArray(this);
                foreach (BufferDescription desc in this.VertexBuffers)
                {
                    if (desc.Buffer != null)
                    {
                        using (Binding vboBinding = desc.Buffer.Bind())
                        {
                            foreach (VertexAttributePointer vertexPointer in desc.VertexAttributePointers.OrderBy(vap => vap.Index))
                            {
                                vertexPointer.Enable();
                                vertexPointer.Apply();
                            }
                        }
                    }
                }
                this.IndexBuffer.Bind();
            }
            finally
            {
                GL.BindVertexArray(0);
            }
            this.IndexBuffer.Unbind();
        }