1 /** 2 Copyright: Copyright (c) 2017-2018 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 module voxelman.graphics.vao; 7 8 import voxelman.graphics.gl; 9 import voxelman.graphics.vbo; 10 11 enum PrimitiveType : GLenum 12 { 13 POINTS = GL_POINTS, 14 LINE_STRIP = GL_LINE_STRIP, 15 LINE_LOOP = GL_LINE_LOOP, 16 LINES = GL_LINES, 17 //LINE_STRIP_ADJACENCY = GL_LINE_STRIP_ADJACENCY, 18 //LINES_ADJACENCY = GL_LINES_ADJACENCY, 19 TRIANGLE_STRIP = GL_TRIANGLE_STRIP, 20 TRIANGLE_FAN = GL_TRIANGLE_FAN, 21 TRIANGLES = GL_TRIANGLES, 22 //TRIANGLE_STRIP_ADJACENCY = GL_TRIANGLE_STRIP_ADJACENCY, 23 //TRIANGLES_ADJACENCY = GL_TRIANGLES_ADJACENCY, 24 //PATCHES = GL_PATCHES, 25 } 26 27 28 struct Vao 29 { 30 //import core.atomic; 31 //shared static size_t numAllocated; 32 private GLuint handle_; 33 34 GLuint handle() const { 35 return handle_; 36 } 37 38 bool isGenerated() const { 39 return handle_ != 0; 40 } 41 42 void gen() { 43 if (isGenerated) return; 44 //atomicOp!"+="(numAllocated, 1); 45 checkgl!glGenVertexArrays(1, &handle_); 46 } 47 48 void del() { 49 //if (handle_ != 0) atomicOp!"-="(numAllocated, 1); 50 checkgl!glDeleteVertexArrays(1, &handle_); 51 } 52 53 void bind() const { 54 assert(isGenerated); 55 checkgl!glBindVertexArray(handle_); 56 } 57 58 static void unbind() { 59 checkgl!glBindVertexArray(0); 60 } 61 62 // requires binding 63 void drawArrays(PrimitiveType mode, int first, int count) const { 64 checkgl!glDrawArrays(mode, first, count); 65 } 66 }