- Timestamp:
- 10/17/08 16:32:37 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 1 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln
r3037 r3038 7 7 EndProject 8 8 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MainApp", "MainApp.vcproj", "{A564071F-D054-4556-883B-999D7F9CC58C}" 9 ProjectSection(ProjectDependencies) = postProject10 {03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023}11 EndProjectSection12 EndProject13 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IrradianceMapping", "IrradianceMapping.vcproj", "{91680C49-A358-48AE-A02C-66CB884B7D7F}"14 9 ProjectSection(ProjectDependencies) = postProject 15 10 {03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023} … … 34 29 {A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.ActiveCfg = Release|Win32 35 30 {A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.Build.0 = Release|Win32 36 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.ActiveCfg = Debug|Win3237 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.Build.0 = Debug|Win3238 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.ActiveCfg = Release|Win3239 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.Build.0 = Release|Win3240 31 EndGlobalSection 41 32 GlobalSection(SolutionProperties) = preSolution -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp
r2878 r3038 294 294 while (!mIQueue.empty()) 295 295 mQueryQueue.push(GetNextMultiQuery(mIQueue)); 296 297 298 296 } 297 else 298 { 299 299 BvhNodeContainer::const_iterator it, it_end = mIQueue.end(); 300 300 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3036 r3038 9 9 #include "ShadowMapping.h" 10 10 #include "Light.h" 11 #include "ResourceManager.h" 12 11 13 12 14 #include <IL/il.h> … … 260 262 261 263 mFBOs.push_back(mDownSampleFbo); 264 265 InitCg(); 262 266 } 263 267 … … 276 280 277 281 278 void DeferredRenderer::ReleaseCG() 279 { 280 CLEAR_CONTAINER(sShaders); 281 } 282 283 284 bool DeferredRenderer::InitProgram(ShaderProgram **program, 285 CGcontext context, 286 const std::string &filename, 287 const std::string &functionName) 288 { 289 const string fullName = "src/shaders/" + filename + ".cg"; 290 291 *program = new ShaderProgram(context, fullName, RenderState::sCgFragmentProfile, functionName); 292 293 sShaders.push_back(*program); 294 295 if (!(*program)->IsValid()) 296 { 297 cerr << "Program " << functionName << " in " << fullName << " failed to load" << endl; 298 return false; 299 } 300 301 cout << "Program " << functionName << " in " << fullName << " loaded" << endl; 302 303 return true; 304 } 305 306 307 void DeferredRenderer::InitCG(CGcontext context) 282 283 void DeferredRenderer::InitCg() 308 284 { 309 InitProgram(&sCgDeferredProgram, context, "deferred", "main"); 310 InitProgram(&sCgDeferredShadowProgram, context, "deferred", "main_shadow"); 311 InitProgram(&sCgSsaoProgram, context, "ssao", "main"); 312 InitProgram(&sCgGiProgram, context, "globillum", "main"); 313 InitProgram(&sCgCombineIllumProgram, context, "globillum", "combine"); 314 InitProgram(&sCgCombineSsaoProgram, context, "ssao", "combine"); 315 InitProgram(&sCgAntiAliasingProgram, context, "antialiasing", "main"); 316 InitProgram(&sCgToneProgram, context, "tonemap", "ToneMap"); 317 InitProgram(&sCgDownSampleProgram, context, "tonemap", "DownSample"); 318 InitProgram(&sCgToneProgram, context, "tonemap", "ToneMap"); 319 InitProgram(&sCgLogLumProgram, context, "tonemap", "CalcAvgLogLum"); 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"); 320 298 321 299 int i; … … 425 403 426 404 427 cgGLEnableProfile(RenderState::sCgFragmentProfile);405 ResourceManager::GetSingleton()->EnableFragmentProfile(); 428 406 429 407 glDisable(GL_ALPHA_TEST); … … 497 475 498 476 FrameBufferObject::Release(); 499 cgGLDisableProfile(RenderState::sCgFragmentProfile);477 ResourceManager::GetSingleton()->DisableFragmentProfile(); 500 478 } 501 479 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3027 r3038 22 22 23 23 24 typedef std::vector<FrameBufferObject *> FBOContainer;25 24 26 25 /** This class implements a deferred shading algorithm that takes … … 64 63 65 64 void SetShadingMethod(SHADING_METHOD s); 66 67 /** Initialises the deferred shader and loads the required shaders:68 This function has to be called only once.69 */70 static void InitCG(CGcontext context);71 /** Releases all shader resources.72 */73 static void ReleaseCG();74 65 66 // hack: store the color buffer idx for the first flipflip-mrt here 67 // TODO matt: make this less hacky 75 68 static int colorBufferIdx; 69 76 70 77 71 protected: … … 92 86 void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap); 93 87 94 void ComputeToneParameters(FrameBufferObject *fbo, DirectionalLight *light, float &imageKey, float &whiteLum, float &middleGrey); 88 void ComputeToneParameters(FrameBufferObject *fbo, 89 DirectionalLight *light, 90 float &imageKey, 91 float &whiteLum, 92 float &middleGrey); 95 93 96 94 void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey); … … 113 111 void DrawQuad(ShaderProgram *p); 114 112 115 static bool InitProgram(ShaderProgram **program,116 CGcontext context,117 const std::string &filename,118 const std::string &functionName);113 /** Initialises the deferred shader and loads the required shaders: 114 This function has to be called only once. 115 */ 116 void InitCg(); 119 117 120 118 … … 145 143 }; 146 144 145 147 146 } // namespace 148 147 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r3036 r3038 79 79 glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r); 80 80 glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r); 81 82 83 if (mVertexProgram)84 {85 mGPUVertexParameters->UpdateParameters();86 }87 88 if (mFragmentProgram)89 {90 mGPUFragmentParameters->UpdateParameters();91 }92 81 } 93 82 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r3036 r3038 4 4 #include "ShaderProgram.h" 5 5 #include "Texture.h" 6 #include "ResourceManager.h" 7 6 8 7 9 using namespace std; 8 10 11 9 12 namespace CHCDemoEngine 10 13 { 11 12 CGprofile RenderState::sCgFragmentProfile;13 CGprofile RenderState::sCgVertexProfile;14 15 ShaderProgram *RenderState::sCgMrtFragmentProgram = NULL;16 ShaderProgram *RenderState::sCgMrtFragmentTexProgram = NULL;17 ShaderProgram *RenderState::sCgMrtVertexProgram = NULL;18 19 20 int RenderState::sTexParam;21 22 14 23 15 … … 29 21 mLockCullFaceEnabled(false) 30 22 { 31 Reset(); 32 } 33 34 23 SetMode(RENDER); 24 25 mCurrentVboId = -1; 26 mCurrentTexId = 0; 27 28 mCullFaceEnabled = true; 29 mAlphaTestEnabled = false; 30 mTexturesEnabled = false; 31 32 mCurrentVertexProgram = NULL; 33 mCurrentFragmentProgram = NULL; 34 35 glEnable(GL_CULL_FACE); 36 37 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 38 glDisable(GL_ALPHA_TEST); 39 40 glDisable(GL_TEXTURE_2D); 41 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 67 //ResourceManager::GetSingleton()->DisableFragmentProfile(); 68 //ResourceManager::GetSingleton()->DisableVertexProfile(); 69 } 70 71 35 72 bool RenderState::SetMode(Mode mode) 36 73 { … … 51 88 if (mRenderType == DEFERRED) 52 89 { 53 cgGLDisableProfile(sCgFragmentProfile);54 cgGLDisableProfile(sCgVertexProfile);90 ResourceManager::GetSingleton()->DisableFragmentProfile(); 91 ResourceManager::GetSingleton()->DisableFragmentProfile(); 55 92 } 56 93 } … … 73 110 if (mRenderType == DEFERRED) 74 111 { 75 cgGLEnableProfile(sCgFragmentProfile);76 cgGLEnableProfile(sCgVertexProfile);112 ResourceManager::GetSingleton()->EnableFragmentProfile(); 113 ResourceManager::GetSingleton()->EnableVertexProfile(); 77 114 } 78 115 } … … 152 189 if (mRenderType == DEFERRED) 153 190 { 154 if (mat->GetFragmentProgram() && (mat->GetFragmentProgram() != mCurrentFragmentProgram)) 155 { 156 mCurrentFragmentProgram = mat->GetFragmentProgram(); 157 mCurrentFragmentProgram->Bind(); 191 if (mat->GetFragmentProgram()) 192 { 193 if (mat->GetFragmentProgram() != mCurrentFragmentProgram) 194 { 195 mCurrentFragmentProgram = mat->GetFragmentProgram(); 196 mCurrentFragmentProgram->Bind(); 197 } 198 199 mat->GetFragmentProgramParameters()->UpdateParameters(); 200 158 201 } 159 202 160 if (mat->GetVertexProgram() && (mat->GetVertexProgram() != mCurrentVertexProgram)) 161 { 162 mCurrentVertexProgram = mat->GetVertexProgram(); 163 mCurrentVertexProgram->Bind(); 203 if (mat->GetVertexProgram()) 204 { 205 if (mat->GetVertexProgram() != mCurrentVertexProgram) 206 { 207 mCurrentVertexProgram = mat->GetVertexProgram(); 208 mCurrentVertexProgram->Bind(); 209 } 210 211 mat->GetVertexProgramParameters()->UpdateParameters(); 164 212 } 165 213 } … … 181 229 } 182 230 } 183 }184 185 186 void RenderState::Reset()187 {188 SetMode(RENDER);189 190 mCurrentVboId = -1;191 mCurrentTexId = 0;192 193 mCullFaceEnabled = true;194 mAlphaTestEnabled = false;195 mTexturesEnabled = false;196 197 mCurrentVertexProgram = NULL;198 mCurrentFragmentProgram = NULL;199 200 glEnable(GL_CULL_FACE);201 202 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);203 glDisable(GL_ALPHA_TEST);204 205 glDisable(GL_TEXTURE_2D);206 glDisableClientState(GL_TEXTURE_COORD_ARRAY);207 231 } 208 232 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r3034 r3038 4 4 5 5 #include "common.h" 6 #include "glInterface.h"7 #include <Cg/cg.h>8 #include <Cg/cgGL.h>9 6 10 7 … … 75 72 void LockCullFaceEnabled(bool lockCull); 76 73 77 78 ///////////////////79 //-- for deferred shading, we have to switch shaders on and off80 81 static CGprofile sCgFragmentProfile;82 static CGprofile sCgVertexProfile;83 84 static ShaderProgram *sCgMrtFragmentProgram;85 static ShaderProgram *sCgMrtFragmentTexProgram;86 static ShaderProgram *sCgMrtVertexProgram;87 88 static int sTexParam;89 90 74 91 75 protected: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r3031 r3038 248 248 // render pending objects before changing to query mode 249 249 if (mUseRenderQueue && (mRenderState->GetMode() == RenderState::RENDER)) 250 { 250 251 ApplyRenderQueue(); 251 252 } 252 253 253 254 query.BeginQuery(); … … 255 256 // change to query mode and render box 256 257 if (mRenderState->SetMode(RenderState::QUERY)) 258 { 257 259 ++ mStats.mNumStateChanges; 260 } 258 261 259 262 mBvh->RenderBounds(query.GetNodes(), mRenderState, mUseTightBounds); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3037 r3038 13 13 #include "RenderState.h" 14 14 #include "ShaderProgram.h" 15 #include <Cg/cg.h> 16 #include <Cg/cgGL.h> 15 17 16 18 … … 32 34 { 33 35 36 37 ///////// 38 //-- cg stuff 39 40 static CGcontext sCgContext = NULL; 41 42 static CGprofile sCgFragmentProfile; 43 static CGprofile sCgVertexProfile; 44 45 34 46 // only instance of the resource manager 35 47 ResourceManager *ResourceManager::sResourceManager = NULL; 48 49 50 static void cgErrorCallback() 51 { 52 CGerror lastError = cgGetError(); 53 54 if(lastError) 55 { 56 printf("%s\n\n", cgGetErrorString(lastError)); 57 printf("%s\n", cgGetLastListing(sCgContext)); 58 59 printf("Cg error, exiting...\n"); 60 61 exit(0); 62 } 63 } 64 65 66 ResourceManager::ResourceManager() 67 { 68 InitCg(); 69 } 70 36 71 37 72 ResourceManager::~ResourceManager() … … 47 82 CLEAR_CONTAINER(mGPUParameters); 48 83 CLEAR_CONTAINER(mShaders); 84 85 if (sCgContext) 86 cgDestroyContext(sCgContext); 49 87 } 50 88 … … 188 226 189 227 str.read(reinterpret_cast<char *>(&mat->mAlphaTestEnabled), sizeof(bool)); 190 191 228 str.read(reinterpret_cast<char *>(&mat->mCullFaceEnabled), sizeof(bool)); 192 229 … … 204 241 } 205 242 206 mat->mVertexProgram = RenderState::sCgMrtVertexProgram;207 208 243 if (mat->GetTexture()) 209 244 { 210 mat->mFragmentProgram = RenderState::sCgMrtFragmentTexProgram;245 mat->mFragmentProgram = mMrtDefaultFragmentTexProgram; 211 246 212 247 mat->mGPUFragmentParameters = CreateGPUProgramParameters(mat->mFragmentProgram); … … 215 250 else 216 251 { 217 mat->mFragmentProgram = RenderState::sCgMrtFragmentProgram;252 mat->mFragmentProgram = mMrtDefaultFragmentProgram; 218 253 mat->mGPUFragmentParameters = CreateGPUProgramParameters(mat->mFragmentProgram); 219 254 } 220 255 221 mat->mGPUVertexParameters = CreateGPUProgramParameters(RenderState::sCgMrtVertexProgram); 256 mat->mVertexProgram = mMrtDefaultVertexProgram; 257 mat->mGPUVertexParameters = CreateGPUProgramParameters(mat->mVertexProgram); 222 258 223 259 return mat; … … 328 364 329 365 330 ShaderProgram *CreateShaderProgram(const std::string &filename, const std::string &funcName, bool isFragment) 331 { 332 ShaderProgram *p; 366 ShaderProgram *ResourceManager::CreateFragmentProgram(const std::string &filename, const std::string &funcName) 367 { 368 const string fullName = "src/shaders/" + filename + ".cg"; 369 370 ShaderProgram *p = new ShaderProgram(sCgContext, fullName, sCgFragmentProfile, funcName); 371 372 mShaders.push_back(p); 373 374 if (!p->IsValid()) 375 { 376 DEL_PTR(p); 377 cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl; 378 } 379 380 cout << "Program " << funcName << " in " << fullName << " loaded" << endl; 381 333 382 return p; 334 383 } 335 384 336 } 337 385 386 ShaderProgram *ResourceManager::CreateVertexProgram(const std::string &filename, const std::string &funcName) 387 { 388 const string fullName = "src/shaders/" + filename + ".cg"; 389 390 ShaderProgram *p = new ShaderProgram(sCgContext, fullName, sCgVertexProfile, funcName); 391 mShaders.push_back(p); 392 393 if (!p->IsValid()) 394 { 395 DEL_PTR(p); 396 cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl; 397 } 398 399 cout << "Program " << funcName << " in " << fullName << " loaded" << endl; 400 401 return p; 402 } 403 404 405 void ResourceManager::InitCg() 406 { 407 // setup cg 408 cgSetErrorCallback(cgErrorCallback); 409 // create context. 410 sCgContext = cgCreateContext(); 411 // get the optimal fragment profile 412 sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); 413 cgGLSetOptimalOptions(sCgFragmentProfile); 414 // get the optimal vertex profile 415 sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); 416 cgGLSetOptimalOptions(sCgVertexProfile); 417 418 // set textures to auto load 419 cgGLSetManageTextureParameters(sCgContext, false); 420 421 mMrtDefaultVertexProgram = CreateVertexProgram("mrt", "vtx"); 422 mMrtDefaultFragmentProgram = CreateFragmentProgram("mrt", "fragtex");//CreateFragmentProgram("mrt", "frag"); 423 mMrtDefaultFragmentTexProgram = CreateFragmentProgram("mrt", "fragtex"); 424 mMrtDefaultFragmentTexProgram->AddParameter("tex", 0); 425 426 cout << "cg initialization successful" << endl; 427 } 428 429 430 void ResourceManager::EnableFragmentProfile() 431 { 432 cgGLEnableProfile(sCgFragmentProfile); 433 } 434 435 436 void ResourceManager::EnableVertexProfile() 437 { 438 cgGLEnableProfile(sCgVertexProfile); 439 } 440 441 442 void ResourceManager::DisableFragmentProfile() 443 { 444 cgGLDisableProfile(sCgFragmentProfile); 445 } 446 447 448 void ResourceManager::DisableVertexProfile() 449 { 450 cgGLDisableProfile(sCgVertexProfile); 451 452 } 453 454 455 } 456 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
r3037 r3038 63 63 /** Creates a new shader program. 64 64 */ 65 ShaderProgram *CreateShaderProgram(const std::string &filename, const std::string &funcName, bool isFragment); 65 ShaderProgram *CreateFragmentProgram(const std::string &filename, const std::string &funcName); 66 ShaderProgram *CreateVertexProgram(const std::string &filename, const std::string &funcName); 67 68 void EnableFragmentProfile(); 69 void EnableVertexProfile(); 70 71 void DisableFragmentProfile(); 72 void DisableVertexProfile(); 73 66 74 67 75 protected: … … 71 79 singleton pattern. 72 80 */ 73 ResourceManager() {}81 ResourceManager(); 74 82 75 83 ~ResourceManager(); 84 85 86 void InitCg(); 76 87 77 88 void LoadTextures(igzstream &str); … … 88 99 //std::map<int, Shape *> mShapesTable; 89 100 90 // these are kept to be able to delete these resources afterwards 101 102 ///////////// 103 //-- these are kept to be able to delete these resources afterwards 104 91 105 TextureContainer mTextures; 92 106 MaterialContainer mMaterials; … … 94 108 TransformContainer mTrafos; 95 109 GPUParamContainer mGPUParameters; 96 110 ShaderContainer mShaders; 97 111 ShapeContainer mShapes; 98 99 112 LODContainer mLODs; 100 113 … … 102 115 103 116 /// the scene entities 117 104 118 SceneEntityContainer mSceneEntities; 119 120 121 //////////// 122 //-- default shader programs 123 124 ShaderProgram *mMrtDefaultVertexProgram; 125 ShaderProgram *mMrtDefaultFragmentProgram; 126 ShaderProgram *mMrtDefaultFragmentTexProgram; 127 105 128 106 129 private: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
r3036 r3038 26 26 typedef std::vector<CGparameter> CGParameterArray; 27 27 28 struct ParameterPair1f 29 { 30 unsigned int mParameterIdx; 31 float mValue; 32 }; 33 28 29 /** This class represents the parameter values for a given GPU program. 30 */ 34 31 class GPUProgramParameters 35 32 { … … 85 82 */ 86 83 void UpdateParameters(); 87 84 85 88 86 89 87 protected: … … 151 149 152 150 153 151 /** This class represents a wrapper for a GPU shader program (vertex or fragment). 152 */ 154 153 class ShaderProgram 155 154 { … … 167 166 ~ShaderProgram() { if (mProgram != NULL) cgDestroyProgram(mProgram); } 168 167 168 /** Assigns a parameter to the specified index. 169 */ 170 CGparameter AddParameter(const std::string &name, int idx); 171 172 173 ////////////// 174 //-- set shader parameters per index 175 169 176 void SetValue1f(int idx, float value); 170 177 void SetValue2f(int idx, float val1, float val2); … … 178 185 void SetTexture(int idx, unsigned int tex); 179 186 187 188 //////////// 189 //-- set shader parameters per parameter name (slow!) 190 191 /// Float parameters 180 192 void SetValue1f(const std::string &name, float value); 181 193 void SetValue2f(const std::string &name, float val1, float val2); 182 194 void SetValue3f(const std::string &name, float val1, float val, float val3); 183 195 /// Array parameters 184 196 void SetArray1f(const std::string &name, float *vals, int numElements); 185 197 void SetArray2f(const std::string &name, float *vals, int numElements); 186 198 void SetArray3f(const std::string &name, float *vals, int numElements); 187 /** Sets the matrix parameter. 188 */ 199 /// Sets a matrix parameter 189 200 void SetMatrix(const std::string &name, const Matrix4x4 &mat); 190 201 /** Sets the texture parameter. … … 192 203 void SetTexture(const std::string &name, unsigned int tex); 193 204 194 CGparameter AddParameter(const std::string &name, int idx);195 205 /** Binds the program. 196 206 */ … … 226 236 227 237 228 typedef std::vector<ShaderProgram *> ShaderContainer;229 238 230 239 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r3021 r3038 6 6 #include "Polygon3.h" 7 7 #include "Polyhedron.h" 8 #include "ResourceManager.h" 8 9 9 10 #include <IL/il.h> … … 16 17 namespace CHCDemoEngine 17 18 { 18 19 static CGprogram sCgShadowProgram;20 static CGparameter sShadowParam;21 22 19 23 20 static Polyhedron *polyhedron = NULL; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r3036 r3038 9 9 #include "Shape.h" 10 10 #include "Material.h" 11 #include "ResourceManager.h" 12 11 13 12 14 … … 22 24 23 25 26 27 24 28 using namespace CHCDemoEngine; 25 29 using namespace std; 26 30 27 31 28 static ShaderProgram *sCgSkyProgram = NULL;29 static ShaderProgram *sCgMrtFragmentSkyDomeProgram = NULL;30 31 ShaderContainer SkyPreetham::sShaders;32 33 32 34 33 inline float CBQ(float x) … … 44 43 45 44 46 void SkyPreetham::InitCG( CGcontext context)45 void SkyPreetham::InitCG() 47 46 { 48 sCgSkyProgram = new ShaderProgram(context, 49 "src/shaders/sky_preetham.cg", 50 RenderState::sCgVertexProfile, 51 "default_vs"); 52 53 if (sCgSkyProgram->IsValid()) 47 mSkyVtxProgram = 48 ResourceManager::GetSingleton()->CreateVertexProgram("sky_preetham", "default_vs"); 49 50 if (mSkyVtxProgram->IsValid()) 54 51 { 55 sCgSkyProgram->AddParameter("lightDir", 0);56 sCgSkyProgram->AddParameter("thetaSun", 1);57 sCgSkyProgram->AddParameter("zenithColor", 2);58 sCgSkyProgram->AddParameter("aColor", 3);59 sCgSkyProgram->AddParameter("bColor", 4);60 sCgSkyProgram->AddParameter("cColor", 5);61 sCgSkyProgram->AddParameter("dColor", 6);62 sCgSkyProgram->AddParameter("eColor", 7);63 sCgSkyProgram->AddParameter("multiplier", 8);52 mSkyVtxProgram->AddParameter("lightDir", 0); 53 mSkyVtxProgram->AddParameter("thetaSun", 1); 54 mSkyVtxProgram->AddParameter("zenithColor", 2); 55 mSkyVtxProgram->AddParameter("aColor", 3); 56 mSkyVtxProgram->AddParameter("bColor", 4); 57 mSkyVtxProgram->AddParameter("cColor", 5); 58 mSkyVtxProgram->AddParameter("dColor", 6); 59 mSkyVtxProgram->AddParameter("eColor", 7); 60 mSkyVtxProgram->AddParameter("multiplier", 8); 64 61 } 65 62 else 66 63 cerr << "sky program failed to load" << endl; 67 64 68 sShaders.push_back(sCgSkyProgram); 69 70 sCgMrtFragmentSkyDomeProgram = 71 new ShaderProgram(context, 72 "src/shaders/sky_preetham.cg", 73 RenderState::sCgFragmentProfile, 74 "frag_skydome"); 75 76 // simple shader used for just pushing out the fragments to the mrts 77 if (!sCgMrtFragmentSkyDomeProgram->IsValid()) 78 cerr << "fragment skyprogram failed to load" << endl; 79 80 sShaders.push_back(sCgMrtFragmentSkyDomeProgram); 81 } 82 83 84 void SkyPreetham::ReleaseCG() 85 { 86 CLEAR_CONTAINER(sShaders); 65 mSkyFragProgram = 66 ResourceManager::GetSingleton()->CreateFragmentProgram("sky_preetham", "frag_skydome"); 87 67 } 88 68 … … 96 76 Shape *shape = mSkyDome->GetShape(0); 97 77 78 InitCG(); 79 98 80 Material *mat = shape->GetMaterial(); 99 81 100 mat->SetFragmentProgram( sCgMrtFragmentSkyDomeProgram);101 mat->SetVertexProgram( sCgSkyProgram);82 mat->SetFragmentProgram(mSkyFragProgram); 83 mat->SetVertexProgram(mSkyVtxProgram); 102 84 } 103 85 … … 148 130 { 149 131 // use tone mapping 150 sCgSkyProgram->SetValue1f(8, 1.0f);132 vtxParams->SetValue1f(8, 1.0f); 151 133 } 152 134 else 153 135 { 154 136 // no tone mapping => scale 155 sCgSkyProgram->SetValue1f(8, 8e-5f);137 vtxParams->SetValue1f(8, 8e-5f); 156 138 } 157 158 cgGLEnableProfile(RenderState::sCgVertexProfile);159 139 160 140 // Render sky dome. -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h
r3021 r3038 15 15 class RenderState; 16 16 class Camera; 17 class ShaderProgram; 17 18 } 18 19 … … 40 41 bool scaleToRange) const; 41 42 42 static void InitCG(CGcontext context); 43 static void ReleaseCG(); 43 void InitCG(); 44 44 45 45 … … 50 50 51 51 52 /// Members. 53 /* FEffect* mEffect; 52 ////////// 53 54 /* FEffect* mEffect; 54 55 55 56 FEffect* mSunEffect; 56 57 FTexture2D* mSunTexture; 57 58 FVertexBuffer* mSunQuad; 58 */ 59 */ 60 59 61 CHCDemoEngine::SceneEntity *mSkyDome; 60 62 63 /// the turbidity of the sky 61 64 float mTurbidity; 62 65 63 static CHCDemoEngine::ShaderContainer sShaders; 66 CHCDemoEngine::ShaderProgram *mSkyVtxProgram; 67 CHCDemoEngine::ShaderProgram *mSkyFragProgram; 64 68 }; 65 69 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3037 r3038 18 18 #include <time.h> 19 19 #include "glInterface.h" 20 21 #include <Cg/cg.h>22 #include <Cg/cgGL.h>23 20 24 21 … … 66 63 #define MAX_DEPTH_CONST 10.0f 67 64 68 // fbo 65 66 GLuint fontTex; 67 /// fbo 69 68 FrameBufferObject *fbo = NULL; 70 71 GLuint fontTex;72 73 69 /// the renderable scene geometry 74 70 SceneEntityContainer sceneEntities; 75 76 71 // traverses and renders the hierarchy 77 72 RenderTraverser *traverser = NULL; … … 90 85 /// the rendering algorithm 91 86 int renderMode = RenderTraverser::CHCPLUSPLUS; 92 // eye near plane distance87 /// eye near plane distance 93 88 float nearDist = 0.2f; 89 /// eye far plane distance 94 90 float farDist = 1e6f; 95 91 /// the field of view … … 99 95 100 96 int assumedVisibleFrames = 10; 97 101 98 int maxBatchSize = 50; 102 99 … … 233 230 void InitGLstate(); 234 231 void InitRenderTexture(); 235 void InitCg();236 232 void CleanUp(); 237 233 void SetupEyeView(); … … 275 271 void RenderShadowMap(float newfar); 276 272 277 278 279 /////////280 //-- cg stuff281 282 static CGcontext sCgContext = NULL;283 284 static CGparameter sEyePosParamTex;285 static CGparameter sEyePosParam;286 287 273 static Matrix4x4 viewProjMat = IdentityMatrix(); 288 274 static Matrix4x4 oldViewProjMat = IdentityMatrix(); 289 275 290 291 292 static void cgErrorCallback()293 {294 CGerror lastError = cgGetError();295 296 if(lastError)297 {298 printf("%s\n\n", cgGetErrorString(lastError));299 printf("%s\n", cgGetLastListing(sCgContext));300 301 printf("Cg error, exiting...\n");302 303 exit(0);304 }305 }306 276 307 277 … … 452 422 MiddleMotion(0, 0); 453 423 454 // init cg shader programs455 InitCg();456 457 424 perfGraph = new PerformanceGraph(1000); 458 425 … … 532 499 533 500 return 0; 534 }535 536 537 void InitCg(void)538 {539 // setup cg540 cgSetErrorCallback(cgErrorCallback);541 542 // create context.543 sCgContext = cgCreateContext();544 545 // get the optimal profile546 RenderState::sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);547 cgGLSetOptimalOptions(RenderState::sCgFragmentProfile);548 549 RenderState::sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);550 cgGLSetOptimalOptions(RenderState::sCgVertexProfile);551 552 // set textures to auto load553 cgGLSetManageTextureParameters(sCgContext, false);554 555 RenderState::sCgMrtVertexProgram =556 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgVertexProfile, "vtx");557 558 if (!RenderState::sCgMrtVertexProgram->IsValid())559 cerr << "fragment program failed to load" << endl;560 561 RenderState::sCgMrtFragmentTexProgram =562 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgFragmentProfile, "fragtex");563 564 565 if (!RenderState::sCgMrtFragmentTexProgram->IsValid())566 cerr << "fragment tex program failed to load" << endl;567 568 RenderState::sCgMrtFragmentTexProgram->AddParameter("tex", 0);569 570 RenderState::sCgMrtFragmentProgram =571 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgFragmentProfile, "frag");572 573 if (!RenderState::sCgMrtFragmentProgram->IsValid())574 cerr << "fragment program failed to load" << endl;575 576 577 PrintGLerror("init");578 579 DeferredRenderer::InitCG(sCgContext);580 SkyPreetham::InitCG(sCgContext);581 582 cout << "cg initialization successful" << endl;583 501 } 584 502 … … 904 822 state.SetRenderPassType(RenderState::DEFERRED); 905 823 906 cgGLEnableProfile(RenderState::sCgVertexProfile); 907 RenderState::sCgMrtVertexProgram->Bind(); 908 909 cgGLEnableProfile(RenderState::sCgFragmentProfile); 910 RenderState::sCgMrtFragmentProgram->Bind(); 824 loader->EnableVertexProfile(); 825 loader->EnableFragmentProfile(); 911 826 912 827 const Vector3 pos = camera->GetPosition(); … … 991 906 glEnable(GL_LIGHTING); 992 907 993 cgGLDisableProfile(RenderState::sCgFragmentProfile);994 cgGLDisableProfile(RenderState::sCgVertexProfile);908 loader->DisableFragmentProfile(); 909 loader->DisableVertexProfile(); 995 910 996 911 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 1011 926 glDrawBuffers(1, mrt); 1012 927 1013 cgGLDisableProfile(RenderState::sCgFragmentProfile);1014 cgGLDisableProfile(RenderState::sCgVertexProfile);928 loader->DisableFragmentProfile(); 929 loader->DisableVertexProfile(); 1015 930 1016 931 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 1027 942 1028 943 glEnable(GL_MULTISAMPLE_ARB); 1029 1030 cgGLDisableProfile(RenderState::sCgFragmentProfile);1031 cgGLDisableProfile(RenderState::sCgVertexProfile);944 945 loader->DisableFragmentProfile(); 946 loader->DisableVertexProfile(); 1032 947 1033 948 state.SetRenderPassType(RenderState::DEPTH_PASS); … … 1112 1027 FrameBufferObject::Release(); 1113 1028 1114 cgGLDisableProfile(RenderState::sCgVertexProfile);1115 cgGLDisableProfile(RenderState::sCgFragmentProfile);1029 loader->DisableVertexProfile(); 1030 loader->DisableFragmentProfile(); 1116 1031 1117 1032 if (!ssaoShader) ssaoShader = … … 1741 1656 DEL_PTR(shadowMap); 1742 1657 DEL_PTR(shadowTraverser); 1743 DEL_PTR(RenderState::sCgMrtFragmentProgram);1744 DEL_PTR(RenderState::sCgMrtFragmentTexProgram);1745 DEL_PTR(RenderState::sCgMrtVertexProgram);1746 1658 1747 1659 ResourceManager::DelSingleton(); 1748 1660 loader = NULL; 1749 1750 DeferredRenderer::ReleaseCG();1751 SkyPreetham::ReleaseCG();1752 1753 if (sCgContext)1754 cgDestroyContext(sCgContext);1755 1661 } 1756 1662 … … 1963 1869 void RenderSky() 1964 1870 { 1965 cgGLEnableProfile(RenderState::sCgVertexProfile); 1871 loader->EnableVertexProfile(); 1872 loader->EnableFragmentProfile(); 1966 1873 1967 1874 if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) … … 1974 1881 preetham->RenderSkyDome(-light->GetDirection(), camera, &state, !useToneMapping); 1975 1882 1976 cgGLDisableProfile(RenderState::sCgVertexProfile);1977 cgGLDisableProfile(RenderState::sCgFragmentProfile);1883 loader->DisableVertexProfile(); 1884 loader->DisableFragmentProfile(); 1978 1885 } 1979 1886 … … 2050 1957 void RenderShadowMap(float newfar) 2051 1958 { 2052 cgGLDisableProfile(RenderState::sCgFragmentProfile);2053 cgGLDisableProfile(RenderState::sCgVertexProfile);1959 loader->DisableVertexProfile(); 1960 loader->DisableFragmentProfile(); 2054 1961 2055 1962 glDisableClientState(GL_NORMAL_ARRAY); 2056 1963 2057 1964 state.SetRenderPassType(RenderState::DEPTH_PASS); 1965 1966 // hack: disable cull face because of alpha textured balconies 1967 glDisable(GL_CULL_FACE); 2058 1968 state.LockCullFaceEnabled(true); 1969 2059 1970 state.SetUseAlphaToCoverage(false); 2060 1971 … … 2066 1977 // hack: temporarily change camera far plane 2067 1978 camera->SetFar(newfar); 2068 glDisable(GL_CULL_FACE); 2069 1979 2070 1980 // the scene is rendered withouth any shading 2071 1981 shadowMap->ComputeShadowMap(shadowTraverser, viewProjMat); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
r3036 r3038 35 35 class Texture; 36 36 class Material; 37 class ShaderProgram; 38 class FrameBufferObject; 37 39 38 40 struct LODLevel; … … 486 488 typedef std::queue<BvhNode *> BvhNodeQueue; 487 489 490 491 /////// 492 //-- container definitions 493 488 494 typedef std::vector<Shape *> ShapeContainer; 489 495 typedef std::vector<Geometry *> GeometryContainer; … … 495 501 typedef std::vector<Material *> MaterialContainer; 496 502 typedef std::vector<GPUProgramParameters *> GPUParamContainer; 503 typedef std::vector<FrameBufferObject *> FBOContainer; 504 typedef std::vector<ShaderProgram *> ShaderContainer; 497 505 498 506 typedef std::vector<Vector3> VertexArray;
Note: See TracChangeset
for help on using the changeset viewer.