vao_freelist_max_length(vao_freelist_max_length),
texture_freelist_bytes(0)
{
- pthread_mutex_init(&lock, NULL);
+ pthread_mutex_init(&lock, nullptr);
}
ResourcePool::~ResourcePool()
{
assert(program_refcount.empty());
- for (list<GLuint>::const_iterator freelist_it = program_freelist.begin();
- freelist_it != program_freelist.end();
- ++freelist_it) {
- delete_program(*freelist_it);
+ for (GLuint program : program_freelist) {
+ delete_program(program);
}
assert(programs.empty());
assert(program_shaders.empty());
- for (list<GLuint>::const_iterator freelist_it = texture_freelist.begin();
- freelist_it != texture_freelist.end();
- ++freelist_it) {
- GLuint free_texture_num = *freelist_it;
+ for (GLuint free_texture_num : texture_freelist) {
assert(texture_formats.count(free_texture_num) != 0);
texture_freelist_bytes -= estimate_texture_size(texture_formats[free_texture_num]);
texture_formats.erase(free_texture_num);
void *context = get_gl_context_identifier();
cleanup_unlinked_fbos(context);
- for (map<void *, std::list<FBOFormatIterator> >::iterator context_it = fbo_freelist.begin();
- context_it != fbo_freelist.end();
- ++context_it) {
- if (context_it->first != context) {
+ for (const auto &context_and_fbos : fbo_freelist) {
+ if (context_and_fbos.first != context) {
// If this does not hold, the client should have called clean_context() earlier.
- assert(context_it->second.empty());
+ assert(context_and_fbos.second.empty());
continue;
}
- for (list<FBOFormatIterator>::const_iterator freelist_it = context_it->second.begin();
- freelist_it != context_it->second.end();
- ++freelist_it) {
- FBOFormatIterator fbo_it = *freelist_it;
+ for (FBOFormatIterator fbo_it : context_and_fbos.second) {
glDeleteFramebuffers(1, &fbo_it->second.fbo_num);
check_error();
fbo_formats.erase(fbo_it);
break;
}
}
+ for (map<string, GLuint>::iterator program_it = compute_programs.begin();
+ program_it != compute_programs.end();
+ ++program_it) {
+ if (program_it->second == glsl_program_num) {
+ compute_programs.erase(program_it);
+ found_program = true;
+ break;
+ }
+ }
assert(found_program);
- map<GLuint, stack<GLuint> >::iterator instance_list_it = program_instances.find(glsl_program_num);
+ map<GLuint, stack<GLuint>>::iterator instance_list_it = program_instances.find(glsl_program_num);
assert(instance_list_it != program_instances.end());
while (!instance_list_it->second.empty()) {
map<GLuint, ShaderSpec>::iterator shader_it =
program_shaders.find(glsl_program_num);
- assert(shader_it != program_shaders.end());
-
- glDeleteShader(shader_it->second.vs_obj);
- glDeleteShader(shader_it->second.fs_obj);
- program_shaders.erase(shader_it);
+ if (shader_it == program_shaders.end()) {
+ // Should be a compute shader.
+ map<GLuint, ComputeShaderSpec>::iterator compute_shader_it =
+ compute_program_shaders.find(glsl_program_num);
+ assert(compute_shader_it != compute_program_shaders.end());
+
+ glDeleteShader(compute_shader_it->second.cs_obj);
+ compute_program_shaders.erase(compute_shader_it);
+ } else {
+ glDeleteShader(shader_it->second.vs_obj);
+ glDeleteShader(shader_it->second.fs_obj);
+ program_shaders.erase(shader_it);
+ }
}
GLuint ResourcePool::compile_glsl_program(const string& vertex_shader,
glGetProgramiv(glsl_program_num, GL_LINK_STATUS, &success);
if (success == GL_FALSE) {
GLchar error_log[1024] = {0};
- glGetProgramInfoLog(glsl_program_num, 1024, NULL, error_log);
+ glGetProgramInfoLog(glsl_program_num, 1024, nullptr, error_log);
fprintf(stderr, "Error linking program: %s\n", error_log);
exit(1);
}
check_error();
glsl_program_num = link_compute_program(cs_obj);
- output_debug_shader(compute_shader, "compute");
+ output_debug_shader(compute_shader, "comp");
compute_programs.insert(make_pair(key, glsl_program_num));
add_master_program(glsl_program_num);
glGetProgramiv(glsl_program_num, GL_LINK_STATUS, &success);
if (success == GL_FALSE) {
GLchar error_log[1024] = {0};
- glGetProgramInfoLog(glsl_program_num, 1024, NULL, error_log);
+ glGetProgramInfoLog(glsl_program_num, 1024, nullptr, error_log);
fprintf(stderr, "Error linking program: %s\n", error_log);
exit(1);
}
{
pthread_mutex_lock(&lock);
- map<GLuint, GLuint>::const_iterator master_it = program_masters.find(instance_program_num);
+ auto master_it = program_masters.find(instance_program_num);
assert(master_it != program_masters.end());
assert(program_instances.count(master_it->second));
pthread_mutex_lock(&lock);
// See if there's a texture on the freelist we can use.
- for (list<GLuint>::iterator freelist_it = texture_freelist.begin();
+ for (auto freelist_it = texture_freelist.begin();
freelist_it != texture_freelist.end();
++freelist_it) {
GLuint texture_num = *freelist_it;
}
// Find any reasonable format given the internal format; OpenGL validates it
- // even though we give NULL as pointer.
+ // even though we give nullptr as pointer.
GLenum format;
switch (internal_format) {
case GL_RGBA32F_ARB:
check_error();
glBindTexture(GL_TEXTURE_2D, texture_num);
check_error();
- glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, type, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, type, nullptr);
check_error();
glBindTexture(GL_TEXTURE_2D, 0);
check_error();
// not be in the right context, so don't delete it right away;
// the cleanup in release_fbo() (which calls cleanup_unlinked_fbos())
// will take care of actually doing that later.
- for (map<pair<void *, GLuint>, FBO>::iterator format_it = fbo_formats.begin();
- format_it != fbo_formats.end();
- ++format_it) {
+ for (auto &key_and_fbo : fbo_formats) {
for (unsigned i = 0; i < num_fbo_attachments; ++i) {
- if (format_it->second.texture_num[i] == free_texture_num) {
- format_it->second.texture_num[i] = GL_INVALID_INDEX;
+ if (key_and_fbo.second.texture_num[i] == free_texture_num) {
+ key_and_fbo.second.texture_num[i] = GL_INVALID_INDEX;
}
}
}
pthread_mutex_lock(&lock);
if (fbo_freelist.count(context) != 0) {
// See if there's an FBO on the freelist we can use.
- list<FBOFormatIterator>::iterator end = fbo_freelist[context].end();
- for (list<FBOFormatIterator>::iterator freelist_it = fbo_freelist[context].begin();
- freelist_it != end; ++freelist_it) {
+ auto end = fbo_freelist[context].end();
+ for (auto freelist_it = fbo_freelist[context].begin(); freelist_it != end; ++freelist_it) {
FBOFormatIterator fbo_it = *freelist_it;
if (fbo_it->second.texture_num[0] == texture0_num &&
fbo_it->second.texture_num[1] == texture1_num &&
pthread_mutex_lock(&lock);
if (vao_freelist.count(context) != 0) {
// See if there's a VAO the freelist we can use.
- list<VAOFormatIterator>::iterator end = vao_freelist[context].end();
- for (list<VAOFormatIterator>::iterator freelist_it = vao_freelist[context].begin();
- freelist_it != end; ++freelist_it) {
+ auto end = vao_freelist[context].end();
+ for (auto freelist_it = vao_freelist[context].begin(); freelist_it != end; ++freelist_it) {
VAOFormatIterator vao_it = *freelist_it;
if (vao_it->second.vbo_num == vbo_num &&
vao_it->second.attribute_indices == attribute_indices) {
glBindBuffer(GL_ARRAY_BUFFER, vbo_num);
check_error();
- for (set<GLint>::const_iterator attr_it = attribute_indices.begin(); attr_it != attribute_indices.end(); ++attr_it) {
- glEnableVertexAttribArray(*attr_it);
+ for (GLint attr : attribute_indices) {
+ glEnableVertexAttribArray(attr);
check_error();
- glVertexAttribPointer(*attr_it, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
+ glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
check_error();
}
void ResourcePool::cleanup_unlinked_fbos(void *context)
{
- list<FBOFormatIterator>::iterator end = fbo_freelist[context].end();
- for (list<FBOFormatIterator>::iterator freelist_it = fbo_freelist[context].begin(); freelist_it != end; ) {
+ auto end = fbo_freelist[context].end();
+ for (auto freelist_it = fbo_freelist[context].begin(); freelist_it != end; ) {
FBOFormatIterator fbo_it = *freelist_it;
bool all_unlinked = true;
char filename[256];
sprintf(filename, "chain-%03d.%s", compiled_shader_num++, suffix.c_str());
FILE *fp = fopen(filename, "w");
- if (fp == NULL) {
+ if (fp == nullptr) {
perror(filename);
exit(1);
}