From 3044caff9268a8063420d2700615112917c53682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Wed, 5 Jun 2019 08:22:01 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@544 a8b55f48-bf90-11e4-a774-851b48703e85 --- qglview/glmaterial.cpp | 2 +- qglview/gltypes.cpp | 2 +- qglview/gltypes.h | 4 +- qglview/loader_dae.cpp | 7 +- qglview/openglwindow.cpp | 2 +- qglview/qglview.cpp | 17 ++- qglview/qglview.h | 3 +- qglview/qglview_test/qglview_window.cpp | 1 + qglview/qglview_test/qglview_window.h | 1 + qglview/qglview_test/qglview_window.ui | 157 ++++++++++++++---------- 10 files changed, 112 insertions(+), 84 deletions(-) diff --git a/qglview/glmaterial.cpp b/qglview/glmaterial.cpp index 776f8d9..683c2bb 100644 --- a/qglview/glmaterial.cpp +++ b/qglview/glmaterial.cpp @@ -173,7 +173,7 @@ void GLTextureManagerBase::convertToNormal(QImage & im) { sum[1] /= wh; sum[2] /= wh; qDebug() << sum[0] << sum[1] << sum[2]; - if ((qAbs(sum[0]) <= 0.05f) && (qAbs(sum[1]) <= 0.05f) && (sum[2] >= 0.4f)) /// already normal + if ((qAbs(sum[0]) <= 0.05f) && (qAbs(sum[1]) <= 0.05f) && (sum[2] >= 0.25f)) /// already normal return; qDebug() << "convert to bump"; QImage dim = QImage(sim.width(), sim.height(), QImage::Format_ARGB32); diff --git a/qglview/gltypes.cpp b/qglview/gltypes.cpp index fbececc..9120259 100644 --- a/qglview/gltypes.cpp +++ b/qglview/gltypes.cpp @@ -22,7 +22,7 @@ #include //__GLWidget__ * currentQGLView; -QMutex globMutex; +//QMutex globMutex; QString readCharsUntilNull(QDataStream & s) { diff --git a/qglview/gltypes.h b/qglview/gltypes.h index 3bf8aa5..fe389df 100644 --- a/qglview/gltypes.h +++ b/qglview/gltypes.h @@ -141,8 +141,8 @@ inline float urand(const float & scale = 1.) {return ((float)rand() / RAND_MAX - inline float uprand(const float & scale = 1.) {return ((float)rand() / RAND_MAX) * scale;} QString readCharsUntilNull(QDataStream & s); QString findFile(const QString & file, const QStringList & pathes); -inline QColor operator *(const QColor & c, float v) {return QColor(c.red() * v, c.green() * v, c.blue() * v, c.alpha() * v);} -inline QColor operator /(const QColor & c, float v) {return QColor(c.red() / v, c.green() / v, c.blue() / v, c.alpha() / v);} +inline QColor operator *(const QColor & c, float v) {return QColor(piClamp(c.red() * v, 0, 255), piClamp(c.green() * v, 0, 255), piClamp(c.blue() * v, 0, 255), piClamp(c.alpha() * v, 0, 255));} +inline QColor operator /(const QColor & c, float v) {return QColor(piClamp(c.red() / v, 0, 255), piClamp(c.green() / v, 0, 255), piClamp(c.blue() / v, 0, 255), piClamp(c.alpha() / v, 0, 255));} //extern __GLWidget__ * currentQGLView; diff --git a/qglview/loader_dae.cpp b/qglview/loader_dae.cpp index 082994e..7c4a1f1 100644 --- a/qglview/loader_dae.cpp +++ b/qglview/loader_dae.cpp @@ -153,15 +153,11 @@ QVector LoaderDAE::readMaterials(QDomElement le, QDomElement li, bool if (!text.isEmpty()) mat.map_normal.bitmap_path = text; ret << mat; - /* qDebug() << "** Material" << mat.name; qDebug() << " emission" << mat.color_self_illumination; qDebug() << " diffuse" << mat.color_diffuse; - qDebug() << " diffuse" << mat.diffuse.bitmap_path; qDebug() << " specular" << mat.color_specular; - qDebug() << " bump" << mat.bump.bitmap_path; qDebug() << " transparency" << mat.transparency; - */ } return ret; } @@ -318,7 +314,7 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, float scale) { co->setName(name + "_" + QString::number(j)); //co->setTransform(m); co->material() = LoaderDAE::materialByName(materials, matname); -//qDebug() << " tri" << co->material().color_diffuse << matname; + qDebug() << " tri" << co->material().name << matname; QVector & vertices(co->VBO().vertices()), & normals(co->VBO().normals()), & uvs(co->VBO().texcoords()); for (int k = 0; k < einp.count(); ++k) { QDomElement di = einp.at(k).toElement(); @@ -366,6 +362,7 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, float scale) { if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toFloat(); ml = dn.elementsByTagName("intensity"); if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toFloat(); + lo->setColor(lo->color() / lo->intensity); QString sv; sv = dl.firstChildElement("constant_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_const = sv.toFloat(); sv = dl.firstChildElement("linear_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_linear = sv.toFloat(); diff --git a/qglview/openglwindow.cpp b/qglview/openglwindow.cpp index 8e578b0..8dc5d39 100644 --- a/qglview/openglwindow.cpp +++ b/qglview/openglwindow.cpp @@ -23,7 +23,7 @@ OpenGLWindow::OpenGLWindow(QWindow *parent) } #endif format.setDepthBufferSize(24); -// format.setSamples(4); + format.setSamples(8); // format.setStencilBufferSize(8); setFormat(format); QSurfaceFormat::setDefaultFormat(format); diff --git a/qglview/qglview.cpp b/qglview/qglview.cpp index 1d39f7e..a653fd9 100644 --- a/qglview/qglview.cpp +++ b/qglview/qglview.cpp @@ -121,6 +121,7 @@ GLRendererBase * QGLView::renderer() { return renderer_; } + void QGLView::setRenderer(GLRendererBase * r, GLRendererBase ** prev) { if (prev != nullptr) *prev = renderer_; renderer_ = r; @@ -235,9 +236,7 @@ void QGLView::selectObject(GLObjectBase * o) { void QGLView::resizeEvent(QResizeEvent * e) { -// if (isExposed()) -// resizeGL(width(), height()); - /* QWindow::resizeEvent(e);*/ + renderLater(); } void QGLView::timerEvent(QTimerEvent *) { @@ -509,6 +508,8 @@ void QGLView::renderSingleSelection(GLObjectBase & o) { QMatrix4x4 curview = start_rp.view_matrix * start_rp.cam_offset_matrix * o.itransform_; uint id = qHash((quint64)&o); ids.insert(id, &o); + glLineWidth(o.line_width > 0.f ? o.line_width : lineWidth_); + glPointSize(o.line_width > 0.f ? o.line_width : lineWidth_); if (shaders_supported){ if (shader_select) { if (shader_select->isLinked()) { @@ -620,11 +621,13 @@ void QGLView::applyFog() { void QGLView::resizeGL(int width, int height) { if (!is_init) return; if (width <= 0 || height <= 0) return; + if (prev_size == QSize(width, height)) return; + prev_size = QSize(width, height); aspect = float(width) / float(height); if (renderer_) renderer_->resize(width, height); + mouse_first = true; //qDebug() << "resize" << width << height; fbo_selection.resize(width, height); - mouse_first = true; iaspect = (aspect == 0.f) ? 0. : 1 / aspect; glViewport(0, 0, width, height); emit glResize(width, height); @@ -632,6 +635,7 @@ void QGLView::resizeGL(int width, int height) { void QGLView::mouseReleaseEvent(QMouseEvent * e) { +// qDebug() << "mouseReleaseEvent" << e << isActive(); // QGraphicsView::mouseReleaseEvent(e); //setCursor(QCursor(Qt::ArrowCursor)); selecting_ = false; @@ -646,6 +650,7 @@ void QGLView::mouseReleaseEvent(QMouseEvent * e) { void QGLView::mousePressEvent(QMouseEvent * e) { +// qDebug() << "mousePressEvent" << e << isActive(); // QGraphicsView::mousePressEvent(e); // mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) , QTransform() ) == 0); selecting_ = false; @@ -661,13 +666,13 @@ void QGLView::mousePressEvent(QMouseEvent * e) { void QGLView::mouseMoveEvent(QMouseEvent * e) { -// qDebug() << e->pos(); +// qDebug() << "mouseMoveEvent" << e << isActive(); // QGraphicsView::mouseMoveEvent(e); //lastPos = e->pos(); if (selecting_) { - return; } +// if (!QRect(QPoint(), size()).contains(e->pos())) return; //if (scene()->itemAt(mapToScene(e->pos())) != 0) return; ///qDebug() << e->x() << e->y(); QRect g_rect(QPoint(), size()); diff --git a/qglview/qglview.h b/qglview/qglview.h index 208b8db..845e776 100644 --- a/qglview/qglview.h +++ b/qglview/qglview.h @@ -99,7 +99,7 @@ public: Q_ENUMS (SelectionMode) void stop(); - void start(float freq = 40.); + void start(float freq = 60.); GLRendererBase * renderer(); void setRenderer(GLRendererBase * r, GLRendererBase ** prev = nullptr); @@ -232,6 +232,7 @@ private: Qt::KeyboardModifier sel_mod; GLRendererBase::RenderingParameters start_rp; QHash features_; + QSize prev_size; float lineWidth_; float fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor; int timer, fps_cnt, sh_id_loc; diff --git a/qglview/qglview_test/qglview_window.cpp b/qglview/qglview_test/qglview_window.cpp index 3dc4877..b871b9b 100644 --- a/qglview/qglview_test/qglview_window.cpp +++ b/qglview/qglview_test/qglview_window.cpp @@ -335,3 +335,4 @@ void QGLViewWindow::on_pushButton_3_clicked() { } } + diff --git a/qglview/qglview_test/qglview_window.h b/qglview/qglview_test/qglview_window.h index 10deb39..2486417 100644 --- a/qglview/qglview_test/qglview_window.h +++ b/qglview/qglview_test/qglview_window.h @@ -88,6 +88,7 @@ private slots: void on_colorBack_colorChanged(QColor color) {view->view()->setBackColor(color);} void on_colorAmbient_colorChanged(QColor color) {view->view()->setAmbientColor(color);} void on_checkCameraOrbit_clicked(bool val) {view->view()->setCameraOrbit(val);} + void on_spinViewLineWidth_valueChanged(double val) {view->view()->setLineWidth(val);} void on_groupShadows_clicked(bool val) {view->view()->setFeature(QGLView::qglShadowsEnabled, val);} void on_groupEyeAccomodation_clicked(bool val) {view->view()->setFeature(QGLView::qglEyeAccomodationEnabled, val);} diff --git a/qglview/qglview_test/qglview_window.ui b/qglview/qglview_test/qglview_window.ui index fb6850f..ba6799b 100644 --- a/qglview/qglview_test/qglview_window.ui +++ b/qglview/qglview_test/qglview_window.ui @@ -53,7 +53,7 @@ - 1 + 0 @@ -96,6 +96,56 @@ + + + + Depth + + + + + + + 0 + + + + + 3 + + + 999999999.000000000000000 + + + 1.000000000000000 + + + + + + + + 0 + 0 + + + + - + + + + + + + 3 + + + 999999999.000000000000000 + + + + + @@ -154,6 +204,24 @@ + + + + Back color + + + + + + + + 10 + 10 + 10 + + + + @@ -172,21 +240,21 @@ - + MSAA - + FXAA - + Hover halo @@ -241,7 +309,7 @@ - + Selection halo @@ -296,7 +364,7 @@ - + Camera @@ -322,71 +390,26 @@ - - - - Depth + + + + 0.000000000000000 + + + 99999.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 - - - - 0 - - - - - 3 - - - 999999999.000000000000000 - - - 1.000000000000000 - - - - - - - - 0 - 0 - - - - - - - - - - - - 3 - - - 999999999.000000000000000 - - - - - - - + + - Back color - - - - - - - - 10 - 10 - 10 - + Line width