From 19f17fa0595dc613c6ca10dcb533f1780cd0718d Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 13 Apr 2018 00:00:36 +0200 Subject: [PATCH] Graphics: Add 2D & cubemap white textures --- ChangeLog.md | 1 + .../Nazara/Graphics/DeferredGeometryPass.hpp | 2 +- .../Nazara/Graphics/DepthRenderTechnique.hpp | 2 +- .../Graphics/ForwardRenderTechnique.hpp | 4 ++-- src/Nazara/Graphics/DeferredGeometryPass.cpp | 6 ++---- src/Nazara/Graphics/DepthRenderTechnique.cpp | 6 ++---- .../Graphics/ForwardRenderTechnique.cpp | 15 ++++----------- src/Nazara/Graphics/Graphics.cpp | 19 +++++++++++++++++++ 8 files changed, 32 insertions(+), 23 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 03a51ba76..7fec5792d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -85,6 +85,7 @@ Nazara Engine: - Fixed Sound copy which was not copying looping state - Fixed Billboard bounding volume - Fixed Directory::GetResultSize and Directory::IsResultDirectory on Posix systems +- Graphics module now register "White2D" and "WhiteCubemap" textures to the TextureLibrary (respectively a 1x1 texture 2D and a 1x1 texture cubemap) Nazara Development Kit: - Added ImageWidget (#139) diff --git a/include/Nazara/Graphics/DeferredGeometryPass.hpp b/include/Nazara/Graphics/DeferredGeometryPass.hpp index cb38508b8..3c7890bfe 100644 --- a/include/Nazara/Graphics/DeferredGeometryPass.hpp +++ b/include/Nazara/Graphics/DeferredGeometryPass.hpp @@ -56,7 +56,7 @@ namespace Nz Buffer m_vertexBuffer; RenderStates m_clearStates; ShaderRef m_clearShader; - Texture m_whiteTexture; + TextureRef m_whiteTexture; VertexBuffer m_billboardPointBuffer; VertexBuffer m_spriteBuffer; diff --git a/include/Nazara/Graphics/DepthRenderTechnique.hpp b/include/Nazara/Graphics/DepthRenderTechnique.hpp index 44ef1fa77..f8f7bc4e3 100644 --- a/include/Nazara/Graphics/DepthRenderTechnique.hpp +++ b/include/Nazara/Graphics/DepthRenderTechnique.hpp @@ -66,7 +66,7 @@ namespace Nz Buffer m_vertexBuffer; RenderStates m_clearStates; ShaderRef m_clearShader; - Texture m_whiteTexture; + TextureRef m_whiteTexture; VertexBuffer m_billboardPointBuffer; VertexBuffer m_spriteBuffer; mutable DepthRenderQueue m_renderQueue; diff --git a/include/Nazara/Graphics/ForwardRenderTechnique.hpp b/include/Nazara/Graphics/ForwardRenderTechnique.hpp index 8fc75fd13..640986e62 100644 --- a/include/Nazara/Graphics/ForwardRenderTechnique.hpp +++ b/include/Nazara/Graphics/ForwardRenderTechnique.hpp @@ -88,13 +88,13 @@ namespace Nz mutable std::vector> m_spriteChains; Buffer m_vertexBuffer; mutable BasicRenderQueue m_renderQueue; - Texture m_whiteTexture; + TextureRef m_whiteCubemap; + TextureRef m_whiteTexture; VertexBuffer m_billboardPointBuffer; VertexBuffer m_spriteBuffer; unsigned int m_maxLightPassPerObject; static IndexBuffer s_quadIndexBuffer; - static Texture s_dummyReflection; static TextureSampler s_reflectionSampler; static TextureSampler s_shadowSampler; static VertexBuffer s_quadVertexBuffer; diff --git a/src/Nazara/Graphics/DeferredGeometryPass.cpp b/src/Nazara/Graphics/DeferredGeometryPass.cpp index 01072bf20..ef7586259 100644 --- a/src/Nazara/Graphics/DeferredGeometryPass.cpp +++ b/src/Nazara/Graphics/DeferredGeometryPass.cpp @@ -48,9 +48,7 @@ namespace Nz { ErrorFlags flags(ErrorFlag_ThrowException, true); - std::array whitePixel = { { 255, 255, 255, 255 } }; - m_whiteTexture.Create(ImageType_2D, PixelFormatType_RGBA8, 1, 1); - m_whiteTexture.Update(whitePixel.data()); + m_whiteTexture = Nz::TextureLibrary::Get("White2D"); m_vertexBuffer.Create(s_vertexBufferSize, DataStorage_Hardware, BufferUsage_Dynamic); @@ -576,7 +574,7 @@ namespace Nz lastMaterial = basicSprites.material; } - const Nz::Texture* overlayTexture = (basicSprites.overlay) ? basicSprites.overlay.Get() : &m_whiteTexture; + const Nz::Texture* overlayTexture = (basicSprites.overlay) ? basicSprites.overlay.Get() : m_whiteTexture.Get(); if (overlayTexture != lastOverlay) { Renderer::SetTexture(overlayTextureUnit, overlayTexture); diff --git a/src/Nazara/Graphics/DepthRenderTechnique.cpp b/src/Nazara/Graphics/DepthRenderTechnique.cpp index c536c4c83..6c858f51c 100644 --- a/src/Nazara/Graphics/DepthRenderTechnique.cpp +++ b/src/Nazara/Graphics/DepthRenderTechnique.cpp @@ -49,9 +49,7 @@ namespace Nz { ErrorFlags flags(ErrorFlag_ThrowException, true); - std::array whitePixel = { {255, 255, 255, 255} }; - m_whiteTexture.Create(ImageType_2D, PixelFormatType_RGBA8, 1, 1); - m_whiteTexture.Update(whitePixel.data()); + m_whiteTexture = Nz::TextureLibrary::Get("White2D"); m_vertexBuffer.Create(s_vertexBufferSize, DataStorage_Hardware, BufferUsage_Dynamic); @@ -587,7 +585,7 @@ namespace Nz lastMaterial = basicSprites.material; } - const Nz::Texture* overlayTexture = (basicSprites.overlay) ? basicSprites.overlay.Get() : &m_whiteTexture; + const Nz::Texture* overlayTexture = (basicSprites.overlay) ? basicSprites.overlay.Get() : m_whiteTexture.Get(); if (overlayTexture != lastOverlay) { Renderer::SetTexture(overlayTextureUnit, overlayTexture); diff --git a/src/Nazara/Graphics/ForwardRenderTechnique.cpp b/src/Nazara/Graphics/ForwardRenderTechnique.cpp index 904d87dfd..142e559eb 100644 --- a/src/Nazara/Graphics/ForwardRenderTechnique.cpp +++ b/src/Nazara/Graphics/ForwardRenderTechnique.cpp @@ -52,9 +52,8 @@ namespace Nz { ErrorFlags flags(ErrorFlag_ThrowException, true); - std::array whitePixel = { {255, 255, 255, 255} }; - m_whiteTexture.Create(ImageType_2D, PixelFormatType_RGBA8, 1, 1); - m_whiteTexture.Update(whitePixel.data()); + m_whiteCubemap = Nz::TextureLibrary::Get("WhiteCubemap"); + m_whiteTexture = Nz::TextureLibrary::Get("White2D"); m_vertexBuffer.Create(s_vertexBufferSize, DataStorage_Hardware, BufferUsage_Dynamic); @@ -219,10 +218,6 @@ namespace Nz s_shadowSampler.SetFilterMode(SamplerFilter_Bilinear); s_shadowSampler.SetWrapMode(SamplerWrap_Clamp); - - std::array whitePixels = { { 255, 255, 255, 255, 255, 255 } }; - s_dummyReflection.Create(ImageType_Cubemap, PixelFormatType_L8, 1, 1); - s_dummyReflection.Update(whitePixels.data()); } catch (const std::exception& e) { @@ -239,7 +234,6 @@ namespace Nz void ForwardRenderTechnique::Uninitialize() { - s_dummyReflection.Destroy(); s_quadIndexBuffer.Reset(); s_quadVertexBuffer.Reset(); } @@ -247,7 +241,7 @@ namespace Nz /*! * \brief Chooses the nearest lights for one object * - * \param object Sphere symbolising the object + * \param object Sphere symbolizing the object * \param includeDirectionalLights Should directional lights be included in the computation */ @@ -726,7 +720,7 @@ namespace Nz lastMaterial = basicSprites.material; } - const Nz::Texture* overlayTexture = (basicSprites.overlay) ? basicSprites.overlay.Get() : &m_whiteTexture; + const Nz::Texture* overlayTexture = (basicSprites.overlay) ? basicSprites.overlay.Get() : m_whiteTexture.Get(); if (overlayTexture != lastOverlay) { Renderer::SetTexture(overlayTextureUnit, overlayTexture); @@ -897,7 +891,6 @@ namespace Nz } IndexBuffer ForwardRenderTechnique::s_quadIndexBuffer; - Texture ForwardRenderTechnique::s_dummyReflection; TextureSampler ForwardRenderTechnique::s_reflectionSampler; TextureSampler ForwardRenderTechnique::s_shadowSampler; VertexBuffer ForwardRenderTechnique::s_quadVertexBuffer; diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index 5ae1d8554..b8538a163 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -156,6 +156,21 @@ namespace Nz Font::SetDefaultAtlas(std::make_shared()); + // Textures + std::array whitePixels = { { 255, 255, 255, 255, 255, 255 } }; + + Nz::TextureRef whiteTexture = Nz::Texture::New(); + whiteTexture->Create(ImageType_2D, PixelFormatType_L8, 1, 1); + whiteTexture->Update(whitePixels.data()); + + TextureLibrary::Register("White2D", std::move(whiteTexture)); + + Nz::TextureRef whiteCubemap = Nz::Texture::New(); + whiteCubemap->Create(ImageType_Cubemap, PixelFormatType_L8, 1, 1); + whiteCubemap->Update(whitePixels.data()); + + TextureLibrary::Register("WhiteCubemap", std::move(whiteCubemap)); + onExit.Reset(); NazaraNotice("Initialized: Graphics module"); @@ -217,6 +232,10 @@ namespace Nz defaultAtlas.reset(); + // Textures + TextureLibrary::Unregister("White2D"); + TextureLibrary::Unregister("WhiteCubemap"); + // Loaders Loaders::UnregisterMesh(); Loaders::UnregisterTexture();