Graphics: Use default white texture if material has empty texture slot
This commit is contained in:
parent
a18415216b
commit
6bab824e4f
|
|
@ -54,7 +54,7 @@ namespace Nz
|
||||||
|
|
||||||
struct DefaultTextures
|
struct DefaultTextures
|
||||||
{
|
{
|
||||||
std::shared_ptr<Texture> whiteTexture2d;
|
std::array<std::shared_ptr<Texture>, ImageTypeCount> whiteTextures;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set);
|
static void FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set);
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ namespace Nz
|
||||||
m_fullscreenVertexDeclaration.reset();
|
m_fullscreenVertexDeclaration.reset();
|
||||||
m_blitPipeline.reset();
|
m_blitPipeline.reset();
|
||||||
m_blitPipelineLayout.reset();
|
m_blitPipelineLayout.reset();
|
||||||
m_defaultTextures.whiteTexture2d.reset();
|
m_defaultTextures.whiteTextures.fill(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set)
|
void Graphics::FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set)
|
||||||
|
|
@ -184,10 +184,15 @@ namespace Nz
|
||||||
texInfo.pixelFormat = PixelFormat::L8;
|
texInfo.pixelFormat = PixelFormat::L8;
|
||||||
texInfo.type = ImageType::E2D;
|
texInfo.type = ImageType::E2D;
|
||||||
|
|
||||||
std::array<UInt8, 4> texData = { 0xFF, 0xFF, 0xFF, 0xFF };
|
std::array<UInt8, 6> whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
|
|
||||||
m_defaultTextures.whiteTexture2d = m_renderDevice->InstantiateTexture(texInfo);
|
for (std::size_t i = 0; i < ImageTypeCount; ++i)
|
||||||
m_defaultTextures.whiteTexture2d->Update(texData.data());
|
{
|
||||||
|
texInfo.type = static_cast<ImageType>(i);
|
||||||
|
|
||||||
|
m_defaultTextures.whiteTextures[i] = m_renderDevice->InstantiateTexture(texInfo);
|
||||||
|
m_defaultTextures.whiteTextures[i]->Update(whitePixels.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,15 +79,19 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Use "missing" texture
|
//TODO: Use "missing" texture
|
||||||
if (textureSlot.texture)
|
Texture* texture = textureSlot.texture.get();
|
||||||
|
if (!texture)
|
||||||
{
|
{
|
||||||
bindings.push_back({
|
const auto& defaultTextures = Graphics::Instance()->GetDefaultTextures();
|
||||||
textureSetting.bindingIndex,
|
texture = defaultTextures.whiteTextures[UnderlyingCast(textureSetting.type)].get();
|
||||||
ShaderBinding::TextureBinding {
|
|
||||||
textureSlot.texture.get(), textureSlot.sampler.get()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bindings.push_back({
|
||||||
|
textureSetting.bindingIndex,
|
||||||
|
ShaderBinding::TextureBinding {
|
||||||
|
texture, textureSlot.sampler.get()
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shared UBO (TODO)
|
// Shared UBO (TODO)
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Nz
|
||||||
};
|
};
|
||||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(vertexBufferData);
|
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<RenderSpriteChain>(0, materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data()));
|
elements.emplace_back(std::make_unique<RenderSpriteChain>(0, materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ namespace Nz
|
||||||
currentShaderBinding = nullptr;
|
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({});
|
const auto& defaultSampler = graphics->GetSamplerCache().Get({});
|
||||||
|
|
||||||
for (std::size_t i = 0; i < elementCount; ++i)
|
for (std::size_t i = 0; i < elementCount; ++i)
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,11 @@ namespace Nz
|
||||||
switch (params.type)
|
switch (params.type)
|
||||||
{
|
{
|
||||||
case ImageType::E1D:
|
case ImageType::E1D:
|
||||||
|
m_texture.TexStorage2D(GL::TextureTarget::Target2D, params.mipmapLevel, format->internalFormat, params.width, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImageType::E1D_Array:
|
case ImageType::E1D_Array:
|
||||||
|
m_texture.TexStorage2D(GL::TextureTarget::Target2D, params.mipmapLevel, format->internalFormat, params.width, params.height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImageType::E2D:
|
case ImageType::E2D:
|
||||||
|
|
@ -36,17 +38,16 @@ namespace Nz
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImageType::E2D_Array:
|
case ImageType::E2D_Array:
|
||||||
|
m_texture.TexStorage3D(GL::TextureTarget::Target2D_Array, params.mipmapLevel, format->internalFormat, params.width, params.height, params.depth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImageType::E3D:
|
case ImageType::E3D:
|
||||||
|
m_texture.TexStorage3D(GL::TextureTarget::Target3D, params.mipmapLevel, format->internalFormat, params.width, params.height, params.depth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImageType::Cubemap:
|
case ImageType::Cubemap:
|
||||||
m_texture.TexStorage2D(GL::TextureTarget::Cubemap, params.mipmapLevel, format->internalFormat, params.width, params.height);
|
m_texture.TexStorage2D(GL::TextureTarget::Cubemap, params.mipmapLevel, format->internalFormat, params.width, params.height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.DidLastCallSucceed())
|
if (!context.DidLastCallSucceed())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue