Overte C++ Documentation
GLBuffer.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_GLBuffer_h
9 #define hifi_gpu_gl_GLBuffer_h
10 
11 #include "GLShared.h"
12 #include "GLBackend.h"
13 
14 namespace gpu { namespace gl {
15 
16 class GLBuffer : public GLObject<Buffer> {
17 public:
18  template <typename GLBufferType>
19  static GLBufferType* sync(GLBackend& backend, const Buffer& buffer) {
20  if (buffer.getSysmem().getSize() != 0) {
21  if (buffer._getUpdateCount == 0) {
22  qWarning() << "Unsynced buffer";
23  }
24  if (buffer._getUpdateCount < buffer._applyUpdateCount) {
25  qWarning() << "Unsynced buffer " << buffer._getUpdateCount << " " << buffer._applyUpdateCount;
26  }
27  }
28  GLBufferType* object = Backend::getGPUObject<GLBufferType>(buffer);
29 
30  // Has the storage size changed?
31  if (!object || object->_stamp != buffer._renderSysmem.getStamp()) {
32  object = new GLBufferType(backend.shared_from_this(), buffer, object);
33  }
34 
35  if (0 != (buffer._renderPages._flags & PageManager::DIRTY)) {
36  object->transfer();
37  }
38 
39  return object;
40  }
41 
42  template <typename GLBufferType>
43  static GLuint getId(GLBackend& backend, const Buffer& buffer) {
44  GLBuffer* bo = sync<GLBufferType>(backend, buffer);
45  if (bo) {
46  return bo->_buffer;
47  } else {
48  return 0;
49  }
50  }
51 
52  template <typename GLBufferType>
53  static GLuint getIdUnsynced(GLBackend& backend, const Buffer& buffer) {
54  GLBufferType* object = Backend::getGPUObject<GLBufferType>(buffer);
55  if (object) {
56  return object->_buffer;
57  } else {
58  return 0;
59  }
60  }
61 
62  const GLuint& _buffer { _id };
63  const GLuint _size;
64  const Stamp _stamp;
65 
66  ~GLBuffer();
67 
68  virtual void transfer() = 0;
69 
70 protected:
71  GLBuffer(const std::weak_ptr<GLBackend>& backend, const Buffer& buffer, GLuint id);
72 };
73 
74 } }
75 
76 #endif