[9407] | 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: |
---|
[11075] | 23 | * David 'davidsa' Salvisberg |
---|
[9407] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[9419] | 29 | /** |
---|
| 30 | @file RenderQueueListener.cc |
---|
[9420] | 31 | @brief Implementation of the RenderQueueListener class. |
---|
[9419] | 32 | */ |
---|
| 33 | |
---|
[9407] | 34 | #include "RenderQueueListener.h" |
---|
| 35 | |
---|
| 36 | #include <OgreRoot.h> |
---|
| 37 | #include <OgreRenderQueueListener.h> |
---|
[9448] | 38 | #include <OgreHardwareOcclusionQuery.h> |
---|
[9407] | 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
[11075] | 42 | RenderQueueListener::RenderQueueListener() : pixelCount_(0), pixelState_(PixelState::READY_FOR_RENDER) |
---|
[9448] | 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 | |
---|
[9419] | 52 | /** |
---|
| 53 | @brief |
---|
[9448] | 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 | { |
---|
[11075] | 61 | if(this->pixelState_==PixelState::READY_FOR_ACCESS) |
---|
[9448] | 62 | { |
---|
| 63 | this->hardwareOcclusionQuery_->pullOcclusionQuery(&(this->pixelCount_)); |
---|
[11075] | 64 | this->pixelState_=PixelState::READY_FOR_RENDER; |
---|
[9448] | 65 | } |
---|
| 66 | return this->pixelCount_; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | @brief |
---|
[9419] | 71 | This function is called just before a RenderQueueGroup is rendered, this function is called by Ogre automatically with the correct parameters. |
---|
| 72 | |
---|
[9448] | 73 | In this case we use it to set the stencil buffer parameters of the render system and issue a Hardware Occlusion Query |
---|
[9419] | 74 | */ |
---|
[9407] | 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 | { |
---|
[9448] | 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); |
---|
[9407] | 94 | } |
---|
[11075] | 95 | if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==PixelState::READY_FOR_RENDER) |
---|
[9448] | 96 | { |
---|
| 97 | this->hardwareOcclusionQuery_->beginOcclusionQuery(); |
---|
[11075] | 98 | this->pixelState_=PixelState::QUERY_STARTED; |
---|
[9448] | 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 | } |
---|
[9407] | 101 | } |
---|
[9419] | 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 | */ |
---|
[9407] | 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 | } |
---|
[11075] | 117 | if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==PixelState::QUERY_STARTED) |
---|
[9448] | 118 | { |
---|
| 119 | this->hardwareOcclusionQuery_->endOcclusionQuery(); |
---|
[11075] | 120 | this->pixelState_=PixelState::READY_FOR_ACCESS; |
---|
[9448] | 121 | } |
---|
[9407] | 122 | } |
---|
| 123 | } |
---|