Code cleanup

This commit is contained in:
Atlante45 2016-01-11 16:29:27 -08:00
parent 3f90312375
commit 0008b1a055
4 changed files with 47 additions and 79 deletions

View file

@ -3635,10 +3635,15 @@ public:
render::ItemID BackgroundRenderData::_item = 0;
namespace render {
template <> const ItemKey payloadGetKey(const BackgroundRenderData::Pointer& stuff) { return ItemKey::Builder::background(); }
template <> const Item::Bound payloadGetBound(const BackgroundRenderData::Pointer& stuff) { return Item::Bound(); }
template <> void payloadRender(const BackgroundRenderData::Pointer& background, RenderArgs* args) {
template <> const ItemKey payloadGetKey(const BackgroundRenderData::Pointer& stuff) {
return ItemKey::Builder::background();
}
template <> const Item::Bound payloadGetBound(const BackgroundRenderData::Pointer& stuff) {
return Item::Bound();
}
template <> void payloadRender(const BackgroundRenderData::Pointer& background, RenderArgs* args) {
Q_ASSERT(args->_batch);
gpu::Batch& batch = *args->_batch;
@ -3646,20 +3651,18 @@ namespace render {
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
auto backgroundMode = skyStage->getBackgroundMode();
if (backgroundMode == model::SunSkyStage::NO_BACKGROUND) {
// this line intentionally left blank
} else {
if (backgroundMode == model::SunSkyStage::SKY_BOX) {
switch (backgroundMode) {
case model::SunSkyStage::SKY_BOX: {
auto skybox = skyStage->getSkybox();
if (skybox && skybox->getCubemap() && skybox->getCubemap()->isDefined()) {
PerformanceTimer perfTimer("skybox");
skybox->render(batch, *(args->_viewFrustum));
} else {
// If no skybox texture is available, render the SKY_DOME while it loads
backgroundMode = model::SunSkyStage::SKY_DOME;
break;
}
// If no skybox texture is available, render the SKY_DOME while it loads
}
if (backgroundMode == model::SunSkyStage::SKY_DOME) {
// fall through to next case
case model::SunSkyStage::SKY_DOME: {
if (Menu::getInstance()->isOptionChecked(MenuOption::Stars)) {
PerformanceTimer perfTimer("stars");
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
@ -3725,6 +3728,11 @@ namespace render {
}
}
break;
case model::SunSkyStage::NO_BACKGROUND:
default:
// this line intentionally left blank
break;
}
}
}

View file

@ -149,7 +149,6 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u
if (_meshes.size() > 0) {
auto textureCache = DependencyManager::get<TextureCache>();
for (auto&& material : _materials) {
QSharedPointer<NetworkTexture> matchingTexture = QSharedPointer<NetworkTexture>();
if (material->diffuseTextureName == name) {
material->diffuseTexture = textureCache->getTexture(url, DEFAULT_TEXTURE);
} else if (material->normalTextureName == name) {

View file

@ -174,19 +174,11 @@ QSharedPointer<Resource> TextureCache::createResource(const QUrl& url,
&Resource::allReferencesCleared);
}
Texture::Texture() {
}
Texture::~Texture() {
}
NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArray& content) :
Resource(url, !content.isEmpty()),
_type(type),
_width(0),
_height(0) {
_textureSource.reset(new gpu::TextureSource());
_type(type)
{
_textureSource = std::make_shared<gpu::TextureSource>();
if (!url.isValid()) {
_loaded = true;
@ -201,24 +193,9 @@ NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArr
}
NetworkTexture::NetworkTexture(const QUrl& url, const TextureLoaderFunc& textureLoader, const QByteArray& content) :
Resource(url, !content.isEmpty()),
_type(CUSTOM_TEXTURE),
_textureLoader(textureLoader),
_width(0),
_height(0) {
_textureSource.reset(new gpu::TextureSource());
if (!url.isValid()) {
_loaded = true;
}
std::string theName = url.toString().toStdString();
// if we have content, load it after we have our self pointer
if (!content.isEmpty()) {
_startedLoading = true;
QMetaObject::invokeMethod(this, "loadContent", Qt::QueuedConnection, Q_ARG(const QByteArray&, content));
}
NetworkTexture(url, CUSTOM_TEXTURE, content)
{
_textureLoader = textureLoader;
}
NetworkTexture::TextureLoaderFunc NetworkTexture::getTextureLoader() const {
@ -248,57 +225,52 @@ NetworkTexture::TextureLoaderFunc NetworkTexture::getTextureLoader() const {
}
}
}
class ImageReader : public QRunnable {
public:
ImageReader(const QWeakPointer<Resource>& texture, const NetworkTexture::TextureLoaderFunc& textureLoader, const QByteArray& data, const QUrl& url = QUrl());
ImageReader(const QWeakPointer<Resource>& texture, const QByteArray& data, const QUrl& url = QUrl());
virtual void run();
private:
static void listSupportedImageFormats();
QWeakPointer<Resource> _texture;
NetworkTexture::TextureLoaderFunc _textureLoader;
QUrl _url;
QByteArray _content;
};
void NetworkTexture::downloadFinished(const QByteArray& data) {
// send the reader off to the thread pool
QThreadPool::globalInstance()->start(new ImageReader(_self, getTextureLoader(), data, _url));
QThreadPool::globalInstance()->start(new ImageReader(_self, data, _url));
}
void NetworkTexture::loadContent(const QByteArray& content) {
QThreadPool::globalInstance()->start(new ImageReader(_self, getTextureLoader(), content, _url));
QThreadPool::globalInstance()->start(new ImageReader(_self, content, _url));
}
ImageReader::ImageReader(const QWeakPointer<Resource>& texture, const NetworkTexture::TextureLoaderFunc& textureLoader, const QByteArray& data,
ImageReader::ImageReader(const QWeakPointer<Resource>& texture, const QByteArray& data,
const QUrl& url) :
_texture(texture),
_textureLoader(textureLoader),
_url(url),
_content(data)
{
}
std::once_flag onceListSupportedFormatsflag;
void listSupportedImageFormats() {
std::call_once(onceListSupportedFormatsflag, [](){
void ImageReader::listSupportedImageFormats() {
static std::once_flag once;
std::call_once(once, []{
auto supportedFormats = QImageReader::supportedImageFormats();
QString formats;
foreach(const QByteArray& f, supportedFormats) {
formats += QString(f) + ",";
}
qCDebug(modelnetworking) << "List of supported Image formats:" << formats;
qCDebug(modelnetworking) << "List of supported Image formats:" << supportedFormats.join(", ");
});
}
void ImageReader::run() {
QSharedPointer<Resource> texture = _texture.toStrongRef();
if (texture.isNull()) {
auto texture = _texture.toStrongRef();
if (!texture) {
qCWarning(modelnetworking) << "Could not get strong ref";
return;
}
@ -325,7 +297,7 @@ void ImageReader::run() {
}
gpu::Texture* theTexture = nullptr;
auto ntex = dynamic_cast<NetworkTexture*>(&*texture);
auto ntex = texture.dynamicCast<NetworkTexture>();
if (ntex) {
theTexture = ntex->getTextureLoader()(image, _url.toString().toStdString());
}
@ -334,8 +306,6 @@ void ImageReader::run() {
Q_ARG(const QImage&, image),
Q_ARG(void*, theTexture),
Q_ARG(int, originalWidth), Q_ARG(int, originalHeight));
}
void NetworkTexture::setImage(const QImage& image, void* voidTexture, int originalWidth,

View file

@ -67,9 +67,6 @@ public:
typedef gpu::Texture* TextureLoader(const QImage& image, const std::string& srcImageName);
typedef std::function<TextureLoader> TextureLoaderFunc;
NetworkTexturePointer getTexture(const QUrl& url, const TextureLoaderFunc& textureLoader,
const QByteArray& content = QByteArray());
protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url,
@ -94,15 +91,9 @@ private:
class Texture {
public:
friend class TextureCache;
Texture();
~Texture();
const gpu::TexturePointer getGPUTexture() const { return _textureSource->getGPUTexture(); }
gpu::TexturePointer getGPUTexture() const { return _textureSource->getGPUTexture(); }
gpu::TextureSourcePointer _textureSource;
protected:
private:
};
/// A texture loaded from the network.
@ -134,14 +125,14 @@ protected:
virtual void imageLoaded(const QImage& image);
TextureType _type;
private:
TextureType _type;
TextureLoaderFunc _textureLoader;
int _originalWidth;
int _originalHeight;
int _width;
int _height;
int _originalWidth { 0 };
int _originalHeight { 0 };
int _width { 0 };
int _height { 0 };
};
#endif // hifi_TextureCache_h