1 /* 2 Copyright (c) 2017-2018 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.rc; 29 30 import dlib.math.vector; 31 import dlib.math.matrix; 32 import dlib.math.transformation; 33 import dlib.geometry.frustum; 34 import derelict.opengl; 35 import dagon.core.event; 36 import dagon.graphics.environment; 37 import dagon.graphics.material; 38 39 struct RenderingContext 40 { 41 Matrix4x4f modelViewMatrix; 42 43 Matrix4x4f modelMatrix; 44 Matrix4x4f invModelMatrix; 45 46 Vector3f cameraPosition; 47 Vector3f prevCameraPosition; 48 49 Matrix4x4f viewMatrix; 50 Matrix4x4f invViewMatrix; 51 52 Matrix4x4f viewRotationMatrix; 53 Matrix4x4f invViewRotationMatrix; 54 55 Matrix4x4f projectionMatrix; 56 Matrix4x4f normalMatrix; 57 58 Matrix4x4f prevViewMatrix; 59 Matrix4x4f prevModelViewProjMatrix; 60 Matrix4x4f blurModelViewProjMatrix; 61 62 Frustum frustum; 63 64 EventManager eventManager; 65 Environment environment; 66 Material overrideMaterial; 67 68 float time; 69 float blurMask; 70 71 bool depthPass; 72 bool colorPass; 73 74 void init(EventManager emngr, Environment env) 75 { 76 modelViewMatrix = Matrix4x4f.identity; 77 modelMatrix = Matrix4x4f.identity; 78 invModelMatrix = Matrix4x4f.identity; 79 cameraPosition = Vector3f(0.0f, 0.0f, 0.0f); 80 prevCameraPosition = Vector3f(0.0f, 0.0f, 0.0f); 81 viewMatrix = Matrix4x4f.identity; 82 invViewMatrix = Matrix4x4f.identity; 83 viewRotationMatrix = Matrix4x4f.identity; 84 invViewRotationMatrix = Matrix4x4f.identity; 85 projectionMatrix = Matrix4x4f.identity; 86 normalMatrix = Matrix4x4f.identity; 87 prevViewMatrix = Matrix4x4f.identity; 88 prevModelViewProjMatrix = Matrix4x4f.identity; 89 blurModelViewProjMatrix = Matrix4x4f.identity; 90 eventManager = emngr; 91 environment = env; 92 overrideMaterial = null; 93 time = 0.0f; 94 depthPass = true; 95 colorPass = true; 96 blurMask = 1.0f; 97 } 98 99 void initPerspective(EventManager emngr, Environment env, float fov, float znear, float zfar) 100 { 101 init(emngr, env); 102 projectionMatrix = perspectiveMatrix(fov, emngr.aspectRatio, znear, zfar); 103 } 104 105 void initOrtho(EventManager emngr, Environment env, float znear, float zfar) 106 { 107 init(emngr, env); 108 projectionMatrix = orthoMatrix(0.0f, emngr.windowWidth, emngr.windowHeight, 0.0f, znear, zfar); 109 } 110 111 void initOrtho(EventManager emngr, Environment env, float w, float h, float znear, float zfar) 112 { 113 init(emngr, env); 114 projectionMatrix = orthoMatrix(0.0f, w, h, 0.0f, znear, zfar); 115 } 116 }