BsGLEventQuery.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsGLEventQuery.h"
  4. #include "BsGLCommandBuffer.h"
  5. #include "Profiling/BsRenderStats.h"
  6. namespace bs { namespace ct
  7. {
  8. GLEventQuery::GLEventQuery(UINT32 deviceIdx)
  9. :mQueryObj(0)
  10. {
  11. assert(deviceIdx == 0 && "Multiple GPUs not supported natively on OpenGL.");
  12. glGenQueries(1, &mQueryObj);
  13. BS_CHECK_GL_ERROR();
  14. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_Query);
  15. }
  16. GLEventQuery::~GLEventQuery()
  17. {
  18. glDeleteQueries(1, &mQueryObj);
  19. BS_CHECK_GL_ERROR();
  20. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_Query);
  21. }
  22. void GLEventQuery::begin(const SPtr<CommandBuffer>& cb)
  23. {
  24. auto execute = [&]()
  25. {
  26. glQueryCounter(mQueryObj, GL_TIMESTAMP);
  27. BS_CHECK_GL_ERROR();
  28. setActive(true);
  29. };
  30. if (cb == nullptr)
  31. execute();
  32. else
  33. {
  34. SPtr<GLCommandBuffer> glCB = std::static_pointer_cast<GLCommandBuffer>(cb);
  35. glCB->queueCommand(execute);
  36. }
  37. }
  38. bool GLEventQuery::isReady() const
  39. {
  40. GLint done = 0;
  41. glGetQueryObjectiv(mQueryObj, GL_QUERY_RESULT_AVAILABLE, &done);
  42. BS_CHECK_GL_ERROR();
  43. return done == GL_TRUE;
  44. }
  45. }}