示例#1
0
        /// <summary>
        /// 在OpenGL中创建VAO。
        /// 创建的过程就是执行一次渲染的过程。
        /// <para>Creates VAO and bind it to specified VBOs.</para>
        /// <para>The whole process of binding is also the process of rendering.</para>
        /// </summary>
        /// <param name="shaderProgram"></param>
        public void Initialize(ShaderProgram shaderProgram)
        {
            if (this.Id != 0)
            {
                return;
            }
            //{ throw new Exception(string.Format("Id[{0}] is already generated!", this.Id)); }

            if (glGenVertexArrays == null)
            {
                glGenVertexArrays    = OpenGL.GetDelegateFor <OpenGL.glGenVertexArrays>();
                glBindVertexArray    = OpenGL.GetDelegateFor <OpenGL.glBindVertexArray>();
                glDeleteVertexArrays = OpenGL.GetDelegateFor <OpenGL.glDeleteVertexArrays>();
            }

            glGenVertexArrays(1, ids);

            this.Bind();// this vertex array object will record all stand-by actions.
            VertexBuffer[] vertexAttributeBuffers = this.VertexAttributeBuffers;
            if (vertexAttributeBuffers != null)
            {
                foreach (VertexBuffer item in vertexAttributeBuffers)
                {
                    item.Standby(shaderProgram);
                }
            }
            this.Unbind();// this vertex array object has recorded all stand-by actions.
        }
示例#2
0
        /// <summary>
        /// 一个vertex array object。(即VAO)
        /// <para>VAO是用来管理VBO的。可以进一步减少DrawCall。</para>
        /// </summary>
        /// <param name="propertyBufferPtrs">给出此VAO要管理的所有VBO。</param>
        public VertexArrayObject(IndexBufferPtr indexBufferPtr, params BufferPtr[] propertyBufferPtrs)
        {
            if (indexBufferPtr == null)
            {
                throw new ArgumentNullException("indexBufferRenderer");
            }
            if (propertyBufferPtrs == null || propertyBufferPtrs.Length == 0)
            {
                throw new ArgumentNullException("propertyBuffers");
            }

            if (glGenVertexArrays == null)
            {
                glGenVertexArrays    = OpenGL.GetDelegateFor <OpenGL.glGenVertexArrays>();
                glBindVertexArray    = OpenGL.GetDelegateFor <OpenGL.glBindVertexArray>();
                glDeleteVertexArrays = OpenGL.GetDelegateFor <OpenGL.glDeleteVertexArrays>();
            }

            this.indexBufferPtr     = indexBufferPtr;
            this.propertyBufferPtrs = propertyBufferPtrs;
        }
示例#3
0
        /// <summary>
        /// 一个vertex array object。(即VAO)
        /// <para>VAO是用来管理VBO的。可以进一步减少DrawCall。</para>
        /// </summary>
        /// <param name="propertyBufferPtrs">给出此VAO要管理的所有VBO。</param>
        public VertexArrayObject(IndexBufferPtr indexBufferPtr, params BufferPtr[] propertyBufferPtrs)
        {
            if (indexBufferPtr == null)
            {
                throw new ArgumentNullException("indexBufferRenderer");
            }
            if (propertyBufferPtrs == null || propertyBufferPtrs.Length == 0)
            {
                throw new ArgumentNullException("propertyBuffers");
            }

            if (glGenVertexArrays == null)
            {
                glGenVertexArrays = OpenGL.GetDelegateFor<OpenGL.glGenVertexArrays>();
                glBindVertexArray = OpenGL.GetDelegateFor<OpenGL.glBindVertexArray>();
                glDeleteVertexArrays = OpenGL.GetDelegateFor<OpenGL.glDeleteVertexArrays>();
            }

            this.IndexBufferPtr = indexBufferPtr;
            this.propertyBufferPtrs = propertyBufferPtrs;
        }
示例#4
0
        /// <summary>
        /// 在OpenGL中创建VAO。
        /// 创建的过程就是执行一次渲染的过程。
        /// <para>Creates VAO and bind it to specified VBOs.</para>
        /// <para>The whole process of binding is also the process of rendering.</para>
        /// </summary>
        /// <param name="shaderProgram"></param>
        public void Initialize(ShaderProgram shaderProgram)
        {
            if (this.Id != 0)
            { throw new Exception(string.Format("Id[{0}] is already generated!", this.Id)); }

            if (glGenVertexArrays == null)
            {
                glGenVertexArrays = OpenGL.GetDelegateFor<OpenGL.glGenVertexArrays>();
                glBindVertexArray = OpenGL.GetDelegateFor<OpenGL.glBindVertexArray>();
                glDeleteVertexArrays = OpenGL.GetDelegateFor<OpenGL.glDeleteVertexArrays>();
            }

            glGenVertexArrays(1, ids);

            this.Bind();// this vertex array object will record all stand-by actions.
            VertexBuffer[] vertexAttributeBuffers = this.VertexAttributeBuffers;
            if (vertexAttributeBuffers != null)
            {
                foreach (VertexBuffer item in vertexAttributeBuffers)
                {
                    item.Standby(shaderProgram);
                }
            }
            this.Unbind();// this vertex array object has recorded all stand-by actions.
        }