1 module gfm.opengl.vao; 2 3 import std..string; 4 5 import derelict.opengl3.gl3; 6 7 import gfm.opengl.opengl; 8 9 /// OpenGL Vertex Array Object wrapper. 10 deprecated("Use GLVAO instead") alias VAO = GLVAO; 11 final class GLVAO 12 { 13 public 14 { 15 /// Creates a VAO. 16 /// Throws: $(D OpenGLException) on error. 17 this(OpenGL gl) 18 { 19 _gl = gl; 20 glGenVertexArrays(1, &_handle); 21 gl.runtimeCheck(); 22 _initialized = true; 23 } 24 25 /// Releases the OpenGL VAO resource. 26 ~this() 27 { 28 if (_initialized) 29 { 30 debug ensureNotInGC("GLVAO"); 31 glDeleteVertexArrays(1, &_handle); 32 _initialized = false; 33 } 34 } 35 deprecated("Use .destroy instead") void close(){} 36 37 /// Uses this VAO. 38 /// Throws: $(D OpenGLException) on error. 39 void bind() 40 { 41 glBindVertexArray(_handle); 42 _gl.runtimeCheck(); 43 } 44 45 /// Unuses this VAO. 46 /// Throws: $(D OpenGLException) on error. 47 void unbind() 48 { 49 glBindVertexArray(0); 50 _gl.runtimeCheck(); 51 } 52 53 /// Returns: Wrapped OpenGL resource handle. 54 GLuint handle() pure const nothrow 55 { 56 return _handle; 57 } 58 } 59 60 private 61 { 62 OpenGL _gl; 63 GLuint _handle; 64 bool _initialized; 65 } 66 }