start moving to PIValueTree
This commit is contained in:
@@ -19,12 +19,13 @@
|
||||
#ifndef glframebuffereffectbase_H
|
||||
#define glframebuffereffectbase_H
|
||||
|
||||
#include "glframebuffer.h"
|
||||
#include "gltypes.h"
|
||||
#include "parameteredobject.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT FramebufferEffectBase {
|
||||
class QGLENGINE_CORE_EXPORT FramebufferEffectBase: public ParameteredObject {
|
||||
friend class FramebufferMipmap;
|
||||
friend class Renderer;
|
||||
|
||||
@@ -32,11 +33,12 @@ public:
|
||||
FramebufferEffectBase();
|
||||
virtual ~FramebufferEffectBase();
|
||||
|
||||
virtual void draw() = 0;
|
||||
virtual QString name() const = 0;
|
||||
|
||||
void setEnabled(bool on) { enabled_ = on; }
|
||||
bool isEnabled() const { return enabled_; }
|
||||
void setParameter(const QString & name, const QVariant & val) { parameters[name] = val; }
|
||||
virtual QString name() const = 0;
|
||||
|
||||
virtual void draw() = 0;
|
||||
|
||||
protected:
|
||||
void resize(int width, int height, bool force = false);
|
||||
@@ -57,9 +59,9 @@ protected:
|
||||
static void deleteShader(QOpenGLShaderProgram *& s);
|
||||
|
||||
private:
|
||||
bool is_loaded = false, enabled_ = true;
|
||||
bool enabled_ = true;
|
||||
bool is_loaded = false;
|
||||
Renderer * r = nullptr;
|
||||
QHash<QString, QVariant> parameters;
|
||||
GLint wid, hei;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "measurer.h"
|
||||
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
@@ -33,6 +34,7 @@ void Measurer::begin(const QString & name) {
|
||||
}
|
||||
|
||||
void Measurer::end() {
|
||||
glFinish();
|
||||
auto ms = et.elapsed_m();
|
||||
QTextStream ts(out);
|
||||
ts << n << ": " << QString::number(ms, 'f', 2) << " ms\n";
|
||||
|
||||
29
src/core/core/parameteredobject.cpp
Normal file
29
src/core/core/parameteredobject.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
QGL Framebuffer effect basic
|
||||
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 "parameteredobject.h"
|
||||
|
||||
|
||||
PIValueTree ParameteredObject::parameters() const {
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
void ParameteredObject::setParameters(const PIValueTree & p) {
|
||||
params.applyValues(p);
|
||||
}
|
||||
39
src/core/core/parameteredobject.h
Normal file
39
src/core/core/parameteredobject.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
QGL Framebuffer effect basic
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef parameteredobject_H
|
||||
#define parameteredobject_H
|
||||
|
||||
#include "qglengine_core_export.h"
|
||||
|
||||
#include <QString>
|
||||
#include <pivaluetree.h>
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT ParameteredObject {
|
||||
public:
|
||||
virtual ~ParameteredObject() {}
|
||||
|
||||
PIValueTree parameters() const;
|
||||
void setParameters(const PIValueTree & p);
|
||||
|
||||
protected:
|
||||
PIValueTree params;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -101,6 +101,7 @@ public:
|
||||
QImage getImage() const { return last_img; }
|
||||
void addFramebufferEffect(FramebufferEffectBase * e);
|
||||
void clearFramebufferEffects() { fb_effects.clear(); }
|
||||
QVector<FramebufferEffectBase *> framebufferEffects() const { return fb_effects; }
|
||||
QString getTimings() const { return timings; }
|
||||
|
||||
QImage materialThumbnail(Material * m) { return rend_mat.materialThumbnail(m); }
|
||||
|
||||
@@ -27,20 +27,34 @@
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QImageReader>
|
||||
#include <QMessageBox>
|
||||
#include <piqt.h>
|
||||
|
||||
|
||||
class Effect1: public FramebufferEffectBase {
|
||||
public:
|
||||
Effect1() {
|
||||
params.addChild({
|
||||
"radius",
|
||||
10,
|
||||
{{PIValueTree::Attribute::minimum, 1}, {PIValueTree::Attribute::maximum, 4000}}
|
||||
});
|
||||
}
|
||||
~Effect1() { deleteShader(mys); }
|
||||
QString name() const { return "Blur"; }
|
||||
void reloadShaders() { QGLEngineShaders::loadShadersMulti(mys, "test1.glsl"); }
|
||||
void draw() {
|
||||
if (!mys) return;
|
||||
if (!mys->isLinked()) return;
|
||||
|
||||
int radius = params["radius"].value().toInt();
|
||||
|
||||
auto planes = getFreePlanes(1);
|
||||
bindPreviousOutput(0);
|
||||
// bindDeferredBuffer(Renderer::dbrNormalZSolid, 1);
|
||||
mys->bind();
|
||||
mys->setUniformValue("tex_in", 0);
|
||||
mys->setUniformValue("radius", radius);
|
||||
mys->setUniformValue("sum_div", (GLfloat)(radius + 1));
|
||||
mys->setUniformValue("step", QVector2D(1, 0));
|
||||
drawScreen(mys);
|
||||
|
||||
@@ -71,8 +85,17 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView
|
||||
view->view()->setHoverHaloEnabled(true);
|
||||
view->view()->setDepthStart(0.1);
|
||||
view->view()->setSelectionMode(Scene::smMultiSelection);
|
||||
view->view()->renderer_.addFramebufferEffect(new Effect1());
|
||||
|
||||
auto * e = new Effect1();
|
||||
view->view()->renderer_.addFramebufferEffect(e);
|
||||
|
||||
PIValueTree params;
|
||||
auto p = e->parameters();
|
||||
p.setName(Q2PIString(e->name()));
|
||||
params.addChild(p);
|
||||
// widgetParameters->setFullEditMode(true);
|
||||
widgetParameters->setGrouping(PIValueTreeEdit::Groups);
|
||||
widgetParameters->setValue(params);
|
||||
|
||||
groupShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsEnabled));
|
||||
groupEyeAccomodation->setChecked(view->view()->isFeatureEnabled(QGLView::qglEyeAccomodationEnabled));
|
||||
@@ -239,6 +262,14 @@ void QGLViewWindow::view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) {
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_buttonParamsApply_clicked() {
|
||||
auto fbel = view->view()->renderer_.framebufferEffects();
|
||||
auto params = widgetParameters->value();
|
||||
for (auto * e: fbel)
|
||||
e->setParameters(params.child(Q2PIString(e->name())));
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionArrow_triggered(bool on) {
|
||||
actionArrow->setChecked(true);
|
||||
actionMove->setChecked(false);
|
||||
|
||||
@@ -98,6 +98,7 @@ private slots:
|
||||
void view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m);
|
||||
|
||||
void on_pushButton_2_clicked() { view->view()->reloadShaders(); }
|
||||
void on_buttonParamsApply_clicked();
|
||||
|
||||
void on_actionArrow_triggered(bool on);
|
||||
void on_actionMove_triggered(bool on);
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget_2">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_5">
|
||||
<attribute name="title">
|
||||
@@ -626,6 +626,70 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_8">
|
||||
<attribute name="title">
|
||||
<string>Parameters</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_12">
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>787</width>
|
||||
<height>403</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_13">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="PIValueTreeEdit" name="widgetParameters" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>414</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonParamsApply">
|
||||
<property name="text">
|
||||
<string>apply</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -994,6 +1058,12 @@
|
||||
<header>textures_editor.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PIValueTreeEdit</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>pivaluetree_edit.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../../qad/libs/blockview/qad_blockview.qrc"/>
|
||||
|
||||
Reference in New Issue
Block a user