}
frag_shader += std::string("#define INPUT ") + effects.back()->effect_id + "\n";
frag_shader.append(read_file("footer.frag"));
- printf("%s\n", frag_shader.c_str());
+
+ // Output shader to a temporary file, for easier debugging.
+ static int compiled_shader_num = 0;
+ char filename[256];
+ sprintf(filename, "chain-%03d.frag", compiled_shader_num++);
+ FILE *fp = fopen(filename, "w");
+ if (fp == NULL) {
+ perror(filename);
+ exit(1);
+ }
+ fprintf(fp, "%s\n", frag_shader.c_str());
+ fclose(fp);
GLuint glsl_program_num = glCreateProgram();
GLuint vs_obj = compile_shader(read_file("vs.vert"), GL_VERTEX_SHADER);
fprintf(fp, "digraph G {\n");
for (unsigned i = 0; i < nodes.size(); ++i) {
- fprintf(fp, " n%ld [label=\"%s\"];\n", (long)nodes[i], nodes[i]->effect->effect_type_id().c_str());
+ // Find out which phase this event belongs to.
+ int in_phase = -1;
+ for (unsigned j = 0; j < phases.size(); ++j) {
+ const Phase* p = phases[j];
+ if (std::find(p->effects.begin(), p->effects.end(), nodes[i]) != p->effects.end()) {
+ assert(in_phase == -1);
+ in_phase = j;
+ }
+ }
+
+ if (in_phase == -1) {
+ fprintf(fp, " n%ld [label=\"%s\"];\n", (long)nodes[i], nodes[i]->effect->effect_type_id().c_str());
+ } else {
+ fprintf(fp, " n%ld [label=\"%s\" style=\"filled\" fillcolor=\"/accent8/%d\"];\n",
+ (long)nodes[i], nodes[i]->effect->effect_type_id().c_str(),
+ (in_phase % 8) + 1);
+ }
for (unsigned j = 0; j < nodes[i]->outgoing_links.size(); ++j) {
std::vector<std::string> labels;
// This needs to be before everything else, since it could
// even apply to inputs (if they are the only effect).
if (node->outgoing_links.empty() &&
- node->output_gamma_curve != output_format.gamma_curve) {
+ node->output_gamma_curve != output_format.gamma_curve &&
+ node->output_gamma_curve != GAMMA_LINEAR) {
return true;
}
// Construct all needed GLSL programs, starting at the output.
construct_glsl_programs(find_output_node());
+ output_dot("step11-split-to-phases.dot");
+
// If we have more than one phase, we need intermediate render-to-texture.
// Construct an FBO, and then as many textures as we need.
// We choose the simplest option of having one texture per output,
finalized = true;
}
-void EffectChain::render_to_screen()
+void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height)
{
assert(finalized);
// Save original viewport.
- GLint viewport[4];
- glGetIntegerv(GL_VIEWPORT, viewport);
+ GLuint x = 0, y = 0;
+
+ if (width == 0 && height == 0) {
+ GLint viewport[4];
+ glGetIntegerv(GL_VIEWPORT, viewport);
+ x = viewport[0];
+ y = viewport[1];
+ width = viewport[2];
+ height = viewport[3];
+ }
// Basic state.
glDisable(GL_BLEND);
// And now the output.
if (phase == phases.size() - 1) {
- // Last phase goes directly to the screen.
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ // Last phase goes to the output the user specified.
+ glBindFramebuffer(GL_FRAMEBUFFER, dest_fbo);
check_error();
- glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
+ glViewport(x, y, width, height);
} else {
Node *output_node = phases[phase]->effects.back();
glFramebufferTexture2D(