/// <summary> /// Prepare VBO content and upload it to the GPU. /// </summary> private void PrepareDataBuffers() { if (useVBO && cn.result != null && cn.result.Vertices > 0) { GL.EnableClientState(ArrayCap.VertexArray); if (cn.result.Normals > 0 && checkNormals.Checked) { GL.EnableClientState(ArrayCap.NormalArray); } if (cn.result.Colors > 0 && checkColors.Checked) { GL.EnableClientState(ArrayCap.ColorArray); } // Vertex array: [color] [normal] coord GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid[0]); int vertexBufferSize = cn.VertexBufferSize(checkNormals.Checked, checkColors.Checked, false); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)vertexBufferSize, IntPtr.Zero, BufferUsageHint.DynamicDraw); IntPtr videoMemoryPtr = GL.MapBuffer(BufferTarget.ArrayBuffer, BufferAccess.WriteOnly); unsafe { stride = cn.FillVertexBuffer((float *)videoMemoryPtr.ToPointer(), checkNormals.Checked, checkColors.Checked, false); } GL.UnmapBuffer(BufferTarget.ArrayBuffer); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.ColorArray); if (useVBO) { GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid[0]); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)0, IntPtr.Zero, BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } } }