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

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