1 module des.gl.object; 2 3 import des.gl.general; 4 5 /// 6 abstract class GLObject(string Subj,bool write_bind=true) : DesObject 7 { 8 mixin DES; 9 mixin ClassLogger; 10 private: 11 12 uint _id; 13 14 static string callFormat(Args...)( string fmt, Args args ) 15 { return format( "checkGLCall!"~fmt, args ); } 16 17 protected: 18 19 GLenum _target; 20 21 /// 22 string log_name; 23 24 public: 25 26 /// `glGen<subject>s( 1, &_id )` 27 this( GLenum trg ) 28 { 29 _target = trg; 30 mixin( callFormat( "glGen%ss( 1, &_id );", Subj ) ); 31 logger = new InstanceLogger( this, 32 format( "%s%d", (log_name ? log_name ~ ":" : ""), _id ) ); 33 } 34 35 final pure const nothrow @nogc @property 36 { 37 /// 38 GLenum target() { return _target; } 39 40 /// return _id 41 uint id() { return _id; } 42 } 43 44 static if( write_bind ) 45 { 46 /// `glBind<subject>( target, id )` 47 void bind() 48 { 49 mixin( callFormat( "glBind%s( target, id );", Subj ) ); 50 debug logger.trace( "pass" ); 51 } 52 53 /// `glBind<subject>( target, 0 )` 54 void unbind() 55 { 56 mixin( callFormat( "glBind%s( target, 0 );", Subj ) ); 57 debug logger.trace( "pass" ); 58 } 59 } 60 else 61 { 62 abstract void bind(); 63 abstract void unbind(); 64 } 65 66 protected: 67 68 override void selfDestroy() 69 { 70 unbind(); 71 mixin( format( "checkGLCall!glDelete%ss( 1, &_id );", Subj ) ); 72 logger.Debug( "pass" ); 73 } 74 }