OpenGLRenderer: Improve/fix Framebuffer handling
This commit is contained in:
parent
78358337f3
commit
4933a389a2
|
|
@ -49,7 +49,6 @@ namespace Nz
|
||||||
bool IsTextureFormatSupported(PixelFormat format, TextureUsage usage) const override;
|
bool IsTextureFormatSupported(PixelFormat format, TextureUsage usage) const override;
|
||||||
|
|
||||||
inline void NotifyBufferDestruction(GLuint buffer) const;
|
inline void NotifyBufferDestruction(GLuint buffer) const;
|
||||||
inline void NotifyFramebufferDestruction(GLuint fbo) const;
|
|
||||||
inline void NotifyProgramDestruction(GLuint program) const;
|
inline void NotifyProgramDestruction(GLuint program) const;
|
||||||
inline void NotifySamplerDestruction(GLuint sampler) const;
|
inline void NotifySamplerDestruction(GLuint sampler) const;
|
||||||
inline void NotifyTextureDestruction(GLuint texture) const;
|
inline void NotifyTextureDestruction(GLuint texture) const;
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,6 @@ namespace Nz
|
||||||
context->NotifyBufferDestruction(buffer);
|
context->NotifyBufferDestruction(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void OpenGLDevice::NotifyFramebufferDestruction(GLuint fbo) const
|
|
||||||
{
|
|
||||||
for (const GL::Context* context : m_contexts)
|
|
||||||
context->NotifyFramebufferDestruction(fbo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void OpenGLDevice::NotifyProgramDestruction(GLuint program) const
|
inline void OpenGLDevice::NotifyProgramDestruction(GLuint program) const
|
||||||
{
|
{
|
||||||
for (const GL::Context* context : m_contexts)
|
for (const GL::Context* context : m_contexts)
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ namespace Nz::GL
|
||||||
virtual ~Context();
|
virtual ~Context();
|
||||||
|
|
||||||
void BindBuffer(BufferTarget target, GLuint buffer, bool force = false) const;
|
void BindBuffer(BufferTarget target, GLuint buffer, bool force = false) const;
|
||||||
void BindFramebuffer(GLuint fbo) const;
|
GLenum BindFramebuffer(GLuint fbo) const;
|
||||||
void BindFramebuffer(FramebufferTarget target, GLuint fbo) const;
|
void BindFramebuffer(FramebufferTarget target, GLuint fbo) const;
|
||||||
void BindProgram(GLuint program) const;
|
void BindProgram(GLuint program) const;
|
||||||
void BindSampler(UInt32 textureUnit, GLuint sampler) const;
|
void BindSampler(UInt32 textureUnit, GLuint sampler) const;
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,16 @@
|
||||||
#define NAZARA_OPENGLRENDERER_GLFRAMEBUFFER_HPP
|
#define NAZARA_OPENGLRENDERER_GLFRAMEBUFFER_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/DeviceObject.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/ContextObject.hpp>
|
||||||
|
|
||||||
namespace Nz::GL
|
namespace Nz::GL
|
||||||
{
|
{
|
||||||
class Framebuffer : public DeviceObject<Framebuffer, GL_FRAMEBUFFER>
|
class Framebuffer : public ContextObject<Framebuffer, GL_FRAMEBUFFER>
|
||||||
{
|
{
|
||||||
friend DeviceObject;
|
friend ContextObject;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Framebuffer() = default;
|
using ContextObject::ContextObject;
|
||||||
Framebuffer(const Framebuffer&) = delete;
|
Framebuffer(const Framebuffer&) = delete;
|
||||||
Framebuffer(Framebuffer&&) noexcept = default;
|
Framebuffer(Framebuffer&&) noexcept = default;
|
||||||
~Framebuffer() = default;
|
~Framebuffer() = default;
|
||||||
|
|
@ -31,8 +31,8 @@ namespace Nz::GL
|
||||||
Framebuffer& operator=(Framebuffer&&) noexcept = default;
|
Framebuffer& operator=(Framebuffer&&) noexcept = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline GLuint CreateHelper(OpenGLDevice& device, const Context& context);
|
static inline GLuint CreateHelper(const Context& context);
|
||||||
static inline void DestroyHelper(OpenGLDevice& device, const Context& context, GLuint objectId);
|
static inline void DestroyHelper(const Context& context, GLuint objectId);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,30 +12,30 @@ namespace Nz::GL
|
||||||
{
|
{
|
||||||
assert(m_objectId);
|
assert(m_objectId);
|
||||||
|
|
||||||
const Context& context = EnsureDeviceContext();
|
const Context& context = EnsureContext();
|
||||||
context.BindFramebuffer(m_objectId);
|
GLenum target = context.BindFramebuffer(m_objectId);
|
||||||
return context.glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
return context.glCheckFramebufferStatus(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Framebuffer::Renderbuffer(GLenum attachment, GLenum renderbuffer)
|
inline void Framebuffer::Renderbuffer(GLenum attachment, GLenum renderbuffer)
|
||||||
{
|
{
|
||||||
assert(m_objectId);
|
assert(m_objectId);
|
||||||
|
|
||||||
const Context& context = EnsureDeviceContext();
|
const Context& context = EnsureContext();
|
||||||
context.BindFramebuffer(m_objectId);
|
GLenum target = context.BindFramebuffer(m_objectId);
|
||||||
context.glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, renderbuffer);
|
context.glFramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, renderbuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Framebuffer::Texture2D(GLenum attachment, GLenum textarget, GLuint texture, GLint level)
|
inline void Framebuffer::Texture2D(GLenum attachment, GLenum textarget, GLuint texture, GLint level)
|
||||||
{
|
{
|
||||||
assert(m_objectId);
|
assert(m_objectId);
|
||||||
|
|
||||||
const Context& context = EnsureDeviceContext();
|
const Context& context = EnsureContext();
|
||||||
context.BindFramebuffer(m_objectId);
|
GLenum target = context.BindFramebuffer(m_objectId);
|
||||||
context.glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, textarget, texture, level);
|
context.glFramebufferTexture2D(target, attachment, textarget, texture, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline GLuint Framebuffer::CreateHelper(OpenGLDevice& /*device*/, const Context& context)
|
inline GLuint Framebuffer::CreateHelper(const Context& context)
|
||||||
{
|
{
|
||||||
GLuint fbo = 0;
|
GLuint fbo = 0;
|
||||||
context.glGenFramebuffers(1U, &fbo);
|
context.glGenFramebuffers(1U, &fbo);
|
||||||
|
|
@ -43,11 +43,11 @@ namespace Nz::GL
|
||||||
return fbo;
|
return fbo;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Framebuffer::DestroyHelper(OpenGLDevice& device, const Context& context, GLuint objectId)
|
inline void Framebuffer::DestroyHelper(const Context& context, GLuint objectId)
|
||||||
{
|
{
|
||||||
context.glDeleteFramebuffers(1U, &objectId);
|
context.glDeleteFramebuffers(1U, &objectId);
|
||||||
|
|
||||||
device.NotifyFramebufferDestruction(objectId);
|
context.NotifyFramebufferDestruction(objectId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Nz
|
||||||
OpenGLFboFramebuffer::OpenGLFboFramebuffer(OpenGLDevice& device, const std::vector<std::shared_ptr<Texture>>& attachments) :
|
OpenGLFboFramebuffer::OpenGLFboFramebuffer(OpenGLDevice& device, const std::vector<std::shared_ptr<Texture>>& attachments) :
|
||||||
OpenGLFramebuffer(FramebufferType::Texture)
|
OpenGLFramebuffer(FramebufferType::Texture)
|
||||||
{
|
{
|
||||||
if (!m_framebuffer.Create(device))
|
if (!m_framebuffer.Create(device.GetReferenceContext()))
|
||||||
throw std::runtime_error("failed to create framebuffer object");
|
throw std::runtime_error("failed to create framebuffer object");
|
||||||
|
|
||||||
std::size_t colorAttachmentCount = 0;
|
std::size_t colorAttachmentCount = 0;
|
||||||
|
|
@ -80,7 +80,7 @@ namespace Nz
|
||||||
|
|
||||||
void OpenGLFboFramebuffer::Activate() const
|
void OpenGLFboFramebuffer::Activate() const
|
||||||
{
|
{
|
||||||
const GL::Context& context = m_framebuffer.EnsureDeviceContext();
|
const GL::Context& context = m_framebuffer.EnsureContext();
|
||||||
|
|
||||||
context.BindFramebuffer(GL::FramebufferTarget::Draw, m_framebuffer.GetObjectId());
|
context.BindFramebuffer(GL::FramebufferTarget::Draw, m_framebuffer.GetObjectId());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,35 +12,23 @@ namespace Nz
|
||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
// OpenGL/OpenGL ES error codes
|
// OpenGL/OpenGL ES error codes
|
||||||
case GL_INVALID_ENUM:
|
case GL_INVALID_ENUM: return "GL_INVALID_ENUM: an unacceptable value is specified for an enumerated argument";
|
||||||
return "an unacceptable value is specified for an enumerated argument";
|
case GL_INVALID_VALUE: return "GL_INVALID_VALUE: a numeric argument is out of range";
|
||||||
break;
|
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION: the specified operation is not allowed in the current state";
|
||||||
|
case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION: the framebuffer object is not complete";
|
||||||
|
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY: there is not enough memory left to execute the command";
|
||||||
|
|
||||||
case GL_INVALID_VALUE:
|
// OpenGL error codes
|
||||||
return "a numeric argument is out of range";
|
case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW: an attempt has been made to perform an operation that would cause an internal stack to underflow";
|
||||||
break;
|
case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW: an attempt has been made to perform an operation that would cause an internal stack to overflow";
|
||||||
|
|
||||||
case GL_INVALID_OPERATION:
|
|
||||||
return "the specified operation is not allowed in the current state";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
|
||||||
return "the framebuffer object is not complete";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GL_OUT_OF_MEMORY:
|
|
||||||
return "there is not enough memory left to execute the command";
|
|
||||||
break;
|
|
||||||
|
|
||||||
// OpenGL error codes
|
|
||||||
case GL_STACK_UNDERFLOW:
|
|
||||||
return "an attempt has been made to perform an operation that would cause an internal stack to underflow.";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GL_STACK_OVERFLOW:
|
|
||||||
return "an attempt has been made to perform an operation that would cause an internal stack to overflow.";
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
// Framebuffer error codes
|
||||||
|
case GL_FRAMEBUFFER_UNDEFINED: return "GL_FRAMEBUFFER_UNDEFINED: default framebuffer does not exist";
|
||||||
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: some framebuffer attachment points are incomplete";
|
||||||
|
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: framebuffer has no image attached to it";
|
||||||
|
case GL_FRAMEBUFFER_UNSUPPORTED: return "GL_FRAMEBUFFER_UNSUPPORTED: framebuffer internal formats violates an implementation-dependent set of restrictions";
|
||||||
|
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: framebuffer mixes multiple samples size for attachements";
|
||||||
|
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: return "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: a framebuffer attachment is layered and a populated attachment is not (or color attachements are not from textures of the same target)";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Unknown OpenGL error (0x" + NumberToString(code, 16) + ')';
|
return "Unknown OpenGL error (0x" + NumberToString(code, 16) + ')';
|
||||||
|
|
|
||||||
|
|
@ -118,9 +118,13 @@ namespace Nz::GL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::BindFramebuffer(GLuint fbo) const
|
GLenum Context::BindFramebuffer(GLuint fbo) const
|
||||||
{
|
{
|
||||||
if (m_state.boundDrawFBO != fbo || m_state.boundReadFBO != fbo)
|
if (m_state.boundDrawFBO == fbo)
|
||||||
|
return GL_DRAW_FRAMEBUFFER;
|
||||||
|
else if (m_state.boundReadFBO == fbo)
|
||||||
|
return GL_READ_FRAMEBUFFER;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (!SetCurrentContext(this))
|
if (!SetCurrentContext(this))
|
||||||
throw std::runtime_error("failed to activate context");
|
throw std::runtime_error("failed to activate context");
|
||||||
|
|
@ -128,6 +132,7 @@ namespace Nz::GL
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
m_state.boundDrawFBO = fbo;
|
m_state.boundDrawFBO = fbo;
|
||||||
m_state.boundReadFBO = fbo;
|
m_state.boundReadFBO = fbo;
|
||||||
|
return GL_FRAMEBUFFER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue