Ignore:
Timestamp:
10/21/08 16:04:27 (16 years ago)
Author:
mattausch
Message:

worked on render queue

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
9 edited

Legend:

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

    r3050 r3054  
    3434        // if lighting is used 
    3535        mLightingEnabled = true; 
     36        /// if depth write should be enabled 
     37        mDepthWriteEnabled = true; 
    3638 
    37         mDepthWriteEnabled = true; 
     39        mRenderQueueBucket = NULL; 
    3840} 
    3941 
     
    5860} 
    5961 
    60  
     62/* 
    6163Technique::Technique(const Technique &tech) 
    6264{ 
     
    8082        mLightingEnabled = tech.mLightingEnabled; 
    8183        mDepthWriteEnabled = tech.mDepthWriteEnabled; 
    82 } 
     84}*/ 
    8385 
    8486 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h

    r3050 r3054  
    1414class GPUProgramParameters; 
    1515class ShaderProgram; 
     16struct RenderQueueBucket; 
    1617 
    1718 
     
    4849{ 
    4950friend class ResourceManager; 
     51friend class RenderQueue; 
    5052 
    5153public: 
     
    5557        Technique(); 
    5658 
    57         Technique(const Technique &tech); 
     59        //Technique(const Technique &tech); 
    5860        /** Sets ambient and diffuse color to color 
    5961        */ 
     
    134136        /// if depth write is enabled 
    135137        bool mDepthWriteEnabled; 
     138        /// pointer to the renderqueue bucket this entity belongs to 
     139        RenderQueueBucket *mRenderQueueBucket; 
    136140}; 
    137141 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp

    r3053 r3054  
    66#include "Camera.h" 
    77#include "Shape.h" 
    8  
     8#include "RenderState.h" 
    99 
    1010using namespace std; 
     
    5151bool RenderQueue::FitsInBucket(Shape *shape, size_t idx) const 
    5252{ 
    53         Technique *tech = shape->GetMaterial()->GetDefaultTechnique(); 
     53        Technique *tech = shape->GetMaterial()->GetTechnique(mState->GetRenderTechnique()); 
    5454 
    5555        // test if entity belongs to this bucket 
    56         // note: rather slows down the application for some reason!! 
    57         if (tech->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled) { cout << "a"; return false; } 
    58         if (tech->IsCullFaceEnabled() != mBuckets[idx]->mCullFaceEnabled) { cout << "b"; return false; } 
    59         if (tech->IsColorWriteEnabled() != mBuckets[idx]->mColorWriteEnabled) { cout << "c"; return false; } 
    60         if (tech->IsLightingEnabled() != mBuckets[idx]->mLightingEnabled) { cout << "d"; return false; } 
    61         if (tech->IsDepthWriteEnabled() != mBuckets[idx]->mDepthWriteEnabled) { cout << "e"; return false; } 
     56        if (tech->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled) { return false; } 
     57        if (tech->IsCullFaceEnabled() != mBuckets[idx]->mCullFaceEnabled) { return false; } 
     58        if (tech->IsColorWriteEnabled() != mBuckets[idx]->mColorWriteEnabled) { return false; } 
     59        if (tech->IsLightingEnabled() != mBuckets[idx]->mLightingEnabled) { return false; } 
     60        if (tech->IsDepthWriteEnabled() != mBuckets[idx]->mDepthWriteEnabled) { return false; } 
     61 
     62        //if (tech->IsColorWriteEnabled()) cout << "x"; 
    6263 
    6364        const bool hasTexture = (tech->GetTexture() != NULL); 
    6465 
    65         if (hasTexture != mBuckets[idx]->mHasTexture) { cout << "f"; return false; } 
     66        if (hasTexture != mBuckets[idx]->mHasTexture) { return false; } 
    6667 
    6768        if (hasTexture) 
    6869        { 
    69                 if (tech->GetTexture()->GetWidth() != mBuckets[idx]->mTexWidth) { cout << "g"; return false; } 
    70                 if (tech->GetTexture()->GetHeight() != mBuckets[idx]->mTexHeight) { cout << "h"; return false; } 
    71                 if (tech->GetTexture()->GetFormat() != mBuckets[idx]->mTexFormat) { cout << "i"; return false; } 
    72         } 
    73  
    74         if (!tech->GetFragmentProgram() && mBuckets[idx]->mHasFragmentProgram) { cout << "j"; return false; } 
    75         if (!tech->GetVertexProgram() && mBuckets[idx]->mHasVertexProgram) { cout << "h"; return false; } 
    76  
     70                if (tech->GetTexture()->GetWidth() != mBuckets[idx]->mTexWidth) { return false; } 
     71                if (tech->GetTexture()->GetHeight() != mBuckets[idx]->mTexHeight) {return false; } 
     72                if (tech->GetTexture()->GetFormat() != mBuckets[idx]->mTexFormat) { return false; } 
     73        } 
     74 
     75        //if (!tech->GetFragmentProgram() && mBuckets[idx]->mHasFragmentProgram) { return false; } 
     76        //if (!tech->GetVertexProgram() && mBuckets[idx]->mHasVertexProgram) { return false; } 
     77        if (tech->GetFragmentProgram() != mBuckets[idx]->mFragmentProgram) { return false; } 
     78        if (tech->GetVertexProgram() != mBuckets[idx]->mVertexProgram) { return false; } 
    7779 
    7880        return true; 
     
    9597void RenderQueue::Enqueue(Shape *shape) 
    9698{ 
    97         RenderQueueBucket *bucket; 
     99        Technique *tech = shape->GetMaterial()->GetTechnique(mState->GetRenderTechnique()); 
     100        RenderQueueBucket *bucket = tech->mRenderQueueBucket; 
     101 
    98102        ++ mNumEntries; 
    99103         
    100         if (shape->mRenderQueueBucket) 
    101         { 
    102                 bucket = shape->mRenderQueueBucket; 
    103         } 
    104         else 
     104        if (!bucket) 
    105105        { 
    106106                bool bucketFound = false; 
     
    119119                        RenderQueueBucket *bucket = new RenderQueueBucket(); 
    120120                        bucket->mMinDistance = -1; 
    121  
    122                         Technique *tech = shape->GetMaterial()->GetDefaultTechnique(); 
    123121 
    124122                        bucket->mAlphaTestEnabled = tech->IsAlphaTestEnabled(); 
     
    150148                        } 
    151149 
    152                         bucket->mHasVertexProgram = tech->GetVertexProgram() != NULL; 
    153                         bucket->mHasFragmentProgram = tech->GetFragmentProgram() != NULL; 
     150                        //      bucket->mHasVertexProgram = (tech->GetVertexProgram() != NULL); 
     151                        //      bucket->mHasFragmentProgram = (tech->GetFragmentProgram() != NULL); 
     152                        bucket->mVertexProgram = tech->GetVertexProgram(); 
     153                        bucket->mFragmentProgram = tech->GetFragmentProgram(); 
    154154 
    155155                        mBuckets.push_back(bucket); 
    156  
    157                         cout << "num buckets: " << (int)mBuckets.size() << endl; 
     156                        //cout << "increased #buckets to " << (int)mBuckets.size() << endl; 
    158157                } 
    159158 
    160159                bucket = mBuckets[i]; 
    161                 shape->mRenderQueueBucket = bucket; 
     160                tech->mRenderQueueBucket = bucket; 
    162161        } 
    163162 
     
    226225                        Shape *shape = *sit; 
    227226                         
    228                         Technique *tech = shape->GetMaterial()->GetDefaultTechnique(); 
     227                        Technique *tech = shape->GetMaterial()->GetTechnique(mState->GetRenderTechnique()); 
    229228                        int tsize = tech->GetTexture() ? tech->GetTexture()->GetByteSize() : 0; 
    230229                         
     
    239238void RenderQueue::Sort() 
    240239{ 
    241         // sort buckets itself 
     240        // sort buckets itself by distance 
    242241        sort(mBuckets.begin(), mBuckets.end(), CompDist); 
    243242} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h

    r3051 r3054  
    3333        bool mCullFaceEnabled; 
    3434 
    35         bool mHasVertexProgram; 
    36         bool mHasFragmentProgram; 
     35        //bool mHasVertexProgram; 
     36        //bool mHasFragmentProgram; 
     37        ShaderProgram *mVertexProgram; 
     38        ShaderProgram *mFragmentProgram; 
    3739 
    3840        /// minimal distance to the camera 
     
    6567        */ 
    6668        void Enqueue(SceneEntity *entity); 
     69        /** Enqueues a single shape. 
     70        */ 
     71        void Enqueue(Shape *shape); 
    6772        /** Sets the current render state 
    6873        */ 
     
    7782        */ 
    7883        void Apply(); 
    79  
     84        /** Clears the render queue 
     85        */ 
     86        void Clear(); 
    8087 
    8188protected: 
     
    8390        void Sort(); 
    8491 
    85         void Enqueue(Shape *shape); 
    86  
    8792        inline bool FitsInBucket(Shape *shape, size_t idx) const; 
    88         /** Clears the render queue 
    89         */ 
    90         void Clear(); 
    9193        /** Renders the contents of the render queue. 
    9294        */ 
     
    104106        //SceneEntityContainer mEntities; 
    105107        int mMinSizeForSorting; 
    106  
    107108        /// each bucket contains objects with similar materials that don't cause a hard state change 
    108109        std::vector<RenderQueueBucket *> mBuckets; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h

    r3052 r3054  
    5151        void DisableFragmentProfile(); 
    5252        void DisableVertexProfile(); 
     53        /** Returns pointer to shape container. 
     54        */ 
     55        const ShapeContainer * const GetShapes() const { return &mShapes; } 
     56        /** Returns pointer to scene entity container. 
     57        */ 
     58        const SceneEntityContainer * const GetSceneEntities() const { return &mSceneEntities; } 
    5359 
    5460        /** Returns the resource manager as a singleton. 
     
    97103        ShapeContainer mShapes; 
    98104        LODContainer mLODs; 
    99  
    100105        /// the scene entities 
    101106        SceneEntityContainer mSceneEntities; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp

    r2957 r3054  
    1313mGeometry(geometry),  
    1414mMaterial(mat),  
    15 mParent(parent),  
    16 mRenderQueueBucket(NULL) 
     15mParent(parent) 
    1716{ 
    1817        mCenter = GetBoundingBox().Center(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h

    r3034 r3054  
    6868        Material *mMaterial; 
    6969        SceneEntity *mParent; 
    70  
    71         /// pointer to the renderqueue bucket this entity belongs to 
    72         RenderQueueBucket *mRenderQueueBucket; 
    7370}; 
    7471 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp

    r3048 r3054  
    143143        else 
    144144        { 
    145                 // no tone mapping => scale 
     145                // no tone mapping => scale to range 
    146146                vtxParams->SetValue1f(8, 8e-5f); 
    147147        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3052 r3054  
    162162int horizontalMotionBegin = 0; 
    163163 
    164  
    165164bool leftKeyPressed = false; 
    166165bool rightKeyPressed = false; 
     
    170169bool ascendKeyPressed = false; 
    171170 
     171bool altKeyPressed = false; 
     172 
    172173bool showHelp = false; 
    173174bool showStatistics = false; 
     
    193194bool showShadowMap = false; 
    194195bool renderLightView = false; 
    195  
    196 bool altKeyPressed = false; 
    197  
    198196bool useHDR = true; 
    199197 
     198PerfTimer frameTimer, algTimer; 
     199 
     200PerformanceGraph *perfGraph = NULL; 
     201 
    200202static float ssaoTempCohFactor = 255.0; 
    201  
    202  
    203 PerfTimer frameTimer, algTimer; 
    204  
    205203static int sCurrentMrtSet = 0; 
    206204 
    207 PerformanceGraph *perfGraph = NULL; 
    208  
     205 
     206#define CAMERA_PASS 0 
     207#define LIGHT_PASS 1 
    209208 
    210209//DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_POISSON; 
     
    267266void RenderShadowMap(float newfar); 
    268267 
     268 
    269269static Matrix4x4 viewProjMat = IdentityMatrix(); 
    270270static Matrix4x4 oldViewProjMat = IdentityMatrix(); 
     
    356356 
    357357                //cout << "model path: " << model_path << endl; 
    358  
    359358                cout << "**** end parameters ****" << endl << endl; 
    360359        } 
     
    454453        Matrix4x4 transl = TranslationMatrix(cubeCenter); 
    455454 
    456         SceneEntityContainer dummy; 
    457          
    458455        string skyDomeStr(model_path + "sky.dem"); 
    459456 
     
    479476        visualization = new Visualization(bvh, camera, NULL, &state); 
    480477         
     478        for (int i = 0; i < 3; ++ i) 
     479        { 
     480                state.SetRenderTechnique((RenderState::RenderTechnique)i); 
     481 
     482                // fill all shapes into the render queue        once so we can establish the buckets 
     483                ShapeContainer::const_iterator sit, sit_end = (*loader->GetShapes()).end(); 
     484 
     485                for (sit = (*loader->GetShapes()).begin(); sit != sit_end; ++ sit) 
     486                { 
     487                        renderQueue->Enqueue(*sit); 
     488                } 
     489         
     490                //renderQueue->Apply(); 
     491                // just clear queue again 
     492                renderQueue->Clear(); 
     493        } 
     494 
    481495        state.SetRenderTechnique(RenderState::FORWARD); 
    482496 
     
    978992                // change CHC++ set of state variables (must be done for each change of camera because 
    979993                // otherwise the temporal coherency is broken 
    980                 BvhNode::SetCurrentState(1); 
     994                BvhNode::SetCurrentState(LIGHT_PASS); 
    981995                shadowMap->RenderShadowView(shadowTraverser, viewProjMat); 
    982                 BvhNode::SetCurrentState(0); 
     996                BvhNode::SetCurrentState(CAMERA_PASS); 
    983997        } 
    984998        else 
     
    10131027        { 
    10141028                FrameBufferObject::Release(); 
    1015  
    1016                 //loader->DisableVertexProfile(); 
    1017                 //loader->DisableFragmentProfile(); 
    10181029 
    10191030                if (!ssaoShader) ssaoShader =  
     
    19601971        // this must be done for each change of camera because 
    19611972        // otherwise the temporal coherency is broken 
    1962         BvhNode::SetCurrentState(1); 
    1963  
     1973        BvhNode::SetCurrentState(LIGHT_PASS); 
    19641974        // hack: temporarily change camera far plane 
    19651975        camera->SetFar(newfar); 
    1966  
    19671976        // the scene is rendered withouth any shading    
    19681977        shadowMap->ComputeShadowMap(shadowTraverser, viewProjMat); 
     
    19771986 
    19781987        // change back state 
    1979         BvhNode::SetCurrentState(0); 
    1980 } 
     1988        BvhNode::SetCurrentState(CAMERA_PASS); 
     1989} 
Note: See TracChangeset for help on using the changeset viewer.