+GLuint ResourcePool::create_vec2_vao(const set<GLint> &attribute_indices, GLuint vbo_num)
+{
+ void *context = get_gl_context_identifier();
+
+ 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) {
+ VAOFormatIterator vao_it = *freelist_it;
+ if (vao_it->second.vbo_num == vbo_num &&
+ vao_it->second.attribute_indices == attribute_indices) {
+ vao_freelist[context].erase(freelist_it);
+ pthread_mutex_unlock(&lock);
+ return vao_it->second.vao_num;
+ }
+ }
+ }
+
+ // Create a new one.
+ VAO vao_format;
+ vao_format.attribute_indices = attribute_indices;
+ vao_format.vbo_num = vbo_num;
+
+ glGenVertexArrays(1, &vao_format.vao_num);
+ check_error();
+ glBindVertexArray(vao_format.vao_num);
+ check_error();
+ 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);
+ check_error();
+ glVertexAttribPointer(*attr_it, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
+ check_error();
+ }
+
+ glBindVertexArray(0);
+ check_error();
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ check_error();
+
+ pair<void *, GLuint> key(context, vao_format.vao_num);
+ assert(vao_formats.count(key) == 0);
+ vao_formats.insert(make_pair(key, vao_format));
+
+ pthread_mutex_unlock(&lock);
+ return vao_format.vao_num;
+}
+
+void ResourcePool::release_vec2_vao(GLuint vao_num)
+{
+ void *context = get_gl_context_identifier();
+
+ pthread_mutex_lock(&lock);
+ VAOFormatIterator vao_it = vao_formats.find(make_pair(context, vao_num));
+ assert(vao_it != vao_formats.end());
+ vao_freelist[context].push_front(vao_it);
+
+ shrink_vao_freelist(context, vao_freelist_max_length);
+ pthread_mutex_unlock(&lock);
+}
+