+ set_pixel_data(current_image->pixels.get());
+}
+
+void ImageInput::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num)
+{
+ // See if the background thread has given us a new version of our image.
+ // Note: The old version might still be lying around in other ImageInputs
+ // (in fact, it's likely), but at least the total amount of memory used
+ // is bounded. Currently we don't even share textures between them,
+ // so there's a fair amount of OpenGL memory waste anyway (the cache
+ // is mostly there to save startup time, not RAM).
+ {
+ unique_lock<mutex> lock(all_images_lock);
+ if (all_images[filename] != current_image) {
+ current_image = all_images[filename];
+ set_pixel_data(current_image->pixels.get());
+ }
+ }
+ movit::FlatInput::set_gl_state(glsl_program_num, prefix, sampler_num);
+}
+
+shared_ptr<const ImageInput::Image> ImageInput::load_image(const string &filename)
+{
+ unique_lock<mutex> lock(all_images_lock); // Held also during loading.
+ if (all_images.count(filename)) {
+ return all_images[filename];
+ }
+
+ all_images[filename] = load_image_raw(filename);
+ timespec first_modified = all_images[filename]->last_modified;
+ update_threads[filename] =
+ thread(bind(update_thread_func, filename, first_modified));
+
+ return all_images[filename];