BsGLEventQuery.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_Query);
  14. }
  15. GLEventQuery::~GLEventQuery()
  16. {
  17. glDeleteQueries(1, &mQueryObj);
  18. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_Query);
  19. }
  20. void GLEventQuery::begin(const SPtr<CommandBuffer>& cb)
  21. {
  22. auto execute = [&]()
  23. {
  24. glQueryCounter(mQueryObj, GL_TIMESTAMP);
  25. setActive(true);
  26. };
  27. if (cb == nullptr)
  28. execute();
  29. else
  30. {
  31. SPtr<GLCommandBuffer> glCB = std::static_pointer_cast<GLCommandBuffer>(cb);
  32. glCB->queueCommand(execute);
  33. }
  34. }
  35. bool GLEventQuery::isReady() const
  36. {
  37. GLint done = 0;
  38. glGetQueryObjectiv(mQueryObj, GL_QUERY_RESULT_AVAILABLE, &done);
  39. return done == GL_TRUE;
  40. }
  41. }}