Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreGLHardwareOcclusionQuery.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://ogre.sourceforge.net/
00006 
00007 Copyright © 2000-2003 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 
00026 #include "OgreGLHardwareOcclusionQuery.h"
00027 #include "OgreException.h"
00028 
00029 namespace Ogre {
00030 
00031 int GLHardwareOcclusionQuery::m_Skip = 0;
00032 
00040 /* Functions used;
00041 
00042 glGenOcclusionQueriesNV_ptr( 1, m_uintQuery );
00043 glDeleteOcclusionQueriesNV_ptr( 1, &m_uintQuery[0] );
00044 glBeginOcclusionQueryNV_ptr( m_uintQuery[0] );
00045 glEndOcclusionQueryNV_ptr();
00046 glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, NumOfFragments );
00047 
00048   TO DO: change this to the new ARB functions...
00049 
00050 */
00051 
00052 
00057 GLHardwareOcclusionQuery::GLHardwareOcclusionQuery() 
00058 { 
00059     m_uintPixelCount = 0; 
00060     m_SkipCounter = 0;
00061 
00062     // Check for hardware occlusion support
00063     if( glDeleteOcclusionQueriesNV_ptr != 0 )   // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported.
00064     {
00065         m_bHWOcclusionSupport = true;
00066     }
00067     else
00068     {
00069         m_bHWOcclusionSupport = false;
00070     }
00071 
00072     if( m_bHWOcclusionSupport )
00073     {
00074         glGenOcclusionQueriesNV_ptr( 1, m_uintQuery );  
00075     }
00076 }
00077 
00078 
00082 GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery() 
00083 { 
00084     if( m_bHWOcclusionSupport )
00085     {
00086         glDeleteOcclusionQueriesNV_ptr( 1, &m_uintQuery[0] );  
00087     }   
00088 }
00089 
00090 //------------------------------------------------------------------
00091 // Occlusion query functions (see base class documentation for this)
00092 //--
00093 void GLHardwareOcclusionQuery::beginOcclusionQuery() 
00094 { 
00095     if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported
00096     {
00097         if  ( m_SkipCounter ==  m_Skip ) { m_SkipCounter = 0; };        // Counter starts at 0 again at m_Skip 
00098         if ( m_SkipCounter == 0 && m_uintPixelCount != 0 ) // New or none visable objects must allways be tested but visable objects can be skiped
00099         {
00100             glBeginOcclusionQueryNV_ptr( m_uintQuery[0] );
00101         }
00102     }
00103 }
00104     
00105 void GLHardwareOcclusionQuery::endOcclusionQuery() 
00106 { 
00107     if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported
00108     {
00109         if( m_SkipCounter == 0 && m_uintPixelCount != 0 ) // New or none visable objects must allways be tested but visable objects can be skiped
00110         {
00111             glEndOcclusionQueryNV_ptr();
00112         }
00113         m_SkipCounter++;
00114     }
00115 }
00116 
00117 bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int * NumOfFragments) 
00118 {
00119     if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported
00120     {
00121         glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, NumOfFragments );
00122     } 
00123     else
00124     {
00125         *NumOfFragments = 100000;       // Fails quitlly -> every object tested is visable.
00126     }
00127 
00128     m_uintPixelCount = *NumOfFragments; 
00129 
00130     return true;
00131 }
00132 
00133 //------------------------------------------------------------------
00134 // OpenGL dosn't use the flag, but to fulfil the abstract interface we need to include this function.
00135 // Using this function in OpenGL mode simple works the same way as calling the other function without the flag parameter,
00136 // but in DX9 it works differentlly, see notes in the DX9 implementation.
00137 //--
00138 bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag  ) 
00139 {
00140     if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported
00141     {
00142         glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, NumOfFragments );
00143     }
00144     else
00145     {
00146         *NumOfFragments = 100000;       // Fails quitlly -> every object tested is visable.
00147     }
00148 
00149     m_uintPixelCount = *NumOfFragments; 
00150     
00151     return true;
00152 }
00153 
00154 
00155 }
00156 
00157 

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:25 2004