summaryrefslogtreecommitdiff
path: root/src/wx
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-04-28 01:34:09 +0200
committerCarl Hetherington <cth@carlh.net>2025-04-28 02:31:15 +0200
commit05b7c7ebb03187664c73dc91e08135a15237558d (patch)
tree9e995b74ab65f86f74cfe2f743e49d54ef07050a /src/wx
parentd13addc4a274b51e841fb93c39e1573535efe32d (diff)
Small cleanup to wrap uniform variables.
Diffstat (limited to 'src/wx')
-rw-r--r--src/wx/gl_util.cc26
-rw-r--r--src/wx/gl_util.h24
-rw-r--r--src/wx/gl_video_view.cc84
-rw-r--r--src/wx/gl_video_view.h4
4 files changed, 85 insertions, 53 deletions
diff --git a/src/wx/gl_util.cc b/src/wx/gl_util.cc
index 4407fb1bb..8c09acd0e 100644
--- a/src/wx/gl_util.cc
+++ b/src/wx/gl_util.cc
@@ -381,5 +381,31 @@ Coords::set_array_buffer()
}
+void
+Uniform::setup(int program, char const* name)
+{
+ _location = glGetUniformLocation(program, name);
+ check_gl_error("glGetUniformLocation");
+}
+
+
+void
+UniformVec4f::set(float a, float b, float c, float d)
+{
+ DCPOMATIC_ASSERT(_location != -1);
+ glUniform4f(_location, a, b, c, d);
+ check_gl_error("glUniform4f");
+}
+
+
+void
+Uniform1i::set(int v)
+{
+ DCPOMATIC_ASSERT(_location != -1);
+ glUniform1i(_location, v);
+ check_gl_error("glUniform1i");
+}
+
+
#endif
diff --git a/src/wx/gl_util.h b/src/wx/gl_util.h
index f5ea15c90..101a35721 100644
--- a/src/wx/gl_util.h
+++ b/src/wx/gl_util.h
@@ -146,6 +146,30 @@ private:
};
+class Uniform
+{
+public:
+ void setup(int program, char const* name);
+
+protected:
+ int _location = -1;
+};
+
+
+class UniformVec4f : public Uniform
+{
+public:
+ void set(float a, float b, float c, float d);
+};
+
+
+class Uniform1i : public Uniform
+{
+public:
+ void set(int v);
+};
+
+
}
}
diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc
index ea92c14b9..61bc55f05 100644
--- a/src/wx/gl_video_view.cc
+++ b/src/wx/gl_video_view.cc
@@ -262,27 +262,33 @@ GLVideoView::setup_shaders()
_coords.setup();
- auto texture_0 = glGetUniformLocation(_view.program(), "texture_sampler_0");
- check_gl_error("glGetUniformLocation");
- glUniform1i(texture_0, 0);
- check_gl_error("glUniform1i");
- auto texture_1 = glGetUniformLocation(_view.program(), "texture_sampler_1");
- check_gl_error("glGetUniformLocation");
- glUniform1i(texture_1, 1);
- check_gl_error("glUniform1i");
- auto texture_2 = glGetUniformLocation(_view.program(), "texture_sampler_2");
- check_gl_error("glGetUniformLocation");
- glUniform1i(texture_2, 2);
- check_gl_error("glUniform1i");
- auto texture_3 = glGetUniformLocation(_view.program(), "texture_sampler_3");
- check_gl_error("glGetUniformLocation");
- glUniform1i(texture_3, 3);
- check_gl_error("glUniform1i");
-
- _fragment_type = glGetUniformLocation(_view.program(), "type");
- check_gl_error("glGetUniformLocation");
- set_outline_content_colour(_view.program());
- set_crop_guess_colour(_view.program());
+ Uniform1i texture_0;
+ texture_0.setup(_view.program(), "texture_sampler_0");
+ texture_0.set(0);
+
+ Uniform1i texture_1;
+ texture_1.setup(_view.program(), "texture_sampler_1");
+ texture_1.set(0);
+
+ Uniform1i texture_2;
+ texture_2.setup(_view.program(), "texture_sampler_2");
+ texture_2.set(0);
+
+ Uniform1i texture_3;
+ texture_3.setup(_view.program(), "texture_sampler_3");
+ texture_3.set(0);
+
+ _fragment_type.setup(_view.program(), "type");
+
+ UniformVec4f outline_uniform;
+ outline_uniform.setup(_view.program(), "outline_content_colour");
+ auto outline = outline_content_colour();
+ outline_uniform.set(outline.Red() / 255.0f, outline.Green() / 255.0f, outline.Blue() / 255.0f, 1.0f);
+
+ UniformVec4f crop_uniform;
+ crop_uniform.setup(_view.program(), "crop_guess_colour");
+ auto crop = crop_guess_colour();
+ crop_uniform.set(crop.Red() / 255.0f, crop.Green() / 255.0f, crop.Blue() / 255.0f, 1.0f);
auto ublas_to_gl = [](boost::numeric::ublas::matrix<double> const& ublas, GLfloat* gl) {
gl[0] = static_cast<float>(ublas(0, 0));
@@ -337,28 +343,6 @@ GLVideoView::setup_shaders()
void
-GLVideoView::set_outline_content_colour(GLuint program)
-{
- auto uniform = glGetUniformLocation(program, "outline_content_colour");
- check_gl_error("glGetUniformLocation");
- auto colour = outline_content_colour();
- glUniform4f(uniform, colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f);
- check_gl_error("glUniform4f");
-}
-
-
-void
-GLVideoView::set_crop_guess_colour(GLuint program)
-{
- auto uniform = glGetUniformLocation(program, "crop_guess_colour");
- check_gl_error("glGetUniformLocation");
- auto colour = crop_guess_colour();
- glUniform4f(uniform, colour.Red() / 255.0f, colour.Green() / 255.0f, colour.Blue() / 255.0f, 1.0f);
- check_gl_error("glUniform4f");
-}
-
-
-void
GLVideoView::draw()
{
auto pv = player_video().first;
@@ -380,13 +364,13 @@ GLVideoView::draw()
}
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();
@@ -394,16 +378,16 @@ GLVideoView::draw()
_image.draw();
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();
_subtitle.draw();
}
if (_viewer->outline_content()) {
- glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::OUTLINE_CONTENT));
+ _fragment_type.set(static_cast<GLint>(FragmentType::OUTLINE_CONTENT));
_outline_content.draw();
}
if (auto guess = _viewer->crop_guess()) {
- glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::CROP_GUESS));
+ _fragment_type.set(static_cast<GLint>(FragmentType::CROP_GUESS));
_crop_guess.draw();
}
diff --git a/src/wx/gl_video_view.h b/src/wx/gl_video_view.h
index b6cd92c27..dddcbff48 100644
--- a/src/wx/gl_video_view.h
+++ b/src/wx/gl_video_view.h
@@ -71,8 +71,6 @@ private:
void set_image(std::shared_ptr<const PlayerVideo> pv);
void check_for_butler_errors();
void ensure_context();
- void set_outline_content_colour(GLuint program);
- void set_crop_guess_colour(GLuint program);
void setup_shaders();
void create_textures();
@@ -121,7 +119,7 @@ private:
dcpomatic::gl::Coords::OutlineRectangle _crop_guess;
dcpomatic::gl::Coords::FilledRectangle _subtitle;
- GLint _fragment_type;
+ dcpomatic::gl::Uniform1i _fragment_type;
std::shared_ptr<wxTimer> _timer;