refactor texture loading, maps invert channels works
This commit is contained in:
@@ -38,7 +38,7 @@ RendererBase::RendererBase(QGLView * view_)
|
||||
, textures_empty(false)
|
||||
, textures_maps(true) {
|
||||
textures_manager = new TextureManager(view);
|
||||
maps_size = QSize(512, 512);
|
||||
maps_size = QSize(1024, 1024);
|
||||
maps_hash = 0;
|
||||
tex_coeff[0] = tex_coeff[1] = 0;
|
||||
}
|
||||
@@ -147,41 +147,21 @@ void RendererBase::fillSelectionsBuffer(QVector<uchar> & buffer, bool yes, int s
|
||||
|
||||
void RendererBase::reloadMaterials(Scene & scene) {
|
||||
// qDebug() << "reloadMaterias";
|
||||
QList<Map *> maps[2];
|
||||
QList<Map *> maps;
|
||||
QMap<QString, int> tex_layers[2];
|
||||
foreach(Material * m, scene.materials) {
|
||||
if (m->map_diffuse.hasBitmap()) maps[0] << &(m->map_diffuse);
|
||||
if (m->map_normal.hasBitmap()) maps[1] << &(m->map_normal);
|
||||
if (m->map_metalness.hasBitmap()) maps[0] << &(m->map_metalness);
|
||||
if (m->map_roughness.hasBitmap()) maps[0] << &(m->map_roughness);
|
||||
if (m->map_emission.hasBitmap()) maps[0] << &(m->map_emission);
|
||||
if (m->map_relief.hasBitmap()) maps[0] << &(m->map_relief);
|
||||
for (Material * m: scene.materials) {
|
||||
m->load(textures_manager);
|
||||
}
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
foreach(Map * m, maps[i])
|
||||
tex_layers[i][m->bitmap_path] = 0;
|
||||
}
|
||||
int layers_count = tex_layers[0].size() + tex_layers[1].size(), cl = -1;
|
||||
uint cur_maps_hash = qHash(tex_layers[0].keys()) ^ (qHash(tex_layers[1].keys()) + 0xF00FF00F);
|
||||
uint cur_maps_hash = textures_manager->texturesHash();
|
||||
if (maps_hash != cur_maps_hash) {
|
||||
maps_hash = cur_maps_hash;
|
||||
textures_maps.resize(view, maps_size, layers_count);
|
||||
// textures_maps.resize(view, maps_size, textures_manager->texturesCount());
|
||||
textures_maps.bind(view);
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
QMutableMapIterator<QString, int> it(tex_layers[i]);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
QImage im = textures_manager->loadTextureImage(it.key(), i == 1);
|
||||
textures_maps.load(view, im, ++cl);
|
||||
it.value() = cl;
|
||||
}
|
||||
foreach(Map * m, maps[i]) {
|
||||
m->_layer = tex_layers[i].value(m->bitmap_path);
|
||||
// qDebug() << "assign" << m->bitmap_path << "layer" << m->_layer;
|
||||
}
|
||||
}
|
||||
textures_maps.mipmaps(view);
|
||||
// qDebug() << "load" << (cl+1) << "bitmaps";
|
||||
textures_manager->loadToTexture2DArray(&textures_maps, maps_size);
|
||||
qDebug() << "loaded" << textures_maps.layersCount() << "bitmaps";
|
||||
}
|
||||
for (Material * m: scene.materials) {
|
||||
m->setMapsLayers(textures_manager);
|
||||
}
|
||||
|
||||
QGLMaterial glm;
|
||||
|
||||
Reference in New Issue
Block a user