1 //////////////////////////////////////////////////////////////////////////////// 2 // Scorched3D (c) 2000-2011 3 // 4 // This file is part of Scorched3D. 5 // 6 // Scorched3D 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 2 of the License, or 9 // (at your option) any later version. 10 // 11 // Scorched3D 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 along 17 // with this program; if not, write to the Free Software Foundation, Inc., 18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 //////////////////////////////////////////////////////////////////////////////// 20 21 #if !defined(__INCLUDE_Landscapeh_INCLUDE__) 22 #define __INCLUDE_Landscapeh_INCLUDE__ 23 24 #include <GLEXT/GLTexture.h> 25 #include <GLEXT/GLShadowFrameBuffer.h> 26 27 class Wall; 28 class ShadowMap; 29 class Smoke; 30 class ProgressCounter; 31 class Water; 32 class LandscapePoints; 33 class Sky; 34 class GLSLShaderSetup; 35 class Landscape 36 { 37 public: 38 static Landscape *instance(); 39 40 enum LandscapeTextureType 41 { 42 eDefault, 43 eOther 44 }; 45 46 void generate(ProgressCounter *counter = 0); 47 void recalculateLandscape(); 48 void recalculateRoof(); 49 void restoreLandscapeTexture(); 50 51 // Access to internal objects getSmoke()52 Smoke &getSmoke() { return *smoke_; } 53 ShadowMap &getShadowMap(); getWall()54 Wall &getWall() { return *wall_; } getSky()55 Sky &getSky() { return *sky_; } getWater()56 Water &getWater() { return *water_; } getPoints()57 LandscapePoints &getPoints() { return *points_; } 58 59 // Textures created during landscape texturing getMainMap()60 Image &getMainMap() { return mainMap_; } getScorchMap()61 Image &getScorchMap() { return scorchMap_; } getMainTexture()62 GLTexture &getMainTexture() { return texture_; } getMagTexture()63 GLTexture &getMagTexture() { return magTexture_; } getPlanATexture()64 GLTexture &getPlanATexture() { return planAlphaTexture_; } getPlanTexture()65 GLTexture &getPlanTexture() { return planTexture_; } getLandscapeTexture1()66 GLTexture &getLandscapeTexture1() { return landTex1_; } getGroundTexture()67 GLTexture &getGroundTexture() { return groundTexture_; } getDetailTexture()68 GLTexture &getDetailTexture() { return detailTexture_; } getRoofTexture()69 GLTexture &getRoofTexture() { return roofTexture_; } getArenaMainTexture()70 GLTexture &getArenaMainTexture() { return arenaMainTexture_; } 71 getTextureType()72 LandscapeTextureType getTextureType() { return textureType_; } setTextureType(LandscapeTextureType type)73 void setTextureType(LandscapeTextureType type) { textureType_ = type; } 74 getShadowTextureMatrix()75 float *getShadowTextureMatrix() { return shadowTextureMatrix_; } getShadowFrameBuffer()76 GLShadowFrameBuffer &getShadowFrameBuffer() { return shadowFrameBuffer_; } 77 78 void updatePlanTexture(); 79 void updatePlanATexture(); 80 int getPlanTexSize(); 81 int getMapTexSize(); 82 getChangeCount()83 unsigned int getChangeCount() { return changeCount_; } 84 85 void drawTearDown(); 86 void drawSetup(); 87 void drawLand(); 88 void drawWater(); 89 void drawObjects(); 90 void drawShadows(); 91 void calculateVisibility(); 92 93 void simulate(float frameTime); 94 95 protected: 96 static Landscape *instance_; 97 98 // All objects that are used to draw the scene 99 Wall *wall_; 100 Sky *sky_; 101 Smoke *smoke_; 102 Water *water_; 103 LandscapeTextureType textureType_; 104 LandscapePoints *points_; 105 106 // Textures used for landscape 107 GLTexture texture_; 108 GLTexture magTexture_; 109 GLTexture planTexture_; 110 GLTexture planAlphaTexture_; 111 GLTexture detailTexture_; 112 GLTexture roofTexture_; 113 GLTexture landTex1_; 114 GLTexture groundTexture_; 115 GLTexture arenaMainTexture_; 116 GLTexture arenaSurroundTexture_; 117 Image mainMap_; 118 Image scorchMap_; 119 Image bitmapPlanAlphaAlpha_; 120 Image bitmapPlanAlpha_; 121 Image bitmapPlan_; 122 123 // Shadow map 124 float shadowTextureMatrix_[16]; 125 float lightModelMatrix_[16]; 126 float lightProjMatrix_[16]; 127 GLShadowFrameBuffer shadowFrameBuffer_; 128 GLSLShaderSetup *landShader_; 129 GLTexture colorDepthMap_; 130 131 // Variables used to set when the water is refreshed 132 bool resetLandscape_, resetRoof_; 133 float resetLandscapeTimer_, resetRoofTimer_; 134 unsigned int changeCount_; 135 136 void savePlan(); 137 void actualDrawLandTextured(); 138 void actualDrawLandReflection(); 139 void actualDrawLandShader(); 140 void createShadowMatrix(); 141 void drawGraphicalTextureMap(GLTexture &texture); 142 143 // Nasty, we really need some kind of viewport/rendering context 144 // that the current rendering state for the scene can be stored. 145 // Useful for things that relate to each drawn scene rather than 146 // global. e.g. camera window vs main window 147 struct CameraContext 148 { 149 CameraContext(); 150 151 ShadowMap *shadowMap_; 152 } cameraContexts_[2]; 153 154 private: 155 Landscape(); 156 virtual ~Landscape(); 157 }; 158 159 160 #endif 161