From d8069308ee2c68aea54e9185e61a639f9d62b248 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 3 Oct 2020 20:42:16 +0300 Subject: [PATCH] Support all texture types for framebuffer color target --- libs/gfx/include/psemek/gfx/framebuffer.hpp | 3 +++ libs/gfx/source/framebuffer.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/libs/gfx/include/psemek/gfx/framebuffer.hpp b/libs/gfx/include/psemek/gfx/framebuffer.hpp index b461f22c..00174aff 100644 --- a/libs/gfx/include/psemek/gfx/framebuffer.hpp +++ b/libs/gfx/include/psemek/gfx/framebuffer.hpp @@ -24,7 +24,10 @@ namespace psemek::gfx void bind() const; + void color(texture_1d const & tex, int attachment = 0); void color(texture_2d const & tex, int attachment = 0); + void color(texture_3d const & tex, int layer, int attachment = 0); + void color(texture_2d_array const & tex, int layer, int attachment = 0); void color(renderbuffer const & rb, int attachment = 0); void depth(renderbuffer const & rb); diff --git a/libs/gfx/source/framebuffer.cpp b/libs/gfx/source/framebuffer.cpp index 307bc567..b0a4349a 100644 --- a/libs/gfx/source/framebuffer.cpp +++ b/libs/gfx/source/framebuffer.cpp @@ -57,12 +57,30 @@ namespace psemek::gfx gl::BindFramebuffer(gl::DRAW_FRAMEBUFFER, id_); } + void framebuffer::color(texture_1d const & tex, int attachment) + { + bind(); + gl::FramebufferTexture2D(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, gl::TEXTURE_1D, tex.id(), 0); + } + void framebuffer::color(texture_2d const & tex, int attachment) { bind(); gl::FramebufferTexture2D(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, gl::TEXTURE_2D, tex.id(), 0); } + void framebuffer::color(texture_3d const & tex, int layer, int attachment) + { + bind(); + gl::FramebufferTexture3D(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, gl::TEXTURE_3D, tex.id(), 0, layer); + } + + void framebuffer::color(texture_2d_array const & tex, int layer, int attachment) + { + bind(); + gl::FramebufferTextureLayer(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, tex.id(), 0, layer); + } + void framebuffer::color(renderbuffer const & rb, int attachment) { bind();