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