Panda3D
dxOcclusionQueryContext9.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file dxOcclusionQueryContext9.cxx
10  * @author drose
11  * @date 2007-06-04
12  */
13 
16 #include "pnotify.h"
17 #include "dcast.h"
18 #include "pStatTimer.h"
19 
20 TypeHandle DXOcclusionQueryContext9::_type_handle;
21 
22 /**
23  *
24  */
25 DXOcclusionQueryContext9::
26 ~DXOcclusionQueryContext9() {
27  _query->Release();
28  _query = nullptr;
29 }
30 
31 /**
32  * Returns true if the query's answer is ready, false otherwise. If this
33  * returns false, the application must continue to poll until it returns true.
34  *
35  * It is only valid to call this from the draw thread.
36  */
38 is_answer_ready() const {
39  DWORD result;
40  HRESULT hr = _query->GetData(&result, sizeof(result), 0);
41  return (hr != S_FALSE);
42 }
43 
44 /**
45  * Requests the graphics engine to expedite the pending answer--the
46  * application is now waiting until the answer is ready.
47  *
48  * It is only valid to call this from the draw thread.
49  */
53 }
54 
55 /**
56  * Returns the number of fragments (pixels) of the specified geometry that
57  * passed the depth test. If is_answer_ready() did not return true, this
58  * function may block before it returns.
59  *
60  * It is only valid to call this from the draw thread.
61  */
63 get_num_fragments() const {
64  DWORD result;
65  HRESULT hr = _query->GetData(&result, sizeof(result), 0);
66  if (hr == S_OK) {
67  // The answer is ready now.
68  return result;
69  }
70 
71  {
72  // The answer is not ready; this call will block.
73  PStatTimer timer(DXGraphicsStateGuardian9::_wait_occlusion_pcollector);
74  while (hr == S_FALSE) {
75  hr = _query->GetData(&result, sizeof(result), D3DGETDATA_FLUSH);
76  }
77  }
78 
79  if (FAILED(hr)) {
80  // Some failure, e.g. devicelost. Return a nonzero value as a worst-case
81  // answer.
82  dxgsg9_cat.info()
83  << "occlusion query failed " << D3DERRORSTRING(hr);
84  return 1;
85  }
86 
87  return result;
88 }
DXOcclusionQueryContext9::is_answer_ready
virtual bool is_answer_ready() const
Returns true if the query's answer is ready, false otherwise.
Definition: dxOcclusionQueryContext9.cxx:38
dcast.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pStatTimer.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatTimer
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
Definition: pStatTimer.h:30
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
dxGraphicsStateGuardian9.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DXOcclusionQueryContext9::waiting_for_answer
virtual void waiting_for_answer()
Requests the graphics engine to expedite the pending answer–the application is now waiting until the ...
Definition: dxOcclusionQueryContext9.cxx:51
DXOcclusionQueryContext9::get_num_fragments
virtual int get_num_fragments() const
Returns the number of fragments (pixels) of the specified geometry that passed the depth test.
Definition: dxOcclusionQueryContext9.cxx:63
dxOcclusionQueryContext9.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.