1 /* 2 Copyright (C) 2010-2014 Kristian Duske 3 4 This file is part of TrenchBroom. 5 6 TrenchBroom is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 TrenchBroom is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "RenderContext.h" 21 #include "Renderer/Camera.h" 22 #include "View/MapViewConfig.h" 23 24 namespace TrenchBroom { 25 namespace Renderer { RenderContext(const RenderMode renderMode,const Camera & camera,FontManager & fontManager,ShaderManager & shaderManager)26 RenderContext::RenderContext(const RenderMode renderMode, const Camera& camera, FontManager& fontManager, ShaderManager& shaderManager) : 27 m_renderMode(renderMode), 28 m_camera(camera), 29 m_transformation(m_camera.projectionMatrix(), m_camera.viewMatrix()), 30 m_fontManager(fontManager), 31 m_shaderManager(shaderManager), 32 m_showTextures(true), 33 m_showFaces(true), 34 m_showEdges(true), 35 m_shadeFaces(true), 36 m_showPointEntities(true), 37 m_showPointEntityModels(true), 38 m_showEntityClassnames(true), 39 m_showEntityBounds(true), 40 m_showFog(false), 41 m_showGrid(true), 42 m_gridSize(4), 43 m_hideSelection(false), 44 m_tintSelection(true), 45 m_showSelectionGuide(ShowSelectionGuide_Hide) {} 46 render2D() const47 bool RenderContext::render2D() const { 48 return m_renderMode == RenderMode_2D; 49 } 50 render3D() const51 bool RenderContext::render3D() const { 52 return m_renderMode == RenderMode_3D; 53 } 54 camera() const55 const Camera& RenderContext::camera() const { 56 return m_camera; 57 } 58 transformation()59 Transformation& RenderContext::transformation() { 60 return m_transformation; 61 } 62 fontManager()63 FontManager& RenderContext::fontManager() { 64 return m_fontManager; 65 } 66 shaderManager()67 ShaderManager& RenderContext::shaderManager() { 68 return m_shaderManager; 69 } 70 showTextures() const71 bool RenderContext::showTextures() const { 72 return m_showTextures; 73 } 74 setShowTextures(const bool showTextures)75 void RenderContext::setShowTextures(const bool showTextures) { 76 m_showTextures = showTextures; 77 } 78 showFaces() const79 bool RenderContext::showFaces() const { 80 return m_renderMode == RenderMode_3D && m_showFaces; 81 } 82 setShowFaces(const bool showFaces)83 void RenderContext::setShowFaces(const bool showFaces) { 84 m_showFaces = showFaces; 85 } 86 showEdges() const87 bool RenderContext::showEdges() const { 88 return m_renderMode == RenderMode_2D || m_showEdges; 89 } 90 setShowEdges(const bool showEdges)91 void RenderContext::setShowEdges(const bool showEdges) { 92 m_showEdges = showEdges; 93 } 94 shadeFaces() const95 bool RenderContext::shadeFaces() const { 96 return m_shadeFaces; 97 } 98 setShadeFaces(const bool shadeFaces)99 void RenderContext::setShadeFaces(const bool shadeFaces) { 100 m_shadeFaces = shadeFaces; 101 } 102 showPointEntities() const103 bool RenderContext::showPointEntities() const { 104 return m_showPointEntities; 105 } 106 setShowPointEntities(const bool showPointEntities)107 void RenderContext::setShowPointEntities(const bool showPointEntities) { 108 m_showPointEntities = showPointEntities; 109 } 110 showPointEntityModels() const111 bool RenderContext::showPointEntityModels() const { 112 return m_showPointEntityModels; 113 } 114 setShowPointEntityModels(const bool showPointEntityModels)115 void RenderContext::setShowPointEntityModels(const bool showPointEntityModels) { 116 m_showPointEntityModels = showPointEntityModels; 117 } 118 showEntityClassnames() const119 bool RenderContext::showEntityClassnames() const { 120 return m_showEntityClassnames; 121 } 122 setShowEntityClassnames(const bool showEntityClassnames)123 void RenderContext::setShowEntityClassnames(const bool showEntityClassnames) { 124 m_showEntityClassnames = showEntityClassnames; 125 } 126 showEntityBounds() const127 bool RenderContext::showEntityBounds() const { 128 return m_showEntityBounds; 129 } 130 setShowEntityBounds(const bool showEntityBounds)131 void RenderContext::setShowEntityBounds(const bool showEntityBounds) { 132 m_showEntityBounds = showEntityBounds; 133 } 134 showFog() const135 bool RenderContext::showFog() const { 136 return m_showFog; 137 } 138 setShowFog(const bool showFog)139 void RenderContext::setShowFog(const bool showFog) { 140 m_showFog = showFog; 141 } 142 showGrid() const143 bool RenderContext::showGrid() const { 144 return m_showGrid; 145 } 146 setShowGrid(const bool showGrid)147 void RenderContext::setShowGrid(const bool showGrid) { 148 m_showGrid = showGrid; 149 } 150 gridSize() const151 size_t RenderContext::gridSize() const { 152 return m_gridSize; 153 } 154 setGridSize(const size_t gridSize)155 void RenderContext::setGridSize(const size_t gridSize) { 156 m_gridSize = gridSize; 157 } 158 hideSelection() const159 bool RenderContext::hideSelection() const { 160 return m_hideSelection; 161 } 162 setHideSelection()163 void RenderContext::setHideSelection() { 164 m_hideSelection = true; 165 } 166 tintSelection() const167 bool RenderContext::tintSelection() const { 168 return m_tintSelection; 169 } 170 clearTintSelection()171 void RenderContext::clearTintSelection() { 172 m_tintSelection = false; 173 } 174 showSelectionGuide() const175 bool RenderContext::showSelectionGuide() const { 176 return m_showSelectionGuide == ShowSelectionGuide_Show || m_showSelectionGuide == ShowSelectionGuide_ForceShow; 177 } 178 setShowSelectionGuide()179 void RenderContext::setShowSelectionGuide() { 180 setShowSelectionGuide(ShowSelectionGuide_Show); 181 } 182 setHideSelectionGuide()183 void RenderContext::setHideSelectionGuide() { 184 setShowSelectionGuide(ShowSelectionGuide_Hide); 185 } 186 setForceShowSelectionGuide()187 void RenderContext::setForceShowSelectionGuide() { 188 setShowSelectionGuide(ShowSelectionGuide_ForceShow); 189 } 190 setForceHideSelectionGuide()191 void RenderContext::setForceHideSelectionGuide() { 192 setShowSelectionGuide(ShowSelectionGuide_ForceHide); 193 } 194 setShowSelectionGuide(const ShowSelectionGuide showSelectionGuide)195 void RenderContext::setShowSelectionGuide(const ShowSelectionGuide showSelectionGuide) { 196 switch (showSelectionGuide) { 197 case ShowSelectionGuide_Show: 198 if (m_showSelectionGuide == ShowSelectionGuide_Hide) 199 m_showSelectionGuide = ShowSelectionGuide_Show; 200 break; 201 case ShowSelectionGuide_Hide: 202 if (m_showSelectionGuide == ShowSelectionGuide_Show) 203 m_showSelectionGuide = ShowSelectionGuide_Hide; 204 break; 205 case ShowSelectionGuide_ForceShow: 206 m_showSelectionGuide = ShowSelectionGuide_ForceShow; 207 break; 208 case ShowSelectionGuide_ForceHide: 209 if (m_showSelectionGuide != ShowSelectionGuide_ForceShow) 210 m_showSelectionGuide = ShowSelectionGuide_ForceHide; 211 break; 212 } 213 } 214 } 215 } 216