Changeset 3050 for GTP/trunk/App
- Timestamp:
- 10/20/08 14:51:01 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r3048 r3050 30 30 mFragmentProgram = NULL; 31 31 32 // /if this material can write colors32 // if this material can write colors 33 33 mColorWriteEnabled = true; 34 // /if lighting is used34 // if lighting is used 35 35 mLightingEnabled = true; 36 37 mDepthWriteEnabled = true; 36 38 } 37 39 … … 56 58 } 57 59 60 61 Technique::Technique(const Technique &tech) 62 { 63 mAmbientColor = tech.mAmbientColor; 64 mDiffuseColor = tech.mDiffuseColor; 65 mSpecularColor = tech.mSpecularColor; 66 mEmmisiveColor = tech.mEmmisiveColor; 67 68 mVertexProgram = tech.mVertexProgram; 69 mFragmentProgram = tech.mFragmentProgram; 70 71 mAlphaTestEnabled = tech.mAlphaTestEnabled; 72 mCullFaceEnabled =tech.mCullFaceEnabled; 73 74 mTexture = tech.mTexture; 75 76 mVertexProgramParameters = tech.mVertexProgramParameters; 77 mFragmentProgramParameters = tech.mFragmentProgramParameters; 78 79 mColorWriteEnabled = tech.mColorWriteEnabled; 80 mLightingEnabled = tech.mLightingEnabled; 81 mDepthWriteEnabled = tech.mDepthWriteEnabled; 82 } 58 83 59 84 … … 89 114 mVertexProgramParameters.Reset(); 90 115 mVertexProgramParameters.SetProgram(p); 91 }92 93 94 Technique Technique::GetQueryTechnique()95 {96 Technique tech;97 98 tech.Init();99 100 tech.SetColorWriteEnabled(false);101 tech.SetLightingEnabled(false);102 103 return tech;104 116 } 105 117 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
r3048 r3050 55 55 Technique(); 56 56 57 ~Technique();57 Technique(const Technique &tech); 58 58 /** Sets ambient and diffuse color to color 59 59 */ 60 60 Technique(const RgbaColor &color); 61 62 ~Technique(); 61 63 /** Renders this technique. 62 64 */ … … 88 90 inline void SetLightingEnabled(bool l) { mLightingEnabled = l; } 89 91 inline void SetColorWriteEnabled(bool c) { mColorWriteEnabled = c; } 92 inline void SetDepthWriteEnabled(bool d) { mDepthWriteEnabled = d; } 90 93 91 94 inline bool IsLightingEnabled() const { return mLightingEnabled; } 92 95 inline bool IsColorWriteEnabled() const { return mColorWriteEnabled; } 96 inline bool IsDepthWriteEnabled() const { return mDepthWriteEnabled; } 93 97 94 98 void SetFragmentProgram(ShaderProgram *p); 95 99 void SetVertexProgram(ShaderProgram *p); 96 100 97 ShaderProgram *GetFragmentProgram() { return mFragmentProgram; }98 ShaderProgram *GetVertexProgram() { return mVertexProgram; }101 inline ShaderProgram *GetFragmentProgram() { return mFragmentProgram; } 102 inline ShaderProgram *GetVertexProgram() { return mVertexProgram; } 99 103 100 104 /** Get the set of fragment parameters of this technique … … 104 108 */ 105 109 GPUProgramParameters * const GetVertexProgramParameters() { return &mVertexProgramParameters; } 106 107 static Technique GetQueryTechnique();108 110 109 111 protected: … … 130 132 /// if lighting is used 131 133 bool mLightingEnabled; 134 /// if depth write is enabled 135 bool mDepthWriteEnabled; 132 136 }; 133 137 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r3048 r3050 19 19 mRenderTechnique(FORWARD), 20 20 mUseAlphaToCoverage(true), 21 mLockCullFaceEnabled(false) 21 mLockCullFaceEnabled(false), 22 mCurrentVboId(-1), 23 mCurrentTexId(0), 24 mCullFaceEnabled(true), 25 mAlphaTestEnabled(false), 26 mTexturesEnabled(false), 27 mCurrentVertexProgram(NULL), 28 mCurrentFragmentProgram(NULL), 29 mLightingEnabled(true), 30 mColorWriteEnabled(true), 31 mDepthWriteEnabled(true), 32 mCurrentTechnique(NULL) 33 { 34 SetMode(RENDER); 35 36 glEnable(GL_CULL_FACE); 37 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 38 glDisable(GL_ALPHA_TEST); 39 glDisable(GL_TEXTURE_2D); 40 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 41 glEnable(GL_LIGHTING); 42 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 43 glDepthMask(GL_TRUE); 44 } 45 46 47 void RenderState::Reset() 22 48 { 23 49 SetMode(RENDER); … … 40 66 glDisable(GL_TEXTURE_2D); 41 67 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 42 }43 44 45 void RenderState::Reset()46 {47 SetMode(RENDER);48 49 mCurrentVboId = -1;50 mCurrentTexId = 0;51 52 mCullFaceEnabled = true;53 mAlphaTestEnabled = false;54 mTexturesEnabled = false;55 56 mCurrentVertexProgram = NULL;57 mCurrentFragmentProgram = NULL;58 59 glEnable(GL_CULL_FACE);60 61 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);62 glDisable(GL_ALPHA_TEST);63 64 glDisable(GL_TEXTURE_2D);65 glDisableClientState(GL_TEXTURE_COORD_ARRAY);66 68 67 69 ResourceManager::GetSingleton()->DisableFragmentProfile(); … … 70 72 mFragmentProgramEnabled = false; 71 73 mVertexProgramEnabled = false; 72 } 74 75 mLightingEnabled = true; 76 glEnable(GL_LIGHTING); 77 78 mColorWriteEnabled = true; 79 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 80 81 mDepthWriteEnabled = true; 82 glDepthMask(GL_TRUE); 83 84 mCurrentTechnique = NULL; 85 } 86 73 87 74 88 // q matt: is this function really necessary or would it be better … … 77 91 { 78 92 /////////// 79 //-- just change the mode when necessary93 //-- just change the mode when necessary 80 94 81 95 if (mode == mMode) return false; … … 85 99 if (mode == QUERY) 86 100 { 87 if (mLightingEnabled)88 glDisable(GL_LIGHTING);89 90 if (mColorWriteEnabled)91 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);92 93 if (mFragmentProgramEnabled)94 ResourceManager::GetSingleton()->DisableFragmentProfile();95 96 if (mVertexProgramEnabled)97 ResourceManager::GetSingleton()->DisableVertexProfile();98 99 glDepthMask(GL_FALSE);100 101 101 /// the query box material 102 static Technique queryTech = Technique::GetQueryTechnique();102 static Technique queryTech = GetQueryTechnique(); 103 103 SetState(&queryTech); 104 }105 else // mode returns to render106 {107 /////////////108 //-- restore render state109 110 if (mLightingEnabled)111 glEnable(GL_LIGHTING);112 113 if (mColorWriteEnabled)114 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);115 116 if (mFragmentProgramEnabled)117 ResourceManager::GetSingleton()->EnableFragmentProfile();118 119 if (mVertexProgramEnabled)120 ResourceManager::GetSingleton()->EnableVertexProfile();121 122 glDepthMask(GL_TRUE);123 104 } 124 105 … … 129 110 void RenderState::SetState(Technique *tech) 130 111 { 131 Texture *tex = tech->GetTexture(); 112 if (mCurrentTechnique == tech) 113 return; 114 115 mCurrentTechnique = tech; 116 117 Texture * const tex = tech->GetTexture(); 132 118 133 119 const bool texturing = (tex != NULL); 134 135 bool alphaTest = tech->IsAlphaTestEnabled(); 136 bool cullFace = tech->IsCullFaceEnabled(); 120 const bool alphaTest = tech->IsAlphaTestEnabled(); 121 const bool cullFace = tech->IsCullFaceEnabled(); 122 const bool lighting = tech->IsLightingEnabled(); 123 const bool colorWrite = tech->IsColorWriteEnabled(); 124 const bool depthWrite = tech->IsDepthWriteEnabled(); 125 126 if (mDepthWriteEnabled && !depthWrite) 127 { 128 mDepthWriteEnabled = false; 129 glDepthMask(GL_FALSE); 130 } 131 else if (!mDepthWriteEnabled && depthWrite) 132 { 133 mDepthWriteEnabled = true; 134 glDepthMask(GL_TRUE); 135 } 136 137 if (mLightingEnabled && !lighting) 138 { 139 mLightingEnabled = false; 140 glDisable(GL_LIGHTING); 141 } 142 else if (!mLightingEnabled && lighting) 143 { 144 mLightingEnabled = true; 145 glEnable(GL_LIGHTING); 146 } 147 148 if (mColorWriteEnabled && !colorWrite) 149 { 150 mColorWriteEnabled = false; 151 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 152 } 153 else if (!mColorWriteEnabled && colorWrite) 154 { 155 mColorWriteEnabled = true; 156 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 157 } 137 158 138 159 if (!mLockCullFaceEnabled) … … 172 193 mTexturesEnabled = false; 173 194 174 if (!tech->GetFragmentProgram())195 //if (!tech->GetFragmentProgram()) 175 196 glDisable(GL_TEXTURE_2D); 176 197 … … 179 200 else if (!mTexturesEnabled && texturing) 180 201 { 181 if (mAlphaTestEnabled) 182 { 183 mTexturesEnabled = true; 184 185 if (!tech->GetFragmentProgram()) 186 glEnable(GL_TEXTURE_2D); 187 188 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 189 } 190 } 191 192 /////////////////// 202 mTexturesEnabled = true; 203 204 //if (!tech->GetFragmentProgram()) 205 glEnable(GL_TEXTURE_2D); 206 207 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 208 } 209 210 211 ////////////////// 193 212 //-- fragment and vertex programs 194 213 … … 249 268 if (!mFragmentProgramEnabled) 250 269 { 251 // set FORWARD texture270 // set texture for fixed function rendering 252 271 if (tex) 253 272 { … … 260 279 else 261 280 { 262 mCurrentTexId = 0;281 mCurrentTexId = -1; 263 282 glBindTexture(GL_TEXTURE_2D, 0); 264 283 } 265 284 } 285 } 286 287 288 Technique RenderState::GetQueryTechnique() 289 { 290 Technique tech; 291 292 tech.Init(); 293 294 tech.SetColorWriteEnabled(false); 295 tech.SetLightingEnabled(false); 296 tech.SetDepthWriteEnabled(false); 297 298 return tech; 266 299 } 267 300 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r3048 r3050 75 75 protected: 76 76 77 /** A special query technique. This material 78 has color write, depth write, and lighting turned off 79 */ 80 static Technique GetQueryTechnique(); 81 82 77 83 ////////////////// 78 84 … … 101 107 bool mLightingEnabled; 102 108 bool mColorWriteEnabled; 109 110 Technique *mCurrentTechnique; 111 bool mDepthWriteEnabled; 103 112 }; 104 113 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3048 r3050 159 159 //-- hack: add tree animation (should be done per material script!) 160 160 161 if ( 0)//numLODs > 1)161 if (numLODs > 1) 162 162 { 163 163 ShapeContainer::iterator sstart, send; … … 176 176 177 177 // add the vertex animation program 178 for (int i = 0; i < 2; ++ i)178 for (int i = 0; i < 3; ++ i) 179 179 { 180 180 Technique *tech = mat->GetTechnique(i); … … 320 320 321 321 deferred->SetVertexProgram(mMrtDefaultVertexProgram); 322 mat->AddTechnique(deferred); 322 323 323 324 … … 328 329 depthPass->SetColorWriteEnabled(false); 329 330 depthPass->SetLightingEnabled(false); 330 331 mat->AddTechnique(deferred);332 331 mat->AddTechnique(depthPass); 333 332 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3049 r3050 1012 1012 // this would conveniently solves some issues (e.g, skys without shadows) 1013 1013 1014 RenderSky();1014 //RenderSky(); 1015 1015 1016 1016
Note: See TracChangeset
for help on using the changeset viewer.