rename fbo_t to frame_buffer_t

main
Brett 2024-05-03 20:03:31 -04:00
parent 23f069e9b0
commit 622b706618
6 changed files with 78 additions and 78 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.25)
set(BLT_GRAPHICS_VERSION 0.13.1)
set(BLT_GRAPHICS_VERSION 0.13.2)
set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})

View File

@ -33,18 +33,18 @@ namespace blt::gfx
C(0) C(1) C(2) C(3) C(4) C(5) C(6) C(7) C(8) C(9) C(10) C(11) C(12) C(13) C(14) C(15) C(16) \
C(17) C(18) C(19) C(20) C(21) C(22) C(23) C(24) C(25) C(26) C(27) C(28) C(29) C(30) C(31)
class fbo_t;
class frame_buffer_t;
class rbo_t
class render_buffer_t
{
friend fbo_t;
friend frame_buffer_t;
private:
GLuint rboID;
GLuint storage_type;
blt::i32 width_, height_;
blt::i32 samples = 0;
public:
rbo_t(): rboID(0), storage_type(0), width_(-1), height_(-1)
render_buffer_t(): rboID(0), storage_type(0), width_(-1), height_(-1)
{}
void create();
@ -65,12 +65,12 @@ namespace blt::gfx
void destroy();
static rbo_t make_render_buffer(GLuint storage_type, blt::i32 width, blt::i32 height);
static render_buffer_t make_render_buffer(GLuint storage_type, blt::i32 width, blt::i32 height);
static rbo_t make_render_buffer(GLuint storage_type, blt::i32 width, blt::i32 height, blt::i32 samples);
static render_buffer_t make_render_buffer(GLuint storage_type, blt::i32 width, blt::i32 height, blt::i32 samples);
};
class fbo_t
class frame_buffer_t
{
public:
enum class draw_t : GLuint
@ -91,7 +91,7 @@ namespace blt::gfx
GLuint fboID = 0;
GLuint generic_bind_type = GL_FRAMEBUFFER;
std::vector<blt::gfx::texture_gl*> texture_buffers;
std::vector<rbo_t> render_buffers;
std::vector<render_buffer_t> render_buffers;
blt::i32 width_ = -1, height_ = -1;
public:
// default used for fbo binding
@ -105,18 +105,18 @@ namespace blt::gfx
void updateBuffersStorage(blt::i32 width, blt::i32 height);
// this function takes ownership of the render buffer
void attachRenderBuffer(rbo_t rbo, attachment_t attachment);
void attachRenderBuffer(render_buffer_t rbo, attachment_t attachment);
void blitTexture(const fbo_t& draw, blt::i32 srcX_off = 0, blt::i32 srcY_off = 0, blt::i32 destX_off = 0, blt::i32 destY_off = 0,
void blitTexture(const frame_buffer_t& draw, blt::i32 srcX_off = 0, blt::i32 srcY_off = 0, blt::i32 destX_off = 0, blt::i32 destY_off = 0,
GLuint filter = GL_NEAREST, attachment_t attachment_read = attachment_t::COLOR0,
attachment_t attachment_write = attachment_t::COLOR0) const;
void blitToScreen(blt::i32 width, blt::i32 height) const;
void blitDepth(const fbo_t& draw, blt::i32 srcX_off = 0, blt::i32 srcY_off = 0, blt::i32 destX_off = 0, blt::i32 destY_off = 0,
void blitDepth(const frame_buffer_t& draw, blt::i32 srcX_off = 0, blt::i32 srcY_off = 0, blt::i32 destX_off = 0, blt::i32 destY_off = 0,
GLuint filter = GL_NEAREST) const;
void blitStencil(const fbo_t& draw, blt::i32 srcX_off = 0, blt::i32 srcY_off = 0, blt::i32 destX_off = 0, blt::i32 destY_off = 0,
void blitStencil(const frame_buffer_t& draw, blt::i32 srcX_off = 0, blt::i32 srcY_off = 0, blt::i32 destX_off = 0, blt::i32 destY_off = 0,
GLuint filter = GL_NEAREST) const;
static bool validate();
@ -136,13 +136,13 @@ namespace blt::gfx
}
public:
static fbo_t make_render_texture(blt::i32 width, blt::i32 height);
static frame_buffer_t make_render_texture(blt::i32 width, blt::i32 height);
static fbo_t make_multisample_render_texture(blt::i32 width, blt::i32 height, blt::i32 samples);
static frame_buffer_t make_multisample_render_texture(blt::i32 width, blt::i32 height, blt::i32 samples);
static fbo_t make_render_target(blt::i32 width, blt::i32 height);
static frame_buffer_t make_render_target(blt::i32 width, blt::i32 height);
static fbo_t make_multisample_render_target(blt::i32 width, blt::i32 height, blt::i32 samples);
static frame_buffer_t make_multisample_render_target(blt::i32 width, blt::i32 height, blt::i32 samples);
};
#undef C

View File

@ -148,7 +148,7 @@ namespace blt::gfx
class batch_renderer_2d
{
private:
fbo_t draw_buffer;
frame_buffer_t draw_buffer;
template<typename T>
struct render_object_t

View File

@ -58,13 +58,13 @@ namespace blt::gfx
virtual void draw(i32 width, i32 height) = 0;
fbo_t& getBuffer()
frame_buffer_t& getBuffer()
{
return draw_buffer;
}
protected:
fbo_t draw_buffer;
frame_buffer_t draw_buffer;
};
class pp_engine

View File

@ -19,27 +19,27 @@
namespace blt::gfx
{
void rbo_t::create()
void render_buffer_t::create()
{
glGenRenderbuffers(1, &rboID);
}
void rbo_t::bind() const
void render_buffer_t::bind() const
{
glBindRenderbuffer(GL_RENDERBUFFER, rboID);
}
void rbo_t::unbind()
void render_buffer_t::unbind()
{
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
void rbo_t::destroy()
void render_buffer_t::destroy()
{
glDeleteRenderbuffers(1, &rboID);
}
void rbo_t::updateStorage(blt::i32 width, blt::i32 height)
void render_buffer_t::updateStorage(blt::i32 width, blt::i32 height)
{
width_ = width;
height_ = height;
@ -47,7 +47,7 @@ namespace blt::gfx
glRenderbufferStorage(GL_RENDERBUFFER, storage_type, width, height);
}
void rbo_t::updateStorageMultiSampled(blt::i32 width, blt::i32 height, blt::i32 s)
void render_buffer_t::updateStorageMultiSampled(blt::i32 width, blt::i32 height, blt::i32 s)
{
width_ = width;
height_ = height;
@ -55,19 +55,19 @@ namespace blt::gfx
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, storage_type, width, height);
}
void rbo_t::setStorage(GLuint s_type, blt::i32 width, blt::i32 height)
void render_buffer_t::setStorage(GLuint s_type, blt::i32 width, blt::i32 height)
{
storage_type = s_type;
updateStorage(width, height);
}
void rbo_t::setStorageMultiSampled(GLuint s_type, blt::i32 width, blt::i32 height, blt::i32 s)
void render_buffer_t::setStorageMultiSampled(GLuint s_type, blt::i32 width, blt::i32 height, blt::i32 s)
{
storage_type = s_type;
updateStorageMultiSampled(width, height, s);
}
void rbo_t::resize(blt::i32 width, blt::i32 height)
void render_buffer_t::resize(blt::i32 width, blt::i32 height)
{
if (samples > 0)
updateStorageMultiSampled(width, height, samples);
@ -75,43 +75,43 @@ namespace blt::gfx
updateStorage(width, height);
}
rbo_t rbo_t::make_render_buffer(GLuint storage_type, blt::i32 width, blt::i32 height)
render_buffer_t render_buffer_t::make_render_buffer(GLuint storage_type, blt::i32 width, blt::i32 height)
{
rbo_t rbo{};
render_buffer_t rbo{};
rbo.create();
rbo.bind();
rbo.setStorage(storage_type, width, height);
rbo_t::unbind();
render_buffer_t::unbind();
return rbo;
}
rbo_t rbo_t::make_render_buffer(GLuint storage_type, blt::i32 width, blt::i32 height, blt::i32 samples)
render_buffer_t render_buffer_t::make_render_buffer(GLuint storage_type, blt::i32 width, blt::i32 height, blt::i32 samples)
{
rbo_t rbo{};
render_buffer_t rbo{};
rbo.create();
rbo.bind();
rbo.setStorageMultiSampled(storage_type, width, height, samples);
rbo_t::unbind();
render_buffer_t::unbind();
return rbo;
}
void fbo_t::create(fbo_t::draw_t type)
void frame_buffer_t::create(frame_buffer_t::draw_t type)
{
generic_bind_type = static_cast<GLuint>(type);
glGenFramebuffers(1, &fboID);
}
void fbo_t::bind(draw_t type) const
void frame_buffer_t::bind(draw_t type) const
{
glBindFramebuffer(static_cast<GLuint>(type), fboID);
}
void fbo_t::unbind()
void frame_buffer_t::unbind()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void fbo_t::destroy()
void frame_buffer_t::destroy()
{
glDeleteFramebuffers(1, &fboID);
for (auto& v : render_buffers)
@ -120,12 +120,12 @@ namespace blt::gfx
delete texture;
}
bool fbo_t::validate()
bool frame_buffer_t::validate()
{
return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
}
void fbo_t::attachTexture(blt::gfx::texture_gl* texture, attachment_t attachment, int level)
void frame_buffer_t::attachTexture(blt::gfx::texture_gl* texture, attachment_t attachment, int level)
{
if (width_ == -1)
{
@ -137,7 +137,7 @@ namespace blt::gfx
glFramebufferTexture2D(generic_bind_type, static_cast<GLuint>(attachment), texture->getBindType(), texture->getTextureID(), level);
}
void fbo_t::attachRenderBuffer(rbo_t rbo, fbo_t::attachment_t attachment)
void frame_buffer_t::attachRenderBuffer(render_buffer_t rbo, frame_buffer_t::attachment_t attachment)
{
if (width_ == -1)
{
@ -150,7 +150,7 @@ namespace blt::gfx
glFramebufferRenderbuffer(generic_bind_type, static_cast<GLuint>(attachment), GL_RENDERBUFFER, rbo.rboID);
}
void fbo_t::updateBuffersStorage(blt::i32 width, blt::i32 height)
void frame_buffer_t::updateBuffersStorage(blt::i32 width, blt::i32 height)
{
if (width == width_ && height == height_)
return;
@ -166,12 +166,12 @@ namespace blt::gfx
for (auto& texture : texture_buffers)
texture->updateSize(width, height);
if (!fbo_t::validate())
if (!frame_buffer_t::validate())
BLT_ERROR("Failed to update framebuffer storage size!");
}
void fbo_t::blitTexture(const fbo_t& draw, blt::i32 srcX, blt::i32 srcY, blt::i32 destX, blt::i32 destY, GLuint filter,
attachment_t attachment_read, attachment_t attachment_write) const
void frame_buffer_t::blitTexture(const frame_buffer_t& draw, blt::i32 srcX, blt::i32 srcY, blt::i32 destX, blt::i32 destY, GLuint filter,
attachment_t attachment_read, attachment_t attachment_write) const
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, draw.fboID);
@ -182,21 +182,21 @@ namespace blt::gfx
glBlitFramebuffer(srcX, srcY, width_, height_, destX, destY, draw.width_, draw.height_, GL_COLOR_BUFFER_BIT, filter);
}
void fbo_t::blitDepth(const fbo_t& draw, blt::i32 srcX, blt::i32 srcY, blt::i32 destX, blt::i32 destY, GLuint filter) const
void frame_buffer_t::blitDepth(const frame_buffer_t& draw, blt::i32 srcX, blt::i32 srcY, blt::i32 destX, blt::i32 destY, GLuint filter) const
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, draw.fboID);
glBlitFramebuffer(srcX, srcY, width_, height_, destX, destY, draw.width_, draw.height_, GL_DEPTH_BUFFER_BIT, filter);
}
void fbo_t::blitStencil(const fbo_t& draw, blt::i32 srcX, blt::i32 srcY, blt::i32 destX, blt::i32 destY, GLuint filter) const
void frame_buffer_t::blitStencil(const frame_buffer_t& draw, blt::i32 srcX, blt::i32 srcY, blt::i32 destX, blt::i32 destY, GLuint filter) const
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, draw.fboID);
glBlitFramebuffer(srcX, srcY, width_, height_, destX, destY, draw.width_, draw.height_, GL_STENCIL_BUFFER_BIT, filter);
}
void fbo_t::blitToScreen(blt::i32 width, blt::i32 height) const
void frame_buffer_t::blitToScreen(blt::i32 width, blt::i32 height) const
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
@ -205,9 +205,9 @@ namespace blt::gfx
glBlitFramebuffer(0, 0, width_, height_, 0, 0, width, height, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
}
fbo_t fbo_t::make_render_texture(blt::i32 width, blt::i32 height)
frame_buffer_t frame_buffer_t::make_render_texture(blt::i32 width, blt::i32 height)
{
fbo_t fbo;
frame_buffer_t fbo;
fbo.create();
fbo.bind();
@ -215,19 +215,19 @@ namespace blt::gfx
auto* texture = new texture_gl2D(width, height);
fbo.attachTexture(texture, attachment_t::COLOR0);
rbo_t depth_rbo = rbo_t::make_render_buffer(GL_DEPTH24_STENCIL8, width, height);
render_buffer_t depth_rbo = render_buffer_t::make_render_buffer(GL_DEPTH24_STENCIL8, width, height);
fbo.attachRenderBuffer(depth_rbo, attachment_t::DEPTH_STENCIL);
if (!fbo_t::validate())
if (!frame_buffer_t::validate())
BLT_ERROR("Failed to create render texture framebuffer!");
fbo_t::unbind();
frame_buffer_t::unbind();
return fbo;
}
fbo_t fbo_t::make_multisample_render_texture(blt::i32 width, blt::i32 height, blt::i32 samples)
frame_buffer_t frame_buffer_t::make_multisample_render_texture(blt::i32 width, blt::i32 height, blt::i32 samples)
{
fbo_t fbo;
frame_buffer_t fbo;
fbo.create();
fbo.bind();
@ -235,52 +235,52 @@ namespace blt::gfx
auto* texture = new texture_gl2D_multisample(width, height, samples);
fbo.attachTexture(texture, attachment_t::COLOR0);
rbo_t depth_rbo = rbo_t::make_render_buffer(GL_DEPTH24_STENCIL8, width, height, samples);
render_buffer_t depth_rbo = render_buffer_t::make_render_buffer(GL_DEPTH24_STENCIL8, width, height, samples);
fbo.attachRenderBuffer(depth_rbo, attachment_t::DEPTH_STENCIL);
if (!fbo_t::validate())
if (!frame_buffer_t::validate())
BLT_ERROR("Failed to create render texture framebuffer!");
fbo_t::unbind();
frame_buffer_t::unbind();
return fbo;
}
fbo_t fbo_t::make_multisample_render_target(blt::i32 width, blt::i32 height, blt::i32 samples)
frame_buffer_t frame_buffer_t::make_multisample_render_target(blt::i32 width, blt::i32 height, blt::i32 samples)
{
fbo_t fbo;
frame_buffer_t fbo;
fbo.create();
fbo.bind();
rbo_t color_rbo = rbo_t::make_render_buffer(GL_RGBA8, width, height, samples);
rbo_t depth_rbo = rbo_t::make_render_buffer(GL_DEPTH24_STENCIL8, width, height, samples);
render_buffer_t color_rbo = render_buffer_t::make_render_buffer(GL_RGBA8, width, height, samples);
render_buffer_t depth_rbo = render_buffer_t::make_render_buffer(GL_DEPTH24_STENCIL8, width, height, samples);
fbo.attachRenderBuffer(color_rbo, attachment_t::COLOR0);
fbo.attachRenderBuffer(depth_rbo, attachment_t::DEPTH_STENCIL);
if (!fbo_t::validate())
if (!frame_buffer_t::validate())
BLT_ERROR("Failed to create multi-sampled render texture framebuffer!");
fbo_t::unbind();
frame_buffer_t::unbind();
return fbo;
}
fbo_t fbo_t::make_render_target(blt::i32 width, blt::i32 height)
frame_buffer_t frame_buffer_t::make_render_target(blt::i32 width, blt::i32 height)
{
fbo_t fbo;
frame_buffer_t fbo;
fbo.create();
fbo.bind();
rbo_t color_rbo = rbo_t::make_render_buffer(GL_RGBA8, width, height);
rbo_t depth_rbo = rbo_t::make_render_buffer(GL_DEPTH24_STENCIL8, width, height);
render_buffer_t color_rbo = render_buffer_t::make_render_buffer(GL_RGBA8, width, height);
render_buffer_t depth_rbo = render_buffer_t::make_render_buffer(GL_DEPTH24_STENCIL8, width, height);
fbo.attachRenderBuffer(color_rbo, attachment_t::COLOR0);
fbo.attachRenderBuffer(depth_rbo, attachment_t::DEPTH_STENCIL);
if (!fbo_t::validate())
if (!frame_buffer_t::validate())
BLT_ERROR("Failed to create multi-sampled render texture framebuffer!");
fbo_t::unbind();
frame_buffer_t::unbind();
return fbo;
}

View File

@ -93,16 +93,16 @@ namespace blt::gfx
draw_buffer.bind();
auto* texture = new texture_gl2D(1440, 720);
draw_buffer.attachTexture(texture, fbo_t::attachment_t::COLOR0);
draw_buffer.attachTexture(texture, frame_buffer_t::attachment_t::COLOR0);
auto* mask = new texture_gl2D(1440, 720);
draw_buffer.attachTexture(mask, fbo_t::attachment_t::COLOR1);
draw_buffer.attachTexture(mask, frame_buffer_t::attachment_t::COLOR1);
rbo_t depth_rbo = rbo_t::make_render_buffer(GL_DEPTH24_STENCIL8, 1440, 720);
draw_buffer.attachRenderBuffer(depth_rbo, fbo_t::attachment_t::DEPTH_STENCIL);
render_buffer_t depth_rbo = render_buffer_t::make_render_buffer(GL_DEPTH24_STENCIL8, 1440, 720);
draw_buffer.attachRenderBuffer(depth_rbo, frame_buffer_t::attachment_t::DEPTH_STENCIL);
if (!fbo_t::validate())
if (!frame_buffer_t::validate())
BLT_ERROR("Failed to create render framebuffer!");
fbo_t::unbind();
frame_buffer_t::unbind();
}
void batch_renderer_2d::drawRectangleInternal(const std::string_view texture, const rectangle2d_t& rectangle, const f32 z_index)
@ -187,7 +187,7 @@ namespace blt::gfx
render_reset();
draw_buffer.blitToScreen(width, height);
fbo_t::unbind();
frame_buffer_t::unbind();
}
void batch_renderer_2d::draw_objects()