]> git.sesse.net Git - nageru/commitdiff
Optimize away some glGetUniformLocation calls.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 2 Jul 2017 09:30:39 +0000 (11:30 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 2 Jul 2017 09:30:39 +0000 (11:30 +0200)
chroma_subsampler.cpp
chroma_subsampler.h

index cf46883c5505621416d72303a5e377276f89dfa5..0b214132efbe7e2ee873fab8cf5c27e7df34783f 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();
@@ -293,11 +305,10 @@ 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);
-
+       glUniform2f(cbcr_chroma_offset_0_location, -1.0f / width, 0.0f);
+       check_error();
+       glUniform2f(cbcr_chroma_offset_1_location, -0.0f / width, 0.0f);
+       check_error();
        glUniform1i(cbcr_texture_sampler_uniform, 0);
 
        glBindBuffer(GL_ARRAY_BUFFER, vbo);
@@ -372,14 +383,14 @@ 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();
index d4c1c1ed22c26c4535e476741b137145f48bcf38..6466285960eea21434eccc0455eb0ed40f483a81 100644 (file)
@@ -43,10 +43,13 @@ private:
        GLuint cbcr_program_num;  // Owned by <resource_pool>.
        GLuint cbcr_texture_sampler_uniform;
        GLuint cbcr_position_attribute_index, cbcr_texcoord_attribute_index;
+       GLuint cbcr_chroma_offset_0_location, cbcr_chroma_offset_1_location;
 
        GLuint uyvy_program_num;  // Owned by <resource_pool>.
        GLuint uyvy_y_texture_sampler_uniform, uyvy_cbcr_texture_sampler_uniform;
        GLuint uyvy_position_attribute_index, uyvy_texcoord_attribute_index;
+       GLuint uyvy_luma_offset_0_location, uyvy_luma_offset_1_location;
+       GLuint uyvy_chroma_offset_0_location, uyvy_chroma_offset_1_location;
 
        GLuint v210_program_num;  // Compute shader, so owned by ourselves. Can be 0.
        GLuint v210_in_y_pos, v210_in_cbcr_pos, v210_outbuf_pos;