/src/gl_double_buffer.cpp

https://bitbucket.org/maghoff/radiosity · C++ · 43 lines · 34 code · 9 blank · 0 comment · 1 complexity · 779aadec391b399b3947229e1d822da1 MD5 · raw file

  1. #include <GL/gl.h>
  2. #include "debug_gl.hpp"
  3. #include "gl_double_buffer.hpp"
  4. #include "gl_fbo.hpp"
  5. #include "gl_texture.hpp"
  6. struct gl_double_buffer::impl {
  7. gl_texture tex[2];
  8. gl_fbo fbo[2];
  9. int front;
  10. };
  11. gl_double_buffer::gl_double_buffer() :
  12. d(new impl)
  13. {
  14. d->front = 0;
  15. }
  16. gl_double_buffer::~gl_double_buffer() {
  17. }
  18. void gl_double_buffer::set_size(unsigned width, unsigned height) {
  19. for (int i=0; i<2; ++i) {
  20. glBindTexture(GL_TEXTURE_2D, d->tex[i].get_id());
  21. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, 0);
  22. d->fbo[i].set_size(width, height);
  23. d->fbo[i].render_to(d->tex[i].get_id());
  24. }
  25. }
  26. int gl_double_buffer::front_tex_id() const {
  27. return d->tex[d->front].get_id();
  28. }
  29. int gl_double_buffer::back_fbo_id() const {
  30. return d->fbo[d->front ^ 1].get_id();
  31. }
  32. void gl_double_buffer::flip() {
  33. d->front ^= 1;
  34. }