default unlimit fps, vsync flag

This commit is contained in:
Бычков Андрей
2022-10-12 14:35:01 +03:00
parent c865f9fc94
commit 3b0d1ea0e2
7 changed files with 119 additions and 100 deletions

View File

@@ -72,7 +72,7 @@ public:
public slots: public slots:
void stop(); void stop();
void start(float freq = 60.0); void start(float freq = 0.0);
void setBackColor(const QColor & c); void setBackColor(const QColor & c);
void setLineWidth(const qreal & arg); void setLineWidth(const qreal & arg);
void setFOV(const qreal & arg); void setFOV(const qreal & arg);

View File

@@ -1,72 +1,26 @@
/*
QGL OpenGLWindow
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "openglwindow.h" #include "openglwindow.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QOpenGLPaintDevice> #include <QOpenGLPaintDevice>
#include <QPainter> #include <QPainter>
#include <qopenglext.h>
OpenGLWindow::OpenGLWindow(QWindow *parent) OpenGLWindow::OpenGLWindow(QWindow *parent) : QWindow(parent) {
: QWindow(parent)
, m_context(nullptr)
, m_device(nullptr)
{
setFlags(flags() | Qt::FramelessWindowHint); setFlags(flags() | Qt::FramelessWindowHint);
setSurfaceType(QWindow::OpenGLSurface); setSurfaceType(QWindow::OpenGLSurface);
QSurfaceFormat format = QSurfaceFormat::defaultFormat(); QSurfaceFormat format = QSurfaceFormat::defaultFormat();
// qDebug() << format;
#ifdef QT_OPENGL_ES_2 #ifdef QT_OPENGL_ES_2
format.setRenderableType(QSurfaceFormat::OpenGLES); format.setRenderableType(QSurfaceFormat::OpenGLES);
#else #else
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
format.setVersion(4, 0); format.setVersion(2, 0);
format.setProfile(QSurfaceFormat::CoreProfile); format.setProfile(QSurfaceFormat::NoProfile);
} }
#endif #endif
format.setDepthBufferSize(24); format.setDepthBufferSize(24);
format.setSamples(8); format.setSamples(8);
setFormat(format); setFormat(format);
QSurfaceFormat::setDefaultFormat(format);
}
OpenGLWindow::~OpenGLWindow() {
delete m_device;
}
void OpenGLWindow::render(QPainter *painter) {
}
void OpenGLWindow::initialize() {
}
void OpenGLWindow::render() {
// if (!m_device) m_device = new QOpenGLPaintDevice;
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// m_device->setSize(size() * devicePixelRatio());
// m_device->setDevicePixelRatio(devicePixelRatio());
// QPainter painter(m_device);
// render(&painter);
} }
@@ -77,10 +31,10 @@ void OpenGLWindow::renderLater() {
bool OpenGLWindow::event(QEvent *event) { bool OpenGLWindow::event(QEvent *event) {
switch (event->type()) { switch (event->type()) {
case QEvent::UpdateRequest: case QEvent::UpdateRequest:
renderNow(); renderNow();
return true; return true;
default: default:
return QWindow::event(event); return QWindow::event(event);
} }
} }
@@ -91,15 +45,54 @@ void OpenGLWindow::exposeEvent(QExposeEvent *event) {
} }
void OpenGLWindow::setVSync(bool on) {
QSurfaceFormat f = requestedFormat();
if (on) {
if (f.swapInterval() != 1) {
f.setSwapInterval(1);
setFormat(f);
format_change = true;
}
} else {
if (f.swapInterval() != 0) {
f.setSwapInterval(0);
setFormat(f);
format_change = true;
}
}
}
bool OpenGLWindow::getVSync() const {
return (requestedFormat().swapInterval() == 1);
}
void OpenGLWindow::setSamples(int samples) {
QSurfaceFormat f = requestedFormat();
if (f.samples() != samples) {
f.setSamples(samples);
setFormat(f);
format_change = true;
}
}
int OpenGLWindow::getSamples() const {
return requestedFormat().samples();
}
void OpenGLWindow::renderNow() { void OpenGLWindow::renderNow() {
if (!isExposed()) if (!isExposed()) return;
return;
bool needsInitialize = false; bool needsInitialize = false;
if (!m_context) { if (!m_context || format_change) {
if (m_context) delete m_context;
m_context = new QOpenGLContext(this); m_context = new QOpenGLContext(this);
m_context->setFormat(requestedFormat()); m_context->setFormat(requestedFormat());
m_context->create(); m_context->create();
needsInitialize = true; needsInitialize = true;
format_change = false;
} }
m_context->makeCurrent(this); m_context->makeCurrent(this);
if (needsInitialize) { if (needsInitialize) {
@@ -108,5 +101,6 @@ void OpenGLWindow::renderNow() {
} }
render(); render();
m_context->swapBuffers(this); m_context->swapBuffers(this);
frame_cnt++;
} }

View File

@@ -1,21 +1,3 @@
/*
QGL OpenGLWindow
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QWindow> #include <QWindow>
#include <QOpenGLExtraFunctions> #include <QOpenGLExtraFunctions>
@@ -24,17 +6,21 @@ class QOpenGLContext;
class QOpenGLPaintDevice; class QOpenGLPaintDevice;
class OpenGLWindow: public QWindow, public QOpenGLExtraFunctions class OpenGLWindow : public QWindow, public QOpenGLExtraFunctions {
{
Q_OBJECT Q_OBJECT
public: public:
explicit OpenGLWindow(QWindow *parent = nullptr); explicit OpenGLWindow(QWindow *parent = nullptr);
~OpenGLWindow(); virtual ~OpenGLWindow() {}
virtual void render() {}
virtual void initialize() {}
virtual void render(QPainter *painter);
virtual void render();
virtual void initialize();
QOpenGLContext * context() {return m_context;} QOpenGLContext * context() {return m_context;}
void setVSync(bool on);
bool getVSync() const;
void setSamples(int samples);
int getSamples() const;
int getFrameCounter() const {return frame_cnt;}
public slots: public slots:
void renderLater(); void renderLater();
@@ -45,7 +31,8 @@ protected:
void exposeEvent(QExposeEvent *event) override; void exposeEvent(QExposeEvent *event) override;
private: private:
QOpenGLContext *m_context; QOpenGLContext * m_context = nullptr;
QOpenGLPaintDevice *m_device; bool format_change = false;
int frame_cnt = 0;
}; };

View File

@@ -100,7 +100,7 @@ public:
Q_ENUM(CameraLightMode) Q_ENUM(CameraLightMode)
void stop(); void stop();
void start(float freq = 60.); void start(float freq = 0.);
QColor backColor() const {return backColor_;} QColor backColor() const {return backColor_;}
float lineWidth() const {return lineWidth_;} float lineWidth() const {return lineWidth_;}

View File

@@ -53,6 +53,8 @@ void ViewEditor::assignQGLView(QGLView * v) {
ui->checkService->setChecked(view->isServiceMode()); ui->checkService->setChecked(view->isServiceMode());
ui->lineHDR->setProperty("GLpath", view->environmentMapFile()); ui->lineHDR->setProperty("GLpath", view->environmentMapFile());
ui->lineHDR->setText(QFileInfo(view->environmentMapFile()).fileName()); ui->lineHDR->setText(QFileInfo(view->environmentMapFile()).fileName());
ui->checkVSync->setChecked(view->getVSync());
ui->spinSamples->setValue(view->getSamples());
active = true; active = true;
} }
@@ -177,3 +179,14 @@ void ViewEditor::on_buttonHDRSelect_clicked() {
ui->lineHDR->setProperty("GLpath", str); ui->lineHDR->setProperty("GLpath", str);
view->setEnvironmentMapFile(str); view->setEnvironmentMapFile(str);
} }
void ViewEditor::on_checkVSync_clicked(bool val) {
view->setVSync(val);
}
void ViewEditor::on_spinSamples_valueChanged(int arg1) {
view->setSamples(arg1);
}

View File

@@ -57,11 +57,10 @@ private slots:
void on_checkCameraOrbit_clicked(bool val); void on_checkCameraOrbit_clicked(bool val);
void on_checkService_clicked(bool val); void on_checkService_clicked(bool val);
void on_checkCameraLight_stateChanged(int s); void on_checkCameraLight_stateChanged(int s);
void on_checkVSync_clicked(bool val);
void on_spinSamples_valueChanged(int arg1);
void on_buttonHDRClear_clicked(); void on_buttonHDRClear_clicked();
void on_buttonHDRSelect_clicked(); void on_buttonHDRSelect_clicked();
signals:
}; };
#endif // VIEW_EDITOR_H #endif // VIEW_EDITOR_H

View File

@@ -117,7 +117,7 @@
<item> <item>
<widget class="QToolButton" name="buttonHDRClear"> <widget class="QToolButton" name="buttonHDRClear">
<property name="icon"> <property name="icon">
<iconset resource="../../qad/utils/qad_utils.qrc"> <iconset resource="../../qad/libs/blockview/qad_blockview.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset> <normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property> </property>
</widget> </widget>
@@ -125,7 +125,7 @@
<item> <item>
<widget class="QToolButton" name="buttonHDRSelect"> <widget class="QToolButton" name="buttonHDRSelect">
<property name="icon"> <property name="icon">
<iconset resource="../../qad/application/qad_application.qrc"> <iconset resource="../../qad/libs/blockview/qad_blockview.qrc">
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset> <normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
</property> </property>
</widget> </widget>
@@ -137,6 +137,26 @@
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QCheckBox" name="checkCameraLight">
<property name="text">
<string>Camera light</string>
</property>
<property name="tristate">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkService">
<property name="text">
<string>Service mode</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QCheckBox" name="checkFXAA"> <widget class="QCheckBox" name="checkFXAA">
<property name="text"> <property name="text">
@@ -151,23 +171,29 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="2" column="0">
<widget class="QCheckBox" name="checkService"> <widget class="QCheckBox" name="checkVSync">
<property name="text"> <property name="text">
<string>Service mode</string> <string>VSync</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="2" column="1">
<widget class="QCheckBox" name="checkCameraLight"> <widget class="QSpinBox" name="spinSamples">
<property name="text"> <property name="prefix">
<string>Camera light</string> <string>Samples: </string>
</property> </property>
<property name="tristate"> <property name="minimum">
<bool>true</bool> <number>-1</number>
</property>
<property name="maximum">
<number>16</number>
</property>
<property name="value">
<number>-1</number>
</property> </property>
</widget> </widget>
</item> </item>
@@ -504,8 +530,8 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../../qad/utils/qad_utils.qrc"/> <include location="../../qad/libs/blockview/qad_blockview.qrc"/>
<include location="../../qad/application/qad_application.qrc"/> <include location="../../qad/libs/blockview/qad_blockview.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>