abstraction for gl framebuffer object
#include <render_target.hpp>
Inherited by renderstack::default_render_target.
Public Member Functions | |
render_target () | |
render_target (int width, int height) | |
render_target (int width, int height, int gl_framebuffer_object) | |
int | width () const |
int | height () const |
unsigned int | gl_framebuffer_object () const |
framebuffer_attachment & | attach_texture (int gl_attachment, int gl_format) |
framebuffer_attachment & | attach_renderbuffer (int gl_attachment, int gl_format, int sample_count) |
void | resize (int width, int height) |
void | begin () const |
void | end () const |
void | blit (render_target const &dst) const |
void | check () const |
void | debug () const |
Definition at line 71 of file render_target.hpp.
renderstack::render_target::render_target | ( | ) |
Definition at line 34 of file render_target.cpp.
renderstack::render_target::render_target | ( | int | width, | |
int | height | |||
) |
Definition at line 57 of file render_target.cpp.
00061 : m_width(width) 00062 , m_height(height) 00063 , m_gl_framebuffer_object((unsigned int)(~0)) 00064 { 00065 ::GLboolean res = ::rs_gl_is_framebuffer(m_gl_framebuffer_object); 00066 if(res != GL_FALSE) 00067 { 00068 ::rs_gl_delete_framebuffers(1, &m_gl_framebuffer_object); 00069 } 00070 ::rs_gl_gen_framebuffers(1, &m_gl_framebuffer_object); 00071 00072 ::rs_gl_bind_framebuffer( 00073 GL_FRAMEBUFFER, /* DRAW, READ */ 00074 m_gl_framebuffer_object 00075 ); 00076 }
renderstack::render_target::render_target | ( | int | width, | |
int | height, | |||
int | gl_framebuffer_object | |||
) |
Definition at line 41 of file render_target.cpp.
00046 : m_width(width) 00047 , m_height(height) 00048 , m_gl_framebuffer_object(gl_framebuffer_object) 00049 { 00050 m_gl_framebuffer_object = 0; 00051 00052 framebuffer_attachment attachment(GL_BACK_LEFT, attachment_renderbuffer); 00053 00054 attachment.renderbuffer().set(0); 00055 }
int renderstack::render_target::width | ( | ) | const [inline] |
Definition at line 78 of file render_target.hpp.
int renderstack::render_target::height | ( | ) | const [inline] |
Definition at line 79 of file render_target.hpp.
unsigned int renderstack::render_target::gl_framebuffer_object | ( | ) | const [inline] |
Definition at line 80 of file render_target.hpp.
framebuffer_attachment & renderstack::render_target::attach_texture | ( | int | gl_attachment, | |
int | gl_format | |||
) |
Definition at line 104 of file render_target.cpp.
00105 { 00106 framebuffer_attachment attachment(gl_attachment, attachment_texture); 00107 attachment.texture().set( 00108 m_width, 00109 m_height, 00110 GL_TEXTURE_2D, 00111 GL_TEXTURE_2D, 00112 GL_NEAREST, 00113 GL_NEAREST, 00114 GL_CLAMP_TO_EDGE, 00115 gl_format 00116 ); 00117 00118 attachment.texture().update(); 00119 00120 rs_gl_bind_framebuffer( 00121 GL_FRAMEBUFFER, /* DRAW, READ */ 00122 m_gl_framebuffer_object 00123 ); 00124 00125 rs_gl_framebuffer_texture_2d( 00126 GL_FRAMEBUFFER, /* target DRAW, READ */ 00127 attachment.gl_attachment_point(), /* attachment */ 00128 attachment.texture().gl_teximage_target(), /* textarget */ 00129 attachment.texture().gl_texture_object(), /* texture */ 00130 0 /* level */ 00131 ); 00132 00133 m_attachments.push_back(attachment); 00134 00135 return m_attachments.back(); 00136 }
framebuffer_attachment & renderstack::render_target::attach_renderbuffer | ( | int | gl_attachment, | |
int | gl_format, | |||
int | sample_count | |||
) |
Definition at line 138 of file render_target.cpp.
00143 { 00144 framebuffer_attachment attachment(gl_attachment, attachment_renderbuffer); 00145 00146 attachment.renderbuffer().set(m_width, m_height, gl_format, sample_count); 00147 00148 ::rs_gl_bind_framebuffer( 00149 GL_FRAMEBUFFER, /* DRAW, READ */ 00150 m_gl_framebuffer_object 00151 ); 00152 00153 ::rs_gl_framebuffer_renderbuffer( 00154 GL_FRAMEBUFFER, /* enum target DRAW, READ */ 00155 attachment.gl_attachment_point(), /* attachment */ 00156 GL_RENDERBUFFER, /* renderbuffertarget */ 00157 attachment.renderbuffer().gl_renderbuffer_object() /* renderbuffer */ 00158 ); 00159 00160 m_attachments.push_back(attachment); 00161 00162 check(); 00163 00164 return m_attachments.back(); 00165 }
void renderstack::render_target::resize | ( | int | width, | |
int | height | |||
) |
Definition at line 168 of file render_target.cpp.
void renderstack::render_target::begin | ( | ) | const |
Definition at line 175 of file render_target.cpp.
00176 { 00177 ::rs_gl_bind_framebuffer( 00178 GL_FRAMEBUFFER, /* DRAW, READ */ 00179 m_gl_framebuffer_object 00180 ); 00181 }
void renderstack::render_target::end | ( | ) | const |
Definition at line 183 of file render_target.cpp.
00184 { 00185 ::rs_gl_bind_framebuffer(GL_FRAMEBUFFER, 0); 00186 }
void renderstack::render_target::blit | ( | render_target const & | dst | ) | const |
Definition at line 188 of file render_target.cpp.
00189 { 00190 ::rs_gl_bind_framebuffer(GL_READ_FRAMEBUFFER, gl_framebuffer_object()); 00191 ::rs_gl_bind_framebuffer(GL_DRAW_FRAMEBUFFER, dst.gl_framebuffer_object()); 00192 00193 ::rs_gl_blit_framebuffer( 00194 0, /* GLint srcX0, */ 00195 0, /* GLint srcY0, */ 00196 width(), /* GLint srcX1, */ 00197 height(), /* GLint srcY1, */ 00198 0, /* GLint dstX0, */ 00199 0, /* GLint dstY0, */ 00200 dst.width(), /* GLint dstX1, */ 00201 dst.height(), /* GLint dstY1, */ 00202 GL_COLOR_BUFFER_BIT, /* GLbitfield mask, */ 00203 GL_NEAREST /* GLenum filter */ 00204 ); 00205 }
void renderstack::render_target::check | ( | ) | const |
Definition at line 92 of file render_target.cpp.
00093 { 00094 ::GLenum status = ::rs_gl_check_framebuffer_status(GL_FRAMEBUFFER); 00095 00096 if(status == GL_FRAMEBUFFER_COMPLETE) 00097 { 00098 return; 00099 } 00100 00101 ::rs_log("framebuffer not complete: %s\n", ::rs_gl_enum_string(status)); 00102 }
void renderstack::render_target::debug | ( | ) | const |
Definition at line 207 of file render_target.cpp.
00208 { 00209 int framebuffer = GL_DRAW_FRAMEBUFFER; /* READ, DRAW */ 00210 int color_attachment = GL_COLOR_ATTACHMENT0; /* GL_BACK_LEFT */ 00211 int depth_attachment = GL_DEPTH_ATTACHMENT; 00212 int stencil_attachment = GL_STENCIL_ATTACHMENT; 00213 00214 { 00215 int params[4]; 00216 00217 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00218 framebuffer, /* target, DRAW, READ */ 00219 color_attachment, /* attachment */ 00220 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, /* pname */ 00221 ¶ms[0] /* params */ 00222 ); 00223 ::rs_log( 00224 "color attachment object type = %s\n", 00225 ::rs_gl_enum_string(params[0]) 00226 ); 00227 00228 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00229 framebuffer, /* target, DRAW, READ */ 00230 color_attachment, /* attachment */ 00231 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, /* pname */ 00232 ¶ms[0] /* params */ 00233 ); 00234 ::rs_log("color attachment object name = %d\n", params[0]); 00235 00236 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00237 framebuffer, /* target, DRAW, READ */ 00238 color_attachment, /* attachment */ 00239 GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE, /* pname */ 00240 ¶ms[0] /* params */ 00241 ); 00242 ::rs_log( 00243 "color attachment component type = %s\n", 00244 ::rs_gl_enum_string(params[0]) 00245 ); 00246 00247 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00248 framebuffer, /* target, DRAW, READ */ 00249 color_attachment, /* attachment */ 00250 GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, /* pname */ 00251 ¶ms[0] /* params */ 00252 ); 00253 ::rs_log( 00254 "color attachment color encoding type = %s\n", 00255 ::rs_gl_enum_string(params[0]) 00256 ); 00257 00258 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00259 framebuffer, /* target, DRAW, READ */ 00260 color_attachment, /* attachment */ 00261 GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, /* pname */ 00262 ¶ms[0] /* params */ 00263 ); 00264 ::rs_log( 00265 "color attachment red size = %d\n", 00266 params[0] 00267 ); 00268 00269 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00270 framebuffer, /* target, DRAW, READ */ 00271 color_attachment, /* attachment */ 00272 GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, /* pname */ 00273 ¶ms[0] /* params */ 00274 ); 00275 ::rs_log( 00276 "color attachment green size = %d\n", 00277 params[0] 00278 ); 00279 00280 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00281 framebuffer, /* target, DRAW, READ */ 00282 color_attachment, /* attachment */ 00283 GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, /* pname */ 00284 ¶ms[0] /* params */ 00285 ); 00286 ::rs_log( 00287 "color attachment blue size = %d\n", 00288 params[0] 00289 ); 00290 00291 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00292 framebuffer, /* target, DRAW, READ */ 00293 color_attachment, /* attachment */ 00294 GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, /* pname */ 00295 ¶ms[0] /* params */ 00296 ); 00297 ::rs_log( 00298 "color attachment alpha size = %d\n", 00299 params[0] 00300 ); 00301 00302 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00303 framebuffer, /* target, DRAW, READ */ 00304 depth_attachment, /* attachment */ 00305 GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE, /* pname */ 00306 ¶ms[0] /* params */ 00307 ); 00308 ::rs_log( 00309 "depth attachment depth size = %d\n", 00310 params[0] 00311 ); 00312 00313 ::rs_gl_get_framebuffer_attachment_parameter_iv( 00314 framebuffer, /* target, DRAW, READ */ 00315 stencil_attachment, /* attachment */ 00316 GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, /* pname */ 00317 ¶ms[0] /* params */ 00318 ); 00319 ::rs_log( 00320 "stencil attachment stencil size = %d\n", 00321 params[0] 00322 ); 00323 } 00324 }