Exemple #1
0
        /// <summary>
        /// 将VBO上传到GPU后,就得到VBO的指针。CPU内存中的VBO数据就可以释放掉了。
        /// VBO's pointer got from Buffer's GetBufferPtr() method. It's totally OK to free memory of unmanaged array stored in this buffer object now.
        /// </summary>
        /// <param name="bufferId">用glGenBuffers()得到的VBO的Id。<para>Id got from glGenBuffers();</para></param>
        /// <param name="length">此VBO含有多个个元素?<para>How many elements?</para></param>
        /// <param name="byteLength">此VBO中的数据在内存中占用多少个字节?<para>How many bytes in this buffer?</para></param>
        internal BufferPtr(uint bufferId, int length, int byteLength)
        {
            if (glBindBuffer == null)
            {
                glBindBuffer     = OpenGL.GetDelegateFor <OpenGL.glBindBuffer>();
                glDeleteBuffers  = OpenGL.GetDelegateFor <OpenGL.glDeleteBuffers>();
                glMapBuffer      = OpenGL.GetDelegateFor <OpenGL.glMapBuffer>();
                glMapBufferRange = OpenGL.GetDelegateFor <OpenGL.glMapBufferRange>();
                glUnmapBuffer    = OpenGL.GetDelegateFor <OpenGL.glUnmapBuffer>();
            }

            this.BufferId   = bufferId;
            this.Length     = length;
            this.ByteLength = byteLength;
        }
Exemple #2
0
        /// <summary>
        /// Start to read/write buffer.
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <param name="access"></param>
        /// <param name="bind"></param>
        /// <returns></returns>
        public virtual IntPtr MapBufferRange(int offset, int length, MapBufferRangeAccess access, bool bind = true)
        {
            if (bind)
            {
                if (glBindBuffer == null)
                {
                    glBindBuffer = OpenGL.GetDelegateFor <OpenGL.glBindBuffer>();
                }
                glBindBuffer((uint)this.Target, this.BufferId);
            }

            if (glMapBufferRange == null)
            {
                glMapBufferRange = OpenGL.GetDelegateFor <OpenGL.glMapBufferRange>();
            }
            IntPtr pointer = glMapBufferRange((uint)this.Target, offset, length, (uint)access);

            return(pointer);
        }
Exemple #3
0
        /// <summary>
        /// Start to read/write buffer.
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <param name="access"></param>
        /// <param name="bind"></param>
        /// <returns></returns>
        public virtual IntPtr MapBufferRange(int offset, int length, MapBufferRangeAccess access, bool bind = true)
        {
            if (bind)
            {
                if (glBindBuffer == null) { glBindBuffer = OpenGL.GetDelegateFor<OpenGL.glBindBuffer>(); }
                glBindBuffer((uint)this.Target, this.BufferId);
            }

            if (glMapBufferRange == null) { glMapBufferRange = OpenGL.GetDelegateFor<OpenGL.glMapBufferRange>(); }
            IntPtr pointer = glMapBufferRange((uint)this.Target, offset, length, (uint)access);
            return pointer;
        }