Overte C++ Documentation
GLQuery.h
1 //
2 // Created by Bradley Austin Davis on 2016/05/15
3 // Copyright 2013-2016 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 #ifndef hifi_gpu_gl_GLQuery_h
9 #define hifi_gpu_gl_GLQuery_h
10 
11 #include "GLShared.h"
12 #include "GLBackend.h"
13 
14 namespace gpu { namespace gl {
15 
16 class GLQuery : public GLObject<Query> {
17  using Parent = gpu::gl::GLObject<Query>;
18 public:
19  template <typename GLQueryType>
20  static GLQueryType* sync(GLBackend& backend, const Query& query) {
21  GLQueryType* object = Backend::getGPUObject<GLQueryType>(query);
22 
23  // need to have a gpu object?
24  if (!object) {
25  // All is green, assign the gpuobject to the Query
26  object = new GLQueryType(backend.shared_from_this(), query);
27  (void)CHECK_GL_ERROR();
28  Backend::setGPUObject(query, object);
29  }
30 
31  return object;
32  }
33 
34  template <typename GLQueryType>
35  static GLuint getId(GLBackend& backend, const QueryPointer& query) {
36  if (!query) {
37  return 0;
38  }
39 
40  GLQuery* object = sync<GLQueryType>(backend, *query);
41  if (!object) {
42  return 0;
43  }
44 
45  return object->_endqo;
46  }
47 
48  const GLuint& _endqo = { _id };
49  const GLuint _beginqo = { 0 };
50  GLuint64 _result { (GLuint64)0 };
51  GLuint64 _batchElapsedTime{ (GLuint64)0 };
52  std::chrono::high_resolution_clock::time_point _batchElapsedTimeBegin;
53  uint64_t _profileRangeId { 0 };
54  uint32_t _rangeQueryDepth { 0 };
55 
56 protected:
57  GLQuery(const std::weak_ptr<GLBackend>& backend, const Query& query, GLuint endId, GLuint beginId) : Parent(backend, query, endId), _beginqo(beginId) {}
58  ~GLQuery() {
59  if (_id) {
60  GLuint ids[2] = { _endqo, _beginqo };
61  glDeleteQueries(2, ids);
62  }
63  }
64 };
65 
66 } }
67 
68 #endif