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 VAO 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 ~this() 25 { 26 close(); 27 } 28 29 /// Releases the OpenGL VAO resource. 30 void close() 31 { 32 if (_initialized) 33 { 34 glDeleteVertexArrays(1, &_handle); 35 _initialized = false; 36 } 37 } 38 39 /// Uses this VAO. 40 /// Throws: $(D OpenGLException) on error. 41 void bind() 42 { 43 glBindVertexArray(_handle); 44 _gl.runtimeCheck(); 45 } 46 47 /// Unuses this VAO. 48 /// Throws: $(D OpenGLException) on error. 49 void unbind() 50 { 51 glBindVertexArray(0); 52 _gl.runtimeCheck(); 53 } 54 55 /// Returns: Wrapped OpenGL resource handle. 56 GLuint handle() pure const nothrow 57 { 58 return _handle; 59 } 60 } 61 62 private 63 { 64 OpenGL _gl; 65 GLuint _handle; 66 bool _initialized; 67 } 68 }