OpenGL: Implement Framebuffers

This commit is contained in:
Lynix
2020-05-11 14:03:54 +02:00
parent 34804189d8
commit 2ea03fe05f
8 changed files with 123 additions and 2 deletions

View File

@@ -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);
}
}

View File

@@ -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
{
if (textureUnit >= m_state.textureUnits.size())