diff --git a/src/qt/qt_opengloptions.cpp b/src/qt/qt_opengloptions.cpp index 995fd8401..720d61ef7 100644 --- a/src/qt/qt_opengloptions.cpp +++ b/src/qt/qt_opengloptions.cpp @@ -72,14 +72,14 @@ OpenGLOptions::OpenGLOptions(QObject *parent, bool loadConfig) } void -OpenGLOptions::save() +OpenGLOptions::save() const { video_vsync = m_vsync ? 1 : 0; video_framerate = m_renderBehavior == RenderBehaviorType::SyncWithVideo ? -1 : m_framerate; video_filter_method = m_filter == FilterType::Nearest ? 0 : 1; /* TODO: multiple shaders */ - auto path = m_shaders.first().path.toLocal8Bit(); + auto path = m_shaders.first().path().toLocal8Bit(); if (!path.isEmpty()) memcpy(video_shader, path.constData(), path.size()); diff --git a/src/qt/qt_opengloptions.hpp b/src/qt/qt_opengloptions.hpp index 728b3c4fd..d28b388ba 100644 --- a/src/qt/qt_opengloptions.hpp +++ b/src/qt/qt_opengloptions.hpp @@ -21,31 +21,44 @@ #include #include -struct OpenGLShaderPass { +class OpenGLShaderPass { +public: OpenGLShaderPass(QOpenGLShaderProgram *shader, const QString &path) - : shader(shader) - , path(path) - , vertex_coord(shader->attributeLocation("VertexCoord")) - , tex_coord(shader->attributeLocation("TexCoord")) - , color(shader->attributeLocation("Color")) - , mvp_matrix(shader->uniformLocation("MVPMatrix")) - , input_size(shader->uniformLocation("InputSize")) - , output_size(shader->uniformLocation("OutputSize")) - , texture_size(shader->uniformLocation("TextureSize")) - , frame_count(shader->uniformLocation("FrameCount")) + : m_shader(shader) + , m_path(path) + , m_vertex_coord(shader->attributeLocation("VertexCoord")) + , m_tex_coord(shader->attributeLocation("TexCoord")) + , m_color(shader->attributeLocation("Color")) + , m_mvp_matrix(shader->uniformLocation("MVPMatrix")) + , m_input_size(shader->uniformLocation("InputSize")) + , m_output_size(shader->uniformLocation("OutputSize")) + , m_texture_size(shader->uniformLocation("TextureSize")) + , m_frame_count(shader->uniformLocation("FrameCount")) { } - QOpenGLShaderProgram *shader; - const QString path; - const GLint vertex_coord; - const GLint tex_coord; - const GLint color; - const GLint mvp_matrix; - const GLint input_size; - const GLint output_size; - const GLint texture_size; - const GLint frame_count; + bool bind() const { return m_shader->bind(); } + const QString &path() const { return m_path; } + const GLint &vertex_coord() const { return m_vertex_coord; } + const GLint &tex_coord() const { return m_tex_coord; } + const GLint &color() const { return m_color; } + const GLint &mvp_matrix() const { return m_mvp_matrix; } + const GLint &input_size() const { return m_input_size; } + const GLint &output_size() const { return m_output_size; } + const GLint &texture_size() const { return m_texture_size; } + const GLint &frame_count() const { return m_frame_count; } + +private: + QOpenGLShaderProgram *m_shader; + QString m_path; + GLint m_vertex_coord; + GLint m_tex_coord; + GLint m_color; + GLint m_mvp_matrix; + GLint m_input_size; + GLint m_output_size; + GLint m_texture_size; + GLint m_frame_count; }; class OpenGLOptions : public QObject { @@ -65,7 +78,7 @@ public: bool vSync() const { return m_vsync; } FilterType filter() const; - QList shaders() const { return m_shaders; }; + const QList &shaders() const { return m_shaders; }; void setRenderBehavior(RenderBehaviorType value); void setFrameRate(int value); @@ -73,7 +86,7 @@ public: void setFilter(FilterType value); void addShader(const QString &path); void addDefaultShader(); - void save(); + void save() const; private: RenderBehaviorType m_renderBehavior = SyncWithVideo; diff --git a/src/qt/qt_opengloptionsdialog.cpp b/src/qt/qt_opengloptionsdialog.cpp index 4503e0b90..424b6468b 100644 --- a/src/qt/qt_opengloptionsdialog.cpp +++ b/src/qt/qt_opengloptionsdialog.cpp @@ -40,7 +40,7 @@ OpenGLOptionsDialog::OpenGLOptionsDialog(QWidget *parent, const OpenGLOptions &o ui->vsync->setChecked(options.vSync()); if (!options.shaders().isEmpty()) { - auto path = options.shaders().first().path; + auto path = options.shaders().first().path(); if (!path.isEmpty()) ui->shader->setPlainText(path); } diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index c864d88e5..b7bf8628f 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -281,45 +281,45 @@ OpenGLRenderer::applyOptions() void OpenGLRenderer::applyShader(const OpenGLShaderPass &shader) { - if (!shader.shader->bind()) + if (!shader.bind()) return; - if (shader.vertex_coord != -1) { - glEnableVertexAttribArray(shader.vertex_coord); - glVertexAttribPointer(shader.vertex_coord, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0); + if (shader.vertex_coord() != -1) { + glEnableVertexAttribArray(shader.vertex_coord()); + glVertexAttribPointer(shader.vertex_coord(), 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0); } - if (shader.tex_coord != -1) { - glEnableVertexAttribArray(shader.tex_coord); - glVertexAttribPointer(shader.tex_coord, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *) (2 * sizeof(GLfloat))); + if (shader.tex_coord() != -1) { + glEnableVertexAttribArray(shader.tex_coord()); + glVertexAttribPointer(shader.tex_coord(), 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *) (2 * sizeof(GLfloat))); } - if (shader.color != -1) { - glEnableVertexAttribArray(shader.color); - glVertexAttribPointer(shader.color, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *) (4 * sizeof(GLfloat))); + if (shader.color() != -1) { + glEnableVertexAttribArray(shader.color()); + glVertexAttribPointer(shader.color(), 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *) (4 * sizeof(GLfloat))); } - if (shader.mvp_matrix != -1) { + if (shader.mvp_matrix() != -1) { static const GLfloat mvp[] = { 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f }; - glUniformMatrix4fv(shader.mvp_matrix, 1, GL_FALSE, mvp); + glUniformMatrix4fv(shader.mvp_matrix(), 1, GL_FALSE, mvp); } - if (shader.output_size != -1) - glUniform2f(shader.output_size, destination.width(), destination.height()); + if (shader.output_size() != -1) + glUniform2f(shader.output_size(), destination.width(), destination.height()); - if (shader.input_size != -1) - glUniform2f(shader.input_size, source.width(), source.height()); + if (shader.input_size() != -1) + glUniform2f(shader.input_size(), source.width(), source.height()); - if (shader.texture_size != -1) - glUniform2f(shader.texture_size, source.width(), source.height()); + if (shader.texture_size() != -1) + glUniform2f(shader.texture_size(), source.width(), source.height()); - if (shader.frame_count != -1) - glUniform1i(shader.frame_count, frameCounter); + if (shader.frame_count() != -1) + glUniform1i(shader.frame_count(), frameCounter); } void