qt: Remove QFlags from OpenGLOptions.
Didn't work in ubuntu and was a bad design attempt to mimic win32 options change detection.
This commit is contained in:
@@ -69,8 +69,6 @@ OpenGLOptions::OpenGLOptions(QObject *parent, bool loadConfig)
|
|||||||
addDefaultShader();
|
addDefaultShader();
|
||||||
else
|
else
|
||||||
addShader(shaderPath);
|
addShader(shaderPath);
|
||||||
|
|
||||||
m_modified = ~ModifiedFlags {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -89,56 +87,37 @@ OpenGLOptions::save()
|
|||||||
video_shader[0] = '\0';
|
video_shader[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
OpenGLOptions::FilterType
|
||||||
OpenGLOptions::isModified()
|
OpenGLOptions::filter() const
|
||||||
{
|
{
|
||||||
/* Filter method is controlled externally */
|
/* Filter method is controlled externally */
|
||||||
auto newfilter = video_filter_method == 0
|
return video_filter_method == 0
|
||||||
? FilterType::Nearest
|
? FilterType::Nearest
|
||||||
: FilterType::Linear;
|
: 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
|
void
|
||||||
OpenGLOptions::setRenderBehavior(RenderBehaviorType value)
|
OpenGLOptions::setRenderBehavior(RenderBehaviorType value)
|
||||||
{
|
{
|
||||||
m_renderBehavior = value;
|
m_renderBehavior = value;
|
||||||
m_modified.setFlag(ModifiedFlag::RenderBehaviorModified);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
OpenGLOptions::setFrameRate(int value)
|
OpenGLOptions::setFrameRate(int value)
|
||||||
{
|
{
|
||||||
m_framerate = value;
|
m_framerate = value;
|
||||||
m_modified.setFlag(ModifiedFlag::FrameRateModified);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
OpenGLOptions::setVSync(bool value)
|
OpenGLOptions::setVSync(bool value)
|
||||||
{
|
{
|
||||||
m_vsync = value;
|
m_vsync = value;
|
||||||
m_modified.setFlag(ModifiedFlag::VsyncModified);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
OpenGLOptions::setFilter(FilterType value)
|
OpenGLOptions::setFilter(FilterType value)
|
||||||
{
|
{
|
||||||
m_filter = value;
|
m_filter = value;
|
||||||
m_modified.setFlag(ModifiedFlag::FilterModified);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -190,8 +169,6 @@ OpenGLOptions::addShader(const QString &path)
|
|||||||
throw_shader_error(tr("Error linking shader program in file \"%1\""));
|
throw_shader_error(tr("Error linking shader program in file \"%1\""));
|
||||||
|
|
||||||
m_shaders << OpenGLShaderPass(shader, path);
|
m_shaders << OpenGLShaderPass(shader, path);
|
||||||
|
|
||||||
m_modified.setFlag(ModifiedFlag::ShadersModified);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -202,6 +179,4 @@ OpenGLOptions::addDefaultShader()
|
|||||||
shader->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader);
|
shader->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader);
|
||||||
shader->link();
|
shader->link();
|
||||||
m_shaders << OpenGLShaderPass(shader, QString());
|
m_shaders << OpenGLShaderPass(shader, QString());
|
||||||
|
|
||||||
m_modified.setFlag(ModifiedFlag::ShadersModified);
|
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,6 @@
|
|||||||
#ifndef QT_OPENGLOPTIONS_HPP
|
#ifndef QT_OPENGLOPTIONS_HPP
|
||||||
#define QT_OPENGLOPTIONS_HPP
|
#define QT_OPENGLOPTIONS_HPP
|
||||||
|
|
||||||
#include <QFLags>
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
@@ -53,15 +52,6 @@ class OpenGLOptions : public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ModifiedFlag {
|
|
||||||
RenderBehaviorModified = 0x01,
|
|
||||||
FrameRateModified = 0x02,
|
|
||||||
VsyncModified = 0x04,
|
|
||||||
FilterModified = 0x08,
|
|
||||||
ShadersModified = 0x10
|
|
||||||
};
|
|
||||||
Q_DECLARE_FLAGS(ModifiedFlags, ModifiedFlag)
|
|
||||||
|
|
||||||
enum RenderBehaviorType { SyncWithVideo,
|
enum RenderBehaviorType { SyncWithVideo,
|
||||||
TargetFramerate };
|
TargetFramerate };
|
||||||
|
|
||||||
@@ -70,14 +60,10 @@ public:
|
|||||||
|
|
||||||
OpenGLOptions(QObject *parent = nullptr, bool loadConfig = false);
|
OpenGLOptions(QObject *parent = nullptr, bool loadConfig = false);
|
||||||
|
|
||||||
void save();
|
|
||||||
bool isModified();
|
|
||||||
ModifiedFlags modified();
|
|
||||||
|
|
||||||
RenderBehaviorType renderBehavior() const { return m_renderBehavior; }
|
RenderBehaviorType renderBehavior() const { return m_renderBehavior; }
|
||||||
int framerate() const { return m_framerate; }
|
int framerate() const { return m_framerate; }
|
||||||
bool vSync() const { return m_vsync; }
|
bool vSync() const { return m_vsync; }
|
||||||
FilterType filter() const { return m_filter; }
|
FilterType filter() const;
|
||||||
|
|
||||||
QList<OpenGLShaderPass> shaders() const { return m_shaders; };
|
QList<OpenGLShaderPass> shaders() const { return m_shaders; };
|
||||||
|
|
||||||
@@ -85,19 +71,16 @@ public:
|
|||||||
void setFrameRate(int value);
|
void setFrameRate(int value);
|
||||||
void setVSync(bool value);
|
void setVSync(bool value);
|
||||||
void setFilter(FilterType value);
|
void setFilter(FilterType value);
|
||||||
|
|
||||||
void addShader(const QString &path);
|
void addShader(const QString &path);
|
||||||
void addDefaultShader();
|
void addDefaultShader();
|
||||||
|
void save();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RenderBehaviorType m_renderBehavior = SyncWithVideo;
|
RenderBehaviorType m_renderBehavior = SyncWithVideo;
|
||||||
int m_framerate = -1;
|
int m_framerate = -1;
|
||||||
bool m_vsync = false;
|
bool m_vsync = false;
|
||||||
FilterType m_filter = Nearest;
|
FilterType m_filter = Nearest;
|
||||||
ModifiedFlags m_modified = {};
|
|
||||||
QList<OpenGLShaderPass> m_shaders;
|
QList<OpenGLShaderPass> m_shaders;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(OpenGLOptions::ModifiedFlags)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -250,34 +250,32 @@ OpenGLRenderer::setupBuffers()
|
|||||||
void
|
void
|
||||||
OpenGLRenderer::applyOptions()
|
OpenGLRenderer::applyOptions()
|
||||||
{
|
{
|
||||||
/* TODO: make something else; this was a bad idea. */
|
/* TODO: change detection in options */
|
||||||
|
|
||||||
auto modified = options->modified();
|
if (options->framerate() > 0) {
|
||||||
|
|
||||||
if (modified.testFlag(OpenGLOptions::FrameRateModified) && options->framerate() > 0) {
|
|
||||||
int interval = (int) ceilf(1000.f / (float) options->framerate());
|
int interval = (int) ceilf(1000.f / (float) options->framerate());
|
||||||
renderTimer->setInterval(std::chrono::milliseconds(interval));
|
renderTimer->setInterval(std::chrono::milliseconds(interval));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modified.testFlag(OpenGLOptions::RenderBehaviorModified)) {
|
if (options->renderBehavior() == OpenGLOptions::TargetFramerate)
|
||||||
if (options->renderBehavior() == OpenGLOptions::TargetFramerate)
|
renderTimer->start();
|
||||||
renderTimer->start();
|
else
|
||||||
else
|
renderTimer->stop();
|
||||||
renderTimer->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (modified.testFlag(OpenGLOptions::VsyncModified)) {
|
auto format = this->format();
|
||||||
auto format = this->format();
|
int interval = options->vSync() ? 1 : 0;
|
||||||
format.setSwapInterval(options->vSync() ? 1 : 0);
|
|
||||||
|
if (format.swapInterval() != interval) {
|
||||||
|
format.setSwapInterval(interval);
|
||||||
setFormat(format);
|
setFormat(format);
|
||||||
context->setFormat(format);
|
context->setFormat(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modified.testFlag(OpenGLOptions::FilterModified)) {
|
GLint filter = options->filter() == OpenGLOptions::Linear ? GL_LINEAR : GL_NEAREST;
|
||||||
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_MIN_FILTER, filter);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
|
||||||
}
|
currentFilter = options->filter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -329,7 +327,7 @@ OpenGLRenderer::render()
|
|||||||
{
|
{
|
||||||
context->makeCurrent(this);
|
context->makeCurrent(this);
|
||||||
|
|
||||||
if (options->isModified())
|
if (options->filter() != currentFilter)
|
||||||
applyOptions();
|
applyOptions();
|
||||||
|
|
||||||
/* TODO: multiple shader passes */
|
/* TODO: multiple shader passes */
|
||||||
|
@@ -79,6 +79,8 @@ private:
|
|||||||
GLuint textureID = 0;
|
GLuint textureID = 0;
|
||||||
int frameCounter = 0;
|
int frameCounter = 0;
|
||||||
|
|
||||||
|
OpenGLOptions::FilterType currentFilter;
|
||||||
|
|
||||||
void *unpackBuffer = nullptr;
|
void *unpackBuffer = nullptr;
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
Reference in New Issue
Block a user