diff --git a/src/qt/qt_opengloptions.cpp b/src/qt/qt_opengloptions.cpp index 1f2460794..995fd8401 100644 --- a/src/qt/qt_opengloptions.cpp +++ b/src/qt/qt_opengloptions.cpp @@ -69,8 +69,6 @@ OpenGLOptions::OpenGLOptions(QObject *parent, bool loadConfig) addDefaultShader(); else addShader(shaderPath); - - m_modified = ~ModifiedFlags {}; } void @@ -89,56 +87,37 @@ OpenGLOptions::save() video_shader[0] = '\0'; } -bool -OpenGLOptions::isModified() +OpenGLOptions::FilterType +OpenGLOptions::filter() const { /* Filter method is controlled externally */ - auto newfilter = video_filter_method == 0 + return video_filter_method == 0 ? FilterType::Nearest : FilterType::Linear; - - if (m_filter != newfilter) { - m_filter = newfilter; - m_modified.setFlag(ModifiedFlag::FilterModified); - } - - return m_modified != ModifiedFlags {}; -} - -OpenGLOptions::ModifiedFlags -OpenGLOptions::modified() -{ - ModifiedFlags temp {}; - std::swap(temp, m_modified); - return temp; } void OpenGLOptions::setRenderBehavior(RenderBehaviorType value) { m_renderBehavior = value; - m_modified.setFlag(ModifiedFlag::RenderBehaviorModified); } void OpenGLOptions::setFrameRate(int value) { m_framerate = value; - m_modified.setFlag(ModifiedFlag::FrameRateModified); } void OpenGLOptions::setVSync(bool value) { m_vsync = value; - m_modified.setFlag(ModifiedFlag::VsyncModified); } void OpenGLOptions::setFilter(FilterType value) { m_filter = value; - m_modified.setFlag(ModifiedFlag::FilterModified); } void @@ -190,8 +169,6 @@ OpenGLOptions::addShader(const QString &path) throw_shader_error(tr("Error linking shader program in file \"%1\"")); m_shaders << OpenGLShaderPass(shader, path); - - m_modified.setFlag(ModifiedFlag::ShadersModified); } void @@ -202,6 +179,4 @@ OpenGLOptions::addDefaultShader() shader->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader); shader->link(); m_shaders << OpenGLShaderPass(shader, QString()); - - m_modified.setFlag(ModifiedFlag::ShadersModified); } diff --git a/src/qt/qt_opengloptions.hpp b/src/qt/qt_opengloptions.hpp index 2cbb1f2b2..728b3c4fd 100644 --- a/src/qt/qt_opengloptions.hpp +++ b/src/qt/qt_opengloptions.hpp @@ -17,7 +17,6 @@ #ifndef QT_OPENGLOPTIONS_HPP #define QT_OPENGLOPTIONS_HPP -#include #include #include #include @@ -53,15 +52,6 @@ class OpenGLOptions : public QObject { Q_OBJECT public: - enum ModifiedFlag { - RenderBehaviorModified = 0x01, - FrameRateModified = 0x02, - VsyncModified = 0x04, - FilterModified = 0x08, - ShadersModified = 0x10 - }; - Q_DECLARE_FLAGS(ModifiedFlags, ModifiedFlag) - enum RenderBehaviorType { SyncWithVideo, TargetFramerate }; @@ -70,14 +60,10 @@ public: OpenGLOptions(QObject *parent = nullptr, bool loadConfig = false); - void save(); - bool isModified(); - ModifiedFlags modified(); - RenderBehaviorType renderBehavior() const { return m_renderBehavior; } int framerate() const { return m_framerate; } bool vSync() const { return m_vsync; } - FilterType filter() const { return m_filter; } + FilterType filter() const; QList shaders() const { return m_shaders; }; @@ -85,19 +71,16 @@ public: void setFrameRate(int value); void setVSync(bool value); void setFilter(FilterType value); - void addShader(const QString &path); void addDefaultShader(); + void save(); private: RenderBehaviorType m_renderBehavior = SyncWithVideo; int m_framerate = -1; bool m_vsync = false; FilterType m_filter = Nearest; - ModifiedFlags m_modified = {}; QList m_shaders; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(OpenGLOptions::ModifiedFlags) - #endif diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 206cf0a69..c864d88e5 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -250,34 +250,32 @@ OpenGLRenderer::setupBuffers() void OpenGLRenderer::applyOptions() { - /* TODO: make something else; this was a bad idea. */ + /* TODO: change detection in options */ - auto modified = options->modified(); - - if (modified.testFlag(OpenGLOptions::FrameRateModified) && options->framerate() > 0) { + if (options->framerate() > 0) { int interval = (int) ceilf(1000.f / (float) options->framerate()); renderTimer->setInterval(std::chrono::milliseconds(interval)); } - if (modified.testFlag(OpenGLOptions::RenderBehaviorModified)) { - if (options->renderBehavior() == OpenGLOptions::TargetFramerate) - renderTimer->start(); - else - renderTimer->stop(); - } + if (options->renderBehavior() == OpenGLOptions::TargetFramerate) + renderTimer->start(); + else + renderTimer->stop(); - if (modified.testFlag(OpenGLOptions::VsyncModified)) { - auto format = this->format(); - format.setSwapInterval(options->vSync() ? 1 : 0); + auto format = this->format(); + int interval = options->vSync() ? 1 : 0; + + if (format.swapInterval() != interval) { + format.setSwapInterval(interval); setFormat(format); context->setFormat(format); } - if (modified.testFlag(OpenGLOptions::FilterModified)) { - GLint filter = options->filter() == OpenGLOptions::Linear ? GL_LINEAR : GL_NEAREST; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); - } + GLint filter = options->filter() == OpenGLOptions::Linear ? GL_LINEAR : GL_NEAREST; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); + + currentFilter = options->filter(); } void @@ -329,7 +327,7 @@ OpenGLRenderer::render() { context->makeCurrent(this); - if (options->isModified()) + if (options->filter() != currentFilter) applyOptions(); /* TODO: multiple shader passes */ diff --git a/src/qt/qt_openglrenderer.hpp b/src/qt/qt_openglrenderer.hpp index 1d8bc036d..d22bcb82c 100644 --- a/src/qt/qt_openglrenderer.hpp +++ b/src/qt/qt_openglrenderer.hpp @@ -79,6 +79,8 @@ private: GLuint textureID = 0; int frameCounter = 0; + OpenGLOptions::FilterType currentFilter; + void *unpackBuffer = nullptr; void initialize();