- Timestamp:
- 05/30/05 03:20:23 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp
r99 r115 27 27 #include "OgreException.h" 28 28 29 29 30 namespace Ogre { 30 31 int GLHardwareOcclusionQuery::m_Skip = 0;32 31 33 32 /** … … 36 35 * 37 36 * @author Lee Sandberg email: lee@abcmedia.se 37 * 38 * Updated on 12/7/2004 by Chris McGuirk 39 * - Implemented ARB_occlusion_query 38 40 */ 39 41 40 /* Functions used;41 42 glGenOcclusionQueriesNV_ptr( 1, m_uintQuery );43 glDeleteOcclusionQueriesNV_ptr( 1, &m_uintQuery[0] );44 glBeginOcclusionQueryNV_ptr( m_uintQuery[0] );45 glEndOcclusionQueryNV_ptr();46 glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, NumOfFragments );47 48 TO DO: change this to the new ARB functions...49 50 */51 52 #ifndef GTP_VISIBILITY_MODIFIED_OGRE53 42 /** 54 43 * Default object constructor … … 57 46 GLHardwareOcclusionQuery::GLHardwareOcclusionQuery() 58 47 { 59 m_uintPixelCount = 0; 60 m_SkipCounter = 0; 48 mPixelCount = 0; 49 mSkipCounter = 0; 50 mSkipInterval = 0; 61 51 62 52 // Check for hardware occlusion support 63 if( glDeleteOcclusionQueriesNV_ptr != 0 ) // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported. 53 // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported. 54 //if (glGenQueriesARB_ptr != 0) 55 if (glGenOcclusionQueriesNV_ptr != 0) 64 56 { 65 m _bHWOcclusionSupport = true;57 mHasOcclusionSupport = true; 66 58 } 67 59 else 68 60 { 69 m _bHWOcclusionSupport = false;61 mHasOcclusionSupport = false; 70 62 } 71 63 72 if( m_bHWOcclusionSupport)64 if(mHasOcclusionSupport) 73 65 { 74 glGenOcclusionQueriesNV_ptr( 1, m_uintQuery ); 66 //glGenQueriesARB_ptr(1, &mQueryID ); 67 glGenOcclusionQueriesNV_ptr(1, &mQueryID); 75 68 } 76 69 } 77 78 70 79 71 /** … … 82 74 GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery() 83 75 { 84 if( m _bHWOcclusionSupport )76 if( mHasOcclusionSupport ) 85 77 { 86 glDeleteOcclusionQueriesNV_ptr( 1, &m_uintQuery[0] ); 78 //glDeleteQueriesARB_ptr(1, &mQueryID); 79 glDeleteOcclusionQueriesNV_ptr(1, &mQueryID); 87 80 } 88 81 } … … 93 86 void GLHardwareOcclusionQuery::beginOcclusionQuery() 94 87 { 95 if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 88 // Make it fail silently if hardware occlusion isn't supported 89 if(mHasOcclusionSupport) 96 90 { 97 if ( m_SkipCounter == m_Skip ) { m_SkipCounter = 0; }; // Counter starts at 0 again at m_Skip 98 if ( m_SkipCounter == 0 && m_uintPixelCount != 0 ) // New or none visable objects must allways be tested but visable objects can be skiped 91 // Counter starts at 0 again at mSkipInterval 92 #ifndef GTP_VISIBILITY_MODIFIED_OGRE 93 if(mSkipCounter == mSkipInterval) 94 #else 95 if (mSkipCounter >= mSkipInterval) // otherwise no query ever issued if mSkipInterval = 0 ! 96 #endif // GTP_VISIBILITY_MODIFIED_OGRE 97 { 98 mSkipCounter = 0; 99 } 100 101 if (mSkipCounter == 0) 99 102 { 100 glBeginOcclusionQueryNV_ptr( m_uintQuery[0] ); 103 //glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, mQueryID); 104 glBeginOcclusionQueryNV_ptr(mQueryID); 101 105 } 102 106 } … … 105 109 void GLHardwareOcclusionQuery::endOcclusionQuery() 106 110 { 107 if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 111 // Make it fail silently if hardware occlusion isn't supported 112 if(mHasOcclusionSupport) 108 113 { 109 if( m _SkipCounter == 0 && m_uintPixelCount != 0 ) // New or none visable objects must allways be tested but visable objects can be skiped114 if( mSkipCounter == 0) 110 115 { 116 //glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB); 111 117 glEndOcclusionQueryNV_ptr(); 112 118 } 113 m_SkipCounter++;114 }115 }116 119 117 bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int * NumOfFragments) 118 { 119 if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 120 { 121 glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, NumOfFragments ); 120 mSkipCounter++; 122 121 } 123 else124 {125 *NumOfFragments = 100000; // Fails quitlly -> every object tested is visable.126 }127 128 m_uintPixelCount = *NumOfFragments;129 130 return true;131 122 } 132 123 133 124 //------------------------------------------------------------------ 134 // OpenGL dosn't use the flag, but to fulfil the abstract interface we need to include this function. 135 // Using this function in OpenGL mode simple works the same way as calling the other function without the flag parameter, 136 // but in DX9 it works differentlly, see notes in the DX9 implementation. 137 //-- 125 // OpenGL dosn't use the flag paramter. 126 //------------------------------------------------------------------ 138 127 bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag ) 139 128 { 140 if( m _bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported129 if( mHasOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 141 130 { 142 glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, NumOfFragments ); 131 //glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments); 132 glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments); 143 133 } 144 134 else … … 147 137 } 148 138 149 m _uintPixelCount = *NumOfFragments;139 mPixelCount = *NumOfFragments; 150 140 151 141 return true; 152 142 } 153 143 154 #else // GTP_VISIBILITY_MODIFIED_OGRE 155 156 //------------------------------------------------------------------ 157 GLHardwareOcclusionQuery::GLHardwareOcclusionQuery() 158 { 159 m_uintPixelCount = 0; 160 m_SkipCounter = 0; 161 162 // Check for hardware occlusion support 163 if ( glDeleteOcclusionQueriesNV_ptr != 0 ) // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported. 164 //if ( glDeleteQueriesARB_ptr != 0 ) 165 { 166 m_bHWOcclusionSupport = true; 167 } 168 else 169 { 170 m_bHWOcclusionSupport = false; 171 } 172 173 if ( m_bHWOcclusionSupport ) 174 { 175 glGenOcclusionQueriesNV_ptr( 1, m_uintQuery ); 176 //glGenQueriesARB_ptr(1, m_uintQuery); 177 } 178 } 179 180 181 //------------------------------------------------------------------ 182 GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery() 183 { 184 if ( m_bHWOcclusionSupport ) 185 { 186 glDeleteOcclusionQueriesNV_ptr( 1, &m_uintQuery[0] ); 187 //glDeleteQueriesARB_ptr(1, &m_uintQuery[0]); 188 } 189 } 190 191 //------------------------------------------------------------------ 192 void GLHardwareOcclusionQuery::beginOcclusionQuery() 193 { 194 if ( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 195 { 196 // do the actual occlusion query for this node 197 glBeginOcclusionQueryNV_ptr( m_uintQuery[0] ); 198 //glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, m_uintQuery[0]); 199 } 200 } 201 202 void GLHardwareOcclusionQuery::endOcclusionQuery() 203 { 204 if ( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 205 { 206 glEndOcclusionQueryNV_ptr(); 207 //glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB); 208 } 209 } 210 //------------------------------------------------------------------ 211 bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int * NumOfFragments, const bool waitForResult) 144 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 145 //------------------------------------------------------------------ 146 bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int * NumOfFragments, const bool waitForResult, const HW_OCCLUSIONQUERY flag) 212 147 { 213 148 unsigned int isAvailable = GL_TRUE; 214 //int isAvailable = GL_TRUE;215 149 216 if( m_bHWOcclusionSupport)150 if (mHasOcclusionSupport) 217 151 { 218 152 if (!waitForResult) 219 153 { 220 glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_AVAILABLE_NV, &isAvailable ); 221 //glGetQueryivARB_ptr(m_uintQuery[0], GL_QUERY_RESULT_AVAILABLE_ARB, &isAvailable); 154 // use nv queries rather that arb because they are faster (no flush) 155 //glGetQueryivARB_ptr(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &isAvailable); 156 glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_AVAILABLE_NV, &isAvailable); 222 157 } 223 158 224 159 if (isAvailable == GL_TRUE) 225 160 { 226 glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, NumOfFragments);227 //glGetQueryObjectuivARB_ptr( m_uintQuery[0], GL_QUERY_RESULT_ARB, NumOfFragments);161 //glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments); 162 glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments); 228 163 } 229 164 } … … 234 169 } 235 170 236 m_uintPixelCount = *NumOfFragments;171 mPixelCount = *NumOfFragments; 237 172 238 173 return isAvailable == GL_TRUE; 239 174 } 240 175 241 //------------------------------------------------------------------ 242 bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, const HW_OCCLUSIONQUERY flag ) 243 { 244 return pullOcclusionQuery(NumOfFragments, waitForResult); 176 #endif // GTP_VIBILITY_MODIFIED_OGRE 245 177 } 246 247 #endif // GTP_VISIBILITY_MODIFIED_OGRE248 249 250 }251 252
Note: See TracChangeset
for help on using the changeset viewer.