]> git.sesse.net Git - nageru/commitdiff
Make CbCr subsampling VBO permanent, mostly to reduce the amount of debugging spew...
authorSteinar H. Gunderson <steinar+vlc@gunderson.no>
Wed, 24 Feb 2016 09:45:08 +0000 (10:45 +0100)
committerSteinar H. Gunderson <steinar+vlc@gunderson.no>
Wed, 24 Feb 2016 09:45:08 +0000 (10:45 +0100)
mixer.cpp
mixer.h

index 7edeb311207fc2d6d3b296eb1a846191568c5986..ec333ef1124357dfffa3554557f0a6650839ff7a 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -199,6 +199,15 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards)
        vector<string> frag_shader_outputs;
        cbcr_program_num = resource_pool->compile_glsl_program(cbcr_vert_shader, cbcr_frag_shader, frag_shader_outputs);
 
+       float vertices[] = {
+               0.0f, 2.0f,
+               0.0f, 0.0f,
+               2.0f, 0.0f
+       };
+       cbcr_vbo = generate_vbo(2, GL_FLOAT, sizeof(vertices), vertices);
+       cbcr_position_attribute_index = glGetAttribLocation(cbcr_program_num, "position");
+       cbcr_texcoord_attribute_index = glGetAttribLocation(cbcr_program_num, "texcoord");
+
        r128.init(2, OUTPUT_FREQUENCY);
        r128.integr_start();
 
@@ -214,6 +223,7 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards)
 Mixer::~Mixer()
 {
        resource_pool->release_glsl_program(cbcr_program_num);
+       glDeleteBuffers(1, &cbcr_vbo);
        BMUSBCapture::stop_bm_thread();
 
        for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
@@ -880,12 +890,6 @@ void Mixer::subsample_chroma(GLuint src_tex, GLuint dst_tex)
        glGenVertexArrays(1, &vao);
        check_error();
 
-       float vertices[] = {
-               0.0f, 2.0f,
-               0.0f, 0.0f,
-               2.0f, 0.0f
-       };
-
        glBindVertexArray(vao);
        check_error();
 
@@ -912,14 +916,23 @@ void Mixer::subsample_chroma(GLuint src_tex, GLuint dst_tex)
        float chroma_offset_0[] = { -0.5f / WIDTH, 0.0f };
        set_uniform_vec2(cbcr_program_num, "foo", "chroma_offset_0", chroma_offset_0);
 
-       GLuint position_vbo = fill_vertex_attribute(cbcr_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
-       GLuint texcoord_vbo = fill_vertex_attribute(cbcr_program_num, "texcoord", 2, GL_FLOAT, sizeof(vertices), vertices);  // Same as vertices.
+       glBindBuffer(GL_ARRAY_BUFFER, cbcr_vbo);
+       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();
+       }
 
        glDrawArrays(GL_TRIANGLES, 0, 3);
        check_error();
 
-       cleanup_vertex_attribute(cbcr_program_num, "position", position_vbo);
-       cleanup_vertex_attribute(cbcr_program_num, "texcoord", texcoord_vbo);
+       for (GLint attr_index : { cbcr_position_attribute_index, cbcr_texcoord_attribute_index }) {
+               glDisableVertexAttribArray(attr_index);
+               check_error();
+       }
 
        glUseProgram(0);
        check_error();
diff --git a/mixer.h b/mixer.h
index ef112b8c73c07648bba43fd262d3f54c87fc5094..0d375f84b12021101441dcc5b54734e400605619 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -262,6 +262,8 @@ private:
        std::atomic<unsigned> audio_source_channel{0};
        std::unique_ptr<movit::EffectChain> display_chain;
        GLuint cbcr_program_num;  // Owned by <resource_pool>.
+       GLuint cbcr_vbo;  // Holds position and texcoord data.
+       GLuint cbcr_position_attribute_index, cbcr_texcoord_attribute_index;
        std::unique_ptr<H264Encoder> h264_encoder;
 
        // Effects part of <display_chain>. Owned by <display_chain>.