Merge pull request #4749 from samcake/temp1

Fix the dark objects rendering in porto and apartment due to the tga texture files not loaded correctly
This commit is contained in:
Brad Hefta-Gaub 2015-05-01 17:39:17 -07:00
commit 6c4a4d0cdc
3 changed files with 42 additions and 25 deletions

View file

@ -1746,8 +1746,12 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
material.id = getID(object.properties);
material._material = model::MaterialPointer(new model::Material());
material._material->setEmissive(material.emissive);
material._material->setDiffuse(material.diffuse);
material._material->setEmissive(material.emissive);
if (glm::all(glm::equal(material.diffuse, glm::vec3(0.0f)))) {
material._material->setDiffuse(material.diffuse);
} else {
material._material->setDiffuse(material.diffuse);
}
material._material->setSpecular(material.specular);
material._material->setShininess(material.shininess);

View file

@ -75,7 +75,7 @@ GLBackend::GLFramebuffer* GLBackend::syncGPUObject(const Framebuffer& framebuffe
}
}
#if (GPU_FEATURE_PROFILE == GPU_LEGACY)
// for reasons that i don;t understand yet, it seems that on mac gl, a fbo must have a color buffer...
// for reasons that i don't understand yet, it seems that on mac gl, a fbo must have a color buffer...
else {
GLuint renderBuffer = 0;
glGenRenderbuffers(1, &renderBuffer);

View file

@ -19,6 +19,7 @@
#include <QResizeEvent>
#include <QRunnable>
#include <QThreadPool>
#include <qimagereader.h>
#include <glm/glm.hpp>
#include <glm/gtc/random.hpp>
@ -28,6 +29,8 @@
#include "gpu/GLBackend.h"
#include <mutex>
TextureCache::TextureCache() :
_permutationNormalTexture(0),
_whiteTexture(0),
@ -344,27 +347,7 @@ NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArr
_loaded = true;
}
// default to white/blue/black
/* 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);
*/
std::string theName = url.toString().toStdString();
// if we have content, load it after we have our self pointer
if (!content.isEmpty()) {
_startedLoading = true;
@ -396,6 +379,18 @@ ImageReader::ImageReader(const QWeakPointer<Resource>& texture, QNetworkReply* r
_content(content) {
}
std::once_flag onceListSuppoertedFormatsflag;
void listSupportedImageFormats() {
std::call_once(onceListSuppoertedFormatsflag, [](){
auto supportedFormats = QImageReader::supportedImageFormats();
QString formats;
foreach(const QByteArray& f, supportedFormats) {
formats += QString(f) + ",";
}
qCDebug(renderutils) << "List of supported Image formats:" << formats;
});
}
void ImageReader::run() {
QSharedPointer<Resource> texture = _texture.toStrongRef();
if (texture.isNull()) {
@ -409,11 +404,29 @@ void ImageReader::run() {
_content = _reply->readAll();
_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 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)
const int MAXIMUM_AREA_SIZE = 2097152;
int imageArea = image.width() * image.height();