OcclusionQueryHandle.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include "anki/gr/OcclusionQueryHandle.h"
  6. #include "anki/gr/gl/OcclusionQueryImpl.h"
  7. #include "anki/gr/GlHandleDeferredDeleter.h"
  8. namespace anki {
  9. //==============================================================================
  10. OcclusionQueryHandle::OcclusionQueryHandle()
  11. {}
  12. //==============================================================================
  13. OcclusionQueryHandle::~OcclusionQueryHandle()
  14. {}
  15. //==============================================================================
  16. Error OcclusionQueryHandle::create(GlDevice* dev, ResultBit condRenderingBit)
  17. {
  18. class Command: public GlCommand
  19. {
  20. public:
  21. OcclusionQueryHandle m_handle;
  22. ResultBit m_condRenderingBit;
  23. Command(OcclusionQueryHandle& handle, ResultBit condRenderingBit)
  24. : m_handle(handle),
  25. m_condRenderingBit(condRenderingBit)
  26. {}
  27. Error operator()(CommandBufferImpl*)
  28. {
  29. Error err = m_handle._get().create(m_condRenderingBit);
  30. GlHandleState oldState = m_handle._setState(
  31. (err) ? GlHandleState::ERROR : GlHandleState::CREATED);
  32. ANKI_ASSERT(oldState == GlHandleState::TO_BE_CREATED);
  33. (void)oldState;
  34. return err;
  35. }
  36. };
  37. using Alloc = GlAllocator<OcclusionQueryImpl>;
  38. using DeleteCommand = GlDeleteObjectCommand<OcclusionQueryImpl, Alloc>;
  39. using Deleter =
  40. GlHandleDeferredDeleter<OcclusionQueryImpl, Alloc, DeleteCommand>;
  41. CommandBufferHandle cmd;
  42. Error err = cmd.create(dev);
  43. if(!err)
  44. {
  45. err = _createAdvanced(dev, dev->_getAllocator(), Deleter());
  46. }
  47. if(!err)
  48. {
  49. _setState(GlHandleState::TO_BE_CREATED);
  50. cmd._pushBackNewCommand<Command>(*this, condRenderingBit);
  51. cmd.flush();
  52. }
  53. return err;
  54. }
  55. //==============================================================================
  56. void OcclusionQueryHandle::begin(CommandBufferHandle& commands)
  57. {
  58. class Command: public GlCommand
  59. {
  60. public:
  61. OcclusionQueryHandle m_handle;
  62. Command(OcclusionQueryHandle& handle)
  63. : m_handle(handle)
  64. {}
  65. Error operator()(CommandBufferImpl*)
  66. {
  67. m_handle._get().begin();
  68. return ErrorCode::NONE;
  69. }
  70. };
  71. commands._pushBackNewCommand<Command>(*this);
  72. }
  73. //==============================================================================
  74. void OcclusionQueryHandle::end(CommandBufferHandle& commands)
  75. {
  76. class Command: public GlCommand
  77. {
  78. public:
  79. OcclusionQueryHandle m_handle;
  80. Command(OcclusionQueryHandle& handle)
  81. : m_handle(handle)
  82. {}
  83. Error operator()(CommandBufferImpl*)
  84. {
  85. m_handle._get().end();
  86. return ErrorCode::NONE;
  87. }
  88. };
  89. commands._pushBackNewCommand<Command>(*this);
  90. }
  91. } // end namespace anki