Ignore:
Timestamp:
06/06/05 18:55:02 (19 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp

    r119 r120  
    1515        GtpVisibility::VisibilityManager *visManager):  
    1616mVisibilityManager(visManager),  
    17 mUseDepthPass(false), 
    1817mIsDepthPass(false), 
    1918mShowVisualization(false), 
     
    2221mVisualizeCulledNodes(false), 
    2322mSkipTransparents(false), 
    24 mDelayRenderTransparents(true) 
    25 { 
    26         mHierarchyInterface =  
    27                 new OctreeHierarchyInterface(this, mDestRenderSystem); 
    28  
    29     //mDisplayNodes = true; 
     23mDelayRenderTransparents(true), 
     24mUseDepthPass(false) 
     25{ 
     26        mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem); 
     27 
     28        //mDisplayNodes = true; 
    3029        //mShowBoundingBoxes = true; 
    3130 
     
    5756VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager() 
    5857{ 
    59         delete mHierarchyInterface; 
    60 } 
    61 //----------------------------------------------------------------------- 
    62 Pass *VisibilityTerrainSceneManager::setPass(Pass* pass) 
    63 { 
     58        if (mHierarchyInterface) 
     59        { 
     60                delete mHierarchyInterface; 
     61                mHierarchyInterface = NULL; 
     62        } 
     63} 
     64//----------------------------------------------------------------------- 
     65/*Pass *VisibilityTerrainSceneManager::setPass(Pass* pass) 
     66{ 
     67        static bool myLastUsedVertexProgram = false; 
     68    static bool myLastUsedFragmentProgram = false; 
     69 
    6470        // set depth fill pass only if depth write enabled 
    65         Pass *usedPass = (mIsDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass); 
    66  
    67         if (mIsDepthPass) 
    68         { 
    69                 //if (pass->isTransparent())    return pass; 
    70  
    71                 // set vertex program of current pass 
    72         if (pass->hasVertexProgram() && (pass->getVertexProgramName() != mDepthPass->getVertexProgramName())) 
    73                 { 
    74                         mDepthPass->setVertexProgram(pass->getVertexProgramName()); 
    75  
    76                         if (mDepthPass->hasVertexProgram()) 
    77                         { 
    78                                 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 
    79                                 // Load this program if not done already 
    80                                 if (!prg->isLoaded()) prg->load(); 
    81                                 // Copy params 
    82                                 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 
    83                         } 
    84                 } 
    85                 else if (mDepthPass->hasVertexProgram()) 
    86                 { 
    87                         mDepthPass->setVertexProgram(""); 
    88                 } 
    89         } 
    90  
    91         TerrainSceneManager::setPass(usedPass); 
     71        Pass *usedPass = pass; 
     72 
     73        if (mIsDepthPass && pass->getDepthWriteEnabled()) 
     74        { 
     75                usedPass = mDepthPass;           
     76        } 
     77 
     78    if (mIlluminationStage == IRS_RENDER_TO_TEXTURE) 
     79    { 
     80        // Derive a special shadow caster pass from this one 
     81        usedPass = deriveShadowCasterPass(usedPass); 
     82    } 
     83    else if (mIlluminationStage == IRS_RENDER_MODULATIVE_PASS) 
     84    { 
     85        usedPass = deriveShadowReceiverPass(usedPass); 
     86    } 
     87 
     88        bool passSurfaceAndLightParams = true; 
     89 
     90        // take original pass here 
     91    if (usedPass->hasVertexProgram()) 
     92    { 
     93        mDestRenderSystem->bindGpuProgram(usedPass->getVertexProgram()->_getBindingDelegate()); 
     94        // bind parameters later since they can be per-object 
     95        myLastUsedVertexProgram = true; 
     96        // does the vertex program want surface and light params passed to rendersystem? 
     97        passSurfaceAndLightParams = usedPass->getVertexProgram()->getPassSurfaceAndLightStates(); 
     98    } 
     99    else 
     100    { 
     101        // Unbind program? 
     102        if (myLastUsedVertexProgram) 
     103        { 
     104            mDestRenderSystem->unbindGpuProgram(GPT_VERTEX_PROGRAM); 
     105            myLastUsedVertexProgram = false; 
     106        } 
     107        // Set fixed-function vertex parameters 
     108    } 
     109 
     110    if (passSurfaceAndLightParams) 
     111    { 
     112        // Set surface reflectance properties, only valid if lighting is enabled 
     113        if (usedPass->getLightingEnabled()) 
     114        { 
     115            mDestRenderSystem->_setSurfaceParams(  
     116                usedPass->getAmbient(),  
     117                usedPass->getDiffuse(),  
     118                usedPass->getSpecular(),  
     119                usedPass->getSelfIllumination(),  
     120                usedPass->getShininess(), 
     121                                usedPass->getVertexColourTracking() ); 
     122        } 
     123 
     124        // Dynamic lighting enabled? 
     125        mDestRenderSystem->setLightingEnabled(usedPass->getLightingEnabled()); 
     126    } 
     127 
     128    // Using a fragment program? 
     129    if (usedPass->hasFragmentProgram()) 
     130    { 
     131        mDestRenderSystem->bindGpuProgram( 
     132            usedPass->getFragmentProgram()->_getBindingDelegate()); 
     133        // bind parameters later since they can be per-object 
     134        myLastUsedFragmentProgram = true; 
     135    } 
     136    else 
     137    { 
     138        // Unbind program? 
     139        if (myLastUsedFragmentProgram) 
     140        { 
     141            mDestRenderSystem->unbindGpuProgram(GPT_FRAGMENT_PROGRAM); 
     142            myLastUsedFragmentProgram = false; 
     143        } 
     144 
     145        // Set fixed-function fragment settings 
     146 
     147        // Fog (assumes we want pixel fog which is the usual) 
     148        // New fog params can either be from scene or from material 
     149        FogMode newFogMode; 
     150        ColourValue newFogColour; 
     151        Real newFogStart, newFogEnd, newFogDensity; 
     152        if (usedPass->getFogOverride()) 
     153        { 
     154            // New fog params from material 
     155            newFogMode = usedPass->getFogMode(); 
     156            newFogColour = usedPass->getFogColour(); 
     157            newFogStart = usedPass->getFogStart(); 
     158            newFogEnd = usedPass->getFogEnd(); 
     159            newFogDensity = usedPass->getFogDensity(); 
     160        } 
     161        else 
     162        { 
     163            // New fog params from scene 
     164            newFogMode = mFogMode; 
     165            newFogColour = mFogColour; 
     166            newFogStart = mFogStart; 
     167            newFogEnd = mFogEnd; 
     168            newFogDensity = mFogDensity; 
     169        } 
     170        mDestRenderSystem->_setFog(newFogMode, newFogColour, newFogDensity, newFogStart, newFogEnd); 
     171 
     172        } 
     173 
     174    // The rest of the settings are the same no matter whether we use programs or not 
     175 
     176    // Set scene blending 
     177    mDestRenderSystem->_setSceneBlending( 
     178        usedPass->getSourceBlendFactor(), usedPass->getDestBlendFactor()); 
     179 
     180 
     181    // Texture unit settings 
     182 
     183    Pass::TextureUnitStateIterator texIter =  usedPass->getTextureUnitStateIterator(); 
     184    size_t unit = 0; 
     185    while(texIter.hasMoreElements()) 
     186    { 
     187        TextureUnitState* pTex = texIter.getNext(); 
     188        mDestRenderSystem->_setTextureUnitSettings(unit, *pTex); 
     189        ++unit; 
     190    } 
     191    // Disable remaining texture units 
     192    mDestRenderSystem->_disableTextureUnitsFrom(usedPass->getNumTextureUnitStates()); 
     193 
     194    // Set up non-texture related material settings 
     195    // Depth buffer settings 
     196    mDestRenderSystem->_setDepthBufferFunction(usedPass->getDepthFunction()); 
     197    mDestRenderSystem->_setDepthBufferCheckEnabled(usedPass->getDepthCheckEnabled()); 
     198    mDestRenderSystem->_setDepthBufferWriteEnabled(usedPass->getDepthWriteEnabled()); 
     199    mDestRenderSystem->_setDepthBias(usedPass->getDepthBias()); 
     200        // Alpha-reject settings 
     201        mDestRenderSystem->_setAlphaRejectSettings( 
     202                usedPass->getAlphaRejectFunction(), usedPass->getAlphaRejectValue()); 
     203    // Set colour write mode 
     204    // Right now we only use on/off, not per-channel 
     205    bool colWrite = usedPass->getColourWriteEnabled(); 
     206    mDestRenderSystem->_setColourBufferWriteEnabled(colWrite, colWrite, colWrite, colWrite); 
     207    // Culling mode 
     208    mDestRenderSystem->_setCullingMode(usedPass->getCullingMode()); 
     209    // Shading 
     210    mDestRenderSystem->setShadingType(usedPass->getShadingMode()); 
    92211 
    93212        return usedPass; 
    94 } 
     213}*/ 
    95214//----------------------------------------------------------------------- 
    96215void VisibilityTerrainSceneManager::ShowVisualization(Camera *cam) 
     
    138257} 
    139258//----------------------------------------------------------------------- 
     259Pass *VisibilityTerrainSceneManager::setPass(Pass* pass) 
     260{ 
     261        // setting vertex program is not efficient 
     262        //Pass *usedPass = ((mIsDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);            
     263        // set depth fill pass only if depth write enabled 
     264        Pass *usedPass = (mIsDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass); 
     265         
     266        if (mIsDepthPass) 
     267        { 
     268                // set vertex program of current pass 
     269        if (pass->hasVertexProgram()) 
     270                { 
     271                        mDepthPass->setVertexProgram(pass->getVertexProgramName()); 
     272 
     273                        if (mDepthPass->hasVertexProgram()) 
     274                        { 
     275                                const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 
     276                                // Load this program if not done already 
     277                                if (!prg->isLoaded()) 
     278                                        prg->load(); 
     279                                // Copy params 
     280                                mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 
     281                        } 
     282                } 
     283                else if (mDepthPass->hasVertexProgram()) 
     284                { 
     285                        mDepthPass->setVertexProgram(""); 
     286                } 
     287        } 
     288        /*else if (mIsItemBufferPass) 
     289        { 
     290                usedPass = mItemBufferPass; 
     291        }*/ 
     292        SceneManager::setPass(usedPass); 
     293 
     294        return usedPass; 
     295} 
     296//----------------------------------------------------------------------- 
    140297void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters) 
    141298{ 
     
    232389                mIsDepthPass = false; 
    233390        } 
     391 
    234392        mSkipTransparents = false; 
    235393 
     
    342500        std::stringstream d; 
    343501 
    344         d << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", " 
     502        d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", " 
     503          << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", " 
     504          << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetUseOptimization()) << ", " 
     505          << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", " 
    345506          << "Hierarchy nodes: " << mNumOctreeNodes << ", "  
    346507          << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", " 
Note: See TracChangeset for help on using the changeset viewer.