]> git.sesse.net Git - movit/blobdiff - effect_chain.cpp
Some more GL state paranoia.
[movit] / effect_chain.cpp
index 899c6a3f4ca9335e518cd3939a452cafe6955801..85c8be374a0702118c74ce2faa3c9c5e6d175674 100644 (file)
@@ -221,9 +221,14 @@ void EffectChain::finalize()
                glGenTextures(num_textures, temp_textures);
 
                unsigned char *empty = new unsigned char[width * height * 4];
+               memset(empty, 0, width * height * 4);
                for (unsigned i = 0; i < num_textures; ++i) {
                        glBindTexture(GL_TEXTURE_2D, temp_textures[i]);
                        check_error();
+                       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, empty);
                        check_error();
                }
@@ -262,6 +267,7 @@ void EffectChain::finalize()
        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);
+       check_error();
        
        glGenTextures(1, &source_image_num);
        check_error();
@@ -325,6 +331,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 {
@@ -334,7 +341,7 @@ void EffectChain::render_to_screen(unsigned char *src)
                if (phases[phase].input_needs_mipmaps) {
                        glGenerateMipmap(GL_TEXTURE_2D);
                        check_error();
-                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+                       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 +359,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,
@@ -394,5 +402,12 @@ void EffectChain::render_to_screen(unsigned char *src)
 
                glEnd();
                check_error();
+
+               // HACK
+               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();
        }
 }