X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain.cpp;h=6362a095adb554dc6adf0e7978f7b3d678e7dfed;hp=b83e81e78a9146339f1a8293f2cc6d5c08eb93cb;hb=6eb839737216564bcaf4645b7ebf6ea9efc2da09;hpb=ba19dad35d753c81041f9111fa4fd3bce168b319 diff --git a/effect_chain.cpp b/effect_chain.cpp index b83e81e..6362a09 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -13,6 +13,7 @@ #include "gamma_compression_effect.h" #include "lift_gamma_gain_effect.h" #include "colorspace_conversion_effect.h" +#include "sandbox_effect.h" #include "saturation_effect.h" #include "mirror_effect.h" #include "vignette_effect.h" @@ -42,6 +43,8 @@ Effect *instantiate_effect(EffectId effect) return new GammaCompressionEffect(); case EFFECT_COLOR_SPACE_CONVERSION: return new ColorSpaceConversionEffect(); + case EFFECT_SANDBOX: + return new SandboxEffect(); case EFFECT_LIFT_GAMMA_GAIN: return new LiftGammaGainEffect(); case EFFECT_SATURATION: @@ -64,7 +67,7 @@ void EffectChain::normalize_to_linear_gamma() } else { GammaExpansionEffect *gamma_conversion = new GammaExpansionEffect(); gamma_conversion->set_int("source_curve", current_gamma_curve); - effects.push_back(gamma_conversion); + gamma_conversion->add_self_to_effect_chain(&effects); } current_gamma_curve = GAMMA_LINEAR; } @@ -75,7 +78,7 @@ void EffectChain::normalize_to_srgb() ColorSpaceConversionEffect *colorspace_conversion = new ColorSpaceConversionEffect(); colorspace_conversion->set_int("source_space", current_color_space); colorspace_conversion->set_int("destination_space", COLORSPACE_sRGB); - effects.push_back(colorspace_conversion); + colorspace_conversion->add_self_to_effect_chain(&effects); current_color_space = COLORSPACE_sRGB; } @@ -91,7 +94,7 @@ Effect *EffectChain::add_effect(EffectId effect_id) normalize_to_srgb(); } - effects.push_back(effect); + effect->add_self_to_effect_chain(&effects); return effect; } @@ -150,8 +153,8 @@ EffectChain::Phase EffectChain::compile_glsl_program(unsigned start_index, unsig frag_shader += replace_prefix(effects[i]->output_fragment_shader(), effect_id); frag_shader += "#undef PREFIX\n"; frag_shader += "#undef FUNCNAME\n"; - frag_shader += "#undef LAST_INPUT\n"; - frag_shader += std::string("#define LAST_INPUT ") + effect_id + "\n"; + frag_shader += "#undef INPUT\n"; + frag_shader += std::string("#define INPUT ") + effect_id + "\n"; frag_shader += "\n"; input_needs_mipmaps |= effects[i]->needs_mipmaps(); @@ -205,7 +208,7 @@ void EffectChain::finalize() // and of course at the end. unsigned start = 0; for (unsigned i = 0; i < effects.size(); ++i) { - if (effects[i]->needs_many_samples() && i != start) { + if (effects[i]->needs_texture_bounce() && i != start) { phases.push_back(compile_glsl_program(start, i)); start = i; } @@ -220,14 +223,16 @@ void EffectChain::finalize() unsigned num_textures = std::max(phases.size() - 1, 2); glGenTextures(num_textures, temp_textures); - unsigned char *empty = new unsigned char[width * height * 4]; for (unsigned i = 0; i < num_textures; ++i) { glBindTexture(GL_TEXTURE_2D, temp_textures[i]); check_error(); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, empty); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + check_error(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + check_error(); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); check_error(); } - delete[] empty; } // Translate the input format to OpenGL's enums. @@ -258,10 +263,8 @@ void EffectChain::finalize() check_error(); glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, width * height * bytes_per_pixel, NULL, GL_STREAM_DRAW); check_error(); - - void *mapped_pbo = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY); - memset(mapped_pbo, 0, width * height * bytes_per_pixel); - glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); + check_error(); glGenTextures(1, &source_image_num); check_error(); @@ -269,9 +272,10 @@ void EffectChain::finalize() check_error(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); check_error(); - glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0)); + // Intel/Mesa seems to have a broken glGenerateMipmap() for non-FBO textures, so do it here. + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, phases[0].input_needs_mipmaps ? GL_TRUE : GL_FALSE); check_error(); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, NULL); check_error(); finalized = true; @@ -325,6 +329,7 @@ void EffectChain::render_to_screen(unsigned char *src) for (unsigned phase = 0; phase < phases.size(); ++phase) { // Set up inputs and outputs for this phase. + glActiveTexture(GL_TEXTURE0); if (phase == 0) { // First phase reads from the input texture (which is already bound). } else { @@ -332,9 +337,12 @@ void EffectChain::render_to_screen(unsigned char *src) check_error(); } if (phases[phase].input_needs_mipmaps) { - glGenerateMipmap(GL_TEXTURE_2D); - check_error(); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + if (phase != 0) { + // For phase 0, it's done further up. + glGenerateMipmap(GL_TEXTURE_2D); + check_error(); + } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); check_error(); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -352,6 +360,7 @@ void EffectChain::render_to_screen(unsigned char *src) GL_TEXTURE_2D, temp_textures[phase % 2], 0); + check_error(); } // We have baked an upside-down transform into the quad coordinates, @@ -399,5 +408,7 @@ void EffectChain::render_to_screen(unsigned char *src) glActiveTexture(GL_TEXTURE0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); check_error(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1000); + check_error(); } }