+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);
+ }
+ }
+ for (size_t i = 0; i < phase->uniforms_mat3.size(); ++i) {
+ const Uniform<Matrix3d> &uniform = phase->uniforms_mat3[i];
+ assert(uniform.num_values == 1);
+ if (uniform.location != -1) {
+ // Convert to float (GLSL has no double matrices).
+ float matrixf[9];
+ for (unsigned y = 0; y < 3; ++y) {
+ for (unsigned x = 0; x < 3; ++x) {
+ matrixf[y + x * 3] = (*uniform.value)(y, x);
+ }
+ }
+ glUniformMatrix3fv(uniform.location, 1, GL_FALSE, matrixf);
+ }
+ }