CmD3D11EventQuery.cpp 1016 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "CmD3D11EventQuery.h"
  2. #include "CmD3D11RenderSystem.h"
  3. #include "CmD3D11Device.h"
  4. #include "CmException.h"
  5. namespace CamelotFramework
  6. {
  7. D3D11EventQuery::D3D11EventQuery()
  8. :mQuery(nullptr), mInitialized(false)
  9. {
  10. }
  11. D3D11EventQuery::~D3D11EventQuery()
  12. {
  13. if(mInitialized)
  14. {
  15. mQuery->Release();
  16. }
  17. }
  18. void D3D11EventQuery::begin()
  19. {
  20. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  21. D3D11Device& device = rs->getPrimaryDevice();
  22. D3D11_QUERY_DESC queryDesc;
  23. queryDesc.Query = D3D11_QUERY_EVENT;
  24. HRESULT hr = device.getD3D11Device()->CreateQuery(&queryDesc, &mQuery);
  25. if(hr != S_OK)
  26. {
  27. CM_EXCEPT(RenderingAPIException, "Failed to create an Event query.");
  28. }
  29. mContext = device.getImmediateContext();
  30. mContext->End(mQuery);
  31. mInitialized = true;
  32. }
  33. bool D3D11EventQuery::isReady() const
  34. {
  35. BOOL queryData;
  36. return mContext->GetData(mQuery, &queryData, sizeof(BOOL), 0) == S_OK;
  37. }
  38. }