/* ----------------------------------------------------------------------------- This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info, see http://ogre.sourceforge.net/ Copyright (c) 2000-2005 The OGRE Team Also see acknowledgements in Readme.html This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt. ----------------------------------------------------------------------------- */ #include "OgreGLHardwareOcclusionQuery.h" #include "OgreException.h" namespace Ogre { bool GLHardwareOcclusionQuery::sUseArbQueries = false; /** * This is a class that is the base class of the query class for * hardware occlusion testing. * * @author Lee Sandberg email: lee@abcmedia.se * * Updated on 12/7/2004 by Chris McGuirk * - Implemented ARB_occlusion_query */ /** * Default object constructor * */ GLHardwareOcclusionQuery::GLHardwareOcclusionQuery() { mPixelCount = 0; mSkipCounter = 0; mSkipInterval = 0; // Check for hardware occlusion support // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported. mHasOcclusionSupportARB = (glGenQueriesARB_ptr != 0); mHasOcclusionSupportNV = (glGenOcclusionQueriesNV_ptr != 0); if (sUseArbQueries && mHasOcclusionSupportARB) glGenQueriesARB_ptr(1, &mQueryID ); else if (!sUseArbQueries && mHasOcclusionSupportNV) glGenOcclusionQueriesNV_ptr(1, &mQueryID); } /** * Object destructor */ GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery() { if (sUseArbQueries && mHasOcclusionSupportARB) glDeleteQueriesARB_ptr(1, &mQueryID); else if (!sUseArbQueries && mHasOcclusionSupportNV) glDeleteOcclusionQueriesNV_ptr(1, &mQueryID); } //------------------------------------------------------------------ // Occlusion query functions (see base class documentation for this) //-- void GLHardwareOcclusionQuery::beginOcclusionQuery() { //if (mSkipCounter >= mSkipInterval) // otherwise no query ever issued if mSkipInterval = 0 ! // mSkipCounter = 0; if (mSkipCounter != 0) return; if (sUseArbQueries && mHasOcclusionSupportARB) glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, mQueryID); else if (!sUseArbQueries && mHasOcclusionSupportNV) glBeginOcclusionQueryNV_ptr(mQueryID); } void GLHardwareOcclusionQuery::endOcclusionQuery() { //if( mSkipCounter != 0) return; if (sUseArbQueries && mHasOcclusionSupportARB) glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB); else if (!sUseArbQueries && mHasOcclusionSupportNV) glEndOcclusionQueryNV_ptr(); // mSkipCounter++; } bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag ) { if (sUseArbQueries && mHasOcclusionSupportARB) glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments); else if (!sUseArbQueries && mHasOcclusionSupportNV) glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments); else *NumOfFragments = 100000; // Fails quietly mPixelCount = *NumOfFragments; return true; } #ifdef GTP_VISIBILITY_MODIFIED_OGRE //------------------------------------------------------------------ bool GLHardwareOcclusionQuery::pullOcclusionQuery(unsigned int * NumOfFragments, const bool waitForResult, const HW_OCCLUSIONQUERY flag) { if (sUseArbQueries && mHasOcclusionSupportARB) { int isAvailable = GL_TRUE; if (!waitForResult) glGetQueryivARB_ptr(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &isAvailable); if (isAvailable == GL_TRUE) glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments); mPixelCount = *NumOfFragments; return isAvailable == GL_TRUE; } else if (!sUseArbQueries && mHasOcclusionSupportNV) { unsigned int isAvailable = GL_TRUE; if (!waitForResult) glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_AVAILABLE_NV, &isAvailable); if (isAvailable == GL_TRUE) glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments); mPixelCount = *NumOfFragments; return isAvailable == GL_TRUE; } // In case hardware occlusion isn't supported, every object is set visible. *NumOfFragments = 100000; mPixelCount = *NumOfFragments; return GL_TRUE; } #endif // GTP_VIBILITY_MODIFIED_OGRE }