From ce5295a55fac635551c13204bbae8708d2dd32cb Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 7 May 2015 17:06:15 -0700 Subject: [PATCH] THese is not final but we have a basic working framework so let's try to share --- interface/src/Application.cpp | 6 ------ .../src/EntityTreeRenderer.cpp | 5 ++++- libraries/gpu/src/gpu/GLBackendTexture.cpp | 4 +--- libraries/model/src/model/Material.h | 1 + libraries/model/src/model/Skybox.cpp | 6 +++--- libraries/model/src/model/Skybox.slf | 7 ++++--- libraries/model/src/model/TextureStorage.cpp | 13 ++++++------- libraries/model/src/model/TextureStorage.h | 18 +++++++++++++----- libraries/render-utils/src/TextureCache.cpp | 2 +- 9 files changed, 33 insertions(+), 29 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2578c498a9..cc99181fe1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3212,12 +3212,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs } else if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) { auto skybox = skyStage->getSkybox(); if (skybox) { - if (!skybox->getCubemap()) { - auto texture = DependencyManager::get()-> - getTexture(QUrl("https://hifi-public.s3.amazonaws.com/ryan/CloudyDay.png"), CUBE_TEXTURE); - skybox->setCubemap(texture->getGPUTexture()); - } - gpu::Batch batch; model::Skybox::render(batch, _viewFrustum, *skybox); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 0fb9296b64..84f12fca2d 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "EntityTreeRenderer.h" @@ -455,7 +456,9 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, if (_bestZone->getSkyboxProperties().getURL().isEmpty()) { stage->getSkybox()->clearCubemap(); } else { - stage->getSkybox()->clearCubemap(); // NOTE: this should be changed to do something to set the cubemap + auto cubeMap = DependencyManager::get()->getTexture(_bestZone->getSkyboxProperties().getURL(), CUBE_TEXTURE); + + stage->getSkybox()->setCubemap(cubeMap->getGPUTexture()); // NOTE: this should be changed to do something to set the cubemap } stage->setBackgroundMode(model::SunSkyStage::SKY_BOX); } diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index df275e16ad..69f2b33d1b 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -370,11 +370,9 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) { glBindTexture(GL_TEXTURE_CUBE_MAP, object->_texture); const int NUM_FACES = 6; const GLenum FACE_LAYOUT[] = { - // GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, - GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_X, + GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z }; - if (needUpdate) { if (texture.isStoredMipAvailable(0)) { Texture::PixelsPointer mip = texture.accessStoredMip(0); diff --git a/libraries/model/src/model/Material.h b/libraries/model/src/model/Material.h index cd4c6d0373..ea0ab808e9 100755 --- a/libraries/model/src/model/Material.h +++ b/libraries/model/src/model/Material.h @@ -41,6 +41,7 @@ public: NUM_MAPS, }; typedef std::map TextureMap; + typedef std::bitset MapFlags; enum FlagBit { DIFFUSE_BIT = 0, diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index c163f8c069..c01d07edfa 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -20,8 +20,8 @@ using namespace model; Skybox::Skybox() { - -/* _cubemap.reset( gpu::Texture::createCube(gpu::Element::COLOR_RGBA_32, 1)); +/* + _cubemap.reset( gpu::Texture::createCube(gpu::Element::COLOR_RGBA_32, 1)); unsigned char texels[] = { 255, 0, 0, 255, 0, 255, 255, 255, @@ -30,7 +30,7 @@ Skybox::Skybox() { 0, 255, 0, 255, 255, 0, 255, 255, }; - _cubemap->assignStoredMip(0, gpu::Element::COLOR_RGBA_32, sizeof(texels), texels); */ + _cubemap->assignStoredMip(0, gpu::Element::COLOR_RGBA_32, sizeof(texels), texels);*/ } void Skybox::setColor(const Color& color) { diff --git a/libraries/model/src/model/Skybox.slf b/libraries/model/src/model/Skybox.slf index 452b9daebe..03f7a5ef8a 100755 --- a/libraries/model/src/model/Skybox.slf +++ b/libraries/model/src/model/Skybox.slf @@ -18,7 +18,8 @@ varying vec3 color; void main(void) { - vec4 texel = textureCube(cubeMap, normalize(normal)); - gl_FragData[0] = texel; - // gl_FragData[0] = vec4(normal, 1.0); + vec3 coord = normalize(normal); + vec4 texel = textureCube(cubeMap, coord); + // gl_FragData[0] = vec4(texel.xyz * color, texel.w); + gl_FragData[0] = vec4(texel.xyz, 1.0); } diff --git a/libraries/model/src/model/TextureStorage.cpp b/libraries/model/src/model/TextureStorage.cpp index cc01941424..499054c34b 100755 --- a/libraries/model/src/model/TextureStorage.cpp +++ b/libraries/model/src/model/TextureStorage.cpp @@ -14,16 +14,15 @@ using namespace model; using namespace gpu; // TextureStorage -TextureStorage::TextureStorage(const QUrl& url, Texture::Type type ) : Texture::Storage(), - _url(url), - _type(type) { - init(); -} +TextureStorage::TextureStorage() : Texture::Storage(), + _gpuTexture(Texture::createFromStorage(this)) +{} TextureStorage::~TextureStorage() { } -void TextureStorage::init() { - _gpuTexture = TexturePointer(Texture::createFromStorage(this)); +void TextureStorage::reset(const QUrl& url, const TextureUsage& usage) { + _url = url; + _usage = usage; } diff --git a/libraries/model/src/model/TextureStorage.h b/libraries/model/src/model/TextureStorage.h index ec56438bf3..2b19a6cc1d 100755 --- a/libraries/model/src/model/TextureStorage.h +++ b/libraries/model/src/model/TextureStorage.h @@ -21,24 +21,32 @@ namespace model { typedef glm::vec3 Color; +class TextureUsage { +public: + gpu::Texture::Type _type{ gpu::Texture::TEX_2D }; + Material::MapFlags _materialUsage{ Material::DIFFUSE_MAP }; + + int _environmentUsage = 0; +}; + // TextureStorage is a specialized version of the gpu::Texture::Storage // It provides the mechanism to create a texture from a Url and the intended usage // that guides the internal format used class TextureStorage : public gpu::Texture::Storage { public: - TextureStorage(const QUrl& url, gpu::Texture::Type type = gpu::Texture::TEX_2D); + TextureStorage(); ~TextureStorage(); const QUrl& getUrl() const { return _url; } - const gpu::Texture::Type getType() const { return _type; } + const gpu::Texture::Type getType() const { return _usage._type; } const gpu::TexturePointer& getGPUTexture() const { return _gpuTexture; } + void reset(const QUrl& url, const TextureUsage& usage); + protected: gpu::TexturePointer _gpuTexture; + TextureUsage _usage; QUrl _url; - gpu::Texture::Type _type; - - void init(); }; typedef std::shared_ptr< TextureStorage > TextureStoragePointer; diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 754ceb5d7e..c88050f7fb 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -525,7 +525,7 @@ void NetworkTexture::setImage(const QImage& image, bool translucent, const QColo if (_type == CUBE_TEXTURE) { if (_height >= (6 * _width)) { - _gpuTexture = gpu::TexturePointer(gpu::Texture::createCube(formatGPU, image.width(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT, gpu::Sampler::WRAP_CLAMP))); + _gpuTexture = gpu::TexturePointer(gpu::Texture::createCube(formatGPU, image.width(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR, gpu::Sampler::WRAP_CLAMP))); _gpuTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits()); _gpuTexture->autoGenerateMips(-1); }