+ if (node->effect->is_single_texture()) {
+ assert(sampler_num - old_sampler_num == 1);
+ node->bound_sampler_num = old_sampler_num;
+ } else {
+ node->bound_sampler_num = -1;
+ }
+ }
+
+ // Uniforms need to come after set_gl_state(), since they can be updated
+ // from there.
+ setup_uniforms(phase);
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+ check_error();
+
+ glUseProgram(0);
+ check_error();
+
+ for (unsigned i = 0; i < phase->effects.size(); ++i) {
+ Node *node = phase->effects[i];
+ node->effect->clear_gl_state();
+ }
+
+ if (!last_phase) {
+ resource_pool->release_fbo(fbo);
+ }
+}
+
+void EffectChain::setup_uniforms(Phase *phase)
+{
+ // TODO: Use UBO blocks.
+ for (size_t i = 0; i < phase->uniforms_sampler2d.size(); ++i) {
+ const Uniform<int> &uniform = phase->uniforms_sampler2d[i];
+ if (uniform.location != -1) {
+ glUniform1iv(uniform.location, uniform.num_values, uniform.value);
+ }
+ }
+ for (size_t i = 0; i < phase->uniforms_bool.size(); ++i) {
+ const Uniform<bool> &uniform = phase->uniforms_bool[i];
+ assert(uniform.num_values == 1);
+ if (uniform.location != -1) {
+ glUniform1i(uniform.location, *uniform.value);
+ }
+ }
+ for (size_t i = 0; i < phase->uniforms_int.size(); ++i) {
+ const Uniform<int> &uniform = phase->uniforms_int[i];
+ if (uniform.location != -1) {
+ glUniform1iv(uniform.location, uniform.num_values, uniform.value);
+ }
+ }
+ for (size_t i = 0; i < phase->uniforms_float.size(); ++i) {
+ const Uniform<float> &uniform = phase->uniforms_float[i];
+ if (uniform.location != -1) {
+ glUniform1fv(uniform.location, uniform.num_values, uniform.value);
+ }
+ }
+ for (size_t i = 0; i < phase->uniforms_vec2.size(); ++i) {
+ const Uniform<float> &uniform = phase->uniforms_vec2[i];
+ if (uniform.location != -1) {
+ glUniform2fv(uniform.location, uniform.num_values, uniform.value);
+ }
+ }
+ for (size_t i = 0; i < phase->uniforms_vec3.size(); ++i) {
+ const Uniform<float> &uniform = phase->uniforms_vec3[i];
+ if (uniform.location != -1) {
+ glUniform3fv(uniform.location, uniform.num_values, uniform.value);
+ }
+ }
+ for (size_t i = 0; i < phase->uniforms_vec4.size(); ++i) {
+ const Uniform<float> &uniform = phase->uniforms_vec4[i];
+ if (uniform.location != -1) {
+ glUniform4fv(uniform.location, uniform.num_values, uniform.value);