mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 19:56:44 +02:00
FIxed the bug about the tga not loading by recognizing the file format type from the filename extension and passing the info to the QImage::fromData()
This commit is contained in:
parent
66a1d1f597
commit
2382183075
2 changed files with 35 additions and 23 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QRunnable>
|
#include <QRunnable>
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
#include <qimagereader.h>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/random.hpp>
|
#include <glm/gtc/random.hpp>
|
||||||
|
@ -28,6 +29,8 @@
|
||||||
|
|
||||||
#include "gpu/GLBackend.h"
|
#include "gpu/GLBackend.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
TextureCache::TextureCache() :
|
TextureCache::TextureCache() :
|
||||||
_permutationNormalTexture(0),
|
_permutationNormalTexture(0),
|
||||||
_whiteTexture(0),
|
_whiteTexture(0),
|
||||||
|
@ -344,27 +347,7 @@ NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArr
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to white/blue/black
|
std::string theName = url.toString().toStdString();
|
||||||
/* glBindTexture(GL_TEXTURE_2D, getID());
|
|
||||||
switch (type) {
|
|
||||||
case NORMAL_TEXTURE:
|
|
||||||
loadSingleColorTexture(OPAQUE_BLUE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SPECULAR_TEXTURE:
|
|
||||||
loadSingleColorTexture(OPAQUE_BLACK);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SPLAT_TEXTURE:
|
|
||||||
loadSingleColorTexture(TRANSPARENT_WHITE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
loadSingleColorTexture(OPAQUE_WHITE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
*/
|
|
||||||
// if we have content, load it after we have our self pointer
|
// if we have content, load it after we have our self pointer
|
||||||
if (!content.isEmpty()) {
|
if (!content.isEmpty()) {
|
||||||
_startedLoading = true;
|
_startedLoading = true;
|
||||||
|
@ -396,6 +379,17 @@ ImageReader::ImageReader(const QWeakPointer<Resource>& texture, QNetworkReply* r
|
||||||
_content(content) {
|
_content(content) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::once_flag onceListSuppoertedFormatsflag;
|
||||||
|
void listSupportedImageFormats() {
|
||||||
|
std::call_once(onceListSuppoertedFormatsflag, [](){
|
||||||
|
auto supportedFormats = QImageReader::supportedImageFormats();
|
||||||
|
qCDebug(renderutils) << "ImageReader:: List of supported formats:";
|
||||||
|
foreach(const QByteArray& f, supportedFormats) {
|
||||||
|
qCDebug(renderutils) << "format = " << f;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void ImageReader::run() {
|
void ImageReader::run() {
|
||||||
QSharedPointer<Resource> texture = _texture.toStrongRef();
|
QSharedPointer<Resource> texture = _texture.toStrongRef();
|
||||||
if (texture.isNull()) {
|
if (texture.isNull()) {
|
||||||
|
@ -409,11 +403,29 @@ void ImageReader::run() {
|
||||||
_content = _reply->readAll();
|
_content = _reply->readAll();
|
||||||
_reply->deleteLater();
|
_reply->deleteLater();
|
||||||
}
|
}
|
||||||
QImage image = QImage::fromData(_content);
|
|
||||||
|
|
||||||
|
listSupportedImageFormats();
|
||||||
|
|
||||||
|
// try to help the QImage loader by extracting the image file format from the url filename ext
|
||||||
|
// Some tga are not created properly for example without it
|
||||||
|
auto filename = _url.fileName().toStdString();
|
||||||
|
auto filenameExtension = filename.substr(filename.find_last_of('.') + 1);
|
||||||
|
QImage image = QImage::fromData(_content, filenameExtension.c_str());
|
||||||
|
|
||||||
|
// Note that QImage.format is the pixel format which is different from the "format" of the image file...
|
||||||
|
auto imageFormat = image.format();
|
||||||
int originalWidth = image.width();
|
int originalWidth = image.width();
|
||||||
int originalHeight = image.height();
|
int originalHeight = image.height();
|
||||||
|
|
||||||
|
if (originalWidth == 0 || originalHeight == 0 || imageFormat == QImage::Format_Invalid) {
|
||||||
|
if (filenameExtension.empty()) {
|
||||||
|
qCDebug(renderutils) << "QImage failed to create from content, no file extension:" << _url;
|
||||||
|
} else {
|
||||||
|
qCDebug(renderutils) << "QImage failed to create from content" << _url;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// enforce a fixed maximum area (1024 * 2048)
|
// enforce a fixed maximum area (1024 * 2048)
|
||||||
const int MAXIMUM_AREA_SIZE = 2097152;
|
const int MAXIMUM_AREA_SIZE = 2097152;
|
||||||
int imageArea = image.width() * image.height();
|
int imageArea = image.width() * image.height();
|
||||||
|
|
|
@ -33,7 +33,7 @@ void main(void) {
|
||||||
packDeferredFragment(
|
packDeferredFragment(
|
||||||
normalize(interpolatedNormal.xyz),
|
normalize(interpolatedNormal.xyz),
|
||||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||||
/*getMaterialDiffuse(mat) **/ diffuse.rgb /** color*/,
|
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||||
getMaterialSpecular(mat),
|
getMaterialSpecular(mat),
|
||||||
getMaterialShininess(mat));
|
getMaterialShininess(mat));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue