Renderer: Add mipmaps generation support

This commit is contained in:
SirLynix
2023-05-14 18:55:41 +02:00
parent 3712b641f8
commit 1d32af53c5
33 changed files with 488 additions and 183 deletions

View File

@@ -8,6 +8,7 @@
#include <Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
#include <Nazara/OpenGLRenderer/OpenGLVaoCache.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/VertexArray.hpp>
@@ -145,6 +146,11 @@ namespace Nz
context->BlitTexture(*command.source, *command.target, command.sourceBox, command.targetBox, command.filter);
}
inline void OpenGLCommandBuffer::Execute(const GL::Context* /*context*/, const BuildTextureMipmapsCommand& command)
{
command.texture->GenerateMipmaps(command.baseLevel, command.levelCount);
}
inline void OpenGLCommandBuffer::Execute(const GL::Context* context, const CopyBufferCommand& command)
{
context->BindBuffer(GL::BufferTarget::CopyRead, command.source);
@@ -197,7 +203,7 @@ namespace Nz
context->glDrawElementsInstanced(ToOpenGL(command.states.pipeline->GetPipelineInfo().primitiveMode), command.indexCount, ToOpenGL(command.states.indexBufferType), origin, command.instanceCount);
}
inline void OpenGLCommandBuffer::Execute(const GL::Context* context, const EndDebugRegionCommand& command)
inline void OpenGLCommandBuffer::Execute(const GL::Context* context, const EndDebugRegionCommand& /*command*/)
{
if (context->glPopDebugGroup)
context->glPopDebugGroup();

View File

@@ -93,6 +93,13 @@ namespace Nz
m_commandBuffer.BlitTexture(sourceTexture, fromBox, targetTexture, toBox, filter);
}
void OpenGLCommandBufferBuilder::BuildMipmaps(Texture& texture, UInt8 baseLevel, UInt8 maxLevel)
{
OpenGLTexture& glTexture = static_cast<OpenGLTexture&>(texture);
glTexture.GenerateMipmaps(baseLevel, maxLevel);
}
void OpenGLCommandBufferBuilder::CopyBuffer(const RenderBufferView& source, const RenderBufferView& target, UInt64 size, UInt64 sourceOffset, UInt64 targetOffset)
{
OpenGLBuffer& sourceBuffer = *static_cast<OpenGLBuffer*>(source.GetBuffer());

View File

@@ -221,6 +221,11 @@ namespace Nz
return std::make_shared<OpenGLTexture>(*this, params);
}
std::shared_ptr<Texture> OpenGLDevice::InstantiateTexture(const TextureInfo& params, const void* initialData, bool buildMipmaps, unsigned int srcWidth, unsigned int srcHeight)
{
return std::make_shared<OpenGLTexture>(*this, params, initialData, buildMipmaps, srcWidth, srcHeight);
}
std::shared_ptr<TextureSampler> OpenGLDevice::InstantiateTextureSampler(const TextureSamplerInfo& params)
{
return std::make_shared<OpenGLTextureSampler>(*this, params);

View File

@@ -13,6 +13,8 @@ namespace Nz
OpenGLTexture::OpenGLTexture(OpenGLDevice& device, const TextureInfo& textureInfo) :
m_textureInfo(textureInfo)
{
m_textureInfo.levelCount = std::min(m_textureInfo.levelCount, Image::GetMaxLevel(m_textureInfo.type, m_textureInfo.width, m_textureInfo.height, m_textureInfo.depth));
if (!m_texture.Create(device))
throw std::runtime_error("failed to create texture object");
@@ -71,6 +73,16 @@ namespace Nz
#endif
}
OpenGLTexture::OpenGLTexture(OpenGLDevice& device, const TextureInfo& textureInfo, const void* initialData, bool buildMipmaps, unsigned int srcWidth, unsigned int srcHeight) :
OpenGLTexture(device, textureInfo)
{
NazaraAssert(initialData, "missing initial data");
Update(initialData, srcWidth, srcHeight, 0);
if (buildMipmaps && m_textureInfo.levelCount > 1)
m_texture.GenerateMipmap();
}
OpenGLTexture::OpenGLTexture(std::shared_ptr<OpenGLTexture> parentTexture, const TextureViewInfo& viewInfo) :
m_parentTexture(std::move(parentTexture))
{