SimpleGL  1.1.0
A framework for platform independent rendering
framebuffer_object.cpp
Go to the documentation of this file.
1 
9 
10 namespace sgl {
11  Renderbuffer* Renderbuffer::current = nullptr;
12 
14  glGenRenderbuffers(1, &handle);
15  }
16 
18  glDeleteRenderbuffers(1, &handle);
19 
20  /* Set current to nullptr if this was the bound renderbuffer object */
21  if (Renderbuffer::current == this) {
22  Renderbuffer::current = nullptr;
23  }
24  }
25 
27  return handle;
28  }
29 
31  /* If already bound return immediately */
32  if (Renderbuffer::current == this) {
33  return;
34  }
35 
36  /* Bind renderbuffer object */
37  glBindRenderbuffer(GL_RENDERBUFFER, handle);
38  Renderbuffer::current = this;
39  }
40 
41  void Renderbuffer::storage(int width, int height) {
42  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
43  }
44 
45  FramebufferGL* FramebufferGL::current = nullptr;
46 
48  glGenFramebuffers(1, &handle);
49  }
50 
52  glDeleteFramebuffers(1, &handle);
53 
54  /* Set current to nullptr if this was the bound framebuffer object */
55  if (FramebufferGL::current == this) {
56  FramebufferGL::current = nullptr;
57  }
58  }
59 
61  return handle;
62  }
63 
65  /* If already bound return immediately */
66  if (FramebufferGL::current == this) {
67  return;
68  }
69 
70  /* Bind framebuffer object */
71  glBindFramebuffer(GL_FRAMEBUFFER, handle);
72  FramebufferGL::current = this;
73  }
74 
76  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->getHandle(), 0);
77  }
78 
80  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, buffer->getHandle());
81  }
82 }
FramebufferGL(void)
Generates a new framebuffer object.
void storage(int width, int height)
Allocates data storage, format and dimensions of the renderbuffer object.
GLuint getHandle()
Returns the handle of the framebuffer object.
GLuint getHandle()
Returns the handle of the renderbuffer object.
Generic namespace for the SimpleGL framework.
Definition: application.hpp:18
void bind()
Binds the framebuffer object.
~Renderbuffer(void)
Deletes the renderbuffer object.
~FramebufferGL(void)
Deletes the framebuffer object.
void setTexture(Texture *texture)
Sets a texture object as a logical buffer to the framebuffer object.
This class wraps an OpenGL texture object.
GLuint getHandle()
Returns the handle of the texture object.
This class wraps an OpenGL framebuffer object.
void setRenderbuffer(Renderbuffer *buffer)
Sets a renderbuffer object as a logical buffer to the framebuffer object.
Renderbuffer(void)
Generates a new renderbuffer object.
This class wraps an OpenGL renderbuffer object.
void bind()
Binds the renderbuffer object.