1 /*
2 Copyright (c) 2019-2020 Timur Gafarov
3 
4 Boost Software License - Version 1.0 - August 17th, 2003
5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 
12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 */
27 
28 module dagon.graphics.state;
29 
30 import dlib.math.vector;
31 import dlib.math.matrix;
32 import dlib.geometry.frustum;
33 
34 import dagon.core.bindings;
35 import dagon.core.time;
36 import dagon.graphics.material;
37 import dagon.graphics.shader;
38 import dagon.graphics.environment;
39 import dagon.graphics.light;
40 
41 struct GraphicsState
42 {
43     int layer;
44     float blurMask;
45     float gbufferMask;
46 
47     Vector2f resolution;
48     float zNear;
49     float zFar;
50 
51     Vector3f cameraPosition;
52 
53     Matrix4x4f modelMatrix;
54     Matrix4x4f invModelMatrix;
55     Matrix4x4f invViewRotationMatrix;
56 
57     Matrix4x4f viewMatrix;
58     Matrix4x4f invViewMatrix;
59 
60     Matrix4x4f projectionMatrix;
61     Matrix4x4f invProjectionMatrix;
62 
63     Matrix4x4f modelViewMatrix;
64     Matrix4x4f normalMatrix;
65     
66     Matrix4x4f prevViewMatrix;
67     Matrix4x4f prevModelViewMatrix;
68     
69     Frustum frustum;
70 
71     Material material;
72     Shader shader;
73     Environment environment;
74     Light light;
75 
76     bool colorMask;
77     bool depthMask;
78 
79     bool culling;
80     
81     float opacity;
82 
83     GLuint colorTexture;
84     GLuint depthTexture;
85     GLuint normalTexture;
86     GLuint pbrTexture;
87     GLuint occlusionTexture;
88     
89     Time time;
90     
91     float localTime; // 0.0 .. 1.0
92 
93     void reset()
94     {
95         layer = 1;
96         blurMask = 1.0f;
97         gbufferMask = 1.0f;
98 
99         resolution = Vector2f(0.0f, 0.0f);
100         zNear = 0.0f;
101         zFar = 0.0f;
102 
103         cameraPosition = Vector3f(0.0f, 0.0f, 0.0f);
104 
105         modelMatrix = Matrix4x4f.identity;
106         invModelMatrix = Matrix4x4f.identity;
107 
108         viewMatrix = Matrix4x4f.identity;
109         invViewMatrix = Matrix4x4f.identity;
110         invViewRotationMatrix = Matrix4x4f.identity;
111 
112         projectionMatrix = Matrix4x4f.identity;
113         invProjectionMatrix = Matrix4x4f.identity;
114 
115         modelViewMatrix = Matrix4x4f.identity;
116         normalMatrix = Matrix4x4f.identity;
117         
118         prevViewMatrix = Matrix4x4f.identity;
119         prevModelViewMatrix = Matrix4x4f.identity;
120 
121         material = null;
122         shader = null;
123         environment = null;
124         light = null;
125 
126         colorMask = true;
127         depthMask = true;
128 
129         culling = true;
130         
131         opacity = 1.0f;
132 
133         colorTexture = 0;
134         depthTexture = 0;
135         normalTexture = 0;
136         pbrTexture = 0;
137         occlusionTexture = 0;
138         
139         time = Time(0.0, 0.0);
140         localTime = 0.0f;
141     }
142 }