1 /*
2 Copyright (c) 2019-2022 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     GLuint texcoordTexture; // used only for terrains
89     
90     Time time;
91     
92     float localTime; // 0.0 .. 1.0
93 
94     void reset()
95     {
96         layer = 1;
97         blurMask = 1.0f;
98         gbufferMask = 1.0f;
99 
100         resolution = Vector2f(0.0f, 0.0f);
101         zNear = 0.0f;
102         zFar = 0.0f;
103 
104         cameraPosition = Vector3f(0.0f, 0.0f, 0.0f);
105 
106         modelMatrix = Matrix4x4f.identity;
107         invModelMatrix = Matrix4x4f.identity;
108 
109         viewMatrix = Matrix4x4f.identity;
110         invViewMatrix = Matrix4x4f.identity;
111         invViewRotationMatrix = Matrix4x4f.identity;
112 
113         projectionMatrix = Matrix4x4f.identity;
114         invProjectionMatrix = Matrix4x4f.identity;
115 
116         modelViewMatrix = Matrix4x4f.identity;
117         normalMatrix = Matrix4x4f.identity;
118         
119         prevViewMatrix = Matrix4x4f.identity;
120         prevModelViewMatrix = Matrix4x4f.identity;
121 
122         material = null;
123         shader = null;
124         environment = null;
125         light = null;
126 
127         colorMask = true;
128         depthMask = true;
129 
130         culling = true;
131         
132         opacity = 1.0f;
133 
134         colorTexture = 0;
135         depthTexture = 0;
136         normalTexture = 0;
137         pbrTexture = 0;
138         occlusionTexture = 0;
139         texcoordTexture = 0;
140         
141         time = Time(0.0, 0.0);
142         localTime = 0.0f;
143     }
144 }