diff --git a/src/core/core/gltypes.cpp b/src/core/core/gltypes.cpp index 66e8ab7..aa2894f 100644 --- a/src/core/core/gltypes.cpp +++ b/src/core/core/gltypes.cpp @@ -54,6 +54,7 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x, glSetPolygonMode(GL_FILL); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); + // glColor4f(1, 1, 1, 1); int loc = prog ? prog->attributeLocation("qgl_Color") : -1, locv = prog ? prog->attributeLocation("qgl_Vertex") : -1, loct = prog ? prog->attributeLocation("qgl_Texture") : -1, locc = prog ? prog->attributeLocation("view_corner") : -1; QOpenGLFunctions * glFuncs = QOpenGLContext::currentContext()->functions(); diff --git a/src/core/core/glvertexobject.cpp b/src/core/core/glvertexobject.cpp index 803ac73..5514663 100644 --- a/src/core/core/glvertexobject.cpp +++ b/src/core/core/glvertexobject.cpp @@ -111,6 +111,7 @@ void VertexObject::loadSelections(QOpenGLExtraFunctions * f, const QVectorglDrawElementsInstanced(geom_type, vert_cout, GL_UNSIGNED_INT, 0, obj_count); release(f); diff --git a/src/core/render/gltexture_manager.cpp b/src/core/render/gltexture_manager.cpp index ce9d3a6..dd1c97f 100644 --- a/src/core/render/gltexture_manager.cpp +++ b/src/core/render/gltexture_manager.cpp @@ -68,8 +68,14 @@ GLuint TextureManager::loadTexture(const QString & path, bool is_normal, MapBake QImage TextureManager::loadTextureImage(const QString & path, bool is_normal, MapBakeOptions opts, uint * result_hash) { if (result_hash) *result_hash = 0; + if (path.isEmpty()) return QImage(); QString p = findFile(path); - if (p.isEmpty()) return QImage(); + if (p.isEmpty()) { + missed << path; + // p = findFile(path); + // if (p.isEmpty()) return QImage(); + return QImage(); + } uint hash = mapHash(p, is_normal, opts); QImage image = cache_image.value(hash); if (!image.isNull()) { @@ -251,6 +257,11 @@ void TextureManager::clearImageCache() { } +void TextureManager::clearMissed() { + missed.clear(); +} + + void TextureManager::loadToTexture2DArray(Texture2DArray * array, QSize map_size) { array->resize(f, map_size, texturesCount()); array_layers.clear(); @@ -262,4 +273,5 @@ void TextureManager::loadToTexture2DArray(Texture2DArray * array, QSize map_size array_layers[it.key()] = cl; } array->mipmaps(f); + emit filesUsed(texturesCount()); } diff --git a/src/core/render/gltexture_manager.h b/src/core/render/gltexture_manager.h index 1e06696..9c9eae3 100644 --- a/src/core/render/gltexture_manager.h +++ b/src/core/render/gltexture_manager.h @@ -29,7 +29,9 @@ #include -class QGLENGINE_CORE_EXPORT TextureManager { +class QGLENGINE_CORE_EXPORT TextureManager: public QObject { + Q_OBJECT + public: TextureManager(QOpenGLExtraFunctions * f_): f(f_) {} virtual ~TextureManager() {} @@ -50,12 +52,15 @@ public: int texturesCount() const { return cache_image.size(); } uint texturesHash() const { return qHash(cache_image.keys()); } void clearImageCache(); + void clearMissed(); + const QSet & missedFiles() const { return missed; } void loadToTexture2DArray(Texture2DArray * array, QSize map_size); static void addSearchPath(const QString & path); static void clearSearchPathes() { search_pathes.clear(); } static QStringList searchPathes() { return search_pathes; } + static void setSearchPathes(const QStringList & pl) { search_pathes = pl; } static QString findFile(const QString & path); protected: @@ -69,7 +74,12 @@ protected: QMap cache_loaded; QMap cache_image; QMap array_layers; + QSet missed; QStringList tex_pathes; + +signals: + void loadingDone(); + void filesUsed(int); }; diff --git a/src/core/render/renderer.cpp b/src/core/render/renderer.cpp index b7683f2..9f7dcf4 100644 --- a/src/core/render/renderer.cpp +++ b/src/core/render/renderer.cpp @@ -119,7 +119,7 @@ void Renderer::reloadShaders() { shader_fxaa = nullptr; if (tone_proc.shader_sum) delete tone_proc.shader_sum; tone_proc.shader_sum = nullptr; - QString dir = ":/shaders/"; + QString dir = "./shaders/"; while (it.hasNext()) { it.next(); loadShadersMulti(shaders[it.key()], dir + it.value(), true, shader_defines.value(it.key())); @@ -409,21 +409,22 @@ void Renderer::renderScene() { fbo_out.bindColorTexture(obrSolidSpot, 2); fbo_out.bindColorTexture(obrTransparentOmni, 3); fbo_out.bindColorTexture(obrTransparentSpot, 4); - fbo_out.setWriteBuffer(obrGeneral0); + fbo_out.setWriteBuffer(obrLighting); renderQuad(prog, quad); } phase.end(); - cur_write_plane = obrGeneral0; + fbo_out.bind(); + cur_write_plane = obrLighting; /// tonemapping phase.begin("tonemap"); tone_proc.process(); auto free = getFreePlanes(0); if (bindShader(srTonemapPass, &prog)) { - fbo_out.bind(); prog->setUniformValue("gamma", gamma_); prog->setUniformValue("frame_max", tone_proc.frameMax()); + // qDebug() << tone_proc.frameMax(); fbo_out.bindColorTexture(prev_write_plane, 0); renderQuad(prog, quad); } else { diff --git a/src/core/render/renderer.h b/src/core/render/renderer.h index cdaeb30..3517cc4 100644 --- a/src/core/render/renderer.h +++ b/src/core/render/renderer.h @@ -63,6 +63,7 @@ class QGLENGINE_CORE_EXPORT Renderer: public RendererBase { obrSolidSpot, obrTransparentOmni, obrTransparentSpot, + obrLighting, obrGeneral0, obrGeneral1, diff --git a/src/core/render/renderer_base.cpp b/src/core/render/renderer_base.cpp index e2a3700..0d57a2c 100644 --- a/src/core/render/renderer_base.cpp +++ b/src/core/render/renderer_base.cpp @@ -147,8 +147,7 @@ void RendererBase::fillSelectionsBuffer(QVector & buffer, bool yes, int s void RendererBase::reloadMaterials(Scene & scene) { // qDebug() << "reloadMaterias"; - QList maps; - QMap tex_layers[2]; + textures_manager->clearMissed(); for (Material * m: scene.materials) { m->load(textures_manager); } @@ -163,6 +162,7 @@ void RendererBase::reloadMaterials(Scene & scene) { for (Material * m: scene.materials) { m->setMapsLayers(textures_manager); } + textures_manager->loadingDone(); QGLMaterial glm; cur_materials_.clear(); diff --git a/src/core/render/renderer_selection.cpp b/src/core/render/renderer_selection.cpp index 1f36b11..0243234 100644 --- a/src/core/render/renderer_selection.cpp +++ b/src/core/render/renderer_selection.cpp @@ -158,10 +158,10 @@ void RendererSelection::renderSelection(Scene & scene) { prog->setUniformValue("fb_hover", (int)sbrSrcHover); prog->setUniformValue("fb_selection", (int)sbrSrcSelect); prog->setUniformValue("hover_id", - QVector4D(float(id_hover & 0xFF) / 255.f, - float((id_hover >> 8) & 0xFF) / 255.f, - float((id_hover >> 16) & 0xFF) / 255.f, - float((id_hover >> 24) & 0xFF) / 255.f)); + QVector4D(float(id_hover & 0xFF) / 255.f, + float((id_hover >> 8) & 0xFF) / 255.f, + float((id_hover >> 16) & 0xFF) / 255.f, + float((id_hover >> 24) & 0xFF) / 255.f)); r->renderQuad(prog, r->quad, view->camera()); } diff --git a/src/core/render/renderer_service.cpp b/src/core/render/renderer_service.cpp index ba455c8..7698e11 100644 --- a/src/core/render/renderer_service.cpp +++ b/src/core/render/renderer_service.cpp @@ -379,7 +379,6 @@ void RendererService::drawLights() { r->fillSelectionsBuffer(rs.cur_selections_, lights2objectList(v->scene()->lights_used.value(Light::Omni))); omni_mesh->loadSelections(v, rs.cur_selections_); omni_mesh->draw(v, cur_objects.size()); - ObjectBaseList ll = lights2objectList(r->view->scene()->lights_used.value(Light::Cone)); fillAimedObjects(ll, line_spot_f); cone_mesh->loadObjects(v, cur_objects); diff --git a/src/core/render/tonemapping_proc.cpp b/src/core/render/tonemapping_proc.cpp index d8a67b8..a2c0b34 100644 --- a/src/core/render/tonemapping_proc.cpp +++ b/src/core/render/tonemapping_proc.cpp @@ -31,7 +31,7 @@ TonemappingProc::TonemappingProc(Renderer * rend) : QThread() , r(rend) , fbo_1x1(r->view, 1, false, GL_RGB32F) - , fbomm(r->fbo_out, Renderer::obrGeneral0, 3) + , fbomm(r->fbo_out, Renderer::obrLighting, 3) , buffer_vbo(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW) { shader_sum = 0; timer_delim = 0; diff --git a/src/qglview_test/qglview_window.cpp b/src/qglview_test/qglview_window.cpp index 3c38fd8..3d400a4 100644 --- a/src/qglview_test/qglview_window.cpp +++ b/src/qglview_test/qglview_window.cpp @@ -34,6 +34,7 @@ public: QString name() const { return "Blur"; } void reloadShaders() { QGLEngineShaders::loadShadersMulti(mys, "test1.glsl"); } void draw() { + if (!mys) return; auto planes = getFreePlanes(1); bindPreviousOutput(0); // bindDeferredBuffer(Renderer::dbrNormalZSolid, 1); @@ -69,7 +70,7 @@ 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()); + view->view()->renderer_.addFramebufferEffect(new Effect1()); groupShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsEnabled)); @@ -106,6 +107,7 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView objectEditor->assignQGLView(view->view()); primitiveEditor->assignQGLView(view->view()); viewEditor->assignQGLView(view->view()); + widgetTextures->assignQGLView(view->view()); session.load(); @@ -169,6 +171,7 @@ void QGLViewWindow::loadFile(const QString & path, bool import) { view->view()->focusOn(view->scene()->boundingBox()); } TextureManager::addSearchPath(fi.absoluteDir().path()); + widgetTextures->showPathes(); delete s; } diff --git a/src/qglview_test/qglview_window.ui b/src/qglview_test/qglview_window.ui index 78a5f3b..1177b29 100644 --- a/src/qglview_test/qglview_window.ui +++ b/src/qglview_test/qglview_window.ui @@ -80,7 +80,7 @@ 0 0 - 881 + 761 840 @@ -660,6 +660,16 @@ + + + Search pathes + + + + + + + Object @@ -827,7 +837,7 @@ - + :/icons/document-open.png:/icons/document-open.png @@ -839,7 +849,7 @@ - + :/icons/document-save-all.png:/icons/document-save-all.png @@ -851,7 +861,7 @@ - + :/icons/document-new.png:/icons/document-new.png @@ -863,7 +873,7 @@ - + :/icons/document-save.png:/icons/document-save.png @@ -978,8 +988,16 @@
view_editor.h
1 + + TexturesEditor + QWidget +
textures_editor.h
+ 1 +
+ + diff --git a/src/widgets/textures_editor.cpp b/src/widgets/textures_editor.cpp new file mode 100644 index 0000000..4ecdf78 --- /dev/null +++ b/src/widgets/textures_editor.cpp @@ -0,0 +1,103 @@ +/* + QGL TexturesEditor + 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 . +*/ + +#include "textures_editor.h" + +#include "glmaterial.h" +#include "gltexture_manager.h" +#include "qglview.h" +#include "ui_textures_editor.h" + +#include +#include +#include + + +TexturesEditor::TexturesEditor(QWidget * parent): QWidget(parent) { + ui = new Ui::TexturesEditor(); + ui->setupUi(this); + ui->labelMissed->hide(); + view = 0; +} + + +void TexturesEditor::assignQGLView(QGLView * v) { + view = v; + connect(view->textureManager(), &TextureManager::loadingDone, this, [this]() { showWarning(); }); + connect(view->textureManager(), &TextureManager::filesUsed, this, [this](int count) { ui->labelUsedFiles->setNum(count); }); + showPathes(); +} + + +void TexturesEditor::changeEvent(QEvent * e) { + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: ui->retranslateUi(this); break; + default: break; + } +} + + +void TexturesEditor::showPathes() { + ui->listWidget->clear(); + ui->listWidget->addItems(TextureManager::searchPathes()); +} + + +void TexturesEditor::showWarning() { + QString mf = QStringList(view->textureManager()->missedFiles().values()).join("\n"); + ui->labelMissed->setText(tr("Missed files:") + "\n" + mf); + ui->labelMissed->setHidden(mf.isEmpty()); +} + + +void TexturesEditor::setPathes() { + QStringList pl; + for (int i = 0; i < ui->listWidget->count(); ++i) + pl << ui->listWidget->item(i)->text(); + TextureManager::setSearchPathes(pl); + if (view) view->reloadTextures(); +} + + +void TexturesEditor::on_buttonPathesAdd_clicked() { + QString p = QFileDialog::getExistingDirectory(nullptr, tr("Select search path"), prev_path); + if (p.isEmpty()) return; + prev_path = p; + if (TextureManager::searchPathes().contains(p)) return; + ui->listWidget->addItem(p); + setPathes(); +} + + +void TexturesEditor::on_buttonPathesDelete_clicked() { + qDeleteAll(ui->listWidget->selectedItems()); + setPathes(); +} + + +void TexturesEditor::on_buttonPathesClear_clicked() { + ui->listWidget->clear(); + setPathes(); +} + + +void TexturesEditor::on_buttonReload_clicked() { + if (!view) return; + view->reloadTextures(); +} diff --git a/src/widgets/textures_editor.h b/src/widgets/textures_editor.h new file mode 100644 index 0000000..5b0df07 --- /dev/null +++ b/src/widgets/textures_editor.h @@ -0,0 +1,60 @@ +/* + QGL TexturesEditor + 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 . +*/ + +#ifndef textures_editor_H +#define textures_editor_H + +#include "gltypes.h" + +#include + +namespace Ui { +class TexturesEditor; +} + +class TexturesEditor: public QWidget { + Q_OBJECT + +public: + explicit TexturesEditor(QWidget * parent = 0); + + void assignQGLView(QGLView * v); + +protected: + void changeEvent(QEvent * e); + void setPathes(); + + Ui::TexturesEditor * ui; + QGLView * view; + QString prev_path; + +public slots: + void showPathes(); + +private slots: + void showWarning(); + void on_buttonPathesAdd_clicked(); + void on_buttonPathesDelete_clicked(); + void on_buttonPathesClear_clicked(); + void on_buttonReload_clicked(); + +signals: + void changed(); +}; + +#endif diff --git a/src/widgets/textures_editor.ui b/src/widgets/textures_editor.ui new file mode 100644 index 0000000..84d43d6 --- /dev/null +++ b/src/widgets/textures_editor.ui @@ -0,0 +1,172 @@ + + + TexturesEditor + + + + 0 + 0 + 435 + 347 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + 0 + 0 + + + + Search pathes: + + + + + + + Add + + + + :/icons/list-add.png:/icons/list-add.png + + + + + + + Delete + + + + :/icons/edit-delete.png:/icons/edit-delete.png + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 20 + 10 + + + + + + + + Clear + + + + :/icons/edit-clear.png:/icons/edit-clear.png + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + + + + + + + + + + 0 + 0 + + + + Used files: + + + + + + + 0 + + + + + + + Reload + + + + :/icons/view-refresh.png:/icons/view-refresh.png + + + + + + + + + Missed files: + + + true + + + + + + + + + + + + + + materialChanged() + +