]> git.sesse.net Git - movit/blobdiff - init.cpp
Redo FBO association yet again, this time per-texture.
[movit] / init.cpp
index 4003163d9494843b3eccc42910ca41084b52a691..37e9d70f974ec160c7bd7b2f169767cdcf17b263 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -38,7 +38,7 @@ void measure_texel_subpixel_precision()
        check_error();
        glBindTexture(GL_TEXTURE_2D, dst_texnum);
        check_error();
-       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, 1, 0, GL_RGBA, GL_FLOAT, NULL);
        check_error();
 
        glGenFramebuffers(1, &fbo);
@@ -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_LUMINANCE16F_ARB, 2, 0, GL_LUMINANCE, 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.
@@ -89,40 +89,35 @@ void measure_texel_subpixel_precision()
        // texture coordinates in order not to get long stretches of (1,1,1,...)
        // at the start and (...,0,0,0) at the end.
        float vertices[] = {
+               0.0f, 1.0f,
                0.0f, 0.0f,
-               1.0f, 0.0f,
                1.0f, 1.0f,
-               0.0f, 1.0f
+               1.0f, 0.0f
        };
        float texcoords[] = {
+               0.25f, 0.0f,
                0.25f, 0.0f,
                0.75f, 0.0f,
-               0.75f, 0.0f,
-               0.25f, 0.0f
+               0.75f, 0.0f
        };
 
-       int position_attrib = glGetAttribLocation(glsl_program_num, "position");
-       assert(position_attrib != -1);
-       int texcoord_attrib = glGetAttribLocation(glsl_program_num, "texcoord");
-       assert(texcoord_attrib != -1);
-       glEnableVertexAttribArray(position_attrib);
-       check_error();
-       glVertexAttribPointer(position_attrib, 2, GL_FLOAT, GL_FALSE, 0, vertices);
+       GLuint vao;
+       glGenVertexArrays(1, &vao);
        check_error();
-       glEnableVertexAttribArray(texcoord_attrib);
-       check_error();
-       glVertexAttribPointer(texcoord_attrib, 2, GL_FLOAT, GL_FALSE, 0, texcoords);
+       glBindVertexArray(vao);
        check_error();
 
-       glDrawArrays(GL_QUADS, 0, 4);
+       GLuint position_vbo = fill_vertex_attribute(glsl_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
+       GLuint texcoord_vbo = fill_vertex_attribute(glsl_program_num, "texcoord", 2, GL_FLOAT, sizeof(texcoords), texcoords);
+
+       glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
        check_error();
 
+       cleanup_vertex_attribute(glsl_program_num, "position", position_vbo);
+       cleanup_vertex_attribute(glsl_program_num, "texcoord", texcoord_vbo);
+
        glUseProgram(0);
        check_error();
-       glDisableVertexAttribArray(position_attrib);
-       check_error();
-       glDisableVertexAttribArray(texcoord_attrib);
-       check_error();
 
        // Now read the data back and see what the card did.
        // (We only look at the red channel; the others will surely be the same.)
@@ -141,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();
@@ -153,6 +148,8 @@ void measure_texel_subpixel_precision()
        check_error();
 
        resource_pool.release_glsl_program(glsl_program_num);
+       glDeleteVertexArrays(1, &vao);
+       check_error();
 }
 
 void measure_roundoff_problems()
@@ -192,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_LUMINANCE32F_ARB, 512, 0, GL_LUMINANCE, GL_FLOAT, texdata);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 512, 1, 0, GL_RED, GL_FLOAT, texdata);
        check_error();
 
        // Basic state.
@@ -215,40 +212,33 @@ 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[] = {
+               0.0f, 1.0f,
                0.0f, 0.0f,
-               1.0f, 0.0f,
                1.0f, 1.0f,
-               0.0f, 1.0f
+               1.0f, 0.0f
        };
-       float texcoords[] = {
-               0.25f, 0.0f,
-               0.75f, 0.0f,
-               0.75f, 0.0f,
-               0.25f, 0.0f
-       };
-       int position_attrib = glGetAttribLocation(glsl_program_num, "position");
-       assert(position_attrib != -1);
-       int texcoord_attrib = glGetAttribLocation(glsl_program_num, "texcoord");
-       assert(texcoord_attrib != -1);
-       glEnableVertexAttribArray(position_attrib);
-       check_error();
-       glVertexAttribPointer(position_attrib, 2, GL_FLOAT, GL_FALSE, 0, vertices);
+
+       GLuint vao;
+       glGenVertexArrays(1, &vao);
        check_error();
-       glEnableVertexAttribArray(texcoord_attrib);
+       glBindVertexArray(vao);
        check_error();
-       glVertexAttribPointer(texcoord_attrib, 2, GL_FLOAT, GL_FALSE, 0, texcoords);
+
+       GLuint position_vbo = fill_vertex_attribute(glsl_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
+       GLuint texcoord_vbo = fill_vertex_attribute(glsl_program_num, "texcoord", 2, GL_FLOAT, sizeof(vertices), vertices);  // Same data.
+
+       glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
        check_error();
-       glDrawArrays(GL_QUADS, 0, 4);
+
+       cleanup_vertex_attribute(glsl_program_num, "position", position_vbo);
+       cleanup_vertex_attribute(glsl_program_num, "texcoord", texcoord_vbo);
 
        glUseProgram(0);
        check_error();
-       glDisableVertexAttribArray(position_attrib);
-       check_error();
-       glDisableVertexAttribArray(texcoord_attrib);
 
        // Now read the data back and see what the card did. (Ignore the last value.)
        // (We only look at the red channel; the others will surely be the same.)
@@ -269,7 +259,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();
@@ -281,6 +271,8 @@ void measure_roundoff_problems()
        check_error();
 
        resource_pool.release_glsl_program(glsl_program_num);
+       glDeleteVertexArrays(1, &vao);
+       check_error();
 }
 
 bool check_extensions()