Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/src/orxonox/RenderQueueListener.cc @ 12177

Last change on this file since 12177 was 12177, checked in by siramesh, 5 years ago

Super Orxo Bros Final (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 5.1 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#if OGRE_VERSION >= 0x010900
86                STENCIL_FULL_MASK,
87#endif
88                Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
89        } 
90        if (queueGroupId == RENDER_QUEUE_STENCIL_GLOW)
91        { 
92            Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); 
93            renderSystem->setStencilCheckEnabled(true); 
94            renderSystem->setStencilBufferParams(Ogre::CMPF_NOT_EQUAL,
95                STENCIL_VALUE_FOR_GLOW, STENCIL_FULL_MASK, 
96#if OGRE_VERSION >= 0x010900
97                STENCIL_FULL_MASK,
98#endif
99                Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
100        }
101        if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==PixelState::READY_FOR_RENDER)
102        { 
103            this->hardwareOcclusionQuery_->beginOcclusionQuery();
104            this->pixelState_=PixelState::QUERY_STARTED;
105            //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
106        }
107    }
108   
109    /**
110    @brief
111        This function is called just after a RenderQueueGroup has been rendered, this function is called by Ogre automatically with the correct parameters.
112       
113        in this case we use it to unset the stencil buffer parameters, so the rest of the render queue is unaffected by it.
114    */
115    void RenderQueueListener::renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation)
116    {
117        if (queueGroupId == RENDER_QUEUE_STENCIL_LAST) 
118        {
119            Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); 
120            renderSystem->setStencilCheckEnabled(false); 
121            renderSystem->setStencilBufferParams(); 
122        }
123        if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==PixelState::QUERY_STARTED)
124        {
125            this->hardwareOcclusionQuery_->endOcclusionQuery();
126            this->pixelState_=PixelState::READY_FOR_ACCESS;
127        }
128    }
129}
Note: See TracBrowser for help on using the repository browser.