TAMSVIZ
Visualization and annotation tool for ROS
framebuffer.cpp
1 // TAMSVIZ
2 // (c) 2020 Philipp Ruppel
3 
4 #include "framebuffer.h"
5 
6 #include "renderbuffer.h"
7 #include "texture.h"
8 
9 void Framebuffer::destroy() {
10  if (_id) {
11  GLuint fbo = _id;
12  cleanup([fbo]() { V_GL(glDeleteFramebuffers(1, &fbo)); });
13  _id = 0;
14  }
15 }
16 
17 void Framebuffer::create() {
18  if (!_id) {
19  V_GL(glGenFramebuffers(1, &_id));
20  }
21 }
22 
23 void Framebuffer::bind() {
24  create();
25  V_GL(glBindFramebuffer(GL_FRAMEBUFFER, _id));
26 }
27 
28 void Framebuffer::attach(Renderbuffer &renderbuffer, int attachment) {
29  bind();
30  renderbuffer.create();
31  V_GL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER,
32  renderbuffer.id()));
33 }
34 
35 void Framebuffer::attach(Texture &texture, int attachment) {
36  bind();
37  V_GL(glFramebufferTexture(GL_FRAMEBUFFER, attachment, texture.id(), 0));
38 }