important fix, texture manager
This commit is contained in:
@@ -54,6 +54,7 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x,
|
|||||||
glSetPolygonMode(GL_FILL);
|
glSetPolygonMode(GL_FILL);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
// glColor4f(1, 1, 1, 1);
|
||||||
int loc = prog ? prog->attributeLocation("qgl_Color") : -1, locv = prog ? prog->attributeLocation("qgl_Vertex") : -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;
|
loct = prog ? prog->attributeLocation("qgl_Texture") : -1, locc = prog ? prog->attributeLocation("view_corner") : -1;
|
||||||
QOpenGLFunctions * glFuncs = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions * glFuncs = QOpenGLContext::currentContext()->functions();
|
||||||
|
|||||||
@@ -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) {
|
void VertexObject::draw(QOpenGLExtraFunctions * f, GLenum geom_type, int vert_cout, int obj_count) {
|
||||||
|
if (obj_count <= 0) return;
|
||||||
bind(f);
|
bind(f);
|
||||||
f->glDrawElementsInstanced(geom_type, vert_cout, GL_UNSIGNED_INT, 0, obj_count);
|
f->glDrawElementsInstanced(geom_type, vert_cout, GL_UNSIGNED_INT, 0, obj_count);
|
||||||
release(f);
|
release(f);
|
||||||
|
|||||||
@@ -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) {
|
QImage TextureManager::loadTextureImage(const QString & path, bool is_normal, MapBakeOptions opts, uint * result_hash) {
|
||||||
if (result_hash) *result_hash = 0;
|
if (result_hash) *result_hash = 0;
|
||||||
|
if (path.isEmpty()) return QImage();
|
||||||
QString p = findFile(path);
|
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);
|
uint hash = mapHash(p, is_normal, opts);
|
||||||
QImage image = cache_image.value(hash);
|
QImage image = cache_image.value(hash);
|
||||||
if (!image.isNull()) {
|
if (!image.isNull()) {
|
||||||
@@ -251,6 +257,11 @@ void TextureManager::clearImageCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TextureManager::clearMissed() {
|
||||||
|
missed.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TextureManager::loadToTexture2DArray(Texture2DArray * array, QSize map_size) {
|
void TextureManager::loadToTexture2DArray(Texture2DArray * array, QSize map_size) {
|
||||||
array->resize(f, map_size, texturesCount());
|
array->resize(f, map_size, texturesCount());
|
||||||
array_layers.clear();
|
array_layers.clear();
|
||||||
@@ -262,4 +273,5 @@ void TextureManager::loadToTexture2DArray(Texture2DArray * array, QSize map_size
|
|||||||
array_layers[it.key()] = cl;
|
array_layers[it.key()] = cl;
|
||||||
}
|
}
|
||||||
array->mipmaps(f);
|
array->mipmaps(f);
|
||||||
|
emit filesUsed(texturesCount());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,9 @@
|
|||||||
#include <QOpenGLExtraFunctions>
|
#include <QOpenGLExtraFunctions>
|
||||||
|
|
||||||
|
|
||||||
class QGLENGINE_CORE_EXPORT TextureManager {
|
class QGLENGINE_CORE_EXPORT TextureManager: public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextureManager(QOpenGLExtraFunctions * f_): f(f_) {}
|
TextureManager(QOpenGLExtraFunctions * f_): f(f_) {}
|
||||||
virtual ~TextureManager() {}
|
virtual ~TextureManager() {}
|
||||||
@@ -50,12 +52,15 @@ public:
|
|||||||
int texturesCount() const { return cache_image.size(); }
|
int texturesCount() const { return cache_image.size(); }
|
||||||
uint texturesHash() const { return qHash(cache_image.keys()); }
|
uint texturesHash() const { return qHash(cache_image.keys()); }
|
||||||
void clearImageCache();
|
void clearImageCache();
|
||||||
|
void clearMissed();
|
||||||
|
const QSet<QString> & missedFiles() const { return missed; }
|
||||||
|
|
||||||
void loadToTexture2DArray(Texture2DArray * array, QSize map_size);
|
void loadToTexture2DArray(Texture2DArray * array, QSize map_size);
|
||||||
|
|
||||||
static void addSearchPath(const QString & path);
|
static void addSearchPath(const QString & path);
|
||||||
static void clearSearchPathes() { search_pathes.clear(); }
|
static void clearSearchPathes() { search_pathes.clear(); }
|
||||||
static QStringList searchPathes() { return search_pathes; }
|
static QStringList searchPathes() { return search_pathes; }
|
||||||
|
static void setSearchPathes(const QStringList & pl) { search_pathes = pl; }
|
||||||
static QString findFile(const QString & path);
|
static QString findFile(const QString & path);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -69,7 +74,12 @@ protected:
|
|||||||
QMap<uint, GLuint> cache_loaded;
|
QMap<uint, GLuint> cache_loaded;
|
||||||
QMap<uint, QImage> cache_image;
|
QMap<uint, QImage> cache_image;
|
||||||
QMap<uint, int> array_layers;
|
QMap<uint, int> array_layers;
|
||||||
|
QSet<QString> missed;
|
||||||
QStringList tex_pathes;
|
QStringList tex_pathes;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void loadingDone();
|
||||||
|
void filesUsed(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ void Renderer::reloadShaders() {
|
|||||||
shader_fxaa = nullptr;
|
shader_fxaa = nullptr;
|
||||||
if (tone_proc.shader_sum) delete tone_proc.shader_sum;
|
if (tone_proc.shader_sum) delete tone_proc.shader_sum;
|
||||||
tone_proc.shader_sum = nullptr;
|
tone_proc.shader_sum = nullptr;
|
||||||
QString dir = ":/shaders/";
|
QString dir = "./shaders/";
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
loadShadersMulti(shaders[it.key()], dir + it.value(), true, shader_defines.value(it.key()));
|
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(obrSolidSpot, 2);
|
||||||
fbo_out.bindColorTexture(obrTransparentOmni, 3);
|
fbo_out.bindColorTexture(obrTransparentOmni, 3);
|
||||||
fbo_out.bindColorTexture(obrTransparentSpot, 4);
|
fbo_out.bindColorTexture(obrTransparentSpot, 4);
|
||||||
fbo_out.setWriteBuffer(obrGeneral0);
|
fbo_out.setWriteBuffer(obrLighting);
|
||||||
renderQuad(prog, quad);
|
renderQuad(prog, quad);
|
||||||
}
|
}
|
||||||
phase.end();
|
phase.end();
|
||||||
|
|
||||||
cur_write_plane = obrGeneral0;
|
fbo_out.bind();
|
||||||
|
cur_write_plane = obrLighting;
|
||||||
|
|
||||||
/// tonemapping
|
/// tonemapping
|
||||||
phase.begin("tonemap");
|
phase.begin("tonemap");
|
||||||
tone_proc.process();
|
tone_proc.process();
|
||||||
auto free = getFreePlanes(0);
|
auto free = getFreePlanes(0);
|
||||||
if (bindShader(srTonemapPass, &prog)) {
|
if (bindShader(srTonemapPass, &prog)) {
|
||||||
fbo_out.bind();
|
|
||||||
prog->setUniformValue("gamma", gamma_);
|
prog->setUniformValue("gamma", gamma_);
|
||||||
prog->setUniformValue("frame_max", tone_proc.frameMax());
|
prog->setUniformValue("frame_max", tone_proc.frameMax());
|
||||||
|
// qDebug() << tone_proc.frameMax();
|
||||||
fbo_out.bindColorTexture(prev_write_plane, 0);
|
fbo_out.bindColorTexture(prev_write_plane, 0);
|
||||||
renderQuad(prog, quad);
|
renderQuad(prog, quad);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class QGLENGINE_CORE_EXPORT Renderer: public RendererBase {
|
|||||||
obrSolidSpot,
|
obrSolidSpot,
|
||||||
obrTransparentOmni,
|
obrTransparentOmni,
|
||||||
obrTransparentSpot,
|
obrTransparentSpot,
|
||||||
|
obrLighting,
|
||||||
|
|
||||||
obrGeneral0,
|
obrGeneral0,
|
||||||
obrGeneral1,
|
obrGeneral1,
|
||||||
|
|||||||
@@ -147,8 +147,7 @@ void RendererBase::fillSelectionsBuffer(QVector<uchar> & buffer, bool yes, int s
|
|||||||
|
|
||||||
void RendererBase::reloadMaterials(Scene & scene) {
|
void RendererBase::reloadMaterials(Scene & scene) {
|
||||||
// qDebug() << "reloadMaterias";
|
// qDebug() << "reloadMaterias";
|
||||||
QList<Map *> maps;
|
textures_manager->clearMissed();
|
||||||
QMap<QString, int> tex_layers[2];
|
|
||||||
for (Material * m: scene.materials) {
|
for (Material * m: scene.materials) {
|
||||||
m->load(textures_manager);
|
m->load(textures_manager);
|
||||||
}
|
}
|
||||||
@@ -163,6 +162,7 @@ void RendererBase::reloadMaterials(Scene & scene) {
|
|||||||
for (Material * m: scene.materials) {
|
for (Material * m: scene.materials) {
|
||||||
m->setMapsLayers(textures_manager);
|
m->setMapsLayers(textures_manager);
|
||||||
}
|
}
|
||||||
|
textures_manager->loadingDone();
|
||||||
|
|
||||||
QGLMaterial glm;
|
QGLMaterial glm;
|
||||||
cur_materials_.clear();
|
cur_materials_.clear();
|
||||||
|
|||||||
@@ -158,10 +158,10 @@ void RendererSelection::renderSelection(Scene & scene) {
|
|||||||
prog->setUniformValue("fb_hover", (int)sbrSrcHover);
|
prog->setUniformValue("fb_hover", (int)sbrSrcHover);
|
||||||
prog->setUniformValue("fb_selection", (int)sbrSrcSelect);
|
prog->setUniformValue("fb_selection", (int)sbrSrcSelect);
|
||||||
prog->setUniformValue("hover_id",
|
prog->setUniformValue("hover_id",
|
||||||
QVector4D(float(id_hover & 0xFF) / 255.f,
|
QVector4D(float(id_hover & 0xFF) / 255.f,
|
||||||
float((id_hover >> 8) & 0xFF) / 255.f,
|
float((id_hover >> 8) & 0xFF) / 255.f,
|
||||||
float((id_hover >> 16) & 0xFF) / 255.f,
|
float((id_hover >> 16) & 0xFF) / 255.f,
|
||||||
float((id_hover >> 24) & 0xFF) / 255.f));
|
float((id_hover >> 24) & 0xFF) / 255.f));
|
||||||
r->renderQuad(prog, r->quad, view->camera());
|
r->renderQuad(prog, r->quad, view->camera());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -379,7 +379,6 @@ void RendererService::drawLights() {
|
|||||||
r->fillSelectionsBuffer(rs.cur_selections_, lights2objectList(v->scene()->lights_used.value(Light::Omni)));
|
r->fillSelectionsBuffer(rs.cur_selections_, lights2objectList(v->scene()->lights_used.value(Light::Omni)));
|
||||||
omni_mesh->loadSelections(v, rs.cur_selections_);
|
omni_mesh->loadSelections(v, rs.cur_selections_);
|
||||||
omni_mesh->draw(v, cur_objects.size());
|
omni_mesh->draw(v, cur_objects.size());
|
||||||
|
|
||||||
ObjectBaseList ll = lights2objectList(r->view->scene()->lights_used.value(Light::Cone));
|
ObjectBaseList ll = lights2objectList(r->view->scene()->lights_used.value(Light::Cone));
|
||||||
fillAimedObjects(ll, line_spot_f);
|
fillAimedObjects(ll, line_spot_f);
|
||||||
cone_mesh->loadObjects(v, cur_objects);
|
cone_mesh->loadObjects(v, cur_objects);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ TonemappingProc::TonemappingProc(Renderer * rend)
|
|||||||
: QThread()
|
: QThread()
|
||||||
, r(rend)
|
, r(rend)
|
||||||
, fbo_1x1(r->view, 1, false, GL_RGB32F)
|
, 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) {
|
, buffer_vbo(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW) {
|
||||||
shader_sum = 0;
|
shader_sum = 0;
|
||||||
timer_delim = 0;
|
timer_delim = 0;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public:
|
|||||||
QString name() const { return "Blur"; }
|
QString name() const { return "Blur"; }
|
||||||
void reloadShaders() { QGLEngineShaders::loadShadersMulti(mys, "test1.glsl"); }
|
void reloadShaders() { QGLEngineShaders::loadShadersMulti(mys, "test1.glsl"); }
|
||||||
void draw() {
|
void draw() {
|
||||||
|
if (!mys) return;
|
||||||
auto planes = getFreePlanes(1);
|
auto planes = getFreePlanes(1);
|
||||||
bindPreviousOutput(0);
|
bindPreviousOutput(0);
|
||||||
// bindDeferredBuffer(Renderer::dbrNormalZSolid, 1);
|
// bindDeferredBuffer(Renderer::dbrNormalZSolid, 1);
|
||||||
@@ -69,7 +70,7 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView
|
|||||||
view->view()->setHoverHaloEnabled(true);
|
view->view()->setHoverHaloEnabled(true);
|
||||||
view->view()->setDepthStart(0.1);
|
view->view()->setDepthStart(0.1);
|
||||||
view->view()->setSelectionMode(Scene::smMultiSelection);
|
view->view()->setSelectionMode(Scene::smMultiSelection);
|
||||||
// view->view()->renderer_.addFramebufferEffect(new Effect1());
|
view->view()->renderer_.addFramebufferEffect(new Effect1());
|
||||||
|
|
||||||
|
|
||||||
groupShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsEnabled));
|
groupShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsEnabled));
|
||||||
@@ -106,6 +107,7 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView
|
|||||||
objectEditor->assignQGLView(view->view());
|
objectEditor->assignQGLView(view->view());
|
||||||
primitiveEditor->assignQGLView(view->view());
|
primitiveEditor->assignQGLView(view->view());
|
||||||
viewEditor->assignQGLView(view->view());
|
viewEditor->assignQGLView(view->view());
|
||||||
|
widgetTextures->assignQGLView(view->view());
|
||||||
|
|
||||||
session.load();
|
session.load();
|
||||||
|
|
||||||
@@ -169,6 +171,7 @@ void QGLViewWindow::loadFile(const QString & path, bool import) {
|
|||||||
view->view()->focusOn(view->scene()->boundingBox());
|
view->view()->focusOn(view->scene()->boundingBox());
|
||||||
}
|
}
|
||||||
TextureManager::addSearchPath(fi.absoluteDir().path());
|
TextureManager::addSearchPath(fi.absoluteDir().path());
|
||||||
|
widgetTextures->showPathes();
|
||||||
delete s;
|
delete s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>881</width>
|
<width>761</width>
|
||||||
<height>840</height>
|
<height>840</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -660,6 +660,16 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</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">
|
<widget class="QWidget" name="tab_2">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Object</string>
|
<string>Object</string>
|
||||||
@@ -827,7 +837,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionOpen">
|
<action name="actionOpen">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -839,7 +849,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionSave">
|
<action name="actionSave">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/icons/document-save-all.png</normaloff>:/icons/document-save-all.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -851,7 +861,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionReset">
|
<action name="actionReset">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/icons/document-new.png</normaloff>:/icons/document-new.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -863,7 +873,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionSaveSelected">
|
<action name="actionSaveSelected">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -978,8 +988,16 @@
|
|||||||
<header>view_editor.h</header>
|
<header>view_editor.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>TexturesEditor</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>textures_editor.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
|
<include location="../../../qad/libs/blockview/qad_blockview.qrc"/>
|
||||||
|
<include location="../../../qad/libs/widgets/qad_widgets.qrc"/>
|
||||||
<include location="../core/qglengine_core.qrc"/>
|
<include location="../core/qglengine_core.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
103
src/widgets/textures_editor.cpp
Normal file
103
src/widgets/textures_editor.cpp
Normal 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();
|
||||||
|
}
|
||||||
60
src/widgets/textures_editor.h
Normal file
60
src/widgets/textures_editor.h
Normal 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
|
||||||
172
src/widgets/textures_editor.ui
Normal file
172
src/widgets/textures_editor.ui
Normal 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>
|
||||||
Reference in New Issue
Block a user