X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=resource_pool.cpp;h=201b73c73b7a9ee4855149886a2ec01bc75a6469;hp=b6f6a3145455e69de69ab43559c21ef15436ae0a;hb=983fe15061b6e199877577b363a9f2fa102cf107;hpb=09c983894685554b41f622dadd40ac1a4efc527d diff --git a/resource_pool.cpp b/resource_pool.cpp index b6f6a31..201b73c 100644 --- a/resource_pool.cpp +++ b/resource_pool.cpp @@ -58,8 +58,9 @@ ResourcePool::~ResourcePool() GLuint free_fbo_num = *freelist_it; assert(fbo_formats.count(free_fbo_num) != 0); fbo_formats.erase(free_fbo_num); - glDeleteFramebuffers(1, &free_fbo_num); - check_error(); + // TODO: We currently leak due to FBO sharability issues. + // glDeleteFramebuffers(1, &free_fbo_num); + // check_error(); } assert(fbo_formats.empty()); } @@ -200,6 +201,12 @@ GLuint ResourcePool::create_2d_texture(GLint internal_format, GLsizei width, GLs case GL_SRGB8_ALPHA8: format = GL_RGBA; break; + case GL_RGB32F_ARB: + case GL_RGB16F_ARB: + case GL_RGB8: + case GL_SRGB8: + format = GL_RGB; + break; case GL_RG32F: case GL_RG16F: format = GL_RG; @@ -248,11 +255,27 @@ void ResourcePool::release_2d_texture(GLuint texture_num) texture_formats.erase(free_texture_num); glDeleteTextures(1, &free_texture_num); check_error(); + + // Delete any FBO related to this texture. + for (list::iterator fbo_freelist_it = fbo_freelist.begin(); + fbo_freelist_it != fbo_freelist.end(); ) { + GLuint fbo_num = *fbo_freelist_it; + map::const_iterator format_it = fbo_formats.find(fbo_num); + assert(format_it != fbo_formats.end()); + if (format_it->second.texture_num == free_texture_num) { + fbo_formats.erase(fbo_num); + // TODO: We currently leak due to FBO sharability issues. + // glDeleteFramebuffers(1, &fbo_num); + fbo_freelist.erase(fbo_freelist_it++); + } else { + ++fbo_freelist_it; + } + } } pthread_mutex_unlock(&lock); } -GLuint ResourcePool::create_fbo(void *context, GLint internal_format, GLsizei width, GLsizei height) +GLuint ResourcePool::create_fbo(void *context, GLuint texture_num) { pthread_mutex_lock(&lock); // See if there's an FBO on the freelist we can use. @@ -263,9 +286,7 @@ GLuint ResourcePool::create_fbo(void *context, GLint internal_format, GLsizei wi map::const_iterator format_it = fbo_formats.find(fbo_num); assert(format_it != fbo_formats.end()); if (format_it->second.context == context && - format_it->second.internal_format == internal_format && - format_it->second.width == width && - format_it->second.height == height) { + format_it->second.texture_num == texture_num) { fbo_freelist.erase(freelist_it); pthread_mutex_unlock(&lock); return fbo_num; @@ -276,12 +297,23 @@ GLuint ResourcePool::create_fbo(void *context, GLint internal_format, GLsizei wi GLuint fbo_num; glGenFramebuffers(1, &fbo_num); check_error(); + glBindFramebuffer(GL_FRAMEBUFFER, fbo_num); + check_error(); + glFramebufferTexture2D( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, + texture_num, + 0); + check_error(); + GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + assert(status == GL_FRAMEBUFFER_COMPLETE); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + check_error(); FBO fbo_format; fbo_format.context = context; - fbo_format.internal_format = internal_format; - fbo_format.width = width; - fbo_format.height = height; + fbo_format.texture_num = texture_num; assert(fbo_formats.count(fbo_num) == 0); fbo_formats.insert(make_pair(fbo_num, fbo_format)); @@ -300,8 +332,9 @@ void ResourcePool::release_fbo(GLuint fbo_num) fbo_freelist.pop_front(); assert(fbo_formats.count(free_fbo_num) != 0); fbo_formats.erase(free_fbo_num); - glDeleteFramebuffers(1, &free_fbo_num); - check_error(); + // TODO: We currently leak due to FBO sharability issues. + // glDeleteFramebuffers(1, &free_fbo_num); + // check_error(); } pthread_mutex_unlock(&lock); } @@ -321,6 +354,16 @@ size_t ResourcePool::estimate_texture_size(const Texture2D &texture_format) case GL_SRGB8_ALPHA8: bytes_per_pixel = 4; break; + case GL_RGB32F_ARB: + bytes_per_pixel = 12; + break; + case GL_RGB16F_ARB: + bytes_per_pixel = 6; + break; + case GL_RGB8: + case GL_SRGB8: + bytes_per_pixel = 3; + break; case GL_RG32F: bytes_per_pixel = 8; break;