default unlimit fps, vsync flag
This commit is contained in:
@@ -72,7 +72,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void stop();
|
||||
void start(float freq = 60.0);
|
||||
void start(float freq = 0.0);
|
||||
void setBackColor(const QColor & c);
|
||||
void setLineWidth(const qreal & arg);
|
||||
void setFOV(const qreal & arg);
|
||||
|
||||
100
openglwindow.cpp
100
openglwindow.cpp
@@ -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 <QCoreApplication>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLPaintDevice>
|
||||
#include <QPainter>
|
||||
#include <qopenglext.h>
|
||||
|
||||
|
||||
OpenGLWindow::OpenGLWindow(QWindow *parent)
|
||||
: QWindow(parent)
|
||||
, m_context(nullptr)
|
||||
, m_device(nullptr)
|
||||
{
|
||||
OpenGLWindow::OpenGLWindow(QWindow *parent) : QWindow(parent) {
|
||||
setFlags(flags() | Qt::FramelessWindowHint);
|
||||
setSurfaceType(QWindow::OpenGLSurface);
|
||||
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
|
||||
// qDebug() << format;
|
||||
#ifdef QT_OPENGL_ES_2
|
||||
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
#else
|
||||
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
|
||||
format.setVersion(4, 0);
|
||||
format.setProfile(QSurfaceFormat::CoreProfile);
|
||||
format.setVersion(2, 0);
|
||||
format.setProfile(QSurfaceFormat::NoProfile);
|
||||
}
|
||||
#endif
|
||||
format.setDepthBufferSize(24);
|
||||
format.setSamples(8);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
if (!isExposed())
|
||||
return;
|
||||
if (!isExposed()) return;
|
||||
bool needsInitialize = false;
|
||||
if (!m_context) {
|
||||
if (!m_context || format_change) {
|
||||
if (m_context) delete m_context;
|
||||
m_context = new QOpenGLContext(this);
|
||||
m_context->setFormat(requestedFormat());
|
||||
m_context->create();
|
||||
needsInitialize = true;
|
||||
format_change = false;
|
||||
}
|
||||
m_context->makeCurrent(this);
|
||||
if (needsInitialize) {
|
||||
@@ -108,5 +101,6 @@ void OpenGLWindow::renderNow() {
|
||||
}
|
||||
render();
|
||||
m_context->swapBuffers(this);
|
||||
frame_cnt++;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <QOpenGLExtraFunctions>
|
||||
|
||||
@@ -24,17 +6,21 @@ class QOpenGLContext;
|
||||
class QOpenGLPaintDevice;
|
||||
|
||||
|
||||
class OpenGLWindow: public QWindow, public QOpenGLExtraFunctions
|
||||
{
|
||||
class OpenGLWindow : public QWindow, public QOpenGLExtraFunctions {
|
||||
Q_OBJECT
|
||||
public:
|
||||
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;}
|
||||
void setVSync(bool on);
|
||||
bool getVSync() const;
|
||||
void setSamples(int samples);
|
||||
int getSamples() const;
|
||||
int getFrameCounter() const {return frame_cnt;}
|
||||
|
||||
public slots:
|
||||
void renderLater();
|
||||
@@ -45,7 +31,8 @@ protected:
|
||||
void exposeEvent(QExposeEvent *event) override;
|
||||
|
||||
private:
|
||||
QOpenGLContext *m_context;
|
||||
QOpenGLPaintDevice *m_device;
|
||||
QOpenGLContext * m_context = nullptr;
|
||||
bool format_change = false;
|
||||
int frame_cnt = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
Q_ENUM(CameraLightMode)
|
||||
|
||||
void stop();
|
||||
void start(float freq = 60.);
|
||||
void start(float freq = 0.);
|
||||
|
||||
QColor backColor() const {return backColor_;}
|
||||
float lineWidth() const {return lineWidth_;}
|
||||
|
||||
@@ -53,6 +53,8 @@ void ViewEditor::assignQGLView(QGLView * v) {
|
||||
ui->checkService->setChecked(view->isServiceMode());
|
||||
ui->lineHDR->setProperty("GLpath", view->environmentMapFile());
|
||||
ui->lineHDR->setText(QFileInfo(view->environmentMapFile()).fileName());
|
||||
ui->checkVSync->setChecked(view->getVSync());
|
||||
ui->spinSamples->setValue(view->getSamples());
|
||||
active = true;
|
||||
}
|
||||
|
||||
@@ -177,3 +179,14 @@ void ViewEditor::on_buttonHDRSelect_clicked() {
|
||||
ui->lineHDR->setProperty("GLpath", str);
|
||||
view->setEnvironmentMapFile(str);
|
||||
}
|
||||
|
||||
|
||||
void ViewEditor::on_checkVSync_clicked(bool val) {
|
||||
view->setVSync(val);
|
||||
}
|
||||
|
||||
|
||||
void ViewEditor::on_spinSamples_valueChanged(int arg1) {
|
||||
view->setSamples(arg1);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,11 +57,10 @@ private slots:
|
||||
void on_checkCameraOrbit_clicked(bool val);
|
||||
void on_checkService_clicked(bool val);
|
||||
void on_checkCameraLight_stateChanged(int s);
|
||||
void on_checkVSync_clicked(bool val);
|
||||
void on_spinSamples_valueChanged(int arg1);
|
||||
void on_buttonHDRClear_clicked();
|
||||
void on_buttonHDRSelect_clicked();
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
#endif // VIEW_EDITOR_H
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonHDRClear">
|
||||
<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>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -125,7 +125,7 @@
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonHDRSelect">
|
||||
<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>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -137,6 +137,26 @@
|
||||
</item>
|
||||
<item>
|
||||
<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">
|
||||
<widget class="QCheckBox" name="checkFXAA">
|
||||
<property name="text">
|
||||
@@ -151,23 +171,29 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="checkService">
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="checkVSync">
|
||||
<property name="text">
|
||||
<string>Service mode</string>
|
||||
<string>VSync</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="checkCameraLight">
|
||||
<property name="text">
|
||||
<string>Camera light</string>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="spinSamples">
|
||||
<property name="prefix">
|
||||
<string>Samples: </string>
|
||||
</property>
|
||||
<property name="tristate">
|
||||
<bool>true</bool>
|
||||
<property name="minimum">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>16</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -504,8 +530,8 @@
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../qad/utils/qad_utils.qrc"/>
|
||||
<include location="../../qad/application/qad_application.qrc"/>
|
||||
<include location="../../qad/libs/blockview/qad_blockview.qrc"/>
|
||||
<include location="../../qad/libs/blockview/qad_blockview.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user