Changeset 3057 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 10/21/08 18:10:50 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3038 r3057 9 9 #include "ShadowMapping.h" 10 10 #include "Light.h" 11 #include "ResourceManager.h" 12 11 #include "ShaderManager.h" 13 12 14 13 #include <IL/il.h> … … 283 282 void DeferredRenderer::InitCg() 284 283 { 285 ResourceManager *rm = ResourceManager::GetSingleton(); 286 287 sCgDeferredProgram = rm->CreateFragmentProgram("deferred", "main"); 288 sCgDeferredShadowProgram = rm->CreateFragmentProgram("deferred", "main_shadow"); 289 sCgSsaoProgram = rm->CreateFragmentProgram("ssao", "main"); 290 sCgGiProgram = rm->CreateFragmentProgram("globillum", "main"); 291 sCgCombineIllumProgram = rm->CreateFragmentProgram("globillum", "combine"); 292 sCgCombineSsaoProgram = rm->CreateFragmentProgram("ssao", "combine"); 293 sCgAntiAliasingProgram = rm->CreateFragmentProgram("antialiasing", "main"); 294 sCgToneProgram = rm->CreateFragmentProgram("tonemap", "ToneMap"); 295 sCgDownSampleProgram = rm->CreateFragmentProgram("tonemap", "DownSample"); 296 sCgToneProgram = rm->CreateFragmentProgram("tonemap", "ToneMap"); 297 sCgLogLumProgram = rm->CreateFragmentProgram("tonemap", "CalcAvgLogLum"); 284 ShaderManager *sm = ShaderManager::GetSingleton(); 285 286 sCgDeferredProgram = sm->CreateFragmentProgram("deferred", "main", "deferredFrag"); 287 sCgDeferredShadowProgram = sm->CreateFragmentProgram("deferred", "main_shadow", "deferredFragShader"); 288 sCgSsaoProgram = sm->CreateFragmentProgram("ssao", "main", "ssaoFrag"); 289 sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "giFrag"); 290 sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "combineGi"); 291 sCgCombineSsaoProgram = sm->CreateFragmentProgram("ssao", "combine", "combineSsao"); 292 sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing"); 293 sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap"); 294 sCgDownSampleProgram = sm->CreateFragmentProgram("tonemap", "DownSample", "downSample"); 295 sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum"); 298 296 299 297 int i; … … 403 401 404 402 405 ResourceManager::GetSingleton()->EnableFragmentProfile();403 ShaderManager::GetSingleton()->EnableFragmentProfile(); 406 404 407 405 glDisable(GL_ALPHA_TEST); … … 475 473 476 474 FrameBufferObject::Release(); 477 ResourceManager::GetSingleton()->DisableFragmentProfile();475 ShaderManager::GetSingleton()->DisableFragmentProfile(); 478 476 } 479 477 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r3050 r3057 4 4 #include "ShaderProgram.h" 5 5 #include "Texture.h" 6 #include " ResourceManager.h"6 #include "ShaderManager.h" 7 7 8 8 … … 67 67 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 68 68 69 ResourceManager::GetSingleton()->DisableFragmentProfile();70 ResourceManager::GetSingleton()->DisableVertexProfile();69 ShaderManager::GetSingleton()->DisableFragmentProfile(); 70 ShaderManager::GetSingleton()->DisableVertexProfile(); 71 71 72 72 mFragmentProgramEnabled = false; … … 219 219 { 220 220 mFragmentProgramEnabled = true; 221 ResourceManager::GetSingleton()->EnableFragmentProfile();221 ShaderManager::GetSingleton()->EnableFragmentProfile(); 222 222 } 223 223 … … 235 235 { 236 236 mFragmentProgramEnabled = false; 237 ResourceManager::GetSingleton()->DisableFragmentProfile();237 ShaderManager::GetSingleton()->DisableFragmentProfile(); 238 238 } 239 239 } … … 246 246 { 247 247 mVertexProgramEnabled = true; 248 ResourceManager::GetSingleton()->EnableVertexProfile();248 ShaderManager::GetSingleton()->EnableVertexProfile(); 249 249 } 250 250 … … 262 262 { 263 263 mVertexProgramEnabled = false; 264 ResourceManager::GetSingleton()->DisableVertexProfile();264 ShaderManager::GetSingleton()->DisableVertexProfile(); 265 265 } 266 266 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3055 r3057 12 12 #include "RenderState.h" 13 13 #include "ShaderProgram.h" 14 #include <Cg/cg.h> 15 #include <Cg/cgGL.h> 14 #include "ShaderManager.h" 16 15 17 16 … … 34 33 35 34 36 /////////37 //-- cg stuff38 39 static CGcontext sCgContext = NULL;40 41 static CGprofile sCgFragmentProfile;42 static CGprofile sCgVertexProfile;43 44 static ShaderProgram *sTreeAnimationProgramMrt;45 static ShaderProgram *sTreeAnimationProgram;46 47 48 35 // only instance of the resource manager 49 36 ResourceManager *ResourceManager::sResourceManager = NULL; 50 37 51 38 52 static void cgErrorCallback()53 {54 CGerror lastError = cgGetError();55 56 if(lastError)57 {58 printf("%s\n\n", cgGetErrorString(lastError));59 printf("%s\n", cgGetLastListing(sCgContext));60 61 printf("Cg error, exiting...\n");62 63 exit(0);64 }65 }66 67 68 39 ResourceManager::ResourceManager() 69 40 { 70 InitCg();71 41 } 72 42 … … 82 52 CLEAR_CONTAINER(mShapes); 83 53 CLEAR_CONTAINER(mLODs); 84 CLEAR_CONTAINER(mGPUParameters);85 CLEAR_CONTAINER(mShaders);86 87 if (sCgContext)88 cgDestroyContext(sCgContext);89 54 } 90 55 … … 160 125 sceneGeom->AddLODLevel(lodLevel); 161 126 } 127 128 static ShaderProgram *sTreeAnimationProgram = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimation"); 129 static ShaderProgram *sTreeAnimationProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimationMrt"); 162 130 163 131 /////////// … … 310 278 //-- add technique for deferred shading 311 279 280 static ShaderProgram *sDefaultFragmentProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultFragmentMrt"); 281 static ShaderProgram *sDefaultFragmentTexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultFragmentTexMrt"); 282 static ShaderProgram *sDefaultVertexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultVertexMrt"); 283 312 284 Technique *deferred = new Technique(*tech); 313 285 314 286 if (deferred->GetTexture()) 315 287 { 316 deferred->SetFragmentProgram( mMrtDefaultFragmentTexProgram);288 deferred->SetFragmentProgram(sDefaultFragmentTexProgramMrt); 317 289 deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0); 318 290 deferred->GetFragmentProgramParameters()->SetTexture(1, tech->GetTexture()->GetId()); … … 320 292 else 321 293 { 322 deferred->SetFragmentProgram( mMrtDefaultFragmentProgram);294 deferred->SetFragmentProgram(sDefaultFragmentTexProgramMrt); 323 295 deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0); 324 296 } 325 297 326 deferred->SetVertexProgram( mMrtDefaultVertexProgram);298 deferred->SetVertexProgram(sDefaultVertexProgramMrt); 327 299 mat->AddTechnique(deferred); 328 300 … … 435 407 } 436 408 437 438 ShaderProgram *ResourceManager::CreateFragmentProgram(const std::string &filename, 439 const std::string &funcName) 440 { 441 const string fullName = "src/shaders/" + filename + ".cg"; 442 443 ShaderProgram *p = new ShaderProgram(sCgContext, fullName, sCgFragmentProfile, funcName); 444 mShaders.push_back(p); 445 446 if (!p->IsValid()) 447 { 448 DEL_PTR(p); 449 cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl; 450 } 451 452 cout << "Program " << funcName << " in " << fullName << " loaded" << endl; 453 454 return p; 455 } 456 457 458 ShaderProgram *ResourceManager::CreateVertexProgram(const std::string &filename, const std::string &funcName) 459 { 460 const string fullName = "src/shaders/" + filename + ".cg"; 461 462 ShaderProgram *p = new ShaderProgram(sCgContext, fullName, sCgVertexProfile, funcName); 463 mShaders.push_back(p); 464 465 if (!p->IsValid()) 466 { 467 DEL_PTR(p); 468 cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl; 469 } 470 else 471 cout << "Program " << funcName << " in " << fullName << " loaded" << endl; 472 473 return p; 474 } 475 476 477 void ResourceManager::InitCg() 478 { 479 // setup cg 480 cgSetErrorCallback(cgErrorCallback); 481 // create context. 482 sCgContext = cgCreateContext(); 483 // get the optimal fragment profile 484 sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); 485 cgGLSetOptimalOptions(sCgFragmentProfile); 486 // get the optimal vertex profile 487 sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); 488 cgGLSetOptimalOptions(sCgVertexProfile); 489 490 // set textures to auto load 491 cgGLSetManageTextureParameters(sCgContext, false); 492 493 mMrtDefaultVertexProgram = CreateVertexProgram("mrt", "vtx"); 494 mMrtDefaultFragmentProgram = CreateFragmentProgram("mrt", "frag"); 495 mMrtDefaultFragmentTexProgram = CreateFragmentProgram("mrt", "fragtex"); 496 497 // provide the current view matrix 498 mMrtDefaultFragmentProgram->AddParameter("viewMatrix", 0); 499 mMrtDefaultFragmentTexProgram->AddParameter("viewMatrix", 0); 500 // add a texture parameter 501 mMrtDefaultFragmentTexProgram->AddParameter("tex", 1); 502 503 504 //////////// 505 //-- hack: apply hardcoded tree animation (should be provided with a material script!) 506 507 sTreeAnimationProgram = CreateVertexProgram("treeanimation", "animateVtx"); 508 sTreeAnimationProgramMrt = CreateVertexProgram("treeanimation", "animateVtxMrt"); 509 510 sTreeAnimationProgram->AddParameter("timer", 0); 511 sTreeAnimationProgram->AddParameter("windDir", 1); 512 sTreeAnimationProgram->AddParameter("windStrength", 2); 513 sTreeAnimationProgram->AddParameter("minMaxPos", 3); 514 sTreeAnimationProgram->AddParameter("frequency", 4); 515 sTreeAnimationProgram->AddParameter("lightDir", 5); 516 517 sTreeAnimationProgramMrt->AddParameter("timer", 0); 518 sTreeAnimationProgramMrt->AddParameter("windDir", 1); 519 sTreeAnimationProgramMrt->AddParameter("windStrength", 2); 520 sTreeAnimationProgramMrt->AddParameter("minMaxPos", 3); 521 sTreeAnimationProgramMrt->AddParameter("frequency", 4); 522 523 cout << "cg initialization successful" << endl; 524 } 525 526 527 void ResourceManager::EnableFragmentProfile() 528 { 529 cgGLEnableProfile(sCgFragmentProfile); 530 } 531 532 533 void ResourceManager::EnableVertexProfile() 534 { 535 cgGLEnableProfile(sCgVertexProfile); 536 } 537 538 539 void ResourceManager::DisableFragmentProfile() 540 { 541 cgGLDisableProfile(sCgFragmentProfile); 542 } 543 544 545 void ResourceManager::DisableVertexProfile() 546 { 547 cgGLDisableProfile(sCgVertexProfile); 548 549 } 550 551 552 } 553 409 } 410 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
r3054 r3057 1 #ifndef __R esourceManager_H__2 #define __R esourceManager_H__1 #ifndef __RESOURCEMANAGER_H__ 2 #define __RESOURCEMANAGER_H__ 3 3 4 4 … … 38 38 */ 39 39 int GetNumEntities() const { return (int)mSceneEntities.size(); } 40 /** Creates new gpu program parameters.41 */42 GPUProgramParameters *CreateGPUProgramParameters(ShaderProgram *p);43 /** Creates a new shader program.44 */45 ShaderProgram *CreateFragmentProgram(const std::string &filename, const std::string &funcName);46 ShaderProgram *CreateVertexProgram(const std::string &filename, const std::string &funcName);47 48 void EnableFragmentProfile();49 void EnableVertexProfile();50 51 void DisableFragmentProfile();52 void DisableVertexProfile();53 40 /** Returns pointer to shape container. 54 41 */ … … 57 44 */ 58 45 const SceneEntityContainer * const GetSceneEntities() const { return &mSceneEntities; } 59 60 46 /** Returns the resource manager as a singleton. 61 47 */ … … 74 60 75 61 ~ResourceManager(); 76 77 78 void InitCg();79 62 80 63 void LoadTextures(igzstream &str); … … 99 82 GeometryContainer mGeometry; 100 83 TransformContainer mTrafos; 101 GPUParamContainer mGPUParameters;102 ShaderContainer mShaders;103 84 ShapeContainer mShapes; 104 85 LODContainer mLODs; 105 86 /// the scene entities 106 87 SceneEntityContainer mSceneEntities; 107 108 109 ////////////110 //-- default shader programs111 112 ShaderProgram *mMrtDefaultVertexProgram;113 ShaderProgram *mMrtDefaultFragmentProgram;114 ShaderProgram *mMrtDefaultFragmentTexProgram;115 116 88 117 89 private: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp
r3056 r3057 179 179 isFragment ? sCgFragmentProfile : sCgVertexProfile, funcName); 180 180 181 ShaderMap::const_iterator it = mShaderMap.find(name); 182 183 if (it == mShaderMap.end()) 181 if (GetShaderProgram(name)) 184 182 { 183 cerr << "Program name " << name << "already chosen" << endl; 184 185 185 DEL_PTR(p); 186 187 cerr << "Program name " << name << "already chosen" << endl;188 186 return p; 189 187 } … … 191 189 if (!p->IsValid()) 192 190 { 191 cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl; 192 193 193 DEL_PTR(p); 194 cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl;195 194 return p; 196 195 } 197 196 197 198 // everything ok 198 199 cout << "Program " << funcName << " in " << fullName << " loaded" << endl; 199 200 … … 205 206 206 207 207 } 208 208 ShaderProgram *ShaderManager::GetShaderProgram(const std::string &name) 209 { 210 ShaderMap::const_iterator it = mShaderMap.find(name); 211 212 if (it == mShaderMap.end()) 213 return NULL; 214 215 return (*it).second; 216 } 217 218 219 } 220 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.h
r3056 r3057 27 27 /** Returns the resource manager as a singleton. 28 28 */ 29 static ShaderManager *GetSingleton();29 inline static ShaderManager *GetSingleton(); 30 30 /** We also want full control over the delete. 31 31 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r3054 r3057 9 9 #include "Shape.h" 10 10 #include "Material.h" 11 #include " ResourceManager.h"11 #include "ShaderManager.h" 12 12 13 13 … … 46 46 { 47 47 mSkyVtxProgram = 48 ResourceManager::GetSingleton()->CreateVertexProgram("sky_preetham", "default_vs");48 ShaderManager::GetSingleton()->CreateVertexProgram("sky_preetham", "default_vs", "skyVtx"); 49 49 50 50 if (mSkyVtxProgram->IsValid()) … … 64 64 65 65 mSkyFragProgram = 66 ResourceManager::GetSingleton()->CreateFragmentProgram("sky_preetham", "frag_skydome");66 ShaderManager::GetSingleton()->CreateFragmentProgram("sky_preetham", "frag_skydome", "skyFragMrt"); 67 67 } 68 68 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3054 r3057 53 53 #include "SkyPreetham.h" 54 54 #include "Texture.h" 55 #include "EntityMerger.h" 55 //#include "EntityMerger.h" 56 #include "ShaderManager.h" 56 57 57 58 using namespace std; … … 75 76 /// handles scene loading 76 77 ResourceManager *loader = NULL; 78 /// handles scene loading 79 ShaderManager *shaderManager = NULL; 77 80 /// the scene camera 78 81 Camera *camera = NULL; … … 419 422 420 423 loader = ResourceManager::GetSingleton(); 424 shaderManager = ShaderManager::GetSingleton(); 421 425 422 426 const string filename = string(model_path + "city.dem"); … … 829 833 state.SetRenderTechnique(RenderState::DEFERRED); 830 834 831 loader->EnableVertexProfile();832 loader->EnableFragmentProfile();835 shaderManager->EnableVertexProfile(); 836 shaderManager->EnableFragmentProfile(); 833 837 834 838 const Vector3 pos = camera->GetPosition(); … … 1655 1659 1656 1660 ResourceManager::DelSingleton(); 1661 ShaderManager::DelSingleton(); 1662 1657 1663 loader = NULL; 1664 shaderManager = NULL; 1658 1665 } 1659 1666 … … 1955 1962 void RenderShadowMap(float newfar) 1956 1963 { 1957 loader->DisableVertexProfile();1958 loader->DisableFragmentProfile();1964 shaderManager->DisableVertexProfile(); 1965 shaderManager->DisableFragmentProfile(); 1959 1966 1960 1967 glDisableClientState(GL_NORMAL_ARRAY);
Note: See TracChangeset
for help on using the changeset viewer.