All Classes Files Functions Variables Typedefs Pages
FrameBuffer.hpp
1 #pragma once
2 
3 #include "GLObject.hpp"
4 #include "Texture.hpp"
5 #include "FrameBuffer.fpp"
6 #include "HotFrameBuffer.fpp"
7 #include "../util/ColorCore.hpp"
8 
9 #include <GL/glew.h>
10 #include <functional>
11 #include <memory>
12 #include <vector>
13 
14 namespace lumina {
15 namespace internal {
16 
17 struct ColorAttPoint {
18  GLuint handle;
19  TexFormat format;
20 
21  ColorAttPoint() : handle(0) {}
22 };
23 
24 
26 public:
27  virtual ~FrameBufferInterface() = default;
28 
29  virtual void create() = 0;
30  virtual void prime(std::shared_ptr<FrameBufferInterface> fb,
31  std::function<void(HotFrameBuffer&)> func) = 0;
32  virtual void attachColor(int index, const Tex2D& tex) = 0;
33  virtual void attachDepth(const Tex2D& tex) = 0;
34  virtual void attachDepthStencil(const Tex2D& tex) = 0;
35 
36  virtual int countAttachments() = 0;
37 
38  virtual void clearColor(int index, Color32fA color) = 0;
39  virtual void clearDepth(float val) = 0;
40  virtual void clearDepthStencil(float depth, int stencil) = 0;
41 
42 
43 protected:
44  // true if a user defined framebuffer is primed
45  static bool s_isPrimed;
46 
47  friend ::lumina::FrameBuffer;
48 };
49 
51 public:
54 
55  ~UserFrameBuffer();
56 
57  void create() override final;
58  void prime(std::shared_ptr<FrameBufferInterface> fb,
59  std::function<void(HotFrameBuffer&)> func) override final;
60  void attachColor(int index, const Tex2D& tex) override final;
61  void attachDepth(const Tex2D& tex) final;
62  void attachDepthStencil(const Tex2D& tex) final;
63 
64  int countAttachments() override final;
65 
66  void clearColor(int index, Color32fA color);
67  void clearDepth(float val);
68  void clearDepthStencil(float depth, int stencil);
69 
70 private:
71  GLuint m_handle;
72  std::vector<internal::ColorAttPoint> m_colorAtts;
73  GLuint m_depthAtt;
74  GLuint m_depthStencilAtt;
75  bool m_needsUpdate;
76 
77  void updateState();
78  void bind();
79  void unbind();
80 };
81 
82 
84 public:
85  void create() override final;
86  void prime(std::shared_ptr<FrameBufferInterface> fb,
87  std::function<void(HotFrameBuffer&)> func) override final;
88  void attachColor(int index, const Tex2D& tex) override final;
89  void attachDepth(const Tex2D& tex) final;
90  void attachDepthStencil(const Tex2D& tex) final;
91 
92  int countAttachments() override final;
93 
94  void clearColor(int index, Color32fA color);
95  void clearDepth(float val);
96  void clearDepthStencil(float depth, int stencil);
97 };
98 
99 } // namespace internal
100 
101 
107 class FrameBuffer : public NotCopyable {
108 public:
109  FrameBuffer();
110  FrameBuffer(std::shared_ptr<internal::FrameBufferInterface> fb);
111 
112  void create();
113  void prime(std::function<void(HotFrameBuffer&)> func);
114  void attachColor(int index, const Tex2D& tex);
115  void attachDepth(const Tex2D& tex);
116  void attachDepthStencil(const Tex2D& tex);
117 
118  int countAttachments();
119 
120  static bool isPrimed();
121 
122 private:
123  std::shared_ptr<internal::FrameBufferInterface> m_fb;
124 };
125 
126 }
127 
128 #include "FrameBuffer.tpp"
Defines the Texture class that represents a OpenGL texture.
Definition: ColorCore.hpp:99
Definition: NotCloneable.hpp:19
Represents an OpenGL texture.
Definition: Texture.fpp:7
Definition: FrameBuffer.hpp:83
Definition: NotCloneable.hpp:5
Definition: HotFrameBuffer.hpp:20
Definition: GLObject.hpp:37
Definition: FrameBuffer.hpp:17
Definition: FrameBuffer.hpp:25
Definition: FrameBuffer.hpp:50
Wrapper for either a UserFrameBuffer or the DefaultFrameBuffer (provides a layer of indirection) ...
Definition: FrameBuffer.hpp:107