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