source: trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp @ 88

Revision 88, 4.9 KB checked in by mattausch, 19 years ago (diff)
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreD3D9HardwareOcclusionQuery.h"
26#include "OgreRenderSystemCapabilities.h"
27#include "OgreException.h"
28
29namespace Ogre {
30
31int D3D9HardwareOcclusionQuery::m_Skip = 0;
32
33/**
34  * This is a class that is the DirectX9 implementation of
35  * hardware occlusion testing.
36  *
37  * @author Lee Sandberg
38  */
39
40/**
41  * Default object constructor
42  *
43  */
44D3D9HardwareOcclusionQuery::D3D9HardwareOcclusionQuery( IDirect3DDevice9* pD3DDevice )
45{
46        m_pD3DDevice = pD3DDevice;
47        m_uintPixelCount = 0;
48        m_SkipCounter = 0;
49        m_bHWOcclusionSupport = false;
50
51        HRESULT hr = m_pD3DDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &m_pD3DQuery);
52        if ( hr != D3D_OK )
53        {
54                //OGRE_EXCEPT(hr, "D3D9HardwareOcclusionQuery couldn't create hardware occlusion query object.",
55        //        "D3D9HardwareOcclusionQuery::D3D9HardwareOcclusionQuery");
56                m_bHWOcclusionSupport = false;
57        }
58        else
59        {
60                m_bHWOcclusionSupport = true;
61        }
62}
63
64
65/**
66  * Object destructor
67  */
68D3D9HardwareOcclusionQuery::~D3D9HardwareOcclusionQuery()
69{
70        SAFE_RELEASE( m_pD3DQuery );
71}
72
73//------------------------------------------------------------------
74// Occlusion query functions (see base class documentation for this)
75//--
76void D3D9HardwareOcclusionQuery::beginOcclusionQuery()
77{
78        if( m_bHWOcclusionSupport )             // Make it fail silently if hardware occlusion isn't supported
79        {
80                m_pD3DQuery->Issue(D3DISSUE_BEGIN);
81        }
82}
83//------------------------------------------------------------------
84void D3D9HardwareOcclusionQuery::endOcclusionQuery()
85{
86        if( m_bHWOcclusionSupport )     // Make it fail silently if hardware occlusion isn't supported
87        {
88                m_pD3DQuery->Issue(D3DISSUE_END);
89        }
90}
91
92//------------------------------------------------------------------
93// This version of pullOcclusionQuery cases the DX9 API/Driver to flush all commands to the 3D card
94// to allow a fast result from the query, but at the cost of poorer batching of API calls to the card.
95// Note: OpenGL dosn't use this flag at all so the application running OpenGL won't display any different behaviour.
96//--
97bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult )
98{
99        return pullOcclusionQuery(NumOfFragments, waitForResult, HWOCCLUSIONQUERY_FLUSH);
100}
101
102//------------------------------------------------------------------
103// This version of pullOcclusionQuery cases the DX9 API/Driver to not flush all commands to the 3D card
104// to allow a fast result from the query, but the batching of API calls to the card will be normal.
105// But the query wont be processed until the card recives the query in the nexr batch.
106// Note: OpenGL dosn't use this flag at all so the application running OpenGL won't display any different behaviour.
107//--
108bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult,
109                                                                                                     const HW_OCCLUSIONQUERY flag  )
110{
111        DWORD queryFlag = flag == HWOCCLUSIONQUERY_FLUSH ? D3DGETDATA_FLUSH : 0;
112        // TO DO: USE lockOpts= D3D9Mappings::get(options); instead of RS_OCCLUSIONQUERY enum
113
114        return pullOcclusionQuery(NumOfFragments, waitForResult, queryFlag);
115}
116//------------------------------------------------------------------
117bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult,
118                                                                                                     const DWORD queryFlag )
119{
120        HRESULT hr = S_OK;
121
122        if( m_bHWOcclusionSupport )     // In case hardware occlusion isn't supported
123        {       
124                do
125                {
126                        hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), queryFlag );
127                }
128                while(waitForResult && (hr == S_FALSE));
129               
130                m_uintPixelCount = *NumOfFragments;
131        }
132        else
133        {
134                m_uintPixelCount = 100000; // every object is visible
135        }
136       
137        return hr == S_OK;
138}
139} // namespace OGre
Note: See TracBrowser for help on using the repository browser.