Ignore:
Timestamp:
10/09/08 18:36:03 (16 years ago)
Author:
mattausch
Message:

detected memory leaks mainly in shadowmapping!!
strange problems with deferred rendering, seems to be uninitialized sometimes (solved?)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3018 r3019  
    6161 
    6262 
     63ShaderContainer DeferredRenderer::sShaders; 
    6364 
    6465/////////////////////////////////////// 
     
    296297 
    297298 
     299static 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 
    298314DeferredRenderer::DeferredRenderer(int w, int h, Camera *cam, float scaleFactor): 
    299315mWidth(w), mHeight(h),  
     
    303319mSamplingMethod(SAMPLING_POISSON), 
    304320mShadingMethod(DEFAULT), 
    305 mFboIndex(0) 
     321mIllumFboIndex(0) 
    306322{ 
    307323        // create noise texture for ssao 
     
    312328        //-- the flip-flop fbos 
    313329 
    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        } 
    321338 
    322339        mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
    323  
    324340        mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    325341        mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    326 } 
    327  
     342 
     343        mFBOs.push_back(mDownSampleFbo); 
     344} 
    328345 
    329346 
    330347DeferredRenderer::~DeferredRenderer()  
    331348{ 
    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); 
    339351 
    340352        glDeleteTextures(1, &noiseTex); 
     
    350362void DeferredRenderer::Init(CGcontext context) 
    351363{        
     364        ShaderProgram *pr; 
     365 
     366 
    352367        sCgDeferredProgram =  
    353368                cgCreateProgramFromFile(context,  
     
    368383                 
    369384                sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 
     385 
     386                pr = new ShaderProgram(sCgDeferredProgram); 
     387                sShaders.push_back(pr); 
    370388        } 
    371389        else 
     
    407425                sBRParam = cgGetNamedParameter(sCgSsaoProgram, "br");  
    408426                sBLParam = cgGetNamedParameter(sCgSsaoProgram, "bl");  
     427 
     428                pr = new ShaderProgram(sCgSsaoProgram); 
     429                sShaders.push_back(pr); 
    409430        } 
    410431        else 
     
    443464 
    444465                sEyePosGiParam = cgGetNamedParameter(sCgGiProgram, "eyePos"); 
     466 
     467                pr = new ShaderProgram(sCgGiProgram); 
     468                sShaders.push_back(pr); 
    445469        } 
    446470        else 
     
    462486                sSsaoTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "ssaoTex"); 
    463487                sIllumTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "illumTex"); 
     488 
     489                pr = new ShaderProgram(sCgCombinedIllumProgram); 
     490                sShaders.push_back(pr); 
    464491        } 
    465492        else 
     
    484511                sFilterOffsetsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterOffs"); 
    485512                sFilterWeightsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterWeights"); 
     513 
     514                pr = new ShaderProgram(sCgCombinedSsaoProgram); 
     515                sShaders.push_back(pr); 
    486516        } 
    487517        else 
     
    503533                sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");   
    504534                sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 
     535 
     536                pr = new ShaderProgram(sCgAntiAliasingProgram); 
     537                sShaders.push_back(pr); 
    505538        } 
    506539        else 
     
    538571 
    539572                cgGLSetParameterArray2f(sSamplesShadowParam, 0, NUM_PCF_TABS, (const float *)pcfSamples); 
     573 
     574                pr = new ShaderProgram(sCgDeferredShadowProgram); 
     575                sShaders.push_back(pr); 
    540576        } 
    541577        else 
     
    553589        { 
    554590                cgGLLoadProgram(sCgLogLumProgram); 
    555                 sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors");   
     591                sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors");  
     592 
     593                pr = new ShaderProgram(sCgLogLumProgram); 
     594                sShaders.push_back(pr); 
    556595        } 
    557596        else 
     
    576615 
    577616                sColorsTexToneParam = cgGetNamedParameter(sCgToneProgram, "colors");   
     617 
     618                pr = new ShaderProgram(sCgToneProgram); 
     619                sShaders.push_back(pr); 
    578620        } 
    579621        else 
     
    596638                sColorsTexDownSampleParam = cgGetNamedParameter(sCgDownSampleProgram, "colors");  
    597639                sDownSampleOffsetParam = cgGetNamedParameter(sCgDownSampleProgram, "downSampleOffs"); 
     640 
     641                pr = new ShaderProgram(sCgDownSampleProgram); 
     642                sShaders.push_back(pr); 
    598643        } 
    599644        else 
     
    618663        // the other one will be written 
    619664 
    620         mFboIndex = 2 - mFboIndex; 
     665        mIllumFboIndex = 2 - mIllumFboIndex; 
    621666         
    622667 
     
    726771#endif 
    727772 
    728         GLuint oldTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture(); 
     773        GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
    729774 
    730775        glPushAttrib(GL_VIEWPORT_BIT); 
    731         glViewport(0, 0, mFbo->GetWidth(), mFbo->GetHeight()); 
     776        glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 
    732777 
    733778        // read the second buffer, write to the first buffer 
    734         mFbo->Bind(); 
    735         glDrawBuffers(1, mrt + mFboIndex); 
     779        mIllumFbo->Bind(); 
     780        glDrawBuffers(1, mrt + mIllumFboIndex); 
    736781 
    737782         
     
    850895        cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 
    851896 
    852  
     897        // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    853898        glColor3f(1.0f, 1.0f, 1.0f); 
    854899 
     
    939984 
    940985        glPushAttrib(GL_VIEWPORT_BIT); 
    941         glViewport(0, 0, mFbo->GetWidth(), mFbo->GetHeight()); 
     986        glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 
    942987 
    943988        // read the second buffer, write to the first buffer 
    944         mFbo->Bind(); 
    945  
    946         glDrawBuffers(2, mrt + mFboIndex); 
    947  
    948         GLuint oldSsaoTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture(); 
    949         GLuint oldIllumTex = mFbo->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(); 
    950995         
    951996        cgGLBindProgram(sCgGiProgram); 
     
    10241069        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    10251070 
    1026         GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture(); 
    1027         GLuint illumTex = mFbo->GetColorBuffer(mFboIndex + 1)->GetTexture(); 
     1071        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
     1072        GLuint illumTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 
    10281073 
    10291074 
     
    10841129        GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    10851130         
    1086         GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture(); 
     1131        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    10871132 
    10881133        // overwrite old color texture 
Note: See TracChangeset for help on using the changeset viewer.