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

# OgreD3D9HardwareOcclusionQuery.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 #include "OgreD3D9HardwareOcclusionQuery.h"
    00026 #include "OgreRenderSystemCapabilities.h"
    00027 #include "OgreException.h"
    00028
    00029 namespace Ogre {
    00030
    00031 int D3D9HardwareOcclusionQuery::m_Skip = 0;
    00032
    00044 D3D9HardwareOcclusionQuery::D3D9HardwareOcclusionQuery( IDirect3DDevice9* pD3DDevice )
    00045 {
    00046     m_pD3DDevice = pD3DDevice;
    00047     m_uintPixelCount = 0;
    00048     m_SkipCounter = 0;
    00049     m_bHWOcclusionSupport = false;
    00050
    00051     HRESULT hr = m_pD3DDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &m_pD3DQuery);
    00052     if ( hr != D3D_OK )
    00053     {
    00054         //Except(hr, "D3D9HardwareOcclusionQuery couldn't create hardware occlusion query object.",
    00055         //        "D3D9HardwareOcclusionQuery::D3D9HardwareOcclusionQuery");
    00056         m_bHWOcclusionSupport = false;
    00057     }
    00058     else
    00059     {
    00060         m_bHWOcclusionSupport = true;
    00061     }
    00062 }
    00063
    00064
    00068 D3D9HardwareOcclusionQuery::~D3D9HardwareOcclusionQuery()
    00069 {
    00070     SAFE_RELEASE( m_pD3DQuery );
    00071 }
    00072
    00073 //------------------------------------------------------------------
    00074 // Occlusion query functions (see base class documentation for this)
    00075 //--
    00076 void D3D9HardwareOcclusionQuery::beginOcclusionQuery()
    00077 {
    00078     if( m_bHWOcclusionSupport )     // Make it fail silently if hardware occlusion isn't supported
    00079     {
    00080         if  ( m_SkipCounter ==  m_Skip ) { m_SkipCounter = 0; };        // Counter starts at 0 again at m_Skip
    00081
    00082         if ( m_SkipCounter == 0 && m_uintPixelCount != 0 )  // New or none visable objects must allways be tested but visable objects can be skiped
    00083         {
    00084             m_pD3DQuery->Issue(D3DISSUE_BEGIN);
    00085         }
    00086     }
    00087 }
    00088
    00089 void D3D9HardwareOcclusionQuery::endOcclusionQuery()
    00090 {
    00091     if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported
    00092     {
    00093         if (m_SkipCounter == 0 && m_uintPixelCount != 0 ) // New or none visable objects must allways be tested but visable objects can be skiped
    00094         {
    00095             m_pD3DQuery->Issue(D3DISSUE_END);
    00096         }
    00097         m_SkipCounter++;                                 // The skip counter is increased
    00098     }
    00099 }
    00100
    00101 //------------------------------------------------------------------
    00102 // This version of pullOcclusionQuery cases the DX9 API/Driver to flush all commands to the 3D card
    00103 // to allow a fast result from the query, but at the cost of poorer batching of API calls to the card.
    00104 // Note: OpenGL dosn't use this flag at all so the application running OpenGL won't display any different behaviour.
    00105 //--
    00106 bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments)
    00107 {
    00108     HRESULT hr;
    00109
    00110     if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported
    00111     {
    00112         hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), D3DGETDATA_FLUSH );
    00113
    00114         if ( hr != S_OK )
    00115             {
    00116                 return false;
    00117             }
    00118             else
    00119             {
    00120                 m_uintPixelCount = *NumOfFragments;
    00121                 return true;
    00122             }
    00123     }
    00124     else
    00125     {
    00126         m_uintPixelCount = 100000; // Fails quitlly if hardware occlusion is not supported - every object is visable
    00127         return true;
    00128     }
    00129 }
    00130
    00131 //------------------------------------------------------------------
    00132 // This version of pullOcclusionQuery cases the DX9 API/Driver to not flush all commands to the 3D card
    00133 // to allow a fast result from the query, but the batching of API calls to the card will be normal.
    00134 // But the query wont be processed until the card recives the query in the nexr batch.
    00135 // Note: OpenGL dosn't use this flag at all so the application running OpenGL won't display any different behaviour.
    00136 //--
    00137 bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag  )
    00138 {
    00139     HRESULT hr;
    00140
    00141     // TO DO: USE lockOpts= D3D9Mappings::get(options); instead of RS_OCCLUSIONQUERY enum
    00142
    00143     if( m_bHWOcclusionSupport ) // Make it fail silently if hardware occlusion isn't supported
    00144     {
    00145
    00146         switch( flag )
    00147         {
    00148             case HWOCCLUSIONQUERY_FLUSH :
    00149                 hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), D3DGETDATA_FLUSH );
    00150             break;
    00151
    00152             case HWOCCLUSIONQUERY_NOFLUSH :
    00153                 hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), 0 );
    00154             break;
    00155         };
    00156
    00157
    00158
    00159         if ( hr != S_OK )
    00160             {
    00161                 return false;
    00162             }
    00163             else
    00164             {
    00165                 m_uintPixelCount = *NumOfFragments;
    00166                 return true;
    00167             }
    00168     }
    00169     else
    00170     {
    00171         m_uintPixelCount = 100000; // Fails quitlly if hardware occlusion is not supported - every object is visable
    00172         return true;
    00173     }
    00174 }
    00175
    00176
    00177
    00178
    00179 }

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