Merge pull request #4248 from samcake/temp0

Remove unneeded texture memory once loaded to GPU and Lightmap control in FBX
This commit is contained in:
Brad Hefta-Gaub 2015-02-06 16:52:40 -08:00
commit 12ab841191
5 changed files with 30 additions and 4 deletions

View file

@ -1166,7 +1166,7 @@ int matchTextureUVSetToAttributeChannel(const QString& texUVSetName, const QHash
FBXLight extractLight(const FBXNode& object) { FBXLight extractLight(const FBXNode& object) {
FBXLight light; FBXLight light;
int unkwnon = 0;
foreach (const FBXNode& subobject, object.children) { foreach (const FBXNode& subobject, object.children) {
QString childname = QString(subobject.name); QString childname = QString(subobject.name);
if (subobject.name == "Properties70") { if (subobject.name == "Properties70") {
@ -1177,6 +1177,8 @@ FBXLight extractLight(const FBXNode& object) {
QString propname = property.properties.at(0).toString(); QString propname = property.properties.at(0).toString();
if (propname == "Intensity") { if (propname == "Intensity") {
light.intensity = 0.01f * property.properties.at(valIndex).value<double>(); light.intensity = 0.01f * property.properties.at(valIndex).value<double>();
} else if (propname == "Color") {
light.color = getVec3(property.properties, valIndex);
} }
} }
} }
@ -1764,6 +1766,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
if (lightmapLevel <= 0.0f) { if (lightmapLevel <= 0.0f) {
loadLightmaps = false; loadLightmaps = false;
} }
lightmapOffset = glm::clamp((*lit).second.color.x, 0.f, 1.f);
} }
} }
} }
@ -2074,6 +2077,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
glm::vec2 emissiveParams(0.f, 1.f); glm::vec2 emissiveParams(0.f, 1.f);
emissiveParams.x = lightmapOffset; emissiveParams.x = lightmapOffset;
emissiveParams.y = lightmapLevel; emissiveParams.y = lightmapLevel;
QString emissiveTextureID = emissiveTextures.value(childID); QString emissiveTextureID = emissiveTextures.value(childID);
QString ambientTextureID = ambientTextures.value(childID); QString ambientTextureID = ambientTextures.value(childID);
if (loadLightmaps && (!emissiveTextureID.isNull() || !ambientTextureID.isNull())) { if (loadLightmaps && (!emissiveTextureID.isNull() || !ambientTextureID.isNull())) {

View file

@ -174,12 +174,14 @@ public:
QString name; QString name;
Transform transform; Transform transform;
float intensity; float intensity;
float fogValue;
glm::vec3 color; glm::vec3 color;
FBXLight() : FBXLight() :
name(), name(),
transform(), transform(),
intensity(1.0f), intensity(1.0f),
fogValue(0.0f),
color(1.0f) color(1.0f)
{} {}
}; };

View file

@ -271,7 +271,12 @@ void GLBackend::syncGPUObject(const Texture& texture) {
if (texture.isAutogenerateMips()) { if (texture.isAutogenerateMips()) {
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
} }
// At this point the mip piels have been loaded, we can notify
texture.notifyGPULoaded(0);
glBindTexture(GL_TEXTURE_2D, boundTex); glBindTexture(GL_TEXTURE_2D, boundTex);
object->_contentStamp = texture.getDataStamp(); object->_contentStamp = texture.getDataStamp();
} }
@ -302,6 +307,9 @@ void GLBackend::syncGPUObject(const Texture& texture) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
} }
// At this point the mip piels have been loaded, we can notify
texture.notifyGPULoaded(0);
glBindTexture(GL_TEXTURE_2D, boundTex); glBindTexture(GL_TEXTURE_2D, boundTex);
object->_storageStamp = texture.getStamp(); object->_storageStamp = texture.getStamp();
object->_size = texture.getSize(); object->_size = texture.getSize();

View file

@ -17,7 +17,8 @@ using namespace gpu;
Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) : Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) :
_sysmem(size, bytes), _sysmem(size, bytes),
_format(format) { _format(format),
_isGPULoaded(false) {
} }
Texture::Pixels::~Pixels() { Texture::Pixels::~Pixels() {
@ -53,6 +54,14 @@ const Texture::PixelsPointer Texture::Storage::getMip(uint16 level) const {
return PixelsPointer(); return PixelsPointer();
} }
void Texture::Storage::notifyGPULoaded(uint16 level) const {
PixelsPointer mip = getMip(level);
if (mip) {
mip->_isGPULoaded = true;
mip->_sysmem.resize(0);
}
}
bool Texture::Storage::isMipAvailable(uint16 level) const { bool Texture::Storage::isMipAvailable(uint16 level) const {
PixelsPointer mip = getMip(level); PixelsPointer mip = getMip(level);
return (mip && mip->_sysmem.getSize()); return (mip && mip->_sysmem.getSize());

View file

@ -28,6 +28,7 @@ public:
Sysmem _sysmem; Sysmem _sysmem;
Element _format; Element _format;
bool _isGPULoaded;
}; };
typedef QSharedPointer< Pixels > PixelsPointer; typedef QSharedPointer< Pixels > PixelsPointer;
@ -42,7 +43,8 @@ public:
virtual bool allocateMip(uint16 level); virtual bool allocateMip(uint16 level);
virtual bool assignMipData(uint16 level, const Element& format, Size size, const Byte* bytes); virtual bool assignMipData(uint16 level, const Element& format, Size size, const Byte* bytes);
virtual bool isMipAvailable(uint16 level) const; virtual bool isMipAvailable(uint16 level) const;
virtual void notifyGPULoaded(uint16 level) const;
protected: protected:
Texture* _texture; Texture* _texture;
std::vector<PixelsPointer> _mips; std::vector<PixelsPointer> _mips;
@ -168,7 +170,8 @@ public:
// Access the the sub mips // Access the the sub mips
bool isStoredMipAvailable(uint16 level) const { return _storage->isMipAvailable(level); } bool isStoredMipAvailable(uint16 level) const { return _storage->isMipAvailable(level); }
const PixelsPointer accessStoredMip(uint16 level) const { return _storage->getMip(level); } const PixelsPointer accessStoredMip(uint16 level) const { return _storage->getMip(level); }
void notifyGPULoaded(uint16 level) const { return _storage->notifyGPULoaded(level); }
// access sizes for the stored mips // access sizes for the stored mips
uint16 getStoredMipWidth(uint16 level) const; uint16 getStoredMipWidth(uint16 level) const;
uint16 getStoredMipHeight(uint16 level) const; uint16 getStoredMipHeight(uint16 level) const;