important fix, texture manager

This commit is contained in:
2023-02-07 18:11:06 +03:00
parent 9cc870c996
commit 4e62165c80
15 changed files with 401 additions and 20 deletions

View File

@@ -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();

View File

@@ -111,6 +111,7 @@ void VertexObject::loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar
void VertexObject::draw(QOpenGLExtraFunctions * f, GLenum geom_type, int vert_cout, int obj_count) {
if (obj_count <= 0) return;
bind(f);
f->glDrawElementsInstanced(geom_type, vert_cout, GL_UNSIGNED_INT, 0, obj_count);
release(f);

View File

@@ -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());
}

View File

@@ -29,7 +29,9 @@
#include <QOpenGLExtraFunctions>
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<QString> & 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<uint, GLuint> cache_loaded;
QMap<uint, QImage> cache_image;
QMap<uint, int> array_layers;
QSet<QString> missed;
QStringList tex_pathes;
signals:
void loadingDone();
void filesUsed(int);
};

View File

@@ -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 {

View File

@@ -63,6 +63,7 @@ class QGLENGINE_CORE_EXPORT Renderer: public RendererBase {
obrSolidSpot,
obrTransparentOmni,
obrTransparentSpot,
obrLighting,
obrGeneral0,
obrGeneral1,

View File

@@ -147,8 +147,7 @@ void RendererBase::fillSelectionsBuffer(QVector<uchar> & buffer, bool yes, int s
void RendererBase::reloadMaterials(Scene & scene) {
// qDebug() << "reloadMaterias";
QList<Map *> maps;
QMap<QString, int> 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();

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -80,7 +80,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>881</width>
<width>761</width>
<height>840</height>
</rect>
</property>
@@ -660,6 +660,16 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_7">
<attribute name="title">
<string>Search pathes</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="TexturesEditor" name="widgetTextures" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Object</string>
@@ -827,7 +837,7 @@
</action>
<action name="actionOpen">
<property name="icon">
<iconset resource="../core/qglengine_core.qrc">
<iconset resource="../../../qad/libs/blockview/qad_blockview.qrc">
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
</property>
<property name="text">
@@ -839,7 +849,7 @@
</action>
<action name="actionSave">
<property name="icon">
<iconset resource="../core/qglengine_core.qrc">
<iconset resource="../../../qad/libs/widgets/qad_widgets.qrc">
<normaloff>:/icons/document-save-all.png</normaloff>:/icons/document-save-all.png</iconset>
</property>
<property name="text">
@@ -851,7 +861,7 @@
</action>
<action name="actionReset">
<property name="icon">
<iconset resource="../core/qglengine_core.qrc">
<iconset resource="../../../qad/libs/widgets/qad_widgets.qrc">
<normaloff>:/icons/document-new.png</normaloff>:/icons/document-new.png</iconset>
</property>
<property name="text">
@@ -863,7 +873,7 @@
</action>
<action name="actionSaveSelected">
<property name="icon">
<iconset resource="../core/qglengine_core.qrc">
<iconset resource="../../../qad/libs/blockview/qad_blockview.qrc">
<normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset>
</property>
<property name="text">
@@ -978,8 +988,16 @@
<header>view_editor.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TexturesEditor</class>
<extends>QWidget</extends>
<header>textures_editor.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../../qad/libs/blockview/qad_blockview.qrc"/>
<include location="../../../qad/libs/widgets/qad_widgets.qrc"/>
<include location="../core/qglengine_core.qrc"/>
</resources>
<connections/>

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "textures_editor.h"
#include "glmaterial.h"
#include "gltexture_manager.h"
#include "qglview.h"
#include "ui_textures_editor.h"
#include <QInputDialog>
#include <QMessageBox>
#include <qad_types.h>
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();
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef textures_editor_H
#define textures_editor_H
#include "gltypes.h"
#include <QFileDialog>
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

View File

@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TexturesEditor</class>
<widget class="QWidget" name="TexturesEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>435</width>
<height>347</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<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>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Search pathes:</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonPathesAdd">
<property name="toolTip">
<string>Add</string>
</property>
<property name="icon">
<iconset resource="../../../qad/libs/piqt_utils/qad_piqt_widgets.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonPathesDelete">
<property name="toolTip">
<string>Delete</string>
</property>
<property name="icon">
<iconset resource="../../../qad/libs/blockview/qad_blockview.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonPathesClear">
<property name="toolTip">
<string>Clear</string>
</property>
<property name="icon">
<iconset resource="../../../qad/libs/application/qad_application.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listWidget">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Used files:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelUsedFiles">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonReload">
<property name="toolTip">
<string>Reload</string>
</property>
<property name="icon">
<iconset resource="../core/qglengine_core.qrc">
<normaloff>:/icons/view-refresh.png</normaloff>:/icons/view-refresh.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labelMissed">
<property name="text">
<string>Missed files:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../../qad/libs/application/qad_application.qrc"/>
<include location="../../../qad/libs/blockview/qad_blockview.qrc"/>
<include location="../../../qad/libs/piqt_utils/qad_piqt_widgets.qrc"/>
<include location="../core/qglengine_core.qrc"/>
</resources>
<connections/>
<slots>
<slot>materialChanged()</slot>
</slots>
</ui>