Esempio n. 1
0
        /// <summary>
        /// Creates a standard VBO of type T where the length of the VBO is less than or equal to the length of the data.
        /// </summary>
        /// <typeparam name="T">The type of the data being stored in the VBO (make sure it's byte aligned).</typeparam>
        /// <param name="target">The VBO BufferTarget (usually ArrayBuffer or ElementArrayBuffer).</param>
        /// <param name="data">The data to store in the VBO.</param>
        /// <param name="hint">The buffer usage hint (usually StaticDraw).</param>
        /// <param name="length">The length of the VBO (will take the first 'length' elements from data).</param>
        /// <returns>The buffer ID of the VBO on success, 0 on failure.</returns>
        public static uint CreateVBO<T>(BufferTarget target, [In, Out] T[] data, BufferUsageHint hint, int length)
            where T : struct
        {
            uint vboHandle = Gl.GenBuffer();
            if (vboHandle == 0) return 0;

            int size = length * Marshal.SizeOf(typeof(T));

            #if MEMORY_LOGGER
            MemoryLogger.AllocateVBO(vboHandle, size);
            #endif

            Gl.BindBuffer(target, vboHandle);
            Gl.BufferData<T>(target, size, data, hint);
            Gl.BindBuffer(target, 0);
            return vboHandle;
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a standard VBO of type T where the length of the VBO is less than or equal to the length of the data.
        /// </summary>
        /// <typeparam name="T">The type of the data being stored in the VBO (make sure it's byte aligned).</typeparam>
        /// <param name="target">The VBO BufferTarget (usually ArrayBuffer or ElementArrayBuffer).</param>
        /// <param name="data">The data to store in the VBO.</param>
        /// <param name="hint">The buffer usage hint (usually StaticDraw).</param>
        /// <param name="length">The length of the VBO (will take the first 'length' elements from data).</param>
        /// <returns>The buffer ID of the VBO on success, 0 on failure.</returns>
        public static uint CreateVBO <T>(BufferTarget target, [InAttribute, OutAttribute] T[] data, BufferUsageHint hint, int position, int length)
            where T : struct
        {
            uint vboHandle = Gl.GenBuffer();

            if (vboHandle == 0)
            {
                return(0);
            }

            int offset = position * Marshal.SizeOf(typeof(T));
            int size   = length * Marshal.SizeOf(typeof(T));

#if MEMORY_LOGGER
            MemoryLogger.AllocateVBO(vboHandle, size - offset);
#endif

            Gl.BindBuffer(target, vboHandle);
            Gl.BufferData <T>(target, offset, size, data, hint);
            Gl.BindBuffer(target, 0);
            return(vboHandle);
        }