- Timestamp:
- 10/09/08 18:36:03 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3018 r3019 61 61 62 62 63 ShaderContainer DeferredRenderer::sShaders; 63 64 64 65 /////////////////////////////////////// … … 296 297 297 298 299 static void InitBuffer(FrameBufferObject *fbo, int index) 300 { 301 // read the second buffer, write to the first buffer 302 fbo->Bind(); 303 glDrawBuffers(1, mrt + index); 304 305 //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 306 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 307 308 glEnd(); 309 310 FrameBufferObject::Release(); 311 } 312 313 298 314 DeferredRenderer::DeferredRenderer(int w, int h, Camera *cam, float scaleFactor): 299 315 mWidth(w), mHeight(h), … … 303 319 mSamplingMethod(SAMPLING_POISSON), 304 320 mShadingMethod(DEFAULT), 305 m FboIndex(0)321 mIllumFboIndex(0) 306 322 { 307 323 // create noise texture for ssao … … 312 328 //-- the flip-flop fbos 313 329 314 mFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 315 //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 316 317 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 318 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 319 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 320 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 330 mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 331 mFBOs.push_back(mIllumFbo); 332 333 for (int i = 0; i < 4; ++ i) 334 { 335 mIllumFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 336 InitBuffer(mIllumFbo, i); 337 } 321 338 322 339 mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 323 324 340 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 325 341 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 326 } 327 342 343 mFBOs.push_back(mDownSampleFbo); 344 } 328 345 329 346 330 347 DeferredRenderer::~DeferredRenderer() 331 348 { 332 if (sCgSsaoProgram) cgDestroyProgram(sCgSsaoProgram); 333 if (sCgDeferredProgram) cgDestroyProgram(sCgDeferredProgram); 334 if (sCgSsaoProgram) cgDestroyProgram(sCgSsaoProgram); 335 if (sCgGiProgram) cgDestroyProgram(sCgGiProgram); 336 if (sCgAntiAliasingProgram) cgDestroyProgram(sCgAntiAliasingProgram); 337 338 DEL_PTR(mFbo); 349 CLEAR_CONTAINER(sShaders); 350 CLEAR_CONTAINER(mFBOs); 339 351 340 352 glDeleteTextures(1, &noiseTex); … … 350 362 void DeferredRenderer::Init(CGcontext context) 351 363 { 364 ShaderProgram *pr; 365 366 352 367 sCgDeferredProgram = 353 368 cgCreateProgramFromFile(context, … … 368 383 369 384 sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 385 386 pr = new ShaderProgram(sCgDeferredProgram); 387 sShaders.push_back(pr); 370 388 } 371 389 else … … 407 425 sBRParam = cgGetNamedParameter(sCgSsaoProgram, "br"); 408 426 sBLParam = cgGetNamedParameter(sCgSsaoProgram, "bl"); 427 428 pr = new ShaderProgram(sCgSsaoProgram); 429 sShaders.push_back(pr); 409 430 } 410 431 else … … 443 464 444 465 sEyePosGiParam = cgGetNamedParameter(sCgGiProgram, "eyePos"); 466 467 pr = new ShaderProgram(sCgGiProgram); 468 sShaders.push_back(pr); 445 469 } 446 470 else … … 462 486 sSsaoTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "ssaoTex"); 463 487 sIllumTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "illumTex"); 488 489 pr = new ShaderProgram(sCgCombinedIllumProgram); 490 sShaders.push_back(pr); 464 491 } 465 492 else … … 484 511 sFilterOffsetsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterOffs"); 485 512 sFilterWeightsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterWeights"); 513 514 pr = new ShaderProgram(sCgCombinedSsaoProgram); 515 sShaders.push_back(pr); 486 516 } 487 517 else … … 503 533 sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors"); 504 534 sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 535 536 pr = new ShaderProgram(sCgAntiAliasingProgram); 537 sShaders.push_back(pr); 505 538 } 506 539 else … … 538 571 539 572 cgGLSetParameterArray2f(sSamplesShadowParam, 0, NUM_PCF_TABS, (const float *)pcfSamples); 573 574 pr = new ShaderProgram(sCgDeferredShadowProgram); 575 sShaders.push_back(pr); 540 576 } 541 577 else … … 553 589 { 554 590 cgGLLoadProgram(sCgLogLumProgram); 555 sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors"); 591 sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors"); 592 593 pr = new ShaderProgram(sCgLogLumProgram); 594 sShaders.push_back(pr); 556 595 } 557 596 else … … 576 615 577 616 sColorsTexToneParam = cgGetNamedParameter(sCgToneProgram, "colors"); 617 618 pr = new ShaderProgram(sCgToneProgram); 619 sShaders.push_back(pr); 578 620 } 579 621 else … … 596 638 sColorsTexDownSampleParam = cgGetNamedParameter(sCgDownSampleProgram, "colors"); 597 639 sDownSampleOffsetParam = cgGetNamedParameter(sCgDownSampleProgram, "downSampleOffs"); 640 641 pr = new ShaderProgram(sCgDownSampleProgram); 642 sShaders.push_back(pr); 598 643 } 599 644 else … … 618 663 // the other one will be written 619 664 620 m FboIndex = 2 -mFboIndex;665 mIllumFboIndex = 2 - mIllumFboIndex; 621 666 622 667 … … 726 771 #endif 727 772 728 GLuint oldTex = m Fbo->GetColorBuffer(2 -mFboIndex)->GetTexture();773 GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 729 774 730 775 glPushAttrib(GL_VIEWPORT_BIT); 731 glViewport(0, 0, m Fbo->GetWidth(),mFbo->GetHeight());776 glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 732 777 733 778 // read the second buffer, write to the first buffer 734 m Fbo->Bind();735 glDrawBuffers(1, mrt + m FboIndex);779 mIllumFbo->Bind(); 780 glDrawBuffers(1, mrt + mIllumFboIndex); 736 781 737 782 … … 850 895 cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 851 896 852 897 // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 853 898 glColor3f(1.0f, 1.0f, 1.0f); 854 899 … … 939 984 940 985 glPushAttrib(GL_VIEWPORT_BIT); 941 glViewport(0, 0, m Fbo->GetWidth(),mFbo->GetHeight());986 glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 942 987 943 988 // read the second buffer, write to the first buffer 944 m Fbo->Bind();945 946 glDrawBuffers(2, mrt + m FboIndex);947 948 GLuint oldSsaoTex = m Fbo->GetColorBuffer(2 -mFboIndex)->GetTexture();949 GLuint oldIllumTex = m Fbo->GetColorBuffer(2 -mFboIndex + 1)->GetTexture();989 mIllumFbo->Bind(); 990 991 glDrawBuffers(2, mrt + mIllumFboIndex); 992 993 GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 994 GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 950 995 951 996 cgGLBindProgram(sCgGiProgram); … … 1024 1069 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1025 1070 1026 GLuint ssaoTex = m Fbo->GetColorBuffer(mFboIndex)->GetTexture();1027 GLuint illumTex = m Fbo->GetColorBuffer(mFboIndex + 1)->GetTexture();1071 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 1072 GLuint illumTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 1028 1073 1029 1074 … … 1084 1129 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 1085 1130 1086 GLuint ssaoTex = m Fbo->GetColorBuffer(mFboIndex)->GetTexture();1131 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 1087 1132 1088 1133 // overwrite old color texture
Note: See TracChangeset
for help on using the changeset viewer.