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