]> git.sesse.net Git - movit/blobdiff - dither_effect.cpp
Emulate glReadPixels of GL_ALPHA.
[movit] / dither_effect.cpp
index 4643d07180993fdd286e460eba758b08d949d9d3..17c577d4cdacc3ae44a4c79015d46c6e888389d6 100644 (file)
@@ -1,5 +1,6 @@
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 #include <assert.h>
 #include <assert.h>
+#include <stdio.h>
 #include <algorithm>
 
 #include "dither_effect.h"
 #include <algorithm>
 
 #include "dither_effect.h"
@@ -7,6 +8,10 @@
 #include "init.h"
 #include "util.h"
 
 #include "init.h"
 #include "util.h"
 
+using namespace std;
+
+namespace movit {
+
 namespace {
 
 // A simple LCG (linear congruental generator) random generator.
 namespace {
 
 // A simple LCG (linear congruental generator) random generator.
@@ -39,14 +44,14 @@ DitherEffect::~DitherEffect()
        glDeleteTextures(1, &texnum);
 }
 
        glDeleteTextures(1, &texnum);
 }
 
-std::string DitherEffect::output_fragment_shader()
+string DitherEffect::output_fragment_shader()
 {
        char buf[256];
 {
        char buf[256];
-       sprintf(buf, "#define NEED_EXPLICIT_ROUND %d\n", (movit_num_wrongly_rounded > 0));
+       sprintf(buf, "#define NEED_EXPLICIT_ROUND %d\n", (movit_num_wrongly_rounded > 0 && movit_shader_rounding_supported));
        return buf + read_file("dither_effect.frag");
 }
 
        return buf + read_file("dither_effect.frag");
 }
 
-void DitherEffect::update_texture(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
+void DitherEffect::update_texture(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num)
 {
        float *dither_noise = new float[width * height];
        float dither_double_amplitude = 1.0f / (1 << num_bits);
 {
        float *dither_noise = new float[width * height];
        float dither_double_amplitude = 1.0f / (1 << num_bits);
@@ -54,8 +59,8 @@ void DitherEffect::update_texture(GLuint glsl_program_num, const std::string &pr
        // We don't need a strictly nonrepeating dither; reducing the resolution
        // to max 128x128 saves a lot of texture bandwidth, without causing any
        // noticeable harm to the dither's performance.
        // We don't need a strictly nonrepeating dither; reducing the resolution
        // to max 128x128 saves a lot of texture bandwidth, without causing any
        // noticeable harm to the dither's performance.
-       texture_width = std::min(width, 128);
-       texture_height = std::min(height, 128);
+       texture_width = min(width, 128);
+       texture_height = min(height, 128);
 
        // Using the resolution as a seed gives us a consistent dither from frame to frame.
        // It also gives a different dither for e.g. different aspect ratios, which _feels_
 
        // Using the resolution as a seed gives us a consistent dither from frame to frame.
        // It also gives a different dither for e.g. different aspect ratios, which _feels_
@@ -79,13 +84,13 @@ void DitherEffect::update_texture(GLuint glsl_program_num, const std::string &pr
        check_error();
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        check_error();
        check_error();
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        check_error();
-       glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16F_ARB, texture_width, texture_height, 0, GL_LUMINANCE, GL_FLOAT, dither_noise);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, texture_width, texture_height, 0, GL_RED, GL_FLOAT, dither_noise);
        check_error();
 
        delete[] dither_noise;
 }
 
        check_error();
 
        delete[] dither_noise;
 }
 
-void DitherEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
+void DitherEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num)
 {
        Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
 
 {
        Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
 
@@ -119,3 +124,5 @@ void DitherEffect::set_gl_state(GLuint glsl_program_num, const std::string &pref
        set_uniform_float(glsl_program_num, prefix, "round_fac", round_fac);
        set_uniform_float(glsl_program_num, prefix, "inv_round_fac", 1.0f / round_fac);
 }
        set_uniform_float(glsl_program_num, prefix, "round_fac", round_fac);
        set_uniform_float(glsl_program_num, prefix, "inv_round_fac", 1.0f / round_fac);
 }
+
+}  // namespace movit