OpenGLRenderer: Improve/fix Framebuffer handling
This commit is contained in:
@@ -49,7 +49,6 @@ namespace Nz
|
||||
bool IsTextureFormatSupported(PixelFormat format, TextureUsage usage) const override;
|
||||
|
||||
inline void NotifyBufferDestruction(GLuint buffer) const;
|
||||
inline void NotifyFramebufferDestruction(GLuint fbo) const;
|
||||
inline void NotifyProgramDestruction(GLuint program) const;
|
||||
inline void NotifySamplerDestruction(GLuint sampler) const;
|
||||
inline void NotifyTextureDestruction(GLuint texture) const;
|
||||
|
||||
@@ -18,12 +18,6 @@ namespace Nz
|
||||
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
|
||||
{
|
||||
for (const GL::Context* context : m_contexts)
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Nz::GL
|
||||
virtual ~Context();
|
||||
|
||||
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 BindProgram(GLuint program) const;
|
||||
void BindSampler(UInt32 textureUnit, GLuint sampler) const;
|
||||
|
||||
@@ -8,16 +8,16 @@
|
||||
#define NAZARA_OPENGLRENDERER_GLFRAMEBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/DeviceObject.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/ContextObject.hpp>
|
||||
|
||||
namespace Nz::GL
|
||||
{
|
||||
class Framebuffer : public DeviceObject<Framebuffer, GL_FRAMEBUFFER>
|
||||
class Framebuffer : public ContextObject<Framebuffer, GL_FRAMEBUFFER>
|
||||
{
|
||||
friend DeviceObject;
|
||||
friend ContextObject;
|
||||
|
||||
public:
|
||||
Framebuffer() = default;
|
||||
using ContextObject::ContextObject;
|
||||
Framebuffer(const Framebuffer&) = delete;
|
||||
Framebuffer(Framebuffer&&) noexcept = default;
|
||||
~Framebuffer() = default;
|
||||
@@ -31,8 +31,8 @@ namespace Nz::GL
|
||||
Framebuffer& operator=(Framebuffer&&) noexcept = default;
|
||||
|
||||
private:
|
||||
static inline GLuint CreateHelper(OpenGLDevice& device, const Context& context);
|
||||
static inline void DestroyHelper(OpenGLDevice& device, const Context& context, GLuint objectId);
|
||||
static inline GLuint CreateHelper(const Context& context);
|
||||
static inline void DestroyHelper(const Context& context, GLuint objectId);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,30 +12,30 @@ namespace Nz::GL
|
||||
{
|
||||
assert(m_objectId);
|
||||
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.BindFramebuffer(m_objectId);
|
||||
return context.glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
const Context& context = EnsureContext();
|
||||
GLenum target = context.BindFramebuffer(m_objectId);
|
||||
return context.glCheckFramebufferStatus(target);
|
||||
}
|
||||
|
||||
inline void Framebuffer::Renderbuffer(GLenum attachment, GLenum renderbuffer)
|
||||
{
|
||||
assert(m_objectId);
|
||||
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.BindFramebuffer(m_objectId);
|
||||
context.glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, renderbuffer);
|
||||
const Context& context = EnsureContext();
|
||||
GLenum target = context.BindFramebuffer(m_objectId);
|
||||
context.glFramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, renderbuffer);
|
||||
}
|
||||
|
||||
inline void Framebuffer::Texture2D(GLenum attachment, GLenum textarget, GLuint texture, GLint level)
|
||||
{
|
||||
assert(m_objectId);
|
||||
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.BindFramebuffer(m_objectId);
|
||||
context.glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, textarget, texture, level);
|
||||
const Context& context = EnsureContext();
|
||||
GLenum target = context.BindFramebuffer(m_objectId);
|
||||
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;
|
||||
context.glGenFramebuffers(1U, &fbo);
|
||||
@@ -43,11 +43,11 @@ namespace Nz::GL
|
||||
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);
|
||||
|
||||
device.NotifyFramebufferDestruction(objectId);
|
||||
context.NotifyFramebufferDestruction(objectId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user