Renderer: Blit texture to window instead of using a full renderpass

This may improve performance and allow for render targets to customize how they blit the final texture (allowing for render-to-texture)
This commit is contained in:
SirLynix
2023-11-17 16:59:31 +01:00
parent f2e77fb8a5
commit 97d5640967
38 changed files with 448 additions and 265 deletions

View File

@@ -48,6 +48,7 @@ namespace Nz
inline void BindVertexBuffer(UInt32 binding, GLuint vertexBuffer, UInt64 offset = 0);
inline void BlitTexture(const OpenGLTexture& source, const Boxui& sourceBox, const OpenGLTexture& target, const Boxui& targetBox, SamplerFilter filter = SamplerFilter::Nearest);
inline void BlitTextureToWindow(const OpenGLTexture& source, const Boxui& sourceBox, const Boxui& targetBox, SamplerFilter filter = SamplerFilter::Nearest);
inline void BuildMipmaps(OpenGLTexture& texture, UInt8 baseLevel, UInt8 levelCount);
@@ -88,6 +89,7 @@ namespace Nz
#define NAZARA_OPENGL_FOREACH_COMMANDS(cb, lastCb) \
cb(BeginDebugRegionCommand) \
cb(BlitTextureCommand) \
cb(BlitTextureToWindowCommand) \
cb(BuildTextureMipmapsCommand) \
cb(CopyBufferCommand) \
cb(CopyBufferFromMemoryCommand) \
@@ -119,6 +121,7 @@ namespace Nz
inline void Execute(const GL::Context* context, const BeginDebugRegionCommand& command);
inline void Execute(const GL::Context* context, const BlitTextureCommand& command);
inline void Execute(const GL::Context* context, const BlitTextureToWindowCommand& command);
inline void Execute(const GL::Context* context, const BuildTextureMipmapsCommand& command);
inline void Execute(const GL::Context* context, const CopyBufferCommand& command);
inline void Execute(const GL::Context* context, const CopyBufferFromMemoryCommand& command);
@@ -148,6 +151,14 @@ namespace Nz
SamplerFilter filter;
};
struct BlitTextureToWindowCommand
{
const OpenGLTexture* source;
Boxui sourceBox;
Boxui targetBox;
SamplerFilter filter;
};
struct BuildTextureMipmapsCommand
{
OpenGLTexture* texture;

View File

@@ -88,6 +88,18 @@ namespace Nz
m_commands.emplace_back(std::move(blitTexture));
}
inline void OpenGLCommandBuffer::BlitTextureToWindow(const OpenGLTexture& source, const Boxui& sourceBox, const Boxui& targetBox, SamplerFilter filter)
{
BlitTextureToWindowCommand blitTexture = {
&source,
sourceBox,
targetBox,
filter
};
m_commands.emplace_back(std::move(blitTexture));
}
inline void OpenGLCommandBuffer::BuildMipmaps(OpenGLTexture& texture, UInt8 baseLevel, UInt8 levelCount)
{
BuildTextureMipmapsCommand buildMipmaps = {
@@ -258,3 +270,4 @@ namespace Nz
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
#include "OpenGLCommandBuffer.hpp"

View File

@@ -37,6 +37,7 @@ namespace Nz
void BindVertexBuffer(UInt32 binding, const RenderBuffer& vertexBuffer, UInt64 offset = 0) override;
void BlitTexture(const Texture& fromTexture, const Boxui& fromBox, TextureLayout fromLayout, const Texture& toTexture, const Boxui& toBox, TextureLayout toLayout, SamplerFilter filter) override;
void BlitTextureToSwapchain(const Texture& fromTexture, const Boxui& fromBox, TextureLayout fromLayout, const Swapchain& swapchain, std::size_t imageIndex) override;
void BuildMipmaps(Texture& texture, UInt8 baseLevel, UInt8 levelCount, PipelineStageFlags srcStageMask, PipelineStageFlags dstStageMask, MemoryAccessFlags srcAccessMask, MemoryAccessFlags dstAccessMask, TextureLayout oldLayout, TextureLayout newLayout) override;

View File

@@ -32,6 +32,7 @@ namespace Nz
std::shared_ptr<CommandPool> CreateCommandPool(QueueType queueType) override;
inline GL::Context& GetContext();
inline OpenGLDevice& GetDevice();
const OpenGLFramebuffer& GetFramebuffer(std::size_t i) const override;
std::size_t GetFramebufferCount() const override;
PresentMode GetPresentMode() const override;
@@ -50,8 +51,9 @@ namespace Nz
private:
std::optional<OpenGLRenderPass> m_renderPass;
std::size_t m_currentFrame;
std::vector<std::unique_ptr<OpenGLRenderImage>> m_renderImage;
std::shared_ptr<GL::Context> m_context;
std::vector<std::unique_ptr<OpenGLRenderImage>> m_renderImage;
OpenGLDevice& m_device;
OpenGLWindowFramebuffer m_framebuffer;
PresentMode m_presentMode;
PresentModeFlags m_supportedPresentModes;

View File

@@ -12,6 +12,11 @@ namespace Nz
assert(m_context);
return *m_context;
}
inline OpenGLDevice& OpenGLSwapchain::GetDevice()
{
return m_device;
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -29,6 +29,7 @@ namespace Nz
namespace Nz::GL
{
class Framebuffer;
class Texture;
enum class BufferTarget
@@ -141,6 +142,7 @@ namespace Nz::GL
void BindVertexArray(GLuint vertexArray, bool force = false) const;
bool BlitTexture(const OpenGLTexture& source, const OpenGLTexture& destination, const Boxui& srcBox, const Boxui& dstBox, SamplerFilter filter) const;
bool BlitTextureToWindow(const OpenGLTexture& texture, const Boxui& srcBox, const Boxui& dstBox, SamplerFilter filter) const;
bool ClearErrorStack() const;
@@ -217,6 +219,7 @@ namespace Nz::GL
private:
void HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message) const;
bool InitializeBlitFramebuffers() const;
static void BindTextureToFramebuffer(Framebuffer& framebuffer, const OpenGLTexture& texture);
enum class FunctionIndex
{