Stop using 1D textures.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 9 Mar 2014 00:42:27 +0000 (01:42 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 9 Mar 2014 00:44:12 +0000 (01:44 +0100)
1D textures were never part of GLES, so use 2D textures with Nx1 instead.
Supposedly they are just as fast (although it feels a bit less elegant).

fft_pass_effect.cpp
fft_pass_effect.frag
init.cpp
texture1d.frag

index ccca74d..51bde35 100644 (file)
@@ -132,13 +132,13 @@ void FFTPassEffect::set_gl_state(GLuint glsl_program_num, const string &prefix,
 
        glActiveTexture(GL_TEXTURE0 + *sampler_num);
        check_error();
-       glBindTexture(GL_TEXTURE_1D, tex);
+       glBindTexture(GL_TEXTURE_2D, tex);
        check_error();
-       glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        check_error();
-       glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        check_error();
-       glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        check_error();
 
        // Supposedly FFTs are very sensitive to inaccuracies in the twiddle factors,
@@ -147,7 +147,7 @@ void FFTPassEffect::set_gl_state(GLuint glsl_program_num, const string &prefix,
        // small sizes, all components are exact anyway, so we can cheat there
        // (although noting that the source coordinates become somewhat less
        // accurate then, too).
-       glTexImage1D(GL_TEXTURE_1D, 0, (subfft_size <= 4) ? GL_RGBA16F : GL_RGBA32F, fft_size, 0, GL_RGBA, GL_FLOAT, tmp);
+       glTexImage2D(GL_TEXTURE_2D, 0, (subfft_size <= 4) ? GL_RGBA16F : GL_RGBA32F, fft_size, 1, 0, GL_RGBA, GL_FLOAT, tmp);
        check_error();
 
        delete[] tmp;
index 462a673..800653a 100644 (file)
@@ -2,15 +2,15 @@
 // and 0 otherwise.
 
 uniform float PREFIX(num_repeats);
-uniform sampler1D PREFIX(support_tex);
+uniform sampler2D PREFIX(support_tex);
 
 vec4 FUNCNAME(vec2 tc) {
 #if DIRECTION_VERTICAL
-       vec4 support = texture1D(PREFIX(support_tex), tc.y * PREFIX(num_repeats));
+       vec4 support = texture2D(PREFIX(support_tex), vec2(tc.y * PREFIX(num_repeats), 0.0));
         vec4 c1 = INPUT(vec2(tc.x, 1.0 - (tc.y + support.x)));
         vec4 c2 = INPUT(vec2(tc.x, 1.0 - (tc.y + support.y)));
 #else
-       vec4 support = texture1D(PREFIX(support_tex), tc.x * PREFIX(num_repeats));
+       vec4 support = texture2D(PREFIX(support_tex), vec2(tc.x * PREFIX(num_repeats), 0.0));
         vec4 c1 = INPUT(vec2(tc.x + support.x, tc.y));
         vec4 c2 = INPUT(vec2(tc.x + support.y, tc.y));
 #endif
index 0957a11..554aa24 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -58,13 +58,13 @@ void measure_texel_subpixel_precision()
        float texdata[] = { 0, 1 };
        glGenTextures(1, &src_texnum);
        check_error();
-       glBindTexture(GL_TEXTURE_1D, src_texnum);
+       glBindTexture(GL_TEXTURE_2D, src_texnum);
        check_error();
-       glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        check_error();
-       glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        check_error();
-       glTexImage1D(GL_TEXTURE_1D, 0, GL_R16F, 2, 0, GL_RED, GL_FLOAT, texdata);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, 2, 1, 0, GL_RED, GL_FLOAT, texdata);
        check_error();
 
        // Basic state.
@@ -81,7 +81,7 @@ void measure_texel_subpixel_precision()
                read_file("vs.vert"), read_file("texture1d.frag"));
        glUseProgram(glsl_program_num);
        check_error();
-       glUniform1i(glGetUniformLocation(glsl_program_num, "tex"), 0);  // Bind the 1D sampler.
+       glUniform1i(glGetUniformLocation(glsl_program_num, "tex"), 0);  // Bind the 2D sampler.
        check_error();
 
        // Draw the texture stretched over a long quad, interpolating it out.
@@ -136,7 +136,7 @@ void measure_texel_subpixel_precision()
        movit_texel_subpixel_precision = biggest_jump;
 
        // Clean up.
-       glBindTexture(GL_TEXTURE_1D, 0);
+       glBindTexture(GL_TEXTURE_2D, 0);
        check_error();
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        check_error();
@@ -189,13 +189,13 @@ void measure_roundoff_problems()
        }
        glGenTextures(1, &src_texnum);
        check_error();
-       glBindTexture(GL_TEXTURE_1D, src_texnum);
+       glBindTexture(GL_TEXTURE_2D, src_texnum);
        check_error();
-       glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        check_error();
-       glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        check_error();
-       glTexImage1D(GL_TEXTURE_1D, 0, GL_R32F, 512, 0, GL_RED, GL_FLOAT, texdata);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 512, 1, 0, GL_RED, GL_FLOAT, texdata);
        check_error();
 
        // Basic state.
@@ -212,7 +212,7 @@ void measure_roundoff_problems()
                read_file("vs.vert"), read_file("texture1d.frag"));
        glUseProgram(glsl_program_num);
        check_error();
-       glUniform1i(glGetUniformLocation(glsl_program_num, "tex"), 0);  // Bind the 1D sampler.
+       glUniform1i(glGetUniformLocation(glsl_program_num, "tex"), 0);  // Bind the 2D sampler.
 
        // Draw the texture stretched over a long quad, interpolating it out.
        float vertices[] = {
@@ -265,7 +265,7 @@ void measure_roundoff_problems()
        movit_num_wrongly_rounded = wrongly_rounded;
 
        // Clean up.
-       glBindTexture(GL_TEXTURE_1D, 0);
+       glBindTexture(GL_TEXTURE_2D, 0);
        check_error();
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        check_error();
index 4f8b981..c3a8047 100644 (file)
@@ -1,7 +1,7 @@
-uniform sampler1D tex;
+uniform sampler2D tex;
 varying vec2 tc;
 
 void main()
 {
-       gl_FragColor = texture1D(tex, tc.x);
+       gl_FragColor = texture2D(tex, tc);  // Second component is irrelevant.
 }