From dd028b62d9a45e831a64bde29fcaa49e3d8005ff Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 9 Jan 2025 00:34:18 +0100 Subject: Fix subtitle rendering with OpenGL. A number of errors were made when adding the two new video textures for rendering MPEG2. --- src/wx/gl_video_view.cc | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc index 81156c67c..05fedd936 100644 --- a/src/wx/gl_video_view.cc +++ b/src/wx/gl_video_view.cc @@ -197,12 +197,14 @@ static constexpr char fragment_source[] = "uniform sampler2D texture_sampler_0;\n" "uniform sampler2D texture_sampler_1;\n" "uniform sampler2D texture_sampler_2;\n" +"uniform sampler2D texture_sampler_3;\n" /* type = 0: draw outline content rectangle * type = 1: draw crop guess rectangle - * type = 2: draw XYZ image - * type = 3: draw RGB image (with sRGB/Rec709 primaries) - * type = 4: draw RGB image (converting from Rec2020 primaries) - * type = 5; draw YUV image (Y in texture_sampler_0, U in texture_sampler_1, V in texture_sampler_2) + * type = 2: draw XYZ image from texture_sampler_0 + * type = 3: draw RGB image (with sRGB/Rec709 primaries) from texture_sampler_0 + * type = 4: draw RGB image (with sRGB/Rec709 primaries) from texture_sampler_3 + * type = 5: draw RGB image (converting from Rec2020 primaries) from texture_sampler_0 + * type = 6; draw YUV image (Y in texture_sampler_0, U in texture_sampler_1, V in texture_sampler_2) * See FragmentType enum below. */ "uniform int type = 0;\n" @@ -286,10 +288,13 @@ static constexpr char fragment_source[] = " FragColor = texture_bicubic(texture_sampler_0, TexCoord);\n" " break;\n" " case 4:\n" +" FragColor = texture_bicubic(texture_sampler_3, TexCoord);\n" +" break;\n" +" case 5:\n" " FragColor = texture_bicubic(texture_sampler_0, TexCoord);\n" " FragColor = rec2020_rec709_colour_conversion * FragColor;\n" " break;\n" -" case 5:\n" +" case 6:\n" " float y = texture_bicubic(texture_sampler_0, TexCoord).x;\n" " float u = texture_bicubic(texture_sampler_1, TexCoord).x - 0.5;\n" " float v = texture_bicubic(texture_sampler_2, TexCoord).x - 0.5;\n" @@ -309,8 +314,9 @@ enum class FragmentType CROP_GUESS = 1, XYZ_IMAGE = 2, REC709_IMAGE = 3, - REC2020_IMAGE = 4, - YUV420P_IMAGE = 5, + REC709_SUBTITLE = 4, + REC2020_IMAGE = 5, + YUV420P_IMAGE = 6, }; @@ -481,6 +487,10 @@ GLVideoView::setup_shaders () check_gl_error("glGetUniformLocation"); glUniform1i(texture_2, 2); check_gl_error("glUniform1i"); + auto texture_3 = glGetUniformLocation(program, "texture_sampler_3"); + check_gl_error("glGetUniformLocation"); + glUniform1i(texture_3, 3); + check_gl_error("glUniform1i"); _fragment_type = glGetUniformLocation (program, "type"); check_gl_error ("glGetUniformLocation"); @@ -600,7 +610,7 @@ GLVideoView::draw () } glDrawElements (GL_TRIANGLES, indices_video_texture_number, GL_UNSIGNED_INT, reinterpret_cast(indices_video_texture_offset * sizeof(int))); if (_have_subtitle_to_render) { - glUniform1i(_fragment_type, static_cast(FragmentType::REC709_IMAGE)); + glUniform1i(_fragment_type, static_cast(FragmentType::REC709_SUBTITLE)); _subtitle_texture->bind(); glDrawElements (GL_TRIANGLES, indices_subtitle_texture_number, GL_UNSIGNED_INT, reinterpret_cast(indices_subtitle_texture_offset * sizeof(int))); } @@ -664,7 +674,6 @@ GLVideoView::set_image (shared_ptr pv) _subtitle_texture->set (text->image); } - auto const canvas_size = _canvas_size.load(); int const canvas_width = canvas_size.GetWidth(); int const canvas_height = canvas_size.GetHeight(); @@ -796,6 +805,15 @@ GLVideoView::set_image (shared_ptr pv) glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); check_gl_error ("glTexParameterf"); } + + _subtitle_texture->bind(); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + check_gl_error ("glTexParameteri"); + + glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + check_gl_error ("glTexParameterf"); } @@ -909,7 +927,7 @@ try std::unique_ptr texture(new Texture(_optimisation == Optimisation::JPEG2000 ? 2 : 1, i)); _video_textures.push_back(std::move(texture)); } - _subtitle_texture.reset(new Texture(1, 4)); + _subtitle_texture.reset(new Texture(1, 3)); while (true) { boost::mutex::scoped_lock lm (_playing_mutex); -- cgit v1.2.3