+void ResourcePool::increment_program_refcount(GLuint program_num)
+{
+ map<GLuint, int>::iterator refcount_it = program_refcount.find(program_num);
+ if (refcount_it != program_refcount.end()) {
+ ++refcount_it->second;
+ } else {
+ list<GLuint>::iterator freelist_it =
+ find(program_freelist.begin(), program_freelist.end(), program_num);
+ assert(freelist_it != program_freelist.end());
+ program_freelist.erase(freelist_it);
+ program_refcount.insert(make_pair(program_num, 1));
+ }
+}
+
+void ResourcePool::output_debug_shader(const string &shader_src, const string &suffix)
+{
+ if (movit_debug_level == MOVIT_DEBUG_ON) {
+ // Output shader to a temporary file, for easier debugging.
+ static int compiled_shader_num = 0;
+ char filename[256];
+ sprintf(filename, "chain-%03d.%s", compiled_shader_num++, suffix.c_str());
+ FILE *fp = fopen(filename, "w");
+ if (fp == NULL) {
+ perror(filename);
+ exit(1);
+ }
+ fprintf(fp, "%s\n", shader_src.c_str());
+ fclose(fp);
+ }
+}
+
+void ResourcePool::add_master_program(GLuint program_num)
+{
+ program_refcount.insert(make_pair(program_num, 1));
+ stack<GLuint> instances;
+ instances.push(program_num);
+ program_instances.insert(make_pair(program_num, instances));
+ program_masters.insert(make_pair(program_num, program_num));
+}
+