Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 14, 2012, 9:16:18 PM (11 years ago)
Author:
davidsa
Message:

Added Hardware Occlusion Query Capabilities for use in dynamic flare effects, this is still a pretty static implemenation, meaning it will fail with mutltiple HOQ objects on screen, also needs some tidying up and documentation at a later point

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/shaders/src/orxonox/RenderQueueListener.cc

    r9420 r9448  
    3737#include <OgreRoot.h>
    3838#include <OgreRenderQueueListener.h>
     39#include <OgreHardwareOcclusionQuery.h>
    3940
    4041namespace orxonox
    4142{
     43    RenderQueueListener::RenderQueueListener() : pixelCount_(0), pixelState_(RenderQueueListener::READY_FOR_RENDER)
     44    {
     45        hardwareOcclusionQuery_ = Ogre::Root::getSingleton().getRenderSystem()->createHardwareOcclusionQuery(); //create a new HOQ for the scene this listener is used in
     46    }
     47   
     48    RenderQueueListener::~RenderQueueListener()
     49    {
     50        Ogre::Root::getSingleton().getRenderSystem()->destroyHardwareOcclusionQuery(hardwareOcclusionQuery_); //destroy the created HOQ
     51    }
     52   
     53    /**
     54    @brief
     55    This function is returning the current pixel count and resets the pixel state if we're ready to do another Hardware Occlusion Query
     56   
     57    @return
     58    current pixel count taken from the last Hardware Occlusion Query
     59    */
     60    unsigned int RenderQueueListener::getPixelCount()
     61    {
     62        if(this->pixelState_==RenderQueueListener::READY_FOR_ACCESS)
     63        {
     64            this->hardwareOcclusionQuery_->pullOcclusionQuery(&(this->pixelCount_));
     65            this->pixelState_=RenderQueueListener::READY_FOR_RENDER;
     66        }
     67        return this->pixelCount_;
     68    }
     69   
    4270    /**
    4371    @brief
    4472    This function is called just before a RenderQueueGroup is rendered, this function is called by Ogre automatically with the correct parameters.
    4573
    46     In this case we use it to set the stencil buffer parameters of the render system
     74    In this case we use it to set the stencil buffer parameters of the render system and issue a Hardware Occlusion Query
    4775    */
    4876    void RenderQueueListener::renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation)
     
    6088        if (queueGroupId == RENDER_QUEUE_STENCIL_GLOW)
    6189        {
    62               Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem();
    63               renderSystem->setStencilCheckEnabled(true);
    64               renderSystem->setStencilBufferParams(Ogre::CMPF_NOT_EQUAL,
    65                   STENCIL_VALUE_FOR_GLOW, STENCIL_FULL_MASK,
    66                   Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
     90            Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem();
     91            renderSystem->setStencilCheckEnabled(true);
     92            renderSystem->setStencilBufferParams(Ogre::CMPF_NOT_EQUAL,
     93                STENCIL_VALUE_FOR_GLOW, STENCIL_FULL_MASK,
     94                Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
     95        }
     96        if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==RenderQueueListener::READY_FOR_RENDER)
     97        {
     98            this->hardwareOcclusionQuery_->beginOcclusionQuery();
     99            this->pixelState_=RenderQueueListener::QUERY_STARTED;
     100            //TODO: Skip this rendering step altogheter if we haven't requested the pixel count yet, not sure if this is possible without a custom SceneManager
    67101        }
    68102    }
     
    82116            renderSystem->setStencilBufferParams();
    83117        }
     118        if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==RenderQueueListener::QUERY_STARTED)
     119        {
     120            this->hardwareOcclusionQuery_->endOcclusionQuery();
     121            this->pixelState_=RenderQueueListener::READY_FOR_ACCESS;
     122        }
    84123    }
    85124}
Note: See TracChangeset for help on using the changeset viewer.