Overte C++ Documentation
GLFramebuffer.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_GLFramebuffer_h
9 #define hifi_gpu_gl_GLFramebuffer_h
10 
11 #include "GLShared.h"
12 #include "GLBackend.h"
13 
14 namespace gpu { namespace gl {
15 
16 class GLFramebuffer : public GLObject<Framebuffer> {
17 public:
18  template <typename GLFramebufferType>
19  static GLFramebufferType* sync(GLBackend& backend, const Framebuffer& framebuffer) {
20  GLFramebufferType* object = Backend::getGPUObject<GLFramebufferType>(framebuffer);
21 
22  bool needsUpate { false };
23  if (!object ||
24  framebuffer.getDepthStamp() != object->_depthStamp ||
25  framebuffer.getColorStamps() != object->_colorStamps) {
26  needsUpate = true;
27  }
28 
29  // If GPU object already created and in sync
30  if (!needsUpate) {
31  return object;
32  } else if (framebuffer.isEmpty()) {
33  // NO framebuffer definition yet so let's avoid thinking
34  return nullptr;
35  }
36 
37  // need to have a gpu object?
38  if (!object) {
39  // All is green, assign the gpuobject to the Framebuffer
40  object = new GLFramebufferType(backend.shared_from_this(), framebuffer);
41  Backend::setGPUObject(framebuffer, object);
42  (void)CHECK_GL_ERROR();
43  }
44 
45  object->update();
46  return object;
47  }
48 
49  template <typename GLFramebufferType>
50  static GLuint getId(GLBackend& backend, const Framebuffer& framebuffer) {
51  GLFramebufferType* fbo = sync<GLFramebufferType>(backend, framebuffer);
52  if (fbo) {
53  return fbo->_id;
54  } else {
55  return 0;
56  }
57  }
58 
59  const GLuint& _fbo { _id };
60  std::vector<GLenum> _colorBuffers;
61  Stamp _depthStamp { 0 };
62  std::vector<Stamp> _colorStamps;
63 
64 protected:
65  GLenum _status { GL_FRAMEBUFFER_COMPLETE };
66  virtual void update() = 0;
67  bool checkStatus() const;
68 
69  GLFramebuffer(const std::weak_ptr<GLBackend>& backend, const Framebuffer& framebuffer, GLuint id) : GLObject(backend, framebuffer, id) {}
70  ~GLFramebuffer();
71 
72 };
73 
74 } }
75 
76 
77 #endif