[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: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Reto Grieder (physics) |
---|
| 25 | * Co-authors: |
---|
| 26 | * ... |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
[9419] | 30 | /** |
---|
| 31 | @file RenderQueueListener.cc |
---|
[9420] | 32 | @brief Implementation of the RenderQueueListener class. |
---|
[9419] | 33 | */ |
---|
| 34 | |
---|
[9407] | 35 | #include "RenderQueueListener.h" |
---|
| 36 | |
---|
| 37 | #include <OgreRoot.h> |
---|
| 38 | #include <OgreRenderQueueListener.h> |
---|
[9448] | 39 | #include <OgreHardwareOcclusionQuery.h> |
---|
[9407] | 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[9448] | 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 | |
---|
[9419] | 53 | /** |
---|
| 54 | @brief |
---|
[9448] | 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 | |
---|
| 70 | /** |
---|
| 71 | @brief |
---|
[9419] | 72 | This function is called just before a RenderQueueGroup is rendered, this function is called by Ogre automatically with the correct parameters. |
---|
| 73 | |
---|
[9448] | 74 | In this case we use it to set the stencil buffer parameters of the render system and issue a Hardware Occlusion Query |
---|
[9419] | 75 | */ |
---|
[9407] | 76 | void RenderQueueListener::renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation) |
---|
| 77 | { |
---|
| 78 | if (queueGroupId == RENDER_QUEUE_STENCIL_OBJECTS) |
---|
| 79 | { |
---|
| 80 | Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); |
---|
| 81 | |
---|
| 82 | renderSystem->clearFrameBuffer(Ogre::FBT_STENCIL); |
---|
| 83 | renderSystem->setStencilCheckEnabled(true); |
---|
| 84 | renderSystem->setStencilBufferParams(Ogre::CMPF_ALWAYS_PASS, |
---|
| 85 | STENCIL_VALUE_FOR_GLOW, STENCIL_FULL_MASK, |
---|
| 86 | Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false); |
---|
| 87 | } |
---|
| 88 | if (queueGroupId == RENDER_QUEUE_STENCIL_GLOW) |
---|
| 89 | { |
---|
[9448] | 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); |
---|
[9407] | 95 | } |
---|
[9448] | 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 |
---|
| 101 | } |
---|
[9407] | 102 | } |
---|
[9419] | 103 | |
---|
| 104 | /** |
---|
| 105 | @brief |
---|
| 106 | This function is called just after a RenderQueueGroup has been rendered, this function is called by Ogre automatically with the correct parameters. |
---|
| 107 | |
---|
| 108 | in this case we use it to unset the stencil buffer parameters, so the rest of the render queue is unaffected by it. |
---|
| 109 | */ |
---|
[9407] | 110 | void RenderQueueListener::renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation) |
---|
| 111 | { |
---|
| 112 | if (queueGroupId == RENDER_QUEUE_STENCIL_LAST) |
---|
| 113 | { |
---|
| 114 | Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); |
---|
| 115 | renderSystem->setStencilCheckEnabled(false); |
---|
| 116 | renderSystem->setStencilBufferParams(); |
---|
| 117 | } |
---|
[9448] | 118 | if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==RenderQueueListener::QUERY_STARTED) |
---|
| 119 | { |
---|
| 120 | this->hardwareOcclusionQuery_->endOcclusionQuery(); |
---|
| 121 | this->pixelState_=RenderQueueListener::READY_FOR_ACCESS; |
---|
| 122 | } |
---|
[9407] | 123 | } |
---|
| 124 | } |
---|