Loading [MathJax]/extensions/tex2jax.js
Tatooine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
framebuffer.h
Go to the documentation of this file.
1#ifndef TATOOINE_GL_FRAMEBUFFER_H
2#define TATOOINE_GL_FRAMEBUFFER_H
3//==============================================================================
4#include "errorcheck.h"
5#include "dllexport.h"
7//==============================================================================
8namespace tatooine::gl {
9//==============================================================================
10class framebuffer : public id_holder<GLuint> {
11 public:
12 DLL_API framebuffer();
13 DLL_API ~framebuffer();
14 template <typename... Textures>
15 DLL_API framebuffer(const Textures&... textures) : framebuffer{} {
16 constexpr auto num_color_attachements =
17 num_color_components<typename Textures::components...>();
18 unsigned int i = 0;
19 // attach textures one after another, incrementing i if texture is a color
20 // texture
21 (void)std::array{(texture_depth_component<typename Textures::components>
22 ? attach(textures)
23 : attach(textures, i++))...};
24
25 // create array for glDrawBuffers function with all color attachements
26 std::array<GLenum, num_color_attachements> colbufs;
27 auto add_attachement = [j = 0, &colbufs](const auto& tex) mutable {
28 using TA = decltype(tex);
29 using Texture = typename std::decay_t<TA>;
30 using Components = typename Texture::components;
31 if constexpr (texture_color_component<Components>) {
32 colbufs[j] = GL_COLOR_ATTACHMENT0 + j;
33 return GL_COLOR_ATTACHMENT0 + j++;
34 }
35 return GL_NONE;
36 };
37 (void)std::array{add_attachement(textures)...};
38 gl::named_framebuffer_draw_buffers(id(), num_color_attachements, colbufs.data());
39 }
40
41 template <typename T, typename Components>
42 DLL_API GLenum attach(const tex2<T, Components>& tex, unsigned int i = 0);
43 template <typename T>
44 DLL_API GLenum attach(const tex2<T, Depth>& depth_tex);
45 private:
46 // this is necessary for constructor taking variadic parameters
47 template <typename T>
48 constexpr GLenum attach(const tex2<T, Depth>& depth_tex, unsigned int) {
49 return attach(depth_tex);
50 }
51
52 public:
53 DLL_API void bind();
54 DLL_API static void unbind();
55
56 DLL_API void clear();
57
58 //============================================================================
59 private:
60 template <typename... Cs>
61 static constexpr auto num_color_components() {
62 return sum((texture_color_component<Cs> ? 1 : 0)...);
63 }
64 //============================================================================
65 template <typename... Ts>
66 static constexpr auto sum(Ts... ts) {
67 return (ts + ...);
68 }
69};
70//==============================================================================
71} // namespace tatooine::gl
72//==============================================================================
73#endif
Definition: framebuffer.h:10
static constexpr auto sum(Ts... ts)
Definition: framebuffer.h:66
DLL_API GLenum attach(const tex2< T, Components > &tex, unsigned int i=0)
DLL_API framebuffer(const Textures &... textures)
Definition: framebuffer.h:15
static DLL_API void unbind()
static constexpr auto num_color_components()
Definition: framebuffer.h:61
constexpr GLenum attach(const tex2< T, Depth > &depth_tex, unsigned int)
Definition: framebuffer.h:48
DLL_API GLenum attach(const tex2< T, Depth > &depth_tex)
Definition: texture.h:61
Definition: ansiformat.h:6
DLL_API auto named_framebuffer_draw_buffers(GLuint framebuffer, GLsizei n, const GLenum *bufs) -> void
Definition: idholder.h:31