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 final class GLVAO 11 { 12 public 13 { 14 /// Creates a VAO. 15 /// Throws: $(D OpenGLException) on error. 16 this(OpenGL gl) 17 { 18 _gl = gl; 19 glGenVertexArrays(1, &_handle); 20 gl.runtimeCheck(); 21 _initialized = true; 22 } 23 24 /// Releases the OpenGL VAO resource. 25 ~this() 26 { 27 if (_initialized) 28 { 29 debug ensureNotInGC("GLVAO"); 30 glDeleteVertexArrays(1, &_handle); 31 _initialized = false; 32 } 33 } 34 35 /// Uses this VAO. 36 /// Throws: $(D OpenGLException) on error. 37 void bind() 38 { 39 glBindVertexArray(_handle); 40 _gl.runtimeCheck(); 41 } 42 43 /// Unuses this VAO. 44 /// Throws: $(D OpenGLException) on error. 45 void unbind() 46 { 47 glBindVertexArray(0); 48 _gl.runtimeCheck(); 49 } 50 51 /// Returns: Wrapped OpenGL resource handle. 52 GLuint handle() pure const nothrow 53 { 54 return _handle; 55 } 56 } 57 58 private 59 { 60 OpenGL _gl; 61 GLuint _handle; 62 bool _initialized; 63 } 64 }