1 module des.gl.vao; 2 3 import des.gl.general; 4 5 /// 6 struct GLAttrib 7 { 8 /// 9 string name; 10 11 /// by default invalid value < 0 12 int location = -1; 13 /// 14 uint elements; 15 /// 16 GLType type; 17 /// 18 size_t stride; 19 /// 20 size_t offset; 21 /// 22 bool norm; 23 24 pure: 25 /// 26 this( string name, int location, uint elements, 27 GLType type=GLType.FLOAT, 28 size_t stride=0, size_t offset=0, bool norm=false ) 29 { 30 this.name = name; 31 this.location = location; 32 this.elements = elements; 33 this.type = type; 34 this.stride = stride; 35 this.offset = offset; 36 this.norm = norm; 37 } 38 39 size_t dataSize() const @property 40 { 41 if( stride ) return stride; 42 return elements * sizeofGLType( type ); 43 } 44 } 45 46 /// Vertex Array Object 47 final class GLVAO : GLObject!("VertexArray",false) 48 { 49 protected: 50 51 int[int] aaset; 52 53 public: 54 /// 55 static nothrow void unbind(){ glBindVertexArray(0); } 56 57 /// `glGenVertexArrays` 58 this() 59 { 60 super(0); 61 logger.Debug( "pass" ); 62 } 63 64 /// 65 int[] enabled() const @property { return aaset.keys; } 66 67 /// `glBindVertexArray( id )` 68 override void bind() 69 { 70 checkGLCall!glBindVertexArray( id ); 71 debug logger.trace( "pass" ); 72 } 73 74 /// `glBindVertexArray( 0 )` 75 override void unbind() 76 { 77 checkGLCall!glBindVertexArray( 0 ); 78 debug logger.trace( "pass" ); 79 } 80 81 /// `glEnableVertexAttribArray` 82 void enable( int n ) 83 { 84 debug scope(exit) logger.Debug( "[%d]", n ); 85 if( n < 0 ) return; 86 bind(); 87 ntCheckGLCall!glEnableVertexAttribArray( n ); 88 aaset[n] = n; 89 } 90 91 /// `glDisableVertexAttribArray` 92 void disable( int n ) 93 { 94 debug scope(exit) logger.Debug( "[%d]", n ); 95 if( n < 0 ) return; 96 bind(); 97 ntCheckGLCall!glDisableVertexAttribArray( n ); 98 aaset.remove(n); 99 } 100 }