diff --git a/include/Nazara/Graphics/Graphics.hpp b/include/Nazara/Graphics/Graphics.hpp index d6016ba2e..da540562c 100644 --- a/include/Nazara/Graphics/Graphics.hpp +++ b/include/Nazara/Graphics/Graphics.hpp @@ -54,7 +54,7 @@ namespace Nz struct DefaultTextures { - std::shared_ptr whiteTexture2d; + std::array, ImageTypeCount> whiteTextures; }; static void FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set); diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index 3e81eb978..45dbda063 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -110,7 +110,7 @@ namespace Nz m_fullscreenVertexDeclaration.reset(); m_blitPipeline.reset(); m_blitPipelineLayout.reset(); - m_defaultTextures.whiteTexture2d.reset(); + m_defaultTextures.whiteTextures.fill(nullptr); } void Graphics::FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set) @@ -184,10 +184,15 @@ namespace Nz texInfo.pixelFormat = PixelFormat::L8; texInfo.type = ImageType::E2D; - std::array texData = { 0xFF, 0xFF, 0xFF, 0xFF }; + std::array whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - m_defaultTextures.whiteTexture2d = m_renderDevice->InstantiateTexture(texInfo); - m_defaultTextures.whiteTexture2d->Update(texData.data()); + for (std::size_t i = 0; i < ImageTypeCount; ++i) + { + texInfo.type = static_cast(i); + + m_defaultTextures.whiteTextures[i] = m_renderDevice->InstantiateTexture(texInfo); + m_defaultTextures.whiteTextures[i]->Update(whitePixels.data()); + } } } diff --git a/src/Nazara/Graphics/MaterialPass.cpp b/src/Nazara/Graphics/MaterialPass.cpp index f36c4978c..869d87613 100644 --- a/src/Nazara/Graphics/MaterialPass.cpp +++ b/src/Nazara/Graphics/MaterialPass.cpp @@ -79,15 +79,19 @@ namespace Nz } //TODO: Use "missing" texture - if (textureSlot.texture) + Texture* texture = textureSlot.texture.get(); + if (!texture) { - bindings.push_back({ - textureSetting.bindingIndex, - ShaderBinding::TextureBinding { - textureSlot.texture.get(), textureSlot.sampler.get() - } - }); + const auto& defaultTextures = Graphics::Instance()->GetDefaultTextures(); + texture = defaultTextures.whiteTextures[UnderlyingCast(textureSetting.type)].get(); } + + bindings.push_back({ + textureSetting.bindingIndex, + ShaderBinding::TextureBinding { + texture, textureSlot.sampler.get() + } + }); } // Shared UBO (TODO) diff --git a/src/Nazara/Graphics/Sprite.cpp b/src/Nazara/Graphics/Sprite.cpp index 46769afe2..4fb77a95c 100644 --- a/src/Nazara/Graphics/Sprite.cpp +++ b/src/Nazara/Graphics/Sprite.cpp @@ -40,7 +40,7 @@ namespace Nz }; const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(vertexBufferData); - const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTexture2d; + const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; elements.emplace_back(std::make_unique(0, materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data())); } diff --git a/src/Nazara/Graphics/SubmeshRenderer.cpp b/src/Nazara/Graphics/SubmeshRenderer.cpp index 277ac7d7b..e85fdb27e 100644 --- a/src/Nazara/Graphics/SubmeshRenderer.cpp +++ b/src/Nazara/Graphics/SubmeshRenderer.cpp @@ -45,7 +45,7 @@ namespace Nz currentShaderBinding = nullptr; }; - const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTexture2d; + const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; const auto& defaultSampler = graphics->GetSamplerCache().Get({}); for (std::size_t i = 0; i < elementCount; ++i) diff --git a/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp b/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp index 435780de0..e86791191 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp @@ -26,9 +26,11 @@ namespace Nz switch (params.type) { case ImageType::E1D: + m_texture.TexStorage2D(GL::TextureTarget::Target2D, params.mipmapLevel, format->internalFormat, params.width, 1); break; case ImageType::E1D_Array: + m_texture.TexStorage2D(GL::TextureTarget::Target2D, params.mipmapLevel, format->internalFormat, params.width, params.height); break; case ImageType::E2D: @@ -36,17 +38,16 @@ namespace Nz break; case ImageType::E2D_Array: + m_texture.TexStorage3D(GL::TextureTarget::Target2D_Array, params.mipmapLevel, format->internalFormat, params.width, params.height, params.depth); break; case ImageType::E3D: + m_texture.TexStorage3D(GL::TextureTarget::Target3D, params.mipmapLevel, format->internalFormat, params.width, params.height, params.depth); break; case ImageType::Cubemap: m_texture.TexStorage2D(GL::TextureTarget::Cubemap, params.mipmapLevel, format->internalFormat, params.width, params.height); break; - - default: - break; } if (!context.DidLastCallSucceed())