fix async skybox tex loading

This commit is contained in:
Zach Pomerantz 2016-08-30 16:30:53 -07:00
parent f30308b68c
commit abde84b068
2 changed files with 25 additions and 16 deletions

View file

@ -137,9 +137,6 @@ void EntityTreeRenderer::clear() {
// reset the zone to the default (while we load the next scene) // reset the zone to the default (while we load the next scene)
_layeredZones.clear(); _layeredZones.clear();
_pendingAmbientTexture = _pendingSkyboxTexture = false;
_ambientTexture.clear();
_skyboxTexture.clear();
applyZoneAndHasSkybox(nullptr); applyZoneAndHasSkybox(nullptr);
OctreeRenderer::clear(); OctreeRenderer::clear();
@ -197,8 +194,8 @@ void EntityTreeRenderer::update() {
// If we haven't already updated and previously attempted to load a texture, // If we haven't already updated and previously attempted to load a texture,
// check if the texture loaded and apply it // check if the texture loaded and apply it
if (!updated && if (!updated &&
((_pendingSkyboxTexture && _skyboxTexture && _skyboxTexture->isLoaded()) || ((_pendingAmbientTexture && (!_ambientTexture || _ambientTexture->isLoaded())) ||
(_pendingAmbientTexture && _ambientTexture && _ambientTexture->isLoaded()))) { (_pendingSkyboxTexture && (!_skyboxTexture || _skyboxTexture->isLoaded())))) {
applySkyboxAndHasAmbient(); applySkyboxAndHasAmbient();
} }
@ -388,12 +385,12 @@ bool EntityTreeRenderer::applyZoneAndHasSkybox(const std::shared_ptr<ZoneEntityI
} }
// Set the ambient texture // Set the ambient texture
if (zone->getKeyLightProperties().getAmbientURL().isEmpty()) { _ambientTextureURL = zone->getKeyLightProperties().getAmbientURL();
if (_ambientTextureURL.isEmpty()) {
_pendingAmbientTexture = false; _pendingAmbientTexture = false;
_ambientTexture.clear(); _ambientTexture.clear();
} else { } else {
_pendingAmbientTexture = true; _pendingAmbientTexture = true;
_ambientTexture = textureCache->getTexture(zone->getKeyLightProperties().getAmbientURL(), NetworkTexture::CUBE_TEXTURE);
} }
// Set the skybox texture // Set the skybox texture
@ -412,33 +409,36 @@ bool EntityTreeRenderer::layerZoneAndHasSkybox(const std::shared_ptr<ZoneEntityI
switch (zone->getBackgroundMode()) { switch (zone->getBackgroundMode()) {
case BACKGROUND_MODE_SKYBOX: case BACKGROUND_MODE_SKYBOX:
hasSkybox = true;
skybox->setColor(zone->getSkyboxProperties().getColorVec3()); skybox->setColor(zone->getSkyboxProperties().getColorVec3());
if (_zoneUserData != zone->getUserData()) { if (_zoneUserData != zone->getUserData()) {
_zoneUserData = zone->getUserData(); _zoneUserData = zone->getUserData();
std::dynamic_pointer_cast<ProceduralSkybox>(skybox)->parse(_zoneUserData); std::dynamic_pointer_cast<ProceduralSkybox>(skybox)->parse(_zoneUserData);
} }
if (zone->getSkyboxProperties().getURL().isEmpty()) {
skybox->setCubemap(nullptr); _skyboxTextureURL = zone->getSkyboxProperties().getURL();
if (_skyboxTextureURL.isEmpty()) {
_pendingSkyboxTexture = false; _pendingSkyboxTexture = false;
_skyboxTexture.clear(); _skyboxTexture.clear();
} else { } else {
// Update the Texture of the Skybox with the one pointed by this zone
_skyboxTexture = textureCache->getTexture(zone->getSkyboxProperties().getURL(), NetworkTexture::CUBE_TEXTURE);
_pendingSkyboxTexture = true; _pendingSkyboxTexture = true;
} }
applySkyboxAndHasAmbient(); applySkyboxAndHasAmbient();
skyStage->setBackgroundMode(model::SunSkyStage::SKY_BOX); skyStage->setBackgroundMode(model::SunSkyStage::SKY_BOX);
hasSkybox = true;
break; break;
case BACKGROUND_MODE_INHERIT: case BACKGROUND_MODE_INHERIT:
default: default:
// Clear the skybox to release its textures // Clear the skybox to release its textures
_zoneUserData = QString();
skybox->clear(); skybox->clear();
_zoneUserData = QString();
_skyboxTexture.clear();
_pendingSkyboxTexture = false; _pendingSkyboxTexture = false;
_skyboxTexture.clear();
// Let the application background through // Let the application background through
if (applySkyboxAndHasAmbient()) { if (applySkyboxAndHasAmbient()) {
@ -446,6 +446,7 @@ bool EntityTreeRenderer::layerZoneAndHasSkybox(const std::shared_ptr<ZoneEntityI
} else { } else {
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DEFAULT_AMBIENT_TEXTURE); skyStage->setBackgroundMode(model::SunSkyStage::SKY_DEFAULT_AMBIENT_TEXTURE);
} }
break; break;
} }
@ -461,6 +462,9 @@ bool EntityTreeRenderer::applySkyboxAndHasAmbient() {
auto skybox = skyStage->getSkybox(); auto skybox = skyStage->getSkybox();
bool isAmbientSet = false; bool isAmbientSet = false;
if (_pendingAmbientTexture && !_ambientTexture) {
_ambientTexture = textureCache->getTexture(_ambientTextureURL, NetworkTexture::CUBE_TEXTURE);
}
if (_ambientTexture && _ambientTexture->isLoaded()) { if (_ambientTexture && _ambientTexture->isLoaded()) {
_pendingAmbientTexture = false; _pendingAmbientTexture = false;
@ -474,6 +478,9 @@ bool EntityTreeRenderer::applySkyboxAndHasAmbient() {
} }
} }
if (_pendingSkyboxTexture && !_skyboxTexture) {
_skyboxTexture = textureCache->getTexture(_skyboxTextureURL, NetworkTexture::CUBE_TEXTURE);
}
if (_skyboxTexture && _skyboxTexture->isLoaded()) { if (_skyboxTexture && _skyboxTexture->isLoaded()) {
_pendingSkyboxTexture = false; _pendingSkyboxTexture = false;

View file

@ -227,10 +227,12 @@ private:
LayeredZones _layeredZones; LayeredZones _layeredZones;
QString _zoneUserData; QString _zoneUserData;
NetworkTexturePointer _skyboxTexture;
NetworkTexturePointer _ambientTexture; NetworkTexturePointer _ambientTexture;
bool _pendingSkyboxTexture { false }; NetworkTexturePointer _skyboxTexture;
QString _ambientTextureURL;
QString _skyboxTextureURL;
bool _pendingAmbientTexture { false }; bool _pendingAmbientTexture { false };
bool _pendingSkyboxTexture { false };
quint64 _lastZoneCheck { 0 }; quint64 _lastZoneCheck { 0 };
const quint64 ZONE_CHECK_INTERVAL = USECS_PER_MSEC * 100; // ~10hz const quint64 ZONE_CHECK_INTERVAL = USECS_PER_MSEC * 100; // ~10hz