From b068a301bf28c52671102beed7822573207dbf6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Tue, 24 Mar 2015 11:04:36 +0000 Subject: [PATCH] chunkstream version fixedleaselication git-svn-id: svn://db.shs.com.ru/libs@3 a8b55f48-bf90-11e4-a774-851b48703e85 --- FindMinGW.cmake | 2 +- kx_tools/kx_pult.cpp | 32 +++++++--- kx_tools/kx_pult.h | 6 +- make_libs.sh | 4 +- piqt_tools/piqt_connection_edit.cpp | 2 +- qad_application/etabwidget.cpp | 4 +- qad_application/etabwidget.h | 2 +- qad_application/qsingleapplication.cpp | 16 ++--- qad_blockview/blockitem.h | 2 +- qad_graphic/graphic.cpp | 38 ++++++------ qad_graphic/graphic.h | 2 +- qad_graphic/graphic_conf.h | 4 +- qad_utils/chunkstream.cpp | 3 + qad_utils/chunkstream.h | 3 +- qad_widgets/qcodeedit.cpp | 16 +++-- qad_widgets/qpiconsole.cpp | 2 +- qad_widgets/qpiconsole.h | 4 +- qglview/CMakeLists.txt | 4 +- qglview/GLee.h | 1 + qglview/glframebuffer.cpp | 2 + qglview/glframebuffer.h | 3 + qglview/glprimitives.cpp | 82 +++++++++++++++++++++++++ qglview/glprimitives.h | 31 ++++++++++ qglview/gltypes.cpp | 8 ++- qglview/gltypes.h | 35 +++++++---- qglview/main.cpp | 83 +++++++++++++++++++++++++- qglview/mainwindow.cpp | 57 ++++++++++++++---- qglview/renderer_simple.cpp | 39 +++++++++++- qglview/renderer_simple.h | 14 +++-- 29 files changed, 406 insertions(+), 95 deletions(-) diff --git a/FindMinGW.cmake b/FindMinGW.cmake index a34d37b..fcd5208 100644 --- a/FindMinGW.cmake +++ b/FindMinGW.cmake @@ -8,5 +8,5 @@ if (NOT DEFINED MINGW_DIR) message(STATUS "Find MinGW binary path = ${MINGW_BIN}") message(STATUS "Find MinGW include path = ${MINGW_INCLUDE}") message(STATUS "Find MinGW library path = ${MINGW_LIB}") -endif () +endif () endif (${MINGW}) diff --git a/kx_tools/kx_pult.cpp b/kx_tools/kx_pult.cpp index be33d15..8e251dc 100644 --- a/kx_tools/kx_pult.cpp +++ b/kx_tools/kx_pult.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "kx_pult.h" #include "ui_kx_pult.h" @@ -186,7 +187,8 @@ void KX_Pult::timerEvent(QTimerEvent * e) { static QString sPI = QString::number(atan(1) * 4., 'f', 14).leftJustified(14); static int cnt = 0; int si = qMax(cnt - 6, 0); - cnt = (++cnt) % 23; + ++cnt; + cnt %= 23; ui->labelWait->setText(QString(si, QChar(' ')) + sPI.mid(cnt - 6, 6).trimmed()); if (!coeffs.isReady()) return; //ui->table->setK(coeffsK.k()->data(), coeffsK.count()); @@ -399,7 +401,7 @@ void KX_Pult::on_buttonSetDesc_clicked() { QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), kdesc_file, "C/C++ header files(*.h *.hpp);;All files(*)"); if (ret.isEmpty()) return; kdesc_file = QDir::current().relativeFilePath(ret); - updateKDesc(); + updateKDesc(true); } @@ -478,7 +480,7 @@ void KX_Pult::updateDiag() { } -void KX_Pult::updateKDesc() { +void KX_Pult::updateKDesc(bool ask_move) { kdesc.clear(); QFile f(kdesc_file); if (!f.open(QIODevice::ReadOnly)) { @@ -532,7 +534,10 @@ void KX_Pult::updateKDesc() { ui->spinSize->setValue(cind); ui->spinSize->setStyleSheet("background-color: rgb(220, 220, 255);"); } - updateTree(); + bool move = false; + if (ask_move) + move = (QMessageBox::question(this, "KX Pult", "Save values at associated names?", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes); + updateTree(move); } @@ -542,12 +547,21 @@ bool stringComp(const QString & s1, const QString & s2) { return s1 > s2; } -void KX_Pult::updateTree() { + +void KX_Pult::updateTree(bool move) { int sp = ui->treeK->verticalScrollBar()->value(); - ui->treeK->clear(); - ui->treeK->setUpdatesEnabled(false); QApplication::setOverrideCursor(Qt::WaitCursor); //qDebug() << "fill tree ..."; + QMap prev_val; + if (move) { + for (int i = 0; i < ui->treeK->topLevelItemCount(); ++i) { + QTreeWidgetItem * ti = ui->treeK->topLevelItem(i); + if (!ti->text(1).isEmpty()) + prev_val[ti->text(1)] = ti->text(2); + } + } + ui->treeK->clear(); + ui->treeK->setUpdatesEnabled(false); eval.clearCustomVariables(); for (int i = 0; i < K.size_s(); ++i) { QTreeWidgetItem * ti = new QTreeWidgetItem(); @@ -562,6 +576,10 @@ void KX_Pult::updateTree() { knames_sort << kd.name; eval.content.addVariable(kd.name, 0., false); } + if (move && !kd.name.isEmpty()) { + if (prev_val.contains(kd.name)) + coeffs.setFormula(i, Q2PIString(prev_val[kd.name])); + } ti->setText(0, QString::number(i)); ti->setText(1, kd.name); ti->setText(2, PI2QString(coeffs.formula(i))); diff --git a/kx_tools/kx_pult.h b/kx_tools/kx_pult.h index d9f95aa..6fa9a38 100644 --- a/kx_tools/kx_pult.h +++ b/kx_tools/kx_pult.h @@ -118,8 +118,8 @@ private slots: void saving(QPIConfig & conf); void updateGraph(); void updateDiag(); - void updateKDesc(); - void updateTree(); + void updateKDesc(bool ask_move = false); + void updateTree(bool move = false); void filterTree(); void calculate(); void renew(); @@ -138,7 +138,7 @@ private slots: void on_buttonWrite_clicked(); void on_buttonResize_clicked(); void on_buttonSetDesc_clicked(); - void on_buttonReparseDesc_clicked() {updateKDesc();} + void on_buttonReparseDesc_clicked() {updateKDesc(true);} void on_buttonCalculate_clicked() {calculate();} void on_buttonApply_clicked() {renew();} void on_spinSize_valueChanged(int); diff --git a/make_libs.sh b/make_libs.sh index d010bb8..f8cdced 100755 --- a/make_libs.sh +++ b/make_libs.sh @@ -1,5 +1,5 @@ -cmake . -make install $@ +#cmake . +#make install $@ for d in 'qad_widgets' 'qad_utils' 'qad_graphic' 'qad_sql_table' 'qad_application' 'qad_blockview' 'touch_widgets'; do cd $d qmake diff --git a/piqt_tools/piqt_connection_edit.cpp b/piqt_tools/piqt_connection_edit.cpp index 788e7e0..ca1b0be 100644 --- a/piqt_tools/piqt_connection_edit.cpp +++ b/piqt_tools/piqt_connection_edit.cpp @@ -37,7 +37,7 @@ ConnectionEdit::~ConnectionEdit() { void ConnectionEdit::accept() { - bool ok = false; + //bool ok = false; QList bl = ui->blockView->allDevices(); foreach (BlockItem * i, bl) foreach (BlockItem * j, bl) diff --git a/qad_application/etabwidget.cpp b/qad_application/etabwidget.cpp index 492196b..4da9dc3 100644 --- a/qad_application/etabwidget.cpp +++ b/qad_application/etabwidget.cpp @@ -9,10 +9,10 @@ ETabWidget::ETabWidget(QWidget* parent): QTabWidget(parent) { void ETabWidget::retranslate() { for (int i = 0; i < buttons.size(); ++i) - buttons[i].toolTip = QApplication::translate("MainWindow", buttons[i].srcToolTip.toUtf8(), 0, QCoreApplication::UnicodeUTF8); + buttons[i].toolTip = QApplication::translate("MainWindow", buttons[i].srcToolTip.toUtf8(), 0/*, QCoreApplication::UnicodeUTF8*/); QList bl = findChildren(); foreach (QToolButton * i, bl) - i->setToolTip(QApplication::translate("MainWindow", i->property("sourceToolTip").toString().toUtf8(), 0, QCoreApplication::UnicodeUTF8)); + i->setToolTip(QApplication::translate("MainWindow", i->property("sourceToolTip").toString().toUtf8(), 0/*, QCoreApplication::UnicodeUTF8*/)); } diff --git a/qad_application/etabwidget.h b/qad_application/etabwidget.h index 0d55739..ad9f304 100644 --- a/qad_application/etabwidget.h +++ b/qad_application/etabwidget.h @@ -31,7 +31,7 @@ private: void tabRemoved(int) {emit countChanged();} struct TabButton { - TabButton(int r, const QIcon & i, const QString & t) {role = r; icon = i; visible = true; srcToolTip = t; toolTip = QApplication::translate("MainWindow", t.toUtf8(), 0, QCoreApplication::UnicodeUTF8);} + TabButton(int r, const QIcon & i, const QString & t) {role = r; icon = i; visible = true; srcToolTip = t; toolTip = QApplication::translate("MainWindow", t.toUtf8(), 0/*, QCoreApplication::UnicodeUTF8*/);} int role; bool visible; QIcon icon; diff --git a/qad_application/qsingleapplication.cpp b/qad_application/qsingleapplication.cpp index 44f6215..428c4bb 100644 --- a/qad_application/qsingleapplication.cpp +++ b/qad_application/qsingleapplication.cpp @@ -20,7 +20,7 @@ QSingleApplication::QSingleApplication(const QString & app_name): QThread() { shm.attach(); shm.lock(); void * d = shm.data(); - if (d) qMemSet(d, 0, sizeof(quint32)); + if (d) memset(d, 0, sizeof(quint32)); shm.unlock(); start(); //qDebug() << "start listen"; @@ -49,11 +49,11 @@ void QSingleApplication::sendMessage(const QByteArray & m) { quint32 num(0), size = m.size(); void * d = shm.data(); if (d) { - qMemCopy(&num, d, sizeof(quint32)); + memcpy(&num, d, sizeof(quint32)); num++; - qMemCopy(d, &num, sizeof(quint32)); - qMemCopy((((char*)d) + sizeof(quint32)), &size, sizeof(quint32)); - qMemCopy((((char*)d) + sizeof(quint32) + sizeof(quint32)), m.constData(), size); + memcpy(d, &num, sizeof(quint32)); + memcpy((((char*)d) + sizeof(quint32)), &size, sizeof(quint32)); + memcpy((((char*)d) + sizeof(quint32) + sizeof(quint32)), m.constData(), size); } shm.unlock(); } @@ -65,15 +65,15 @@ void QSingleApplication::run() { shm.lock(); const void * d = shm.constData(); if (d) { - qMemCopy(&num, d, sizeof(quint32)); + memcpy(&num, d, sizeof(quint32)); if (pnum != num) { pnum = num; //qDebug() << "new message" << num; - qMemCopy(&size, (((const char*)d) + sizeof(quint32)), sizeof(quint32)); + memcpy(&size, (((const char*)d) + sizeof(quint32)), sizeof(quint32)); if (size <= int(QSA_MSGSIZE)) { QByteArray msg; msg.resize(size); - qMemCopy(msg.data(), (((const char*)d) + sizeof(quint32) + sizeof(quint32)), size); + memcpy(msg.data(), (((const char*)d) + sizeof(quint32) + sizeof(quint32)), size); emit messageReceived(msg); } else { qDebug() << "[QSingleApplication] Invalid message size:" << size; diff --git a/qad_blockview/blockitem.h b/qad_blockview/blockitem.h index c1b1f36..07a0853 100644 --- a/qad_blockview/blockitem.h +++ b/qad_blockview/blockitem.h @@ -149,7 +149,7 @@ public: QList decors() const {return decors_;} QList connectedBuses() const; BlockItemPin * pinByText(const QString & t) const; - BlockItemPin * pinAtBus(BlockBusItem * bus) const; /// TODO return list of connected pins + BlockItemPin * pinAtBus(BlockBusItem * bus) const; QColor color() const {return col;} void setColor(QColor c) {col = c; _resize(size());} QSizeF size() const {return g_main.rect().size();} diff --git a/qad_graphic/graphic.cpp b/qad_graphic/graphic.cpp index 3eff966..b5be13e 100644 --- a/qad_graphic/graphic.cpp +++ b/qad_graphic/graphic.cpp @@ -456,13 +456,13 @@ void Graphic::setHistorySize(double val) { history = val; double x; for (int i = 0; i < graphics.size(); ++i) { - QPolygonF & pol(graphics[i].polyline); + QList & pol(graphics[i].polyline); if (pol.isEmpty()) continue; x = pol.back().x() - history; for (int j = pol.size() - 2; j >= 0 ; --j) if (pol[j].x() < x) { //qDebug() << pol.size() << j; - pol.remove(0, j); + pol.erase(pol.begin(), pol.begin() + j); break; } } @@ -529,26 +529,26 @@ void Graphic::setButtonsPosition(Graphic::Alignment a) { void Graphic::addPoint(const QPointF & p, int graphic, bool update_) { if (graphic >= graphics.size() || graphic < 0) return; if (graphics.at(graphic).polyline.size() == 0) graphics[graphic].max_x = p.x(); - graphics[graphic].polyline.push_back(p); + graphics[graphic].polyline << p; if (graphics.at(graphic).max_x < p.x()) graphics[graphic].max_x = p.x(); tick(graphic, true, update_); } -void Graphic::setGraphicData(const QVector & g, int graphic) { +void Graphic::setGraphicData(const QVector & g, int graphic, bool update_) { if (graphic >= graphics.size() || graphic < 0) return; graphics[graphic].polyline.clear(); - graphics[graphic].polyline = QPolygonF(g); + graphics[graphic].polyline = g.toList(); if (graphics.at(graphic).polyline.size() == 0) { graphics[graphic].max_x = 0.; - tick(graphic, false); + tick(graphic, false, update_); return; } graphics[graphic].max_x = graphics.at(graphic).polyline[0].x(); for (int i = 1; i < graphics.at(graphic).polyline.size(); ++i) if (graphics.at(graphic).max_x < graphics.at(graphic).polyline[i].x()) graphics[graphic].max_x = graphics.at(graphic).polyline[i].x(); - tick(graphic, false); + tick(graphic, false, update_); } @@ -662,7 +662,7 @@ void Graphic::setHistogramData(const QVector & g, int graphic) { //if (ci >= ic) ci = ic - 1; hist[ci]++; } - QPolygonF & cpol(graphics[graphic].polyline); + QList & cpol(graphics[graphic].polyline); if (hist.size() == 1 || range == 0.) { cpol << QPointF(min - 0.5, 0.) << QPointF(min - 0.25, 0.); cpol << QPointF(min - 0.25, hist[0]) << QPointF(min + 0.25, hist[0]); @@ -684,7 +684,7 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y); bool isEmpty = true, anyVisible = false, isTimeLimit = (visible_time > 0.) && !(isRangeX || isRangeY); foreach (const GraphicType & t, graphics) { - const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); + const QList & pol(pause_ ? t.polyline_pause : t.polyline); if (!pol.isEmpty()) { isEmpty = false; break; @@ -704,7 +704,7 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou vx -= visible_time; foreach (const GraphicType & t, graphics) { if (!t.visible) continue; - const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); + const QList & pol(pause_ ? t.polyline_pause : t.polyline); for (int i = 0; i < pol.size(); i++) { cx = pol[i].x(); cy = pol[i].y(); @@ -869,10 +869,10 @@ void Graphic::drawGraphics() { QTransform mat = painter->transform(); painter->resetTransform(); painter->setWorldMatrixEnabled(false); - QPolygonF cpol; + QList cpol; for (int i = 0; i < graphics.size(); ++i) { GraphicType & t(graphics[i]); - QPolygonF & rpol(pause_ ? t.polyline_pause : t.polyline); + QList & rpol(pause_ ? t.polyline_pause : t.polyline); if (t.visible && !rpol.isEmpty()) { pw = t.pen.widthF(); if (t.lines) { @@ -883,16 +883,16 @@ void Graphic::drawGraphics() { painter->setBrush(t.fill_color); //cpol.push_front(QPointF(cpol.front().x(), 0.)); //cpol.push_back(QPointF(cpol.back().x(), 0.)); - painter->drawPolygon(mat.map(cpol)); + painter->drawPolygon(mat.map(QPolygonF(cpol.toVector()))); } else - painter->drawPolyline(mat.map(rpol)); + painter->drawPolyline(mat.map(QPolygonF(rpol.toVector()))); } if (t.points) { if (qRound(t.pointWidth) == t.pointWidth) t.pen.setWidth(qRound(t.pointWidth)); else t.pen.setWidthF(t.pointWidth); t.pen.setCosmetic(true); painter->setPen(t.pen); - painter->drawPoints(mat.map(rpol)); + painter->drawPoints(mat.map(QPolygonF(rpol.toVector()))); if (qRound(pw) == pw) t.pen.setWidth(qRound(pw)); else t.pen.setWidthF(pw); } @@ -1067,13 +1067,13 @@ void Graphic::tick(int index, bool slide, bool update_) { if (slide) { mutex.lock(); GraphicType & t(graphics[index]); - if (t.polyline.size() > 1) if (fabs(t.polyline.back().x() - t.polyline.front().x()) > history) { + while (t.polyline.size() > 1) { + if (fabs(t.polyline.back().x() - t.polyline.front().x()) <= history) break; t.polyline.pop_front(); - if (t.polyline.size() > 1) if (fabs(t.polyline.back().x() - t.polyline.front().x()) > history) t.polyline.pop_front(); - if (t.polyline.size() > 1) if (fabs(t.polyline.back().x() - t.polyline.front().x()) > history) t.polyline.pop_front(); } } if (!update_) { + findGraphicsRect(); mutex.unlock(); return; } @@ -1093,7 +1093,7 @@ void Graphic::on_buttonAutofit_clicked() { isFit = true; bool isEmpty = true; foreach (const GraphicType & t, graphics) { - const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); + const QList & pol(pause_ ? t.polyline_pause : t.polyline); if (!pol.isEmpty()) { isEmpty = false; break; diff --git a/qad_graphic/graphic.h b/qad_graphic/graphic.h index 2c3508f..3f4bc01 100644 --- a/qad_graphic/graphic.h +++ b/qad_graphic/graphic.h @@ -277,7 +277,7 @@ public slots: void addPoint(double x, double y, bool update = true) {addPoint(QPointF(x, y), update);} void addPoint(double y, int graphic, bool update = true) {addPoint(QPointF(graphics.at(graphic).max_x + inc_x, y), graphic, update);} void addPoint(double y, bool update = true) {addPoint(QPointF(graphics[curGraphic].max_x + inc_x, y), update);} - void setGraphicData(const QVector & g, int graphic); + void setGraphicData(const QVector & g, int graphic, bool update_ = true); void setGraphicData(const QVector & g) {setGraphicData(g, curGraphic);} void setGraphicProperties(const QString & name, const QColor & color = Qt::darkRed, Qt::PenStyle style = Qt::SolidLine, double width = 0., bool visible = true) {setGraphicProperties(curGraphic, name, color, style, width, visible);} void setGraphicProperties(int graphic, const QString & name, const QColor & color = Qt::darkRed, Qt::PenStyle style = Qt::SolidLine, double width = 0., bool visible = true); diff --git a/qad_graphic/graphic_conf.h b/qad_graphic/graphic_conf.h index 6d926a6..d812920 100644 --- a/qad_graphic/graphic_conf.h +++ b/qad_graphic/graphic_conf.h @@ -32,8 +32,8 @@ struct GraphicType { } //~GraphicType() {delete pb;} QString name; - QPolygonF polyline; - QPolygonF polyline_pause; + QList polyline; + QList polyline_pause; QPen pen; QColor fill_color; bool lines; diff --git a/qad_utils/chunkstream.cpp b/qad_utils/chunkstream.cpp index 5ab9bbb..8c30120 100644 --- a/qad_utils/chunkstream.cpp +++ b/qad_utils/chunkstream.cpp @@ -2,18 +2,21 @@ void ChunkStream::setSource(const QByteArray & data) { + stream_.setVersion(QDataStream::Qt_4_8); data_ = const_cast(&data); _init(); } void ChunkStream::setSource(QByteArray * data) { + stream_.setVersion(QDataStream::Qt_4_8); data_ = (data ? data : &tmp_data); _init(); } void ChunkStream::setSource(QDataStream & str) { + stream_.setVersion(QDataStream::Qt_4_8); str >> tmp_data; data_ = &tmp_data; _init(); diff --git a/qad_utils/chunkstream.h b/qad_utils/chunkstream.h index a0aa280..18d077e 100644 --- a/qad_utils/chunkstream.h +++ b/qad_utils/chunkstream.h @@ -32,7 +32,7 @@ public: int read() {stream_ >> last_id >> last_data; return last_id;} int getID() {return last_id;} template - T getData() const {T ret; QDataStream s(last_data); s >> ret; return ret;} + T getData() const {T ret; QDataStream s(last_data); s.setVersion(QDataStream::Qt_4_8); s >> ret; return ret;} private: void _init(); @@ -48,6 +48,7 @@ template ChunkStream & operator <<(ChunkStream & s, const ChunkStream::Chunk & c) { QByteArray ba; QDataStream bas(&ba, QIODevice::WriteOnly); + bas.setVersion(QDataStream::Qt_4_8); bas << c.data; s.dataStream() << c.id << ba; return s; diff --git a/qad_widgets/qcodeedit.cpp b/qad_widgets/qcodeedit.cpp index 1671ae5..cff32aa 100644 --- a/qad_widgets/qcodeedit.cpp +++ b/qad_widgets/qcodeedit.cpp @@ -24,7 +24,13 @@ QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent) { completer.setHeaderHidden(true); completer.installEventFilter(this); completer.header()->setDefaultAlignment(Qt::AlignCenter); - completer.header()->setResizeMode(QHeaderView::ResizeToContents); + completer.header()-> +#if (QT_VERSION >= 0x050000) + setSectionResizeMode +#else + setResizeMode +#endif + (QHeaderView::ResizeToContents); completer.header()->setStretchLastSection(true); //completer.setColumnWidth(0, 180); completer.resize(500, 200); @@ -129,8 +135,8 @@ bool QCodeEdit::matchWritten(QString s, QString w) { QChar wc(w[i].toLower()); bool ns = false, bl = true; while (sp < s.size()) { - if (ns || s[sp].toAscii() == '_') { - if (s[sp].toAscii() == '_') {sp++; bl = false; continue;} + if (ns || s[sp].toLatin1() == '_') { + if (s[sp].toLatin1() == '_') {sp++; bl = false; continue;} if (s[sp].isLower() && bl) {sp++; continue;} if (s[sp].toLower() != wc) return false; } @@ -265,7 +271,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) { completer.hide(); QMetaObject::invokeMethod(this, "invokeAutoCompletition", Qt::QueuedConnection, Q_ARG(bool, false)); } else { - if ((kc.isLetterOrNumber() || kc.toAscii() == '_') && completer.isVisible()) + if ((kc.isLetterOrNumber() || kc.toLatin1() == '_') && completer.isVisible()) QMetaObject::invokeMethod(this, "invokeAutoCompletition", Qt::QueuedConnection, Q_ARG(bool, false)); } break; @@ -694,7 +700,7 @@ void QCodeEdit::commitCompletition() { tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); } if (!tc.selectedText().isEmpty()) - if (tc.selectedText()[0].toAscii() == '(') + if (tc.selectedText()[0].toLatin1() == '(') ins_br = false; } if (ins.contains("(")) diff --git a/qad_widgets/qpiconsole.cpp b/qad_widgets/qpiconsole.cpp index 5d287dd..1b0d555 100644 --- a/qad_widgets/qpiconsole.cpp +++ b/qad_widgets/qpiconsole.cpp @@ -220,7 +220,7 @@ void QPIConsole::applyFormat(QLabel * l, QPIConsole::Formats f) { if (f.testFlag(QPIConsole::BackCyan)) bcol = Qt::cyan; if (f.testFlag(QPIConsole::BackWhite)) bcol = Qt::white; if (f.testFlag(QPIConsole::BackLighter)) bcol = bcol.lighter(150); - if (f.testFlag(QPIConsole::BackDarker)) bcol = bcol.darker(150); + //if (f.testFlag(QPIConsole::BackDarker)) bcol = bcol.darker(150); if (f.testFlag(QPIConsole::Inverse)) { QColor tc = fcol; diff --git a/qad_widgets/qpiconsole.h b/qad_widgets/qpiconsole.h index 9af49d4..5e72d33 100644 --- a/qad_widgets/qpiconsole.h +++ b/qad_widgets/qpiconsole.h @@ -53,8 +53,8 @@ public: Scientific = 0x10000000, Lighter = 0x20000000, Darker = 0x40000000, - BackLighter = 0x80000000, - BackDarker = 0x100000000}; + BackLighter = 0x80000000 + }; Q_DECLARE_FLAGS(Formats, Format) Q_FLAGS(Formats) diff --git a/qglview/CMakeLists.txt b/qglview/CMakeLists.txt index 9f351d5..c68d568 100644 --- a/qglview/CMakeLists.txt +++ b/qglview/CMakeLists.txt @@ -4,7 +4,7 @@ find_package(Qt4 REQUIRED) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${QT_INCLUDES}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall") -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}") add_definitions(-DGL_GLEXT_PROTOTYPES) @@ -12,7 +12,7 @@ set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} qad_wid if (${WIN32}) list(APPEND LIBS opengl32 glu32) else (${WIN32}) - list(APPEND LIBS GL GLU) + list(APPEND LIBS GL GLU glut GLEW) endif (${WIN32}) file(GLOB MOCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h") diff --git a/qglview/GLee.h b/qglview/GLee.h index e27d53e..629af12 100644 --- a/qglview/GLee.h +++ b/qglview/GLee.h @@ -56,6 +56,7 @@ #define WIN32_LEAN_AND_MEAN #include #include + #include #elif defined(__APPLE__) || defined(__APPLE_CC__) #define GL_GLEXT_LEGACY #include diff --git a/qglview/glframebuffer.cpp b/qglview/glframebuffer.cpp index 374ec7b..37d15fd 100644 --- a/qglview/glframebuffer.cpp +++ b/qglview/glframebuffer.cpp @@ -81,7 +81,9 @@ void GLFramebuffer::bind() { if (fbo == 0) return; glFlush(); glGetIntegerv(GL_VIEWPORT, prev_view); + //glClearError(); glBindFramebuffer(GL_FRAMEBUFFER, fbo); + //qDebug() << QString::number(glGetError(), 16); QVector buffers; for (int i = 0; i < colors.size(); ++i) buffers << GL_COLOR_ATTACHMENT0 + i; diff --git a/qglview/glframebuffer.h b/qglview/glframebuffer.h index 8582d57..951abcc 100644 --- a/qglview/glframebuffer.h +++ b/qglview/glframebuffer.h @@ -32,6 +32,9 @@ public: GLenum colorFormat() const {return color_format;} GLuint depthTexture() const {return tex_d;} GLenum target() const {return target_;} + int width() const {return wid;} + int height() const {return hei;} + QSize size() const {return QSize(wid, hei);} void resize(int width, int height); void bind(); diff --git a/qglview/glprimitives.cpp b/qglview/glprimitives.cpp index ec91bc6..a099cb2 100644 --- a/qglview/glprimitives.cpp +++ b/qglview/glprimitives.cpp @@ -29,6 +29,16 @@ void GLPrimitivePoint::draw(bool simplest) { +void GLPrimitiveLine::draw(bool simplest) { + glColor3f(material_.color_diffuse.redF(), material_.color_diffuse.greenF(), material_.color_diffuse.blueF()); + glBegin(GL_LINES); + glVertex3d(p0.x(), p0.y(), p0.z()); + glVertex3d(p1.x(), p1.y(), p1.z()); + glEnd(); +} + + + GLPrimitiveCube::GLPrimitiveCube(double width, double length, double height, QVector3D pos): GLObjectBase() { geom_prim = Quads; w = width; @@ -101,3 +111,75 @@ void GLPrimitiveCube::init() { is_init = true; vbo.rebuffer(); } + + +GLPrimitiveEllipsoid::GLPrimitiveEllipsoid(double width, double length, double height, int seg_wl, int seg_h, QVector3D pos) { + geom_prim = GLObjectBase::Triangles; + w = width; + l = length; + h = height; + swl = seg_wl; + sh = seg_h; + moveTo(pos); + init(); +} + + +void GLPrimitiveEllipsoid::putTriangle(const QVector3D & v0, const QVector3D & v1, const QVector3D & v2) { + vbo.vertices() << v0.x() << v0.y() << v0.z() << v1.x() << v1.y() << v1.z() << v2.x() << v2.y() << v2.z(); + QVector3D n = QVector3D::normal(v1 - v0, v2 - v0); + for (int i = 0; i < 3; ++i) + vbo.normals() << n.x() << n.y() << n.z(); + return; + QVector3D s(w, l, h); + n = (v0 * s).normalized(); vbo.normals() << n.x() << n.y() << n.z(); + n = (v1 * s).normalized(); vbo.normals() << n.x() << n.y() << n.z(); + n = (v2 * s).normalized(); vbo.normals() << n.x() << n.y() << n.z(); +} + + +void GLPrimitiveEllipsoid::init() { + QVector points; + vbo.clear(); + vbo.init(); + + int ret = 0, hseg = sh + 1, wlseg = swl + 1; + double crw, crl, a, ch, twl; + QVector3D cp(0., 0., -h / 2.); + points << cp; + for (int i = 1; i < hseg; i++) { + ch = -cos((double)i / hseg * M_PI); + cp.setZ(ch * h / 2.); + twl = sqrt(1. - ch * ch) / 2.; + crw = twl * w; + crl = twl * l; + for (int j = 0; j < wlseg * 2; j++) { + a = (double)j / wlseg * M_PI; + cp.setY(crw * sin(a)); + cp.setX(crl * cos(a)); + points << cp; + ret = points.size() - 1; + if (i == 1) + if (j > 0) putTriangle(points[0], points[ret], points[ret - 1]); + if (j > 0) { + if (i > 1) { + putTriangle(points[ret - wlseg * 2 - 1], points[ret], points[ret - 1]); + putTriangle(points[ret - wlseg * 2], points[ret], points[ret - wlseg * 2 - 1]); + } + } + } + if (i == 1) putTriangle(points[0], points[ret - wlseg * 2 + 1], points[ret]); + else { + putTriangle(points[ret - wlseg * 2 + 1], points[ret], points[ret - wlseg * 2]); + putTriangle(points[ret - wlseg * 2 + 1], points[ret - wlseg * 2], points[ret - wlseg * 4 + 1]); + } + } + points << QVector3D(0., 0., h / 2.); + ret = points.size() - 1; + putTriangle(points[ret - 1], points[ret - wlseg * 2], points[ret]); + for (int j = 1; j < wlseg * 2; j++) + if (j > 0) putTriangle(points[ret - wlseg * 2 + j - 1], points[ret - wlseg * 2 + j], points[ret]); + + is_init = true; + vbo.rebuffer(); +} diff --git a/qglview/glprimitives.h b/qglview/glprimitives.h index 5c47e74..a830c62 100644 --- a/qglview/glprimitives.h +++ b/qglview/glprimitives.h @@ -21,6 +21,7 @@ #include "globject.h" + class GLPrimitivePoint: public GLObjectBase { public: @@ -30,6 +31,21 @@ private: double sz; }; + + + +class GLPrimitiveLine: public GLObjectBase +{ +public: + GLPrimitiveLine(QVector3D p0_ = QVector3D(), QVector3D p1_ = QVector3D()) {p0 = p0_; p1 = p1_;} + virtual void draw(bool simplest = false); +private: + QVector3D p0, p1; +}; + + + + class GLPrimitiveCube: public GLObjectBase { public: @@ -39,4 +55,19 @@ private: double w, l, h; }; + + + +class GLPrimitiveEllipsoid: public GLObjectBase +{ +public: + GLPrimitiveEllipsoid(double width = 1., double length = 1., double height = 1., int seg_wl = 10, int seg_h = 10, QVector3D pos = QVector3D()); + virtual void init(); +private: + void putTriangle(const QVector3D & v0, const QVector3D & v1, const QVector3D & v2); + double w, l, h; + int swl, sh; +}; + + #endif // GLPRIMITIVE_CUBE_H diff --git a/qglview/gltypes.cpp b/qglview/gltypes.cpp index 77330e0..f251d4a 100644 --- a/qglview/gltypes.cpp +++ b/qglview/gltypes.cpp @@ -70,8 +70,12 @@ void createGLTexture(GLuint & tex, int width, int height, const GLenum & format, //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_COMPONENT16 || format == GL_DEPTH_COMPONENT24 || format == GL_DEPTH_COMPONENT32) glTexImage2D(target, 0, format, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); - else - glTexImage2D(target, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + else { + int t = GL_UNSIGNED_BYTE; + if (format == GL_RGB32F || format == GL_RGB16F) + t = GL_FLOAT; + glTexImage2D(target, 0, format, width, height, 0, GL_RGBA, t, 0); + } //qDebug() << QString::number(glGetError(), 16); } diff --git a/qglview/gltypes.h b/qglview/gltypes.h index 0299479..f2ee0c9 100644 --- a/qglview/gltypes.h +++ b/qglview/gltypes.h @@ -25,9 +25,14 @@ #if __QNX__ || __QNXNTO__ # define QNX #endif +#ifdef __APPLE__ +# define MAC +#endif #ifndef WINDOWS # ifndef QNX -# define LINUX +# ifndef MAC +# define LINUX +# endif # endif #endif #if __GNUC__ @@ -39,10 +44,16 @@ #ifdef WINDOWS # include "GLee.h" #else -# include -# include +# ifdef MAC +# include +# include +# include +# else +# include +# include +# include +# endif #endif -#include #include #include #include @@ -79,6 +90,10 @@ #define M_2PI 6.28318530717958647692 #define M_PI_3 1.04719755119659774615 +#ifndef GL_RGBA16F +# define GL_RGBA16F GL_RGBA16F_ARB +#endif + using std::complex; #ifndef PIP_VERSION @@ -270,7 +285,6 @@ public: QVector3D angles() const {return QVector3D(angle_xy, angle_roll, angle_z);} QVector3D direction() const {return (aim_ - pos_).normalized();} QVector3D directionXY() const {QVector3D tv = aim_ - pos_; return QVector3D(tv.x(), tv.y(), 0.).normalized();} - QVector3D pointFromViewport(int x, int y, double z = 0.); double FOV() const {return fov_;} double distance() const {return (pos_ - aim_).length();} double angleZ() const {return angle_z;} @@ -285,8 +299,9 @@ public: void anglesFromPoints(); void apply(const GLdouble & aspect = 1.); void assign(const Camera & c) {pos_ = c.pos_; aim_ = c.aim_; fov_ = c.fov_; angle_z = c.angle_z; angle_xy = c.angle_xy; angle_roll = c.angle_roll; angle_limit_lower_xy = c.angle_limit_lower_xy; angle_limit_upper_xy = c.angle_limit_upper_xy;} - + QVector3D pointFromViewport(int x_, int y_, double z_); private: + QVector3D pos_; QVector3D aim_; GLdouble fov_; @@ -297,11 +312,11 @@ private: GLdouble angle_roll; GLdouble angle_limit_lower_xy; GLdouble angle_limit_upper_xy; + GLdouble modelview[16], projection[16]; + GLint viewport[4]; bool mirror_x; bool mirror_y; - GLint viewport[4]; - GLdouble projection[16]; - GLdouble modelview[16]; + }; extern Camera * currentCamera; @@ -490,7 +505,7 @@ class QGLViewBase public: QGLViewBase() {} Camera & camera() {return camera_;} - void setCamera(const Camera &cam) {camera_ = cam;} + void setCamera(const Camera & camera) {camera_ = camera;} protected: virtual void collectLights() = 0; Camera camera_; diff --git a/qglview/main.cpp b/qglview/main.cpp index aedca00..b8024ff 100644 --- a/qglview/main.cpp +++ b/qglview/main.cpp @@ -18,15 +18,92 @@ #include #include +#include #include -#include "mainwindow.h" +#include +//#include "mainwindow.h" +#include "unistd.h" +#include + +/*void display () +{ + qDebug() << (const char*)glGetString(GLUT_VERSION); + qDebug() << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); + usleep(200000); +}*/ +template +struct garray { + garray(T * _i) {for (int i = 0; i < N; ++i) _c[i] = &(_i[i]);} + T * _c[N]; + garray & operator =(const garray & o) {for (int i = 0; i < N; ++i) *_c[i] = *(o._c[i]); return *this;}; + template + garray & operator =(const garray & o) {for (int i = 0; i < qMin(N, ON); ++i) *_c[i] = *(o._c[i]); return *this;}; +}; + +template +class gvec3 { +public: + gvec3(T def = T()) {x = y = z = def;} + union { + T xyz[3]; + struct {T x, y, z;}; + }; +private: + T _c[3]; + +}; + +template +QDebug operator<<(QDebug d, const gvec3 & c) { + d.nospace() << "(" << c.x << ", " << c.y << ", " << c.z << ")"; + return d.space(); +} + +typedef gvec3 vec3; +typedef gvec3 ivec3; int main(int argc, char ** argv) { + /*float f[3] = {0., 1., 2.}; + float f2[3] = {-1., -1., -1.}; + garray gar(f2); + qDebug() << f2[0] << f2[1] << f2[2]; + gar = garray((float[3]){f[2], f[1], f[0]}); + qDebug() << f2[0] << f2[1] << f2[2];*/ + /*vec3 v0, v1(20); + v0.y = 10; + qDebug() << v0 << v1;*/ + + /*glutInit ( &argc, argv ); + glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); + glutInitWindowSize ( 500, 500 ); + + // prepare context for 3.3 + glutInitContextVersion ( 3, 3 ); + glutInitContextFlags ( GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG ); + glutInitContextProfile ( GLUT_CORE_PROFILE ); + glutCreateWindow ( "Geometry shader example - particles" ); + glutDisplayFunc ( display ); + glewInit (); + if ( !GLEW_VERSION_3_3 ) + { + printf ( "OpenGL 3.3 not supported.\n" ); + + return 1; + } + + glutMainLoop(); + */ + return 0; QApplication a(argc, argv); + /*QGLFormat f; + f.setVersion(3, 3); + f.setSampleBuffers(true); + f.setProfile(QGLFormat::CoreProfile); + QGLFormat::setDefaultFormat(f);*/ //QApplication::setStyle(new QCleanlooksStyle()); QDir::setCurrent(a.applicationDirPath()); //a.setWindowIcon(QIcon(":/icons/peri4_paint.png")); - MainWindow w; - w.show(); + //MainWindow w; + //w.show(); return a.exec(); } diff --git a/qglview/mainwindow.cpp b/qglview/mainwindow.cpp index f6682a4..7b3a286 100644 --- a/qglview/mainwindow.cpp +++ b/qglview/mainwindow.cpp @@ -19,15 +19,19 @@ #include "mainwindow.h" #include +#define EARTH_H 6356863.019 // m +#define EARTH_WL 6378245.000 // m MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() { setupUi(this); colorHalo->setColor(view->selectionHaloColor()); + sel_obj = 0; treeProperties->assignObject(view); //spinSliderShine->setDecimals(2); view->setFrameShape(QFrame::NoFrame); - view->setRenderer(new RendererDeferredShading(view)); + //view->setRenderer(new RendererDeferredShading(view)); + view->setRenderer(new RendererSimple(view)); view->setMouseSelectionEnabled(true); view->setMouseRotateEnabled(true); view->setBackColor(Qt::lightGray); @@ -36,10 +40,10 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() o->setWindowOpacity(.666); view->addObject(o, Qt::Window);*/ view->start(-1); - obj = loadFrom3DSFile("data/test.3DS", 0.15); + /**obj = loadFrom3DSFile("data/test.3DS", 0.15); m.reflectivity = 1; m.reflection.loadPathesFromDirectory("data/e"); - obj->child("sphere001")->setMaterial(m); + obj->child("sphere001")->setMaterial(m);*/ //m.shine = 40; @@ -55,16 +59,41 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() //obj->child("teapot")->setRenderMode(GLObjectBase::Point); //obj->child("teapot")->setLineWidth(2.); //obj->child("cone")->setRenderMode(GLObjectBase::Line); + ///view->camera().setAim(obj->child("sphere001")->pos()); + + obj = new GLPrimitiveEllipsoid(EARTH_WL / 1E+6, EARTH_WL / 1E+6, EARTH_H / 1E+6, 500, 500);//GLPrimitiveCube(); view->addObject(obj); - view->camera().setAim(obj->child("sphere001")->pos()); + + double al = 7.; + obj = new GLPrimitiveLine(QVector3D(0, 0, -al), QVector3D(0, 0, al)); + obj->material().color_diffuse = Qt::darkBlue; obj->setAcceptLight(false); + view->addObject(obj); + obj = new GLPrimitiveLine(QVector3D(-al, 0, 0), QVector3D(al, 0, 0)); + obj->material().color_diffuse = Qt::darkRed; obj->setAcceptLight(false); + view->addObject(obj); + obj = new GLPrimitiveLine(QVector3D(0, -al, 0), QVector3D(0, al, 0)); + obj->material().color_diffuse = Qt::darkGreen; obj->setAcceptLight(false); + view->addObject(obj); + + double lat = deg2rad*(-85.), lng = deg2rad*(15.); + obj = new GLPrimitiveLine(QVector3D(), QVector3D(cos(lng)*cos(lat), sin(lng)*cos(lat), sin(lat)/*(EARTH_H/EARTH_WL)*/)*5); + view->addObject(obj); + view->camera().setPos(QVector3D(10, -20, 20)); + view->camera().setAim(QVector3D()); view->camera().flyToDistance(10); + view->setMouseSelectionEnabled(false); + view->setSelectionHaloEnabled(false); + view->setHoverHaloEnabled(false); + Light * l = new Light(view->camera().pos()); + l->intensity = 0.8; + view->addObject(l); //view->light(0)->light_type = Light::Omni; //obj = loadFrom3DSFile("34.3DS", 0.03); //view->addObject(obj); //view->camera().moveUp(5, true); - ps = new GLParticlesSystem(QVector3D(0,0,5)); + /**ps = new GLParticlesSystem(QVector3D(0,0,5)); ps->setEmitterType(GLParticlesSystem::Box); ps->setBirthRate(5); ps->setSize(1.); @@ -74,17 +103,17 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() ps->setSpeedDirectionJitter(1); //ps->setTextureScale(2, 2); ps->setAddVerticalFaceEnabled(true); - ps->addForce(QVector3D(0,0,-0.98/20)); + ps->addForce(QVector3D(0,0,-0.98/20));*/ //ps->material().diffuse.bitmap_path = "expl_07.png"; //view->addObject(ps); - box = new GLPrimitiveCube(); + /**box = new GLPrimitiveCube(); box->setSelectable(false); box->setRenderMode(GLObjectBase::Line); box->setLineWidth(2.); view->addObject(box); - box->hide(); - while (view->lightsCount() >= 3) view->removeLight(view->lightsCount() - 1); + box->hide();*/ + while (view->lightsCount() >= 5) view->removeLight(view->lightsCount() - 1); //view->addObject(box); //obj = obj->clone(true); @@ -103,7 +132,7 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() }*/ startTimer(1000/60); - connect(view, SIGNAL(hoverChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(hoverChanged(GLObjectBase*,GLObjectBase*))); + //connect(view, SIGNAL(hoverChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(hoverChanged(GLObjectBase*,GLObjectBase*))); connect(view, SIGNAL(selectionChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(selectionChanged(GLObjectBase*,GLObjectBase*))); connect(view, SIGNAL(glInitializeDone()), this, SLOT(glInit())); connect(matEditor, SIGNAL(changed()), this, SLOT(materialChanged())); @@ -114,7 +143,7 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() MainWindow::~MainWindow() { - delete ps; + //delete ps; } @@ -129,6 +158,8 @@ void MainWindow::changeEvent(QEvent * e) { void MainWindow::timerEvent(QTimerEvent * ) { static double t = 0.; + view->light(0)->setPos(view->camera().pos()); + ((RendererSimple*)(view->renderer()))->mpos = view->mapFromGlobal(QCursor::pos()); /*obj->child("tor")->rotateX(0.5); obj->child("tor")->rotateZ(0.1); obj->child("cone")->rotateZ(1); @@ -169,7 +200,7 @@ void MainWindow::selectionChanged(GLObjectBase * cur, GLObjectBase * prev) { sel_obj = cur; //qDebug() << "selected" << (cur != 0 ? cur->name() : "0"); labelName->setText(cur != 0 ? cur->name() : ""); - if (cur == 0) box->hide(); + /**if (cur == 0) box->hide(); else { box->setScale(cur->boundingBox().size()); box->setPos(cur->boundingBox().pos()); @@ -178,7 +209,7 @@ void MainWindow::selectionChanged(GLObjectBase * cur, GLObjectBase * prev) { ps->setEmitterRect(b); cur->addChild(box); box->show(); - } + }*/ objectEditor->setObject(sel_obj); if (sel_obj == 0) return; matEditor->setMaterial(sel_obj->material()); diff --git a/qglview/renderer_simple.cpp b/qglview/renderer_simple.cpp index 003fac0..7776ca4 100644 --- a/qglview/renderer_simple.cpp +++ b/qglview/renderer_simple.cpp @@ -19,8 +19,25 @@ #include "renderer_simple.h" -RendererSimple::RendererSimple(QGLView * view_): GLRendererBase(view_), fbo(2) { +RendererSimple::RendererSimple(QGLView * view_): GLRendererBase(view_), fbo(2) +, fbo_c(1, true, GL_RGBA32F) /// WARNING +{ shader_fxaa = 0; + shader = 0; /// WARNING +} + + +void RendererSimple::reloadShaders() { + if (shader_fxaa == 0) shader_fxaa = new QGLShaderProgram(view.context()); + loadShaders(shader_fxaa, "FXAA", "shaders"); + if (shader == 0) shader = new QGLShaderProgram(view.context()); /// WARNING + loadShaders(shader, "test", "shaders"); /// WARNING +} + + +void RendererSimple::resizeFBO(int w, int h) { + fbo.resize(w, h); + fbo_c.resize(w, h); /// WARNING } @@ -52,9 +69,25 @@ void RendererSimple::renderScene() { } view.camera().apply(view.aspect); setupLights(l, 8); - //glEnable(GL_MULTISAMPLE); + + + fbo_c.bind(); + glClearFramebuffer(); + shader->bind(); /// WARNING renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled()); - renderObjects(GLObjectBase::Transparent, l, 0, true, true, view.isFogEnabled()); + shader->release(); /// WARNING + if (QRect(QPoint(), fbo_c.size()).contains(mpos)) { + //qDebug() << mpos; + GLfloat data[4] = {0, 0, 0, 0}; + glReadPixels(mpos.x(), fbo_c.height() - mpos.y(), 1, 1, GL_RGBA, GL_FLOAT, data); + qDebug() << QVector3D(data[0], data[1], data[2]); + } + fbo_c.release(); + renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled()); + + + //renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled()); + //renderObjects(GLObjectBase::Transparent, l, 0, true, true, view.isFogEnabled()); if (passes > 1) { glSetLightEnabled(false); glSetCapEnabled(GL_BLEND); diff --git a/qglview/renderer_simple.h b/qglview/renderer_simple.h index 0ab9bbe..def303f 100644 --- a/qglview/renderer_simple.h +++ b/qglview/renderer_simple.h @@ -28,15 +28,19 @@ public: virtual ~RendererSimple() {if (shader_fxaa != 0) delete shader_fxaa;} virtual void renderScene(); + + QPoint mpos; protected: - virtual void init(int width, int height) {fbo.resize(width, height);} - virtual void resize(int width, int height) {fbo.resize(width, height);} - virtual void reloadShaders() {if (shader_fxaa == 0) shader_fxaa = new QGLShaderProgram(view.context()); loadShaders(shader_fxaa, "FXAA", "shaders");} + virtual void init(int width, int height) {resizeFBO(width, height);} + virtual void resize(int width, int height) {resizeFBO(width, height);} + virtual void reloadShaders(); private: - GLFramebuffer fbo; - QGLShaderProgram * shader_fxaa; + void resizeFBO(int w, int h); + + GLFramebuffer fbo , fbo_c; + QGLShaderProgram * shader_fxaa , * shader; };