public void SetBufferData(OpenGL gl, OGLBufferDataTarget target, uint[] indices, OGLModelUsage usage, bool compress) { Size = indices.Length; Stride = 1; if (compress) { if (indices.Max() < byte.MaxValue) { // use a byte buffer instead in order to decrease the buffer size. var newIdxs = indices.Select(x => (byte)x).ToArray(); SetBufferData(gl, OGLBufferDataTarget.ArrayBuffer, newIdxs, OGLModelUsage.StaticCopy, Stride); return; } else if (indices.Max() < ushort.MaxValue) { // use a ushort buffer instead in order to decrease the buffer size. var newIdxs = indices.Select(x => (ushort)x).ToArray(); SetBufferData(gl, OGLBufferDataTarget.ArrayBuffer, newIdxs, OGLModelUsage.StaticCopy, Stride); return; } } SetBufferData(gl, SharpGLHelper.OGLBufferDataTarget.ArrayBuffer, indices, SharpGLHelper.OGLModelUsage.StaticCopy, Stride); }
/// <summary> /// Calls the glBufferData(...). The data.Length will be used as value for Size property. /// </summary> /// <param name="gl">The gl.</param> /// <param name="target">The buffer data target.</param> /// <param name="data">The data as float.</param> /// <param name="usage">The usage.</param> /// <param name="stride">The amount of floats that form one input variable.</param> public virtual void SetBufferData(OpenGL gl, OGLBufferDataTarget target, float[] data, OGLModelUsage usage, int stride) { Size = data.Length / stride; Stride = stride; BufferDataType = OGLType.Float; gl.BufferData((uint)target, data, (uint)usage); }
public virtual void ReplaceBufferData(OpenGL gl, OGLBufferDataTarget target, int offset, int size, IntPtr newData, bool bind = false, OGLBindBufferTarget bindTarget = OGLBindBufferTarget.ArrayBuffer) { if (bind) { BindBuffer(gl, bindTarget); } gl.BufferSubData((uint)target, offset, size, newData); }
/// <summary> /// Calls the glBufferData(...). The size will be used as value for Size property. /// </summary> /// <param name="gl">The gl.</param> /// <param name="target">The buffer data target.</param> /// <param name="size">The size of the data buffer.</param> /// <param name="data">The pointer to the data in memory.</param> /// <param name="usage">The usage.</param> public virtual void SetBufferData(OpenGL gl, OGLBufferDataTarget target, int size, IntPtr data, OGLModelUsage usage, int stride, OGLType bufferDataType, bool bind = false, OGLBindBufferTarget bindTarget = OGLBindBufferTarget.ArrayBuffer) { Size = size / stride; Stride = stride; if (bind) { BindBuffer(gl, bindTarget); } gl.BufferData((uint)target, size, data, (uint)usage); }
/// <summary> /// Calls the glBufferData(...). The data.Length will be used as value for Size property. /// </summary> /// <param name="gl">The gl.</param> /// <param name="target">The buffer data target.</param> /// <param name="data">The data as uint.</param> /// <param name="usage">The usage.</param> /// <param name="stride">The amount of uint that form one input variable.</param> public virtual void SetBufferData(OpenGL gl, OGLBufferDataTarget target, uint[] data, OGLModelUsage usage, int stride) { Size = data.Length / stride; Stride = stride; BufferDataType = OGLType.UnsignedInt; var dataSize = data.Length * sizeof(uint); IntPtr newDataPtr = Marshal.AllocHGlobal(dataSize); var intData = new int[data.Length]; Buffer.BlockCopy(data, 0, intData, 0, dataSize); Marshal.Copy(intData, 0, newDataPtr, data.Length); gl.BufferData((uint)target, dataSize, newDataPtr, (uint)usage); }
public virtual void ReplaceBufferData(OpenGL gl, OGLBufferDataTarget target, int offset, uint[] newData, bool bind = false, OGLBindBufferTarget bindTarget = OGLBindBufferTarget.ArrayBuffer) { IntPtr newDataPtr; // Unsafe code. unsafe { // Fix the pointer to the array. fixed(uint *pArray = newData) { // pArray now has the pointer to the array. You can get an IntPtr by casting to void, and passing that in. newDataPtr = new IntPtr((void *)pArray); } } ReplaceBufferData(gl, target, offset, newData.Length, newDataPtr, bind, bindTarget); }
public void SetBufferData(OpenGL gl, OGLBufferDataTarget target, uint[] indices, OGLModelUsage usage, bool compress) { Size = indices.Length; Stride = 1; if(compress) if (indices.Max() < byte.MaxValue) { // use a byte buffer instead in order to decrease the buffer size. var newIdxs = indices.Select(x => (byte)x).ToArray(); SetBufferData(gl, OGLBufferDataTarget.ArrayBuffer, newIdxs, OGLModelUsage.StaticCopy, Stride); return; } else if (indices.Max() < ushort.MaxValue) { // use a ushort buffer instead in order to decrease the buffer size. var newIdxs = indices.Select(x => (ushort)x).ToArray(); SetBufferData(gl, OGLBufferDataTarget.ArrayBuffer, newIdxs, OGLModelUsage.StaticCopy, Stride); return; } SetBufferData(gl, SharpGLHelper.OGLBufferDataTarget.ArrayBuffer, indices, SharpGLHelper.OGLModelUsage.StaticCopy, Stride); }
/// <summary> /// Calls the glBufferData(...). The size will be used as value for Size property. /// </summary> /// <param name="gl">The gl.</param> /// <param name="target">The buffer data target.</param> /// <param name="size">The size of the data buffer.</param> /// <param name="data">The pointer to the data in memory.</param> /// <param name="usage">The usage.</param> public virtual void SetBufferData(OpenGL gl, OGLBufferDataTarget target, int size, IntPtr data, OGLModelUsage usage, int stride, OGLType bufferDataType, bool bind = false, OGLBindBufferTarget bindTarget = OGLBindBufferTarget.ArrayBuffer) { Size = size / stride; Stride = stride; if(bind) BindBuffer(gl, bindTarget); gl.BufferData((uint)target, size, data, (uint)usage); }
/// <summary> /// Calls the glBufferData(...). The data.Length will be used as value for Size property. /// </summary> /// <param name="gl">The gl.</param> /// <param name="target">The buffer data target.</param> /// <param name="data">The data as uint.</param> /// <param name="usage">The usage.</param> /// <param name="stride">The amount of uint that form one input variable.</param> public virtual void SetBufferData(OpenGL gl, OGLBufferDataTarget target, uint[] data, OGLModelUsage usage, int stride) { Size = data.Length / stride; Stride = stride; BufferDataType = OGLType.UnsignedInt; var dataSize = data.Length * sizeof(uint); IntPtr newDataPtr = Marshal.AllocHGlobal(dataSize); var intData = new int[data.Length]; Buffer.BlockCopy(data, 0, intData, 0, dataSize); Marshal.Copy(intData, 0, newDataPtr, data.Length); gl.BufferData((uint)target, dataSize, newDataPtr, (uint)usage); }
/// <summary> /// Calls the glBufferData(...). The data.Length will be used as value for Size property. /// </summary> /// <param name="gl">The gl.</param> /// <param name="target">The buffer data target.</param> /// <param name="data">The data as ushort.</param> /// <param name="usage">The usage.</param> /// <param name="stride">The amount of ushorts that form one input variable.</param> public virtual void SetBufferData(OpenGL gl, OGLBufferDataTarget target, ushort[] data, OGLModelUsage usage, int stride) { Size = data.Length / stride; Stride = stride; BufferDataType = OGLType.UnsignedShort; gl.BufferData((uint)target, data, (uint)usage); }
public virtual void ReplaceBufferData(OpenGL gl, OGLBufferDataTarget target, int offset, int size, IntPtr newData, bool bind = false, OGLBindBufferTarget bindTarget = OGLBindBufferTarget.ArrayBuffer) { if (bind) BindBuffer(gl, bindTarget); gl.BufferSubData((uint)target, offset, size, newData); }
public virtual void ReplaceBufferData(OpenGL gl, OGLBufferDataTarget target, int offset, uint[] newData, bool bind = false, OGLBindBufferTarget bindTarget = OGLBindBufferTarget.ArrayBuffer) { IntPtr newDataPtr; // Unsafe code. unsafe { // Fix the pointer to the array. fixed (uint* pArray = newData) { // pArray now has the pointer to the array. You can get an IntPtr by casting to void, and passing that in. newDataPtr = new IntPtr((void*)pArray); } } ReplaceBufferData(gl, target, offset, newData.Length, newDataPtr, bind, bindTarget); }