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