1 /**
2 * Contains all core code for the Graphics adapters, which is similar across all platforms
3 */
4 module dash.graphics.adapters.adapter;
5 import dash.core.properties, dash.components.userinterface, dash.utility.config, dash.utility.math;
6 
7 import std.typecons: BlackHole;
8 
9 alias NullAdapter = BlackHole!Adapter;
10 
11 /**
12  * Base class for core rendering logic
13  */
14 abstract class Adapter
15 {
16 private:
17     uint _width, _screenWidth;
18     uint _height, _screenHeight;
19     bool _fullscreen, _backfaceCulling, _vsync;
20 
21 public:
22     /// Pixel width of the rendering area
23     mixin( Property!_width );
24     /// Pixel width of the actual window
25     mixin( Property!_screenWidth );
26     /// Pixel height of the rendering area
27     mixin( Property!_height );
28     /// Pixel height of the actual window
29     mixin( Property!_screenHeight );
30     /// If the screen properties match the rendering dimensions
31     mixin( Property!_fullscreen );
32     /// Hiding backsides of triangles
33     mixin( Property!_backfaceCulling );
34     /// Vertical Syncing
35     mixin( Property!_vsync );
36     /**
37      * Initializes the Adapter, called in loading
38      */
39     abstract void initialize();
40     /**
41      * Shuts down the Adapter
42      */
43     abstract void shutdown();
44     /**
45      * Resizes the window and updates FBOs
46      */
47     abstract void resize();
48     /**
49      * Reloads the Adapter without closing
50      */
51     abstract void refresh();
52     /**
53      * Swaps the back buffer to the screen
54      */
55     abstract void swapBuffers();
56 
57     /**
58      * Opens the window
59      */
60     abstract void openWindow();
61     /**
62      * Closes the window
63      */
64     abstract void closeWindow();
65 
66     /**
67      * TODO
68      */
69     abstract void messageLoop();
70 
71     /**
72      * Currently the entire rendering pass for the active Scene. TODO: Refactor the name
73      */
74     abstract void endDraw();
75 
76     /**
77      * Read from the depth buffer at the given point.
78      */
79     abstract float getDepthAtScreenPoint( vec2ui point );
80 
81     /**
82      * Read from the depth buffer at the given point.
83      */
84     abstract uint getObjectIDAtScreenPoint( vec2ui point );
85 
86     /// TODO: Remove in favor of pipelines
87     abstract void initializeDeferredRendering();
88 
89 protected:
90     /**
91      * Loads rendering properties from Config
92      */
93     final void loadProperties()
94     {
95         fullscreen = config.display.fullscreen;
96         if( fullscreen )
97         {
98             width = screenWidth;
99             height = screenHeight;
100         }
101         else
102         {
103             width = config.display.width;
104             height = config.display.height;
105         }
106 
107         backfaceCulling = config.graphics.backfaceCulling;
108         vsync = config.graphics.vsync;
109     }
110 }