[61] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | #include "OgreGLHardwareOcclusionQuery.h"
|
---|
| 27 | #include "OgreException.h"
|
---|
| 28 |
|
---|
| 29 | namespace Ogre {
|
---|
| 30 |
|
---|
[343] | 31 | bool GLHardwareOcclusionQuery::sUseArbQueries = false;
|
---|
[61] | 32 | /**
|
---|
| 33 | * This is a class that is the base class of the query class for
|
---|
| 34 | * hardware occlusion testing.
|
---|
| 35 | *
|
---|
| 36 | * @author Lee Sandberg email: lee@abcmedia.se
|
---|
[115] | 37 | *
|
---|
| 38 | * Updated on 12/7/2004 by Chris McGuirk
|
---|
| 39 | * - Implemented ARB_occlusion_query
|
---|
[61] | 40 | */
|
---|
| 41 |
|
---|
| 42 | /**
|
---|
| 43 | * Default object constructor
|
---|
| 44 | *
|
---|
| 45 | */
|
---|
| 46 | GLHardwareOcclusionQuery::GLHardwareOcclusionQuery()
|
---|
| 47 | {
|
---|
[115] | 48 | mPixelCount = 0;
|
---|
| 49 | mSkipCounter = 0;
|
---|
| 50 | mSkipInterval = 0;
|
---|
[61] | 51 |
|
---|
| 52 | // Check for hardware occlusion support
|
---|
[115] | 53 | // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported.
|
---|
[343] | 54 | mHasOcclusionSupportARB = (glGenQueriesARB_ptr != 0);
|
---|
| 55 | mHasOcclusionSupportNV = (glGenOcclusionQueriesNV_ptr != 0);
|
---|
[61] | 56 |
|
---|
[343] | 57 | if (sUseArbQueries && mHasOcclusionSupportARB)
|
---|
[193] | 58 | glGenQueriesARB_ptr(1, &mQueryID );
|
---|
[343] | 59 | else if (!sUseArbQueries && mHasOcclusionSupportNV)
|
---|
[115] | 60 | glGenOcclusionQueriesNV_ptr(1, &mQueryID);
|
---|
[61] | 61 | }
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * Object destructor
|
---|
| 65 | */
|
---|
| 66 | GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery()
|
---|
| 67 | {
|
---|
[343] | 68 | if (sUseArbQueries && mHasOcclusionSupportARB)
|
---|
[193] | 69 | glDeleteQueriesARB_ptr(1, &mQueryID);
|
---|
[343] | 70 | else if (!sUseArbQueries && mHasOcclusionSupportNV)
|
---|
[115] | 71 | glDeleteOcclusionQueriesNV_ptr(1, &mQueryID);
|
---|
[61] | 72 | }
|
---|
| 73 |
|
---|
| 74 | //------------------------------------------------------------------
|
---|
| 75 | // Occlusion query functions (see base class documentation for this)
|
---|
| 76 | //--
|
---|
| 77 | void GLHardwareOcclusionQuery::beginOcclusionQuery()
|
---|
| 78 | {
|
---|
[343] | 79 | //if (mSkipCounter >= mSkipInterval) // otherwise no query ever issued if mSkipInterval = 0 !
|
---|
| 80 | // mSkipCounter = 0; if (mSkipCounter != 0) return;
|
---|
[115] | 81 |
|
---|
[343] | 82 | if (sUseArbQueries && mHasOcclusionSupportARB)
|
---|
[193] | 83 | glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, mQueryID);
|
---|
[343] | 84 | else if (!sUseArbQueries && mHasOcclusionSupportNV)
|
---|
[115] | 85 | glBeginOcclusionQueryNV_ptr(mQueryID);
|
---|
[61] | 86 | }
|
---|
| 87 |
|
---|
| 88 | void GLHardwareOcclusionQuery::endOcclusionQuery()
|
---|
| 89 | {
|
---|
[343] | 90 | //if( mSkipCounter != 0) return;
|
---|
| 91 | if (sUseArbQueries && mHasOcclusionSupportARB)
|
---|
[193] | 92 | glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB);
|
---|
[343] | 93 | else if (!sUseArbQueries && mHasOcclusionSupportNV)
|
---|
[97] | 94 | glEndOcclusionQueryNV_ptr();
|
---|
[343] | 95 | // mSkipCounter++;
|
---|
[97] | 96 | }
|
---|
[61] | 97 |
|
---|
[97] | 98 | bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag )
|
---|
| 99 | {
|
---|
[343] | 100 | if (sUseArbQueries && mHasOcclusionSupportARB)
|
---|
[193] | 101 | glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
|
---|
[343] | 102 | else if (!sUseArbQueries && mHasOcclusionSupportNV)
|
---|
[115] | 103 | glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
|
---|
[97] | 104 | else
|
---|
[343] | 105 | *NumOfFragments = 100000; // Fails quietly
|
---|
[97] | 106 |
|
---|
[115] | 107 | mPixelCount = *NumOfFragments;
|
---|
[97] | 108 |
|
---|
| 109 | return true;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[115] | 112 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 113 | //------------------------------------------------------------------
|
---|
[343] | 114 | bool GLHardwareOcclusionQuery::pullOcclusionQuery(unsigned int * NumOfFragments,
|
---|
| 115 | const bool waitForResult,
|
---|
| 116 | const HW_OCCLUSIONQUERY flag)
|
---|
[61] | 117 | {
|
---|
[343] | 118 | if (sUseArbQueries && mHasOcclusionSupportARB)
|
---|
[61] | 119 | {
|
---|
[343] | 120 | int isAvailable = GL_TRUE;
|
---|
| 121 |
|
---|
[99] | 122 | if (!waitForResult)
|
---|
[343] | 123 | glGetQueryivARB_ptr(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &isAvailable);
|
---|
| 124 |
|
---|
| 125 | if (isAvailable == GL_TRUE)
|
---|
| 126 | glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
|
---|
| 127 |
|
---|
| 128 | mPixelCount = *NumOfFragments;
|
---|
| 129 |
|
---|
| 130 | return isAvailable == GL_TRUE;
|
---|
| 131 | }
|
---|
| 132 | else if (!sUseArbQueries && mHasOcclusionSupportNV)
|
---|
[88] | 133 | {
|
---|
[343] | 134 | unsigned int isAvailable = GL_TRUE;
|
---|
| 135 |
|
---|
| 136 | if (!waitForResult)
|
---|
[115] | 137 | glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_AVAILABLE_NV, &isAvailable);
|
---|
[88] | 138 |
|
---|
[99] | 139 | if (isAvailable == GL_TRUE)
|
---|
[115] | 140 | glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
|
---|
[343] | 141 |
|
---|
| 142 | mPixelCount = *NumOfFragments;
|
---|
| 143 |
|
---|
| 144 | return isAvailable == GL_TRUE;
|
---|
[88] | 145 | }
|
---|
[343] | 146 |
|
---|
[88] | 147 | // In case hardware occlusion isn't supported, every object is set visible.
|
---|
| 148 | *NumOfFragments = 100000;
|
---|
[115] | 149 | mPixelCount = *NumOfFragments;
|
---|
[61] | 150 |
|
---|
[343] | 151 | return GL_TRUE;
|
---|
[61] | 152 | }
|
---|
| 153 |
|
---|
[115] | 154 | #endif // GTP_VIBILITY_MODIFIED_OGRE
|
---|
[61] | 155 | }
|
---|