OpenGL: Implement Framebuffers
This commit is contained in:
parent
34804189d8
commit
2ea03fe05f
|
|
@ -16,13 +16,27 @@ namespace Nz
|
||||||
class NAZARA_OPENGLRENDERER_API OpenGLFramebuffer : public Framebuffer
|
class NAZARA_OPENGLRENDERER_API OpenGLFramebuffer : public Framebuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum class Type
|
||||||
|
{
|
||||||
|
FBO,
|
||||||
|
Window
|
||||||
|
};
|
||||||
|
|
||||||
|
inline OpenGLFramebuffer(Type type);
|
||||||
OpenGLFramebuffer() = default;
|
OpenGLFramebuffer() = default;
|
||||||
OpenGLFramebuffer(const OpenGLFramebuffer&) = delete;
|
OpenGLFramebuffer(const OpenGLFramebuffer&) = delete;
|
||||||
OpenGLFramebuffer(OpenGLFramebuffer&&) noexcept = default;
|
OpenGLFramebuffer(OpenGLFramebuffer&&) noexcept = default;
|
||||||
~OpenGLFramebuffer() = default;
|
~OpenGLFramebuffer() = default;
|
||||||
|
|
||||||
|
virtual void Activate() const = 0;
|
||||||
|
|
||||||
|
inline Type GetType() const;
|
||||||
|
|
||||||
OpenGLFramebuffer& operator=(const OpenGLFramebuffer&) = delete;
|
OpenGLFramebuffer& operator=(const OpenGLFramebuffer&) = delete;
|
||||||
OpenGLFramebuffer& operator=(OpenGLFramebuffer&&) noexcept = default;
|
OpenGLFramebuffer& operator=(OpenGLFramebuffer&&) noexcept = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Type m_type;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,15 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
inline OpenGLFramebuffer::OpenGLFramebuffer(Type type) :
|
||||||
|
m_type(type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto OpenGLFramebuffer::GetType() const -> Type
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Config.hpp>
|
#include <Nazara/OpenGLRenderer/Config.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLDevice.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLDevice.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLFramebuffer.hpp>
|
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLRenderImage.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLRenderImage.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
|
||||||
|
#include <Nazara/OpenGLRenderer/OpenGLWindowFramebuffer.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
|
||||||
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
@ -43,8 +43,8 @@ namespace Nz
|
||||||
std::shared_ptr<OpenGLDevice> m_device;
|
std::shared_ptr<OpenGLDevice> m_device;
|
||||||
std::vector<OpenGLRenderImage> m_renderImage;
|
std::vector<OpenGLRenderImage> m_renderImage;
|
||||||
std::unique_ptr<GL::Context> m_context;
|
std::unique_ptr<GL::Context> m_context;
|
||||||
OpenGLFramebuffer m_framebuffer;
|
|
||||||
OpenGLRenderPass m_renderPass;
|
OpenGLRenderPass m_renderPass;
|
||||||
|
OpenGLWindowFramebuffer m_framebuffer;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright (C) 2020 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_OPENGLRENDERER_OPENGLWINDOWFRAMEBUFFER_HPP
|
||||||
|
#define NAZARA_OPENGLRENDERER_OPENGLWINDOWFRAMEBUFFER_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequisites.hpp>
|
||||||
|
#include <Nazara/OpenGLRenderer/OpenGLFramebuffer.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
class OpenGLRenderWindow;
|
||||||
|
|
||||||
|
class NAZARA_OPENGLRENDERER_API OpenGLWindowFramebuffer : public OpenGLFramebuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline OpenGLWindowFramebuffer(OpenGLRenderWindow& renderWindow);
|
||||||
|
OpenGLWindowFramebuffer(const OpenGLWindowFramebuffer&) = delete;
|
||||||
|
OpenGLWindowFramebuffer(OpenGLWindowFramebuffer&&) noexcept = default;
|
||||||
|
~OpenGLWindowFramebuffer() = default;
|
||||||
|
|
||||||
|
void Activate() const override;
|
||||||
|
|
||||||
|
OpenGLWindowFramebuffer& operator=(const OpenGLWindowFramebuffer&) = delete;
|
||||||
|
OpenGLWindowFramebuffer& operator=(OpenGLWindowFramebuffer&&) noexcept = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
OpenGLRenderWindow& m_renderWindow;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/OpenGLRenderer/OpenGLWindowFramebuffer.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_OPENGLRENDERER_OpenGLWindowFramebuffer_HPP
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
// Copyright (C) 2020 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - OpenGL Renderer"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/OpenGLRenderer/OpenGLFramebuffer.hpp>
|
||||||
|
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
inline OpenGLWindowFramebuffer::OpenGLWindowFramebuffer(OpenGLRenderWindow& renderWindow) :
|
||||||
|
OpenGLFramebuffer(OpenGLFramebuffer::Type::Window),
|
||||||
|
m_renderWindow(renderWindow)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
||||||
|
|
@ -58,6 +58,12 @@ namespace Nz::GL
|
||||||
KHR
|
KHR
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class FramebufferTarget
|
||||||
|
{
|
||||||
|
Draw,
|
||||||
|
Read
|
||||||
|
};
|
||||||
|
|
||||||
enum class TextureTarget
|
enum class TextureTarget
|
||||||
{
|
{
|
||||||
Cubemap,
|
Cubemap,
|
||||||
|
|
@ -89,6 +95,8 @@ namespace Nz::GL
|
||||||
virtual ~Context();
|
virtual ~Context();
|
||||||
|
|
||||||
void BindBuffer(BufferTarget target, GLuint buffer) const;
|
void BindBuffer(BufferTarget target, GLuint buffer) const;
|
||||||
|
void BindFramebuffer(GLuint fbo) const;
|
||||||
|
void BindFramebuffer(FramebufferTarget target, GLuint fbo) const;
|
||||||
void BindSampler(UInt32 textureUnit, GLuint sampler) const;
|
void BindSampler(UInt32 textureUnit, GLuint sampler) const;
|
||||||
void BindTexture(TextureTarget target, GLuint texture) const;
|
void BindTexture(TextureTarget target, GLuint texture) const;
|
||||||
void BindTexture(UInt32 textureUnit, TextureTarget target, GLuint texture) const;
|
void BindTexture(UInt32 textureUnit, TextureTarget target, GLuint texture) const;
|
||||||
|
|
@ -147,7 +155,10 @@ namespace Nz::GL
|
||||||
std::array<GLuint, UnderlyingCast(BufferTarget::Max) + 1> bufferTargets = { 0 };
|
std::array<GLuint, UnderlyingCast(BufferTarget::Max) + 1> bufferTargets = { 0 };
|
||||||
std::vector<TextureUnit> textureUnits;
|
std::vector<TextureUnit> textureUnits;
|
||||||
GLuint boundProgram = 0;
|
GLuint boundProgram = 0;
|
||||||
|
GLuint boundDrawFBO = 0;
|
||||||
|
GLuint boundReadFBO = 0;
|
||||||
UInt32 currentTextureUnit = 0;
|
UInt32 currentTextureUnit = 0;
|
||||||
|
RenderStates renderStates;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::array<ExtensionStatus, UnderlyingCast(Extension::Max) + 1> m_extensionStatus;
|
std::array<ExtensionStatus, UnderlyingCast(Extension::Max) + 1> m_extensionStatus;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright (C) 2020 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - OpenGL Renderer"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/OpenGLRenderer/OpenGLWindowFramebuffer.hpp>
|
||||||
|
#include <Nazara/OpenGLRenderer/OpenGLRenderWindow.hpp>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
void OpenGLWindowFramebuffer::Activate() const
|
||||||
|
{
|
||||||
|
GL::Context& context = m_renderWindow.GetContext();
|
||||||
|
if (!GL::Context::SetCurrentContext(&context))
|
||||||
|
throw std::runtime_error("failed to bind window context");
|
||||||
|
|
||||||
|
context.BindFramebuffer(GL::FramebufferTarget::Draw, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -36,6 +36,19 @@ namespace Nz::GL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Context::BindFramebuffer(GLuint fbo) const
|
||||||
|
{
|
||||||
|
if (m_state.boundDrawFBO != fbo || m_state.boundReadFBO != fbo)
|
||||||
|
{
|
||||||
|
if (!SetCurrentContext(this))
|
||||||
|
throw std::runtime_error("failed to activate context");
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
m_state.boundDrawFBO = fbo;
|
||||||
|
m_state.boundReadFBO = fbo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Context::BindSampler(UInt32 textureUnit, GLuint sampler) const
|
void Context::BindSampler(UInt32 textureUnit, GLuint sampler) const
|
||||||
{
|
{
|
||||||
if (textureUnit >= m_state.textureUnits.size())
|
if (textureUnit >= m_state.textureUnits.size())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue