+void ResourcePool::clean_context()
+{
+ void *context = get_gl_context_identifier();
+
+ // Currently, we only need to worry about FBOs, as they are the only
+ // non-shareable resource we hold.
+ shrink_fbo_freelist(context, 0);
+ fbo_freelist.erase(context);
+}
+
+void ResourcePool::cleanup_unlinked_fbos(void *context)
+{
+ for (list<GLuint>::iterator freelist_it = fbo_freelist[context].begin();
+ freelist_it != fbo_freelist[context].end(); ) {
+ GLuint fbo_num = *freelist_it;
+ pair<void *, GLuint> key(context, fbo_num);
+ assert(fbo_formats.count(key) != 0);
+ if (fbo_formats[key].texture_num == 0) {
+ glDeleteFramebuffers(1, &fbo_num);
+ check_error();
+ fbo_freelist[context].erase(freelist_it++);
+ } else {
+ freelist_it++;
+ }
+ }
+}
+
+void ResourcePool::shrink_fbo_freelist(void *context, size_t max_length)
+{
+ while (fbo_freelist[context].size() > max_length) {
+ GLuint free_fbo_num = fbo_freelist[context].back();
+ pair<void *, GLuint> key(context, free_fbo_num);
+ fbo_freelist[context].pop_back();
+ assert(fbo_formats.count(key) != 0);
+ fbo_formats.erase(key);
+ glDeleteFramebuffers(1, &free_fbo_num);
+ check_error();
+ }
+}
+