Changeset 115 for trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9
- Timestamp:
- 05/30/05 03:20:23 (19 years ago)
- Location:
- trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/include/OgreD3D9HardwareOcclusionQuery.h
r92 r115 33 33 namespace Ogre { 34 34 35 36 37 35 // If you use multiple rendering passes you can test only the first pass and all other passes don't have to be rendered 38 // if the first pass resultet has too few pixels visable.36 // if the first pass resultet has too few pixels visible. 39 37 40 38 // Be sure to render all occlluder first and whats out so the RenderQue don't switch places on … … 46 44 * 47 45 * @author Lee Sandberg, email lee@abcmedia.se 46 * 47 * Updated on 12/7/2004 by Chris McGuirk 48 48 */ 49 49 class D3D9HardwareOcclusionQuery : public HardwareOcclusionQuery … … 71 71 void beginOcclusionQuery(); 72 72 void endOcclusionQuery(); 73 bool pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag = HWOCCLUSIONQUERY_FLUSH); 74 unsigned int getLastQuerysPixelcount() { return mPixelCount; } 73 75 74 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 75 bool pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, 76 const HW_OCCLUSIONQUERY flag ); 77 bool pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult ); 78 #else 79 bool pullOcclusionQuery( unsigned int* NumOfFragments ); 80 bool pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag ); 81 #endif // GTP_VISIBILITY_MODIFIED_OGRE 82 83 unsigned int getLastQuerysPixelcount() { return m_uintPixelCount; } 84 85 // This functions are optional, it's a simple filter that simply skips some hardware occlusion tests on visable objects only 86 // It's easy to use if you don't have to keep track on which objects are visable (can be skipped) and what objects arn't visable.. 87 // (None visable objects and object you introduce for the first time have allways to be tested allthough the cheepest possible 88 // LOD (Level Of Detail) mesh and material wize). 76 // These functions are optional, it's a simple filter that simply skips some hardware occlusion tests on visible objects only 77 // It's easy to use if you don't have to keep track of which objects are visible (can be skipped) and what objects arn't visible.. 78 // (None visible objects and object you introduce for the first time have always to be tested although the cheapest possible 79 // LOD (Level Of Detail) mesh and material-wise). 89 80 90 81 /** 91 82 * 92 * Remarks This function allows you to set how often the hardware occlusion really aresent to the driver83 * Remarks This function allows you to set how often the hardware occlusion query is sent to the driver 93 84 * if you set it to 0 every hw occlusion test is acctually made. If you set it to 1 only the half of your queries are sent 94 * for all visable objects. 2 will result in 25% of all queries to acctualy be sent. 95 * New and none visable objects will be tested all the time. 96 * This functionality is here because this class can keep track on visable and none visable objects for you. 85 * 2 will result in 25% of all queries to acctualy be sent. 86 * This functionality is here because this class can keep track on visible and none visible objects for you. 97 87 * Once you you set the SkipRate for any hardware occlusion instance it effects all others. 98 88 */ 99 89 90 void setSkipRate( int skip ) { mSkipInterval = skip; } // Using 2 only 50 % of the tests are actully made and 3 results in only 33% of the tests. So on. 91 int getSkipRate() { return mSkipInterval; } 100 92 101 void setSkipRate( int skip ) { m_Skip = skip; } // Using 2 only 50 % of the tests are actually made and 3 results in only 33% of the tests. So on. 102 int getSkipRate() { return m_Skip; }103 93 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 94 bool pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, const HW_OCCLUSIONQUERY flag = HWOCCLUSIONQUERY_FLUSH ); 95 #endif // GTP_VISIBILITY_MODIFIED_OGRE 104 96 //---------------------------------------------------------------------- 105 97 // Protected members … … 107 99 protected: 108 100 109 bool pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, 110 const DWORD queryFlag ); 111 112 unsigned int m_uintPixelCount; 113 IDirect3DQuery9* m_pD3DQuery; 114 IDirect3DDevice9* m_pD3DDevice; // d3d device 115 bool m_bOcclusionQuery; 116 int m_SkipCounter; // m_SkipConter = m_SkipConter % m_Skip; if ( m_SkipConter == 0 && m_uintPixelCount !=0 ) TestHWOcclusion else just return 117 static int m_Skip; // This is shared by all instancies 118 bool m_bHWOcclusionSupport; 101 unsigned int mPixelCount; 102 IDirect3DQuery9* mpQuery; 103 IDirect3DDevice9* mpDevice; 104 int mSkipCounter; 105 int mSkipInterval; 106 bool mHasOcclusionSupport; 119 107 }; 120 108 -
trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp
r97 r115 29 29 namespace Ogre { 30 30 31 int D3D9HardwareOcclusionQuery::m_Skip = 0;32 33 31 /** 34 32 * This is a class that is the DirectX9 implementation of … … 36 34 * 37 35 * @author Lee Sandberg 36 * 37 * Updated on 12/7/2004 by Chris McGuirk 38 38 */ 39 39 40 40 /** 41 41 * Default object constructor 42 *43 42 */ 44 43 D3D9HardwareOcclusionQuery::D3D9HardwareOcclusionQuery( IDirect3DDevice9* pD3DDevice ) 45 44 { 46 m_pD3DDevice = pD3DDevice; 47 m_uintPixelCount = 0; 48 m_SkipCounter = 0; 49 m_bHWOcclusionSupport = false; 45 mpDevice = pD3DDevice; 46 mPixelCount = 0; 47 mSkipCounter = 0; 48 mSkipInterval = 0; 49 mHasOcclusionSupport = false; 50 50 51 HRESULT hr = m_pD3DDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &m_pD3DQuery); 51 // create the occlusion query 52 HRESULT hr = mpDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &mpQuery); 53 52 54 if ( hr != D3D_OK ) 53 55 { 54 //OGRE_EXCEPT(hr, "D3D9HardwareOcclusionQuery couldn't create hardware occlusion query object.", 55 // "D3D9HardwareOcclusionQuery::D3D9HardwareOcclusionQuery"); 56 m_bHWOcclusionSupport = false; 56 mHasOcclusionSupport = false; 57 57 } 58 58 else 59 59 { 60 m_bHWOcclusionSupport = true;60 mHasOcclusionSupport = true; 61 61 } 62 62 } 63 64 63 65 64 /** … … 68 67 D3D9HardwareOcclusionQuery::~D3D9HardwareOcclusionQuery() 69 68 { 70 SAFE_RELEASE( m_pD3DQuery);69 SAFE_RELEASE(mpQuery); 71 70 } 72 71 73 #ifndef GTP_VISIBILITY_MODIFIED_OGRE74 72 //------------------------------------------------------------------ 75 73 // Occlusion query functions (see base class documentation for this) … … 77 75 void D3D9HardwareOcclusionQuery::beginOcclusionQuery() 78 76 { 79 if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 77 // Make it fail silently if hardware occlusion isn't supported 78 if(mHasOcclusionSupport) 80 79 { 81 if ( m_SkipCounter == m_Skip ) { m_SkipCounter = 0; }; // Counter starts at 0 again at m_Skip 82 83 if ( m_SkipCounter == 0 && m_uintPixelCount != 0 ) // New or none visable objects must allways be tested but visable objects can be skiped 80 #ifndef GTP_VISIBILITY_MODIFIED_OGRE 81 // Counter starts at 0 again at mSkipInterval 82 if(mSkipCounter == mSkipInterval) 83 #else 84 if (mSkipCounter >= mSkipInterval) // otherwise no query ever issued if mSkipInterval = 0 ! 85 #endif // GTP_VISIBILITY_MODIFIED_OGRE 84 86 { 85 m_pD3DQuery->Issue(D3DISSUE_BEGIN); 87 mSkipCounter = 0; 88 } 89 //std::stringstream d; d << "count: " << mSkipCounter; 90 //LogManager::getSingleton().logMessage(d.str()); 91 if (mSkipCounter == 0) 92 { 93 mpQuery->Issue(D3DISSUE_BEGIN); 86 94 } 87 95 } 96 88 97 } 89 90 void D3D9HardwareOcclusionQuery::endOcclusionQuery() 91 { 92 if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 98 99 void D3D9HardwareOcclusionQuery::endOcclusionQuery() 93 100 { 94 if (m_SkipCounter == 0 && m_uintPixelCount != 0 ) // New or none visable objects must allways be tested but visable objects can be skiped 95 { 96 m_pD3DQuery->Issue(D3DISSUE_END); 97 } 98 m_SkipCounter++; // The skip counter is increased 101 // Make it fail silently if hardware occlusion isn't supported 102 if(mHasOcclusionSupport) 103 { 104 if(mSkipCounter == 0) 105 { 106 mpQuery->Issue(D3DISSUE_END); 107 } 108 109 // The skip counter is increased 110 mSkipCounter++; 99 111 } 100 112 } 101 113 102 114 //------------------------------------------------------------------ 103 // This version of pullOcclusionQuery cases the DX9 API/Driver to flush all commands to the 3D card 104 // to allow a fast result from the query, but at the cost of poorer batching of API calls to the card. 105 // Note: OpenGL dosn't use this flag at all so the application running OpenGL won't display any different behaviour. 106 //-- 107 bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments) 108 { 109 HRESULT hr; 110 111 if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 112 { 113 hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), D3DGETDATA_FLUSH ); 114 115 if ( hr != S_OK ) 116 { 117 return false; 118 } 119 else 120 { 121 m_uintPixelCount = *NumOfFragments; 122 return true; 123 } 124 } 125 else 126 { 127 m_uintPixelCount = 100000; // Fails quitlly if hardware occlusion is not supported - every object is visable 128 return true; 129 } 130 } 131 132 //------------------------------------------------------------------ 133 // This version of pullOcclusionQuery cases the DX9 API/Driver to not flush all commands to the 3D card 115 // This version of pullOcclusionQuery causes the DX9 API/Driver to not flush all commands to the 3D card 134 116 // to allow a fast result from the query, but the batching of API calls to the card will be normal. 135 // But the query wont be processed until the card recives the query in the nexrbatch.117 // But the query wont be processed until the card recives the query in the next batch. 136 118 // Note: OpenGL dosn't use this flag at all so the application running OpenGL won't display any different behaviour. 137 119 //-- … … 140 122 HRESULT hr; 141 123 142 // TO DO: USE lockOpts= D3D9Mappings::get(options); instead of RS_OCCLUSIONQUERY enum 124 // Make it fail silently if hardware occlusion isn't supported 125 if(mHasOcclusionSupport) 126 { 127 DWORD d3dFlags = (flag == HWOCCLUSIONQUERY_FLUSH) ? D3DGETDATA_FLUSH : 0; 128 129 // run until success (http://www.gamedev.net/reference/programming/features/occlusionculling/page2.asp) 130 while(hr = mpQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), d3dFlags) == S_FALSE); 143 131 144 if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 145 { 146 147 switch( flag ) 148 { 149 case HWOCCLUSIONQUERY_FLUSH : 150 hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), D3DGETDATA_FLUSH ); 151 break; 152 153 case HWOCCLUSIONQUERY_NOFLUSH : 154 hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), 0 ); 155 break; 156 }; 157 158 159 160 if ( hr != S_OK ) 161 { 162 return false; 132 mPixelCount = *NumOfFragments; 163 133 } 164 134 else 165 135 { 166 m_uintPixelCount = *NumOfFragments;167 return true;136 // fail silently if not supported, assume visible i suppose 137 mPixelCount = 100000; 168 138 } 169 } 170 else 171 { 172 m_uintPixelCount = 100000; // Fails quitlly if hardware occlusion is not supported - every object is visable 139 173 140 return true; 174 141 } 175 } 176 # else //GTP_VISIBILITY_MODIFIED_OGRE142 143 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 177 144 //------------------------------------------------------------------ 178 void D3D9HardwareOcclusionQuery::beginOcclusionQuery() 179 { 180 if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported 145 bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, 146 const HW_OCCLUSIONQUERY flag ) 181 147 { 182 m_pD3DQuery->Issue(D3DISSUE_BEGIN); 148 HRESULT hr = S_OK; 149 DWORD queryFlag = (flag == HWOCCLUSIONQUERY_FLUSH) ? D3DGETDATA_FLUSH : 0; 150 151 if (mHasOcclusionSupport) // In case hardware occlusion isn't supported 152 { 153 do 154 { 155 hr = mpQuery->GetData(NumOfFragments, sizeof(NumOfFragments), queryFlag); 156 } 157 while(waitForResult && (hr == S_FALSE)); 158 159 mPixelCount = *NumOfFragments; 160 } 161 else 162 { 163 mPixelCount = 100000; // every object is visible 164 } 165 166 return hr == S_OK; 183 167 } 184 }185 //------------------------------------------------------------------186 void D3D9HardwareOcclusionQuery::endOcclusionQuery()187 {188 if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported189 {190 m_pD3DQuery->Issue(D3DISSUE_END);191 }192 }193 //------------------------------------------------------------------194 bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult )195 {196 return pullOcclusionQuery(NumOfFragments, waitForResult, HWOCCLUSIONQUERY_FLUSH);197 }198 199 //------------------------------------------------------------------200 bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult,201 const HW_OCCLUSIONQUERY flag )202 {203 DWORD queryFlag = flag == HWOCCLUSIONQUERY_FLUSH ? D3DGETDATA_FLUSH : 0;204 // TO DO: USE lockOpts= D3D9Mappings::get(options); instead of RS_OCCLUSIONQUERY enum205 206 return pullOcclusionQuery(NumOfFragments, waitForResult, queryFlag);207 }208 209 //------------------------------------------------------------------210 bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult,211 const DWORD queryFlag )212 {213 HRESULT hr = S_OK;214 215 if( m_bHWOcclusionSupport ) // In case hardware occlusion isn't supported216 {217 do218 {219 hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), queryFlag );220 }221 while(waitForResult && (hr == S_FALSE));222 223 m_uintPixelCount = *NumOfFragments;224 }225 else226 {227 m_uintPixelCount = 100000; // every object is visible228 }229 230 return hr == S_OK;231 }232 168 233 169 234 170 #endif // GTP_VISIBILITY_MODIFIED_OGRE 235 171 236 } // namespace OGre 172 173 }
Note: See TracChangeset
for help on using the changeset viewer.