public VertexBuffer(int size) { OpenGL.glGenBuffers(1, out buffer); OpenGL.CheckGLError(); Bind(); // Generates a buffer with uninitialized memory. OpenGL.glBufferData(OpenGL.GL_ARRAY_BUFFER, new IntPtr(VertexSize * size), IntPtr.Zero, OpenGL.GL_DYNAMIC_DRAW); OpenGL.CheckGLError(); // We need to zero all the memory. Let's generate a smallish array and copy that over the whole buffer. var zeroedArrayElementSize = Math.Min(size, 2048); var ptr = GCHandle.Alloc(new T[zeroedArrayElementSize], GCHandleType.Pinned); try { for (var offset = 0; offset < size; offset += zeroedArrayElementSize) { var length = Math.Min(zeroedArrayElementSize, size - offset); OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER, new IntPtr(VertexSize * offset), new IntPtr(VertexSize * length), ptr.AddrOfPinnedObject()); OpenGL.CheckGLError(); } } finally { ptr.Free(); } }
public void SetData(IntPtr data, int start, int length) { Bind(); OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER, new IntPtr(VertexSize * start), new IntPtr(VertexSize * length), data); OpenGL.CheckGLError(); }
public override void SetData(IntPtr data, int start, int length) { //Console.WriteLine("buffer SetData2()" + buffer); //ActivateVAOBeforeGLDraw(); //ActivateVertextBuffer(); //BindOnce(); OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER, new IntPtr(VertexSize * start), new IntPtr(VertexSize * length), data); OpenGL.CheckGLError(); }
public override void SetData(T[] data, int start, int length) { //Console.WriteLine("buffer SetData() in buffer number : " + buffer); var ptr = GCHandle.Alloc(data, GCHandleType.Pinned); try { OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER, new IntPtr(VertexSize * start), new IntPtr(VertexSize * length), ptr.AddrOfPinnedObject()); } finally { ptr.Free(); } OpenGL.CheckGLError(); }
public void SetData(T[] data, int start, int length) { Bind(); var ptr = GCHandle.Alloc(data, GCHandleType.Pinned); try { OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER, new IntPtr(VertexSize * start), new IntPtr(VertexSize * length), ptr.AddrOfPinnedObject()); } finally { ptr.Free(); } OpenGL.CheckGLError(); }
public VertexBuffer(int size, string ownername) { #if DEBUG_VERTEX Console.WriteLine("VB created owner: " + ownername); #endif this.ownername = ownername; GraphicsContext.VAOReserveStack += 1; //помечаем, что резерв уменьшился. LocalVertexArrayIndex = GraphicsContext.VAOReserveStack; BindOnceOpen(); // Generates a buffer with uninitialized memory. OpenGL.glBufferData(OpenGL.GL_ARRAY_BUFFER, new IntPtr(VertexSize * size), IntPtr.Zero, OpenGL.GL_DYNAMIC_DRAW); OpenGL.CheckGLError(); // We need to zero all the memory. Let's generate a smallish array and copy that over the whole buffer. var zeroedArrayElementSize = Math.Min(size, 2048); var ptr = GCHandle.Alloc(new T[zeroedArrayElementSize], GCHandleType.Pinned); try { for (var offset = 0; offset < size; offset += zeroedArrayElementSize) { var length = Math.Min(zeroedArrayElementSize, size - offset); OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER, new IntPtr(VertexSize * offset), new IntPtr(VertexSize * length), ptr.AddrOfPinnedObject()); OpenGL.CheckGLError(); } } finally { ptr.Free(); } BindOnceClose(); }