PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 9ms RepoModel.GetById 0ms app.codeStats 0ms

/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
 7struct gl_double_buffer::impl {
 8	gl_texture tex[2];
 9	gl_fbo fbo[2];
10	int front;
11};
12
13gl_double_buffer::gl_double_buffer() :
14	d(new impl)
15{
16	d->front = 0;
17}
18
19gl_double_buffer::~gl_double_buffer() {
20}
21
22void gl_double_buffer::set_size(unsigned width, unsigned height) {
23	for (int i=0; i<2; ++i) {
24		glBindTexture(GL_TEXTURE_2D, d->tex[i].get_id());
25		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, 0);
26
27		d->fbo[i].set_size(width, height);
28		d->fbo[i].render_to(d->tex[i].get_id());
29	}
30}
31
32int gl_double_buffer::front_tex_id() const {
33	return d->tex[d->front].get_id();
34}
35
36int gl_double_buffer::back_fbo_id() const {
37	return d->fbo[d->front ^ 1].get_id();
38}
39
40void gl_double_buffer::flip() {
41	d->front ^= 1;
42}
43