From 226192e264e115244bd2c2a0fd708e1ee705c9a7 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 26 Oct 2020 18:39:25 +0300 Subject: [PATCH] Support cubemap textures as framebuffer attachments --- libs/gfx/include/psemek/gfx/framebuffer.hpp | 6 ++++ libs/gfx/source/framebuffer.cpp | 36 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/libs/gfx/include/psemek/gfx/framebuffer.hpp b/libs/gfx/include/psemek/gfx/framebuffer.hpp index 3ce0a458..e8e97375 100644 --- a/libs/gfx/include/psemek/gfx/framebuffer.hpp +++ b/libs/gfx/include/psemek/gfx/framebuffer.hpp @@ -31,10 +31,16 @@ namespace psemek::gfx 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(texture_cubemap const & tex, int attachment = 0); + void color(texture_cubemap const & tex, int face, int attachment = 0); void color(renderbuffer const & rb, int attachment = 0); void depth(texture_2d const & tex); + void depth(texture_cubemap const & tex); + void depth(texture_cubemap const & tex, int face); void depth(renderbuffer const & rb); void depth_stencil(texture_2d const & tex); + void depth_stencil(texture_cubemap const & tex); + void depth_stencil(texture_cubemap const & tex, int face); void depth_stencil(renderbuffer const & rb); GLenum status() const; diff --git a/libs/gfx/source/framebuffer.cpp b/libs/gfx/source/framebuffer.cpp index 897c7663..3fca7d5e 100644 --- a/libs/gfx/source/framebuffer.cpp +++ b/libs/gfx/source/framebuffer.cpp @@ -84,6 +84,18 @@ namespace psemek::gfx gl::FramebufferTextureLayer(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, tex.id(), 0, layer); } + void framebuffer::color(texture_cubemap const & tex, int attachment) + { + bind(); + gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, tex.id(), 0); + } + + void framebuffer::color(texture_cubemap const & tex, int face, int attachment) + { + bind(); + gl::FramebufferTexture2D(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, texture_cubemap::face_to_gl(face), tex.id(), 0); + } + void framebuffer::color(renderbuffer const & rb, int attachment) { bind(); @@ -96,6 +108,18 @@ namespace psemek::gfx gl::FramebufferTexture2D(gl::DRAW_FRAMEBUFFER, gl::DEPTH_ATTACHMENT, gl::TEXTURE_2D, tex.id(), 0); } + void framebuffer::depth(texture_cubemap const & tex) + { + bind(); + gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::DEPTH_ATTACHMENT, tex.id(), 0); + } + + void framebuffer::depth(texture_cubemap const & tex, int face) + { + bind(); + gl::FramebufferTexture2D(gl::DRAW_FRAMEBUFFER, gl::DEPTH_ATTACHMENT, texture_cubemap::face_to_gl(face), tex.id(), 0); + } + void framebuffer::depth(renderbuffer const & rb) { bind(); @@ -108,6 +132,18 @@ namespace psemek::gfx gl::FramebufferTexture2D(gl::DRAW_FRAMEBUFFER, gl::DEPTH_STENCIL_ATTACHMENT, gl::TEXTURE_2D, tex.id(), 0); } + void framebuffer::depth_stencil(texture_cubemap const & tex) + { + bind(); + gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::DEPTH_STENCIL_ATTACHMENT, tex.id(), 0); + } + + void framebuffer::depth_stencil(texture_cubemap const & tex, int face) + { + bind(); + gl::FramebufferTexture2D(gl::DRAW_FRAMEBUFFER, gl::DEPTH_STENCIL_ATTACHMENT, texture_cubemap::face_to_gl(face), tex.id(), 0); + } + void framebuffer::depth_stencil(renderbuffer const & rb) { bind();