]> git.sesse.net Git - nageru/blobdiff - chroma_subsampler.cpp
Release Nageru 1.7.2.
[nageru] / chroma_subsampler.cpp
index cf46883c5505621416d72303a5e377276f89dfa5..96adef1eedb9d360aea76136a17abafa760e8f29 100644 (file)
@@ -102,6 +102,10 @@ ChromaSubsampler::ChromaSubsampler(ResourcePool *resource_pool)
                "} \n";
        cbcr_program_num = resource_pool->compile_glsl_program(cbcr_vert_shader, cbcr_frag_shader, frag_shader_outputs);
        check_error();
+       cbcr_chroma_offset_0_location = get_uniform_location(cbcr_program_num, "foo", "chroma_offset_0");
+       check_error();
+       cbcr_chroma_offset_1_location = get_uniform_location(cbcr_program_num, "foo", "chroma_offset_1");
+       check_error();
 
        cbcr_texture_sampler_uniform = glGetUniformLocation(cbcr_program_num, "cbcr_tex");
        check_error();
@@ -153,6 +157,14 @@ ChromaSubsampler::ChromaSubsampler(ResourcePool *resource_pool)
 
        uyvy_program_num = resource_pool->compile_glsl_program(uyvy_vert_shader, uyvy_frag_shader, frag_shader_outputs);
        check_error();
+       uyvy_luma_offset_0_location = get_uniform_location(uyvy_program_num, "foo", "luma_offset_0");
+       check_error();
+       uyvy_luma_offset_1_location = get_uniform_location(uyvy_program_num, "foo", "luma_offset_1");
+       check_error();
+       uyvy_chroma_offset_0_location = get_uniform_location(uyvy_program_num, "foo", "chroma_offset_0");
+       check_error();
+       uyvy_chroma_offset_1_location = get_uniform_location(uyvy_program_num, "foo", "chroma_offset_1");
+       check_error();
 
        uyvy_y_texture_sampler_uniform = glGetUniformLocation(uyvy_program_num, "y_tex");
        check_error();
@@ -225,7 +237,7 @@ void main()
                check_error();
                if (success == GL_FALSE) {
                        GLchar error_log[1024] = {0};
-                       glGetProgramInfoLog(v210_program_num, 1024, NULL, error_log);
+                       glGetProgramInfoLog(v210_program_num, 1024, nullptr, error_log);
                        fprintf(stderr, "Error linking program: %s\n", error_log);
                        exit(1);
                }
@@ -261,10 +273,7 @@ ChromaSubsampler::~ChromaSubsampler()
 
 void ChromaSubsampler::subsample_chroma(GLuint cbcr_tex, unsigned width, unsigned height, GLuint dst_tex, GLuint dst2_tex)
 {
-       GLuint vao;
-       glGenVertexArrays(1, &vao);
-       check_error();
-
+       GLuint vao = resource_pool->create_vec2_vao({ cbcr_position_attribute_index, cbcr_texcoord_attribute_index }, vbo);
        glBindVertexArray(vao);
        check_error();
 
@@ -293,45 +302,30 @@ void ChromaSubsampler::subsample_chroma(GLuint cbcr_tex, unsigned width, unsigne
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        check_error();
 
-       float chroma_offset_0[] = { -1.0f / width, 0.0f };
-       float chroma_offset_1[] = { -0.0f / width, 0.0f };
-       set_uniform_vec2(cbcr_program_num, "foo", "chroma_offset_0", chroma_offset_0);
-       set_uniform_vec2(cbcr_program_num, "foo", "chroma_offset_1", chroma_offset_1);
-
-       glUniform1i(cbcr_texture_sampler_uniform, 0);
-
-       glBindBuffer(GL_ARRAY_BUFFER, vbo);
+       glUniform2f(cbcr_chroma_offset_0_location, -1.0f / width, 0.0f);
        check_error();
-
-       for (GLint attr_index : { cbcr_position_attribute_index, cbcr_texcoord_attribute_index }) {
-               glEnableVertexAttribArray(attr_index);
-               check_error();
-               glVertexAttribPointer(attr_index, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
-               check_error();
-       }
+       glUniform2f(cbcr_chroma_offset_1_location, -0.0f / width, 0.0f);
+       check_error();
+       glUniform1i(cbcr_texture_sampler_uniform, 0);
 
        glDrawArrays(GL_TRIANGLES, 0, 3);
        check_error();
 
-       for (GLint attr_index : { cbcr_position_attribute_index, cbcr_texcoord_attribute_index }) {
-               glDisableVertexAttribArray(attr_index);
-               check_error();
-       }
-
        glUseProgram(0);
        check_error();
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        check_error();
+       glBindVertexArray(0);
+       check_error();
 
        resource_pool->release_fbo(fbo);
-       glDeleteVertexArrays(1, &vao);
-       check_error();
+       resource_pool->release_vec2_vao(vao);
 }
 
 void ChromaSubsampler::create_uyvy(GLuint y_tex, GLuint cbcr_tex, unsigned width, unsigned height, GLuint dst_tex)
 {
-       GLuint vao;
-       glGenVertexArrays(1, &vao);
+       GLuint vao = resource_pool->create_vec2_vao({ cbcr_position_attribute_index, cbcr_texcoord_attribute_index }, vbo);
+       glBindVertexArray(vao);
        check_error();
 
        glBindVertexArray(vao);
@@ -372,44 +366,32 @@ void ChromaSubsampler::create_uyvy(GLuint y_tex, GLuint cbcr_tex, unsigned width
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        check_error();
 
-       float y_offset_0[] = { -0.5f / width, 0.0f };
-       float y_offset_1[] = {  0.5f / width, 0.0f };
-       float cbcr_offset0[] = { -1.0f / width, 0.0f };
-       float cbcr_offset1[] = { -0.0f / width, 0.0f };
-       set_uniform_vec2(uyvy_program_num, "foo", "luma_offset_0", y_offset_0);
-       set_uniform_vec2(uyvy_program_num, "foo", "luma_offset_1", y_offset_1);
-       set_uniform_vec2(uyvy_program_num, "foo", "chroma_offset_0", cbcr_offset0);
-       set_uniform_vec2(uyvy_program_num, "foo", "chroma_offset_1", cbcr_offset1);
+       glUniform2f(uyvy_luma_offset_0_location, -0.5f / width, 0.0f);
+       check_error();
+       glUniform2f(uyvy_luma_offset_1_location,  0.5f / width, 0.0f);
+       check_error();
+       glUniform2f(uyvy_chroma_offset_0_location, -1.0f / width, 0.0f);
+       check_error();
+       glUniform2f(uyvy_chroma_offset_1_location, -0.0f / width, 0.0f);
+       check_error();
 
        glBindBuffer(GL_ARRAY_BUFFER, vbo);
        check_error();
 
-       for (GLint attr_index : { uyvy_position_attribute_index, uyvy_texcoord_attribute_index }) {
-               if (attr_index == -1) continue;
-               glEnableVertexAttribArray(attr_index);
-               check_error();
-               glVertexAttribPointer(attr_index, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
-               check_error();
-       }
-
        glDrawArrays(GL_TRIANGLES, 0, 3);
        check_error();
 
-       for (GLint attr_index : { uyvy_position_attribute_index, uyvy_texcoord_attribute_index }) {
-               if (attr_index == -1) continue;
-               glDisableVertexAttribArray(attr_index);
-               check_error();
-       }
-
        glActiveTexture(GL_TEXTURE0);
        check_error();
        glUseProgram(0);
        check_error();
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        check_error();
+       glBindVertexArray(0);
+       check_error();
 
        resource_pool->release_fbo(fbo);
-       glDeleteVertexArrays(1, &vao);
+       resource_pool->release_vec2_vao(vao);
 }
 
 void ChromaSubsampler::create_v210(GLuint y_tex, GLuint cbcr_tex, unsigned width, unsigned height, GLuint dst_tex)