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 46 Vector2f resolution; 47 float zNear; 48 float zFar; 49 50 Vector3f cameraPosition; 51 52 Matrix4x4f modelMatrix; 53 Matrix4x4f invModelMatrix; 54 Matrix4x4f invViewRotationMatrix; 55 56 Matrix4x4f viewMatrix; 57 Matrix4x4f invViewMatrix; 58 59 Matrix4x4f projectionMatrix; 60 Matrix4x4f invProjectionMatrix; 61 62 Matrix4x4f modelViewMatrix; 63 Matrix4x4f normalMatrix; 64 65 Matrix4x4f prevViewMatrix; 66 Matrix4x4f prevModelViewMatrix; 67 68 Frustum frustum; 69 70 Material material; 71 Shader shader; 72 Environment environment; 73 Light light; 74 75 bool colorMask; 76 bool depthMask; 77 78 bool culling; 79 80 float opacity; 81 82 GLuint colorTexture; 83 GLuint depthTexture; 84 GLuint normalTexture; 85 GLuint pbrTexture; 86 GLuint occlusionTexture; 87 88 Time time; 89 90 float localTime; // 0.0 .. 1.0 91 92 void reset() 93 { 94 layer = 1; 95 blurMask = 1.0f; 96 97 resolution = Vector2f(0.0f, 0.0f); 98 zNear = 0.0f; 99 zFar = 0.0f; 100 101 cameraPosition = Vector3f(0.0f, 0.0f, 0.0f); 102 103 modelMatrix = Matrix4x4f.identity; 104 invModelMatrix = Matrix4x4f.identity; 105 106 viewMatrix = Matrix4x4f.identity; 107 invViewMatrix = Matrix4x4f.identity; 108 invViewRotationMatrix = Matrix4x4f.identity; 109 110 projectionMatrix = Matrix4x4f.identity; 111 invProjectionMatrix = Matrix4x4f.identity; 112 113 modelViewMatrix = Matrix4x4f.identity; 114 normalMatrix = Matrix4x4f.identity; 115 116 prevViewMatrix = Matrix4x4f.identity; 117 prevModelViewMatrix = Matrix4x4f.identity; 118 119 material = null; 120 shader = null; 121 environment = null; 122 light = null; 123 124 colorMask = true; 125 depthMask = true; 126 127 culling = true; 128 129 opacity = 1.0f; 130 131 colorTexture = 0; 132 depthTexture = 0; 133 normalTexture = 0; 134 pbrTexture = 0; 135 occlusionTexture = 0; 136 137 time = Time(0.0, 0.0); 138 localTime = 0.0f; 139 } 140 }