using namespace std;
+namespace movit {
+
EffectChain::EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool)
: aspect_nom(aspect_nom),
aspect_denom(aspect_denom),
glDepthMask(GL_FALSE);
check_error();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
if (phases.size() > 1) {
glGenFramebuffers(1, &fbo);
check_error();
output_textures.insert(make_pair(phases[phase], tex_num));
}
- glUseProgram(phases[phase]->glsl_program_num);
+ const GLuint glsl_program_num = phases[phase]->glsl_program_num;
+ glUseProgram(glsl_program_num);
check_error();
// Set up RTT inputs for this phase.
check_error();
string texture_name = string("tex_") + phases[phase]->effect_ids[input];
- glUniform1i(glGetUniformLocation(phases[phase]->glsl_program_num, texture_name.c_str()), sampler);
+ glUniform1i(glGetUniformLocation(glsl_program_num, texture_name.c_str()), sampler);
check_error();
}
unsigned sampler_num = phases[phase]->inputs.size();
for (unsigned i = 0; i < phases[phase]->effects.size(); ++i) {
Node *node = phases[phase]->effects[i];
- node->effect->set_gl_state(phases[phase]->glsl_program_num, phases[phase]->effect_ids[node], &sampler_num);
+ node->effect->set_gl_state(glsl_program_num, phases[phase]->effect_ids[node], &sampler_num);
check_error();
}
// Now draw!
- glBegin(GL_QUADS);
-
- glTexCoord2f(0.0f, 0.0f);
- glVertex2f(0.0f, 0.0f);
-
- glTexCoord2f(1.0f, 0.0f);
- glVertex2f(1.0f, 0.0f);
+ float vertices[] = {
+ 0.0f, 0.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+ 0.0f, 1.0f
+ };
+
+ int position_attrib = glGetAttribLocation(glsl_program_num, "position");
+ assert(position_attrib != -1);
+ glEnableVertexAttribArray(position_attrib);
+ check_error();
+ glVertexAttribPointer(position_attrib, 2, GL_FLOAT, GL_FALSE, 0, vertices);
+ check_error();
- glTexCoord2f(1.0f, 1.0f);
- glVertex2f(1.0f, 1.0f);
+ int texcoord_attrib = glGetAttribLocation(glsl_program_num, "texcoord");
+ if (texcoord_attrib != -1) {
+ glEnableVertexAttribArray(texcoord_attrib);
+ check_error();
+ glVertexAttribPointer(texcoord_attrib, 2, GL_FLOAT, GL_FALSE, 0, vertices); // Same as texcoords.
+ check_error();
+ }
- glTexCoord2f(0.0f, 1.0f);
- glVertex2f(0.0f, 1.0f);
+ glDrawArrays(GL_QUADS, 0, 4);
+ check_error();
- glEnd();
+ glUseProgram(0);
+ check_error();
+ glDisableVertexAttribArray(position_attrib);
check_error();
+ if (texcoord_attrib != -1) {
+ glDisableVertexAttribArray(texcoord_attrib);
+ check_error();
+ }
for (unsigned i = 0; i < phases[phase]->effects.size(); ++i) {
Node *node = phases[phase]->effects[i];
check_error();
}
}
+
+} // namespace movit