1 module gfm.bgfx.bgfx; 2 3 4 /// General bgfx exception thrown for all cases. 5 /// However, bgfx has no recoverable errors. 6 final class BgfxException : Exception 7 { 8 this(string msg) 9 { 10 super(msg); 11 } 12 } 13 14 /// Owns the loader. 15 /// This object is passed around to other wrapped objects 16 /// to ensure library loading. 17 final class Bgfx 18 { 19 public 20 { 21 /// Loads DerelictENet and initializes the ENet library. 22 /// Throws: ENetException when enet_initialize fails. 23 this() 24 { 25 try 26 DerelictBgfx.load(); 27 catch(DerelictException e) 28 throw new BgfxException(e.msg); 29 30 bgfx_init(); // TODO pass interfaces 31 32 _bgfxInitialized = true; 33 34 35 36 scope(exit) bgfx_shutdown(); 37 38 bgfx_reset(width, height, reset); 39 } 40 41 ~this() 42 { 43 close(); 44 } 45 46 /// Deinitializes the ENet library and unloads DerelictENet. 47 void close() 48 { 49 if(_bgfxInitialized) 50 { 51 bgfx_shutdown(); 52 DerelictBgfx.unload(); 53 _bgfxInitialized = false; 54 } 55 } 56 } 57 58 private 59 { 60 bool _bgfxInitialized = false; 61 62 } 63 }