Ignore:
Timestamp:
08/22/08 13:20:06 (16 years ago)
Author:
mattausch
Message:

cleaned up code

File:
1 edited

Legend:

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

    r2860 r2861  
    6161SsaoShader::SsaoShader(int w, int h,  
    6262                                           Camera *cam, 
    63                                            float expFactor,  
    6463                                           float scaleFactor 
    6564                                           ): 
    6665mWidth(w), mHeight(h),  
    6766mCamera(cam), 
    68 mExpFactor(expFactor),  
    6967mScaleFactor(scaleFactor) 
    70 {} 
     68{ 
     69         
     70        /////////// 
     71        //-- the flip-flop fbos 
     72 
     73        mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     74        // the diffuse color buffer 
     75        mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false); 
     76         
     77        mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     78        // the diffuse color buffer 
     79        mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false); 
     80         
     81 
     82        // create noise texture for ssao 
     83        CreateNoiseTex2D(); 
     84} 
     85 
     86 
     87SsaoShader::~SsaoShader()  
     88{ 
     89        if (sCgSsaoProgram) 
     90                cgDestroyProgram(sCgSsaoProgram); 
     91 
     92        DEL_PTR(mNewFbo); 
     93        DEL_PTR(mOldFbo); 
     94 
     95        glDeleteTextures(1, &noiseTex); 
     96} 
    7197 
    7298 
    7399void SsaoShader::Init(CGcontext context) 
    74 { 
    75          
     100{        
    76101        /////////////// 
    77102 
     
    112137 
    113138 
    114 void SsaoShader::Render(FrameBufferObject *fbo, FrameBufferObject *fbo2) 
    115 { 
    116         FirstPass(fbo, fbo2); 
    117         SecondPass(fbo, fbo2); 
    118 } 
    119  
    120  
    121 void SsaoShader::FirstPass(FrameBufferObject *fbo, FrameBufferObject *fbo2) 
    122 { 
    123         GLuint positionsTex = fbo->GetColorBuffer(0)->GetTexture(); 
     139void SsaoShader::Render(FrameBufferObject *fbo,  
     140                                                const Matrix4x4 &oldProjViewMatrix, 
     141                                                float expFactor) 
     142{ 
     143        cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 
     144 
     145        // switch roles of old and new fbo 
     146        // the algorihm uses two input fbos, where the one 
     147        // contais the color buffer from the last frame,  
     148        // the other one will be written 
     149        swap(mNewFbo, mOldFbo);  
     150 
     151        FirstPass(fbo, expFactor); 
     152        // the second pass just renders the combined solution 
     153        SecondPass(fbo); 
     154} 
     155 
     156 
     157void SsaoShader::FirstPass(FrameBufferObject *fbo, float expFactor) 
     158{ 
    124159        GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 
    125         GLuint normalsTex = fbo->GetColorBuffer(0)->GetTexture(); 
    126  
    127         GLuint oldTex = fbo2->GetColorBuffer(0)->GetTexture(); 
     160        GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     161        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     162 
     163        // read the second buffer, write to the first buffer 
     164        mNewFbo->Bind(); 
     165        GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 
    128166 
    129167        glPushAttrib(GL_VIEWPORT_BIT); 
     
    172210         
    173211        cgGLSetParameter1f(sMaxDepthParam, mScaleFactor); 
    174         cgGLSetParameter1f(sExpFactorParam, mExpFactor); 
     212        cgGLSetParameter1f(sExpFactorParam, expFactor); 
    175213 
    176214 
     
    215253        glPopAttrib(); 
    216254 
    217         PrintGLerror("displaytexture"); 
    218  
    219         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
    220  
     255        FrameBufferObject::Release(); 
    221256 
    222257        PrintGLerror("ssao first pass"); 
     
    224259 
    225260 
    226 void SsaoShader::SecondPass(FrameBufferObject *fbo, FrameBufferObject *fbo2) 
     261void SsaoShader::SecondPass(FrameBufferObject *fbo) 
    227262{ 
    228263        glEnable(GL_TEXTURE_2D); 
    229264 
    230         glBindTexture(GL_TEXTURE_2D, fbo2->GetColorBuffer(0)->GetTexture()); 
     265        glBindTexture(GL_TEXTURE_2D, mNewFbo->GetColorBuffer(0)->GetTexture()); 
    231266 
    232267        glDisable(GL_LIGHTING); 
     
    274309        mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 
    275310 
    276 #if 1 // matT: debug this!! 
     311#if 0 // matT: debug this!! 
    277312         
    278313        bl = Normalize(nbl - fbl); 
Note: See TracChangeset for help on using the changeset viewer.