- for (unsigned i = 0; i < sorted_effects.size(); ++i) {
- Node *node = sorted_effects[i];
- if (node->effect->num_inputs() == 0) {
- CHECK(node->effect->set_int("needs_mipmaps", input_needs_mipmaps));
- }
- }
- frag_shader += std::string("#define INPUT ") + sorted_effects.back()->effect_id + "\n";
- frag_shader.append(read_file("footer.frag"));
-
- if (movit_debug_level == MOVIT_DEBUG_ON) {
- // 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);
- GLuint fs_obj = compile_shader(frag_shader, GL_FRAGMENT_SHADER);
- glAttachShader(glsl_program_num, vs_obj);
- check_error();
- glAttachShader(glsl_program_num, fs_obj);
- check_error();
- glLinkProgram(glsl_program_num);
- check_error();
-
- Phase *phase = new Phase;
- phase->glsl_program_num = glsl_program_num;
- phase->vertex_shader = vs_obj;
- phase->fragment_shader = fs_obj;
- phase->input_needs_mipmaps = input_needs_mipmaps;
- phase->inputs = true_inputs;
- phase->effects = sorted_effects;