diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-08-19 20:48:01 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-08-25 08:44:48 +0200 |
| commit | 5932d16a8a9e265ce13408128f4434c6912be292 (patch) | |
| tree | 612436d02bf2ea6cabccbbac822d682b26d85ba2 | |
| parent | c1e7425cc3cb55dd0c9ddb15d00b6c2eb2faef0f (diff) | |
Cleanup: wrap glUniform* calls.
| -rw-r--r-- | src/wx/gl_util.cc | 66 | ||||
| -rw-r--r-- | src/wx/gl_util.h | 50 | ||||
| -rw-r--r-- | src/wx/gl_video_view.cc | 65 | ||||
| -rw-r--r-- | src/wx/gl_video_view.h | 3 |
4 files changed, 143 insertions, 41 deletions
diff --git a/src/wx/gl_util.cc b/src/wx/gl_util.cc index ea0673db5..c4b85068b 100644 --- a/src/wx/gl_util.cc +++ b/src/wx/gl_util.cc @@ -19,6 +19,10 @@ */ +#ifdef DCPOMATIC_WINDOWS +#include <GL/glew.h> +#endif + #include "gl_util.h" #include "lib/dcpomatic_assert.h" @@ -56,5 +60,67 @@ dcpomatic::gl::check_error(char const * last) } +Uniform::Uniform(int program, char const* name) +{ + setup(program, name); +} + + +void +Uniform::setup(int program, char const* name) +{ + _location = glGetUniformLocation(program, name); + check_error("glGetUniformLocation"); +} + + +UniformVec4f::UniformVec4f(int program, char const* name) + : Uniform(program, name) +{ + +} + + +void +UniformVec4f::set(float a, float b, float c, float d) +{ + DCPOMATIC_ASSERT(_location != -1); + glUniform4f(_location, a, b, c, d); + check_error("glUniform4f"); +} + + +Uniform1i::Uniform1i(int program, char const* name) + : Uniform(program, name) +{ + +} + + +void +Uniform1i::set(int v) +{ + DCPOMATIC_ASSERT(_location != -1); + glUniform1i(_location, v); + check_error("glUniform1i"); +} + + +UniformMatrix4fv::UniformMatrix4fv(int program, char const* name) + : Uniform(program, name) +{ + +} + + +void +UniformMatrix4fv::set(float const* matrix) +{ + DCPOMATIC_ASSERT(_location != -1); + glUniformMatrix4fv(_location, 1, GL_TRUE, matrix); + check_error("glUniformMatrix4fv"); +} + + #endif diff --git a/src/wx/gl_util.h b/src/wx/gl_util.h index 3f311e200..49f05d53b 100644 --- a/src/wx/gl_util.h +++ b/src/wx/gl_util.h @@ -19,6 +19,10 @@ */ +#ifndef DCPOMATIC_GL_UTIL_H +#define DCPOMATIC_GL_UTIL_H + + namespace dcpomatic { namespace gl { @@ -26,6 +30,52 @@ namespace gl { extern void check_error(char const * last); +class Uniform +{ +public: + Uniform() = default; + Uniform(int program, char const* name); + + void setup(int program, char const* name); + +protected: + int _location = -1; +}; + + +class UniformVec4f : public Uniform +{ +public: + UniformVec4f() = default; + UniformVec4f(int program, char const* name); + + void set(float a, float b, float c, float d); +}; + + +class Uniform1i : public Uniform +{ +public: + Uniform1i() = default; + Uniform1i(int program, char const* name); + + void set(int v); +}; + + +class UniformMatrix4fv : public Uniform +{ +public: + UniformMatrix4fv() = default; + UniformMatrix4fv(int program, char const* name); + + void set(float const* matrix); +}; + + } } + +#endif + diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc index ce846a380..8a9ef0cdd 100644 --- a/src/wx/gl_video_view.cc +++ b/src/wx/gl_video_view.cc @@ -469,25 +469,16 @@ GLVideoView::setup_shaders() glDeleteShader(fragment_shader); glUseProgram(program); - auto texture_0 = glGetUniformLocation(program, "texture_sampler_0"); - check_error("glGetUniformLocation"); - glUniform1i(texture_0, 0); - check_error("glUniform1i"); - auto texture_1 = glGetUniformLocation(program, "texture_sampler_1"); - check_error("glGetUniformLocation"); - glUniform1i(texture_1, 1); - check_error("glUniform1i"); - auto texture_2 = glGetUniformLocation(program, "texture_sampler_2"); - check_error("glGetUniformLocation"); - glUniform1i(texture_2, 2); - check_error("glUniform1i"); - auto texture_3 = glGetUniformLocation(program, "texture_sampler_3"); - check_error("glGetUniformLocation"); - glUniform1i(texture_3, 3); - check_error("glUniform1i"); - - _fragment_type = glGetUniformLocation(program, "type"); - check_error("glGetUniformLocation"); + auto texture_0 = Uniform1i(program, "texture_sampler_0"); + texture_0.set(0); + auto texture_1 = Uniform1i(program, "texture_sampler_1"); + texture_1.set(1); + auto texture_2 = Uniform1i(program, "texture_sampler_2"); + texture_2.set(2); + auto texture_3 = Uniform1i(program, "texture_sampler_3"); + texture_3.set(3); + + _fragment_type.setup(program, "type"); set_outline_content_colour(program); set_crop_guess_colour(program); @@ -516,9 +507,8 @@ GLVideoView::setup_shaders() GLfloat gl_matrix[16]; ublas_to_gl(matrix, gl_matrix); - auto xyz_rec709_colour_conversion = glGetUniformLocation(program, "xyz_rec709_colour_conversion"); - check_error("glGetUniformLocation"); - glUniformMatrix4fv(xyz_rec709_colour_conversion, 1, GL_TRUE, gl_matrix); + auto xyz_rec709_colour_conversion = UniformMatrix4fv(program, "xyz_rec709_colour_conversion"); + xyz_rec709_colour_conversion.set(gl_matrix); } { @@ -529,9 +519,8 @@ GLVideoView::setup_shaders() GLfloat gl_matrix[16]; ublas_to_gl(product, gl_matrix); - auto rec2020_rec709_colour_conversion = glGetUniformLocation(program, "rec2020_rec709_colour_conversion"); - check_error("glGetUniformLocation"); - glUniformMatrix4fv(rec2020_rec709_colour_conversion, 1, GL_TRUE, gl_matrix); + auto rec2020_rec709_colour_conversion = UniformMatrix4fv(program, "rec2020_rec709_colour_conversion"); + rec2020_rec709_colour_conversion.set(gl_matrix); } glLineWidth(1.0f); @@ -550,22 +539,18 @@ GLVideoView::setup_shaders() void GLVideoView::set_outline_content_colour(GLuint program) { - auto uniform = glGetUniformLocation(program, "outline_content_colour"); - check_error("glGetUniformLocation"); + auto uniform = UniformVec4f(program, "outline_content_colour"); auto colour = outline_content_colour(); - glUniform4f(uniform, colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f); - check_error("glUniform4f"); + uniform.set(colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f); } void GLVideoView::set_crop_guess_colour(GLuint program) { - auto uniform = glGetUniformLocation(program, "crop_guess_colour"); - check_error("glGetUniformLocation"); + auto uniform = UniformVec4f(program, "crop_guess_colour"); auto colour = crop_guess_colour(); - glUniform4f(uniform, colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f); - check_error("glUniform4f"); + uniform.set(colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f); } @@ -591,30 +576,30 @@ GLVideoView::draw() glBindVertexArray(_vao); check_error("glBindVertexArray"); if (_optimisation == Optimisation::MPEG2) { - glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::YUV420P_IMAGE)); + _fragment_type.set(static_cast<GLint>(FragmentType::YUV420P_IMAGE)); } else if (_optimisation == Optimisation::JPEG2000) { - glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::XYZ_IMAGE)); + _fragment_type.set(static_cast<GLint>(FragmentType::XYZ_IMAGE)); } else if (_rec2020) { - glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::REC2020_IMAGE)); + _fragment_type.set(static_cast<GLint>(FragmentType::REC2020_IMAGE)); } else { - glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::REC709_IMAGE)); + _fragment_type.set(static_cast<GLint>(FragmentType::REC709_IMAGE)); } for (auto& texture: _video_textures) { texture->bind(); } glDrawElements(GL_TRIANGLES, indices_video_texture_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_video_texture_offset * sizeof(int))); if (_have_subtitle_to_render) { - glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::REC709_SUBTITLE)); + _fragment_type.set(static_cast<GLint>(FragmentType::REC709_SUBTITLE)); _subtitle_texture->bind(); glDrawElements(GL_TRIANGLES, indices_subtitle_texture_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_subtitle_texture_offset * sizeof(int))); } if (_viewer->outline_content()) { - glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::OUTLINE_CONTENT)); + _fragment_type.set(static_cast<GLint>(FragmentType::OUTLINE_CONTENT)); glDrawElements(GL_LINES, indices_outline_content_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_outline_content_offset * sizeof(int))); check_error("glDrawElements"); } if (auto guess = _viewer->crop_guess()) { - glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::CROP_GUESS)); + _fragment_type.set(static_cast<GLint>(FragmentType::CROP_GUESS)); glDrawElements(GL_LINES, indices_crop_guess_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_crop_guess_offset * sizeof(int))); check_error("glDrawElements"); } diff --git a/src/wx/gl_video_view.h b/src/wx/gl_video_view.h index d915636af..a4ea83f70 100644 --- a/src/wx/gl_video_view.h +++ b/src/wx/gl_video_view.h @@ -19,6 +19,7 @@ */ +#include "gl_util.h" #include "lib/crop.h" #include <dcp/warnings.h> LIBDCP_DISABLE_WARNINGS @@ -152,7 +153,7 @@ private: boost::atomic<bool> _one_shot; GLuint _vao; - GLint _fragment_type; + dcpomatic::gl::Uniform1i _fragment_type; bool _setup_shaders_done = false; std::shared_ptr<wxTimer> _timer; |
