vrseasons
changeset 2:eea1b91dc3d4 tip
added is_complete() to framebuffer object and fixed GL_UNSUPPORTED_FRAMEBUFFER on intel
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 13 Apr 2015 16:51:52 +0300 |
parents | 65c2e37c48b2 |
children | |
files | src/rtarg.cc src/rtarg.h |
diffstat | 2 files changed, 26 insertions(+), 2 deletions(-) [+] |
line diff
1.1 --- a/src/rtarg.cc Sun Apr 12 03:39:55 2015 +0300 1.2 +++ b/src/rtarg.cc Mon Apr 13 16:51:52 2015 +0300 1.3 @@ -1,3 +1,4 @@ 1.4 +#include <stdio.h> 1.5 #include "opengl.h" 1.6 #include "rtarg.h" 1.7 1.8 @@ -26,7 +27,7 @@ 1.9 1.10 tex_xsz = next_pow2(xsz); 1.11 tex_ysz = next_pow2(ysz); 1.12 - tex_fmt = check_extension("GL_ARB_texture_float") ? GL_RGB16F : GL_RGB; 1.13 + tex_fmt = check_extension("GL_ARB_texture_float") ? GL_RGBA16F : GL_RGBA; 1.14 1.15 glGenFramebuffers(1, &fbo); 1.16 glBindFramebuffer(GL_FRAMEBUFFER, fbo); 1.17 @@ -35,7 +36,7 @@ 1.18 glBindTexture(GL_TEXTURE_2D, color); 1.19 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.20 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.21 - glTexImage2D(GL_TEXTURE_2D, 0, tex_fmt, tex_xsz, tex_ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 1.22 + glTexImage2D(GL_TEXTURE_2D, 0, tex_fmt, tex_xsz, tex_ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); 1.23 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0); 1.24 1.25 glGenRenderbuffers(1, &depth); 1.26 @@ -43,6 +44,10 @@ 1.27 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, tex_xsz, tex_ysz); 1.28 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth); 1.29 1.30 + if(!is_complete()) { 1.31 + fprintf(stderr, "framebuffer incomplete\n"); 1.32 + } 1.33 + 1.34 return true; 1.35 } 1.36 1.37 @@ -66,6 +71,10 @@ 1.38 1.39 tex_xsz = new_tex_xsz; 1.40 tex_ysz = new_tex_ysz; 1.41 + 1.42 + if(!is_complete()) { 1.43 + fprintf(stderr, "framebuffer incomplete\n"); 1.44 + } 1.45 } 1.46 return true; 1.47 } 1.48 @@ -89,6 +98,20 @@ 1.49 return fbo != 0; 1.50 } 1.51 1.52 +bool RenderTarget::is_complete() const 1.53 +{ 1.54 + if(!fbo) return false; 1.55 + 1.56 + unsigned int prev_fbo; 1.57 + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (int*)&prev_fbo); 1.58 + glBindFramebuffer(GL_FRAMEBUFFER, fbo); 1.59 + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); 1.60 + if(prev_fbo != fbo) { 1.61 + glBindFramebuffer(GL_FRAMEBUFFER, prev_fbo); 1.62 + } 1.63 + return status == GL_FRAMEBUFFER_COMPLETE; 1.64 +} 1.65 + 1.66 unsigned int RenderTarget::get_texture() const 1.67 { 1.68 return color;