我正在学习 opengl 并编写了一个简单的程序,该程序使用缓冲区对象(颜色、位置、法线、元素索引)来绘制如下所示的形状。即使删除和解除绑定,GPU 监控程序显示每次按钮单击后内存使用量都在增加。仅当我关闭应用程序时才会释放内存。如果我多次单击按钮,GPU ram 会填充到 2GB 并开始溢出到主机 ram。如何正确释放资源/缓冲区?
程序流程如下:
When I click a button, the below program is executed:
glControl1.MakeCurrent();
GL.GenBuffers(4,buf)
GL.BindBuffer(BufferTarget.ArrayBuffer,buf[0])
GL.BufferData(BufferTarget.ArrayBuffer,......)
same for buf[1] buf[2] and buf[3](this one ElementArrayBuffer)
Console.WriteLine(GL.GetError()); // no error
GL.Finish();
[iteration loop]
glControl1.MakeCurrent();
GL.BindBuffer(BufferTarget.ArrayBuffer,buf[0])
GL.ColorBuffer(....)
GL.BindBuffer(BufferTarget.ArrayBuffer,buf[1])
GL.VertexBuffer(....)
GL.BindBuffer(BufferTarget.ArrayBuffer,buf[2])
GL.NormalBuffer(....)
GL.BindBuffer(BufferTarget.ElementArrayBuffer,buf[3])
GL.EnableClientStates(.....)
GL.DrawElements(.....) //draws the thing
GL.DisableClientStates(.....)
GL.BindBuffer(BufferTarget.ElementArrayBuffer,0) //is this unbinding?
GL.BindBuffer(BufferTarget.ArrayBuffer,0)
GL.BindBuffer(BufferTarget.ArrayBuffer,0)
GL.BindBuffer(BufferTarget.ArrayBuffer,0)
GL.Finish();
[loop end]
//deleting buffers
glControl1.MakeCurrent()
GL.DeleteBuffers(4,buf)
Console.WriteLine(GL.GetError()); // no error comes
GL.Finish();