Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/RenderQueueListener.cc @ 11359

Last change on this file since 11359 was 11080, checked in by landauf, 8 years ago

merged shaders back to trunk (pps project from HS 2012)

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      David 'davidsa' Salvisberg
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30  @file RenderQueueListener.cc
31  @brief Implementation of the RenderQueueListener class.
32*/
33
34#include "RenderQueueListener.h"
35
36#include <OgreRoot.h>
37#include <OgreRenderQueueListener.h>
38#include <OgreHardwareOcclusionQuery.h>
39
40namespace orxonox
41{
42    RenderQueueListener::RenderQueueListener() : pixelCount_(0), pixelState_(PixelState::READY_FOR_RENDER)
43    {
44        hardwareOcclusionQuery_ = Ogre::Root::getSingleton().getRenderSystem()->createHardwareOcclusionQuery(); //create a new HOQ for the scene this listener is used in
45    }
46   
47    RenderQueueListener::~RenderQueueListener()
48    {
49        Ogre::Root::getSingleton().getRenderSystem()->destroyHardwareOcclusionQuery(hardwareOcclusionQuery_); //destroy the created HOQ
50    }
51   
52    /**
53    @brief
54    This function is returning the current pixel count and resets the pixel state if we're ready to do another Hardware Occlusion Query
55   
56    @return
57    current pixel count taken from the last Hardware Occlusion Query
58    */
59    unsigned int RenderQueueListener::getPixelCount()
60    {
61        if(this->pixelState_==PixelState::READY_FOR_ACCESS)
62        {
63            this->hardwareOcclusionQuery_->pullOcclusionQuery(&(this->pixelCount_));
64            this->pixelState_=PixelState::READY_FOR_RENDER;
65        }
66        return this->pixelCount_;
67    }
68   
69    /**
70    @brief
71    This function is called just before a RenderQueueGroup is rendered, this function is called by Ogre automatically with the correct parameters.
72
73    In this case we use it to set the stencil buffer parameters of the render system and issue a Hardware Occlusion Query
74    */
75    void RenderQueueListener::renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation)
76    {
77        if (queueGroupId == RENDER_QUEUE_STENCIL_OBJECTS)
78        { 
79            Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); 
80
81            renderSystem->clearFrameBuffer(Ogre::FBT_STENCIL); 
82            renderSystem->setStencilCheckEnabled(true); 
83            renderSystem->setStencilBufferParams(Ogre::CMPF_ALWAYS_PASS,
84                STENCIL_VALUE_FOR_GLOW, STENCIL_FULL_MASK, 
85                Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
86        } 
87        if (queueGroupId == RENDER_QUEUE_STENCIL_GLOW)
88        { 
89            Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); 
90            renderSystem->setStencilCheckEnabled(true); 
91            renderSystem->setStencilBufferParams(Ogre::CMPF_NOT_EQUAL,
92                STENCIL_VALUE_FOR_GLOW, STENCIL_FULL_MASK, 
93                Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
94        }
95        if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==PixelState::READY_FOR_RENDER)
96        { 
97            this->hardwareOcclusionQuery_->beginOcclusionQuery();
98            this->pixelState_=PixelState::QUERY_STARTED;
99            //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
100        }
101    }
102   
103    /**
104    @brief
105        This function is called just after a RenderQueueGroup has been rendered, this function is called by Ogre automatically with the correct parameters.
106       
107        in this case we use it to unset the stencil buffer parameters, so the rest of the render queue is unaffected by it.
108    */
109    void RenderQueueListener::renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation)
110    {
111        if (queueGroupId == RENDER_QUEUE_STENCIL_LAST) 
112        {
113            Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); 
114            renderSystem->setStencilCheckEnabled(false); 
115            renderSystem->setStencilBufferParams(); 
116        }
117        if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==PixelState::QUERY_STARTED)
118        {
119            this->hardwareOcclusionQuery_->endOcclusionQuery();
120            this->pixelState_=PixelState::READY_FOR_ACCESS;
121        }
122    }
123}
Note: See TracBrowser for help on using the repository browser.