OcclusionQuery.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "OcclusionQuery.h"
  2. #include "..\Render.h"
  3. OcclusionQuery::OcclusionQuery()
  4. {
  5. Create();
  6. }
  7. OcclusionQuery::~OcclusionQuery()
  8. {
  9. NGRender::pRS->ReleaseQueryNotify(this);
  10. RELEASE_D3D(query, 0);
  11. }
  12. void OcclusionQuery::Create()
  13. {
  14. NGRender::pRS->D3D()->CreateQuery( D3DQUERYTYPE_OCCLUSION, &query);
  15. }
  16. void OcclusionQuery::Release()
  17. {
  18. delete this;
  19. }
  20. void OcclusionQuery::Begin()
  21. {
  22. HRESULT r = query->Issue( D3DISSUE_BEGIN );
  23. }
  24. void OcclusionQuery::End()
  25. {
  26. HRESULT r = query->Issue( D3DISSUE_END );
  27. }
  28. DWORD OcclusionQuery::GetResult(bool bWaitResult)
  29. {
  30. // Loop until the data becomes available
  31. HRESULT r = D3D_OK;
  32. DWORD pixelsVisible = 0;
  33. for (;;)
  34. {
  35. r = query->GetData((void *) &pixelsVisible, sizeof(DWORD), D3DGETDATA_FLUSH);
  36. if (r != S_FALSE)
  37. {
  38. break;
  39. }
  40. if (bWaitResult == false)
  41. {
  42. return 0xFFFFFFFF;
  43. }
  44. }
  45. if (r != D3D_OK)
  46. {
  47. api->Trace("Histogram: Can't get query results!!");
  48. return 0xFFFFFFFF;
  49. }
  50. return pixelsVisible;
  51. }
  52. void OcclusionQuery::OnLostDevice()
  53. {
  54. RELEASE(query);
  55. }
  56. void OcclusionQuery::OnResetDevice()
  57. {
  58. Create();
  59. }