Gorgon Game Engine
FrameBuffer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Geometry/Size.h"
4 #include "../GL.h"
5 #include "../Containers/Collection.h"
6 
7 namespace Gorgon { namespace GL {
8 
13  class FrameBuffer {
14  friend void Resize(const Geometry::Size &size);
15  public:
16  FrameBuffer(const FrameBuffer &) = delete;
17 
18  FrameBuffer &operator = (const FrameBuffer &) = delete;
19 
22  }
23 
26  explicit FrameBuffer(bool depth) : FrameBuffer() {
27  Generate(depth);
28  }
29 
33  void Generate(bool depth);
34 
36  void Destroy();
37 
39  Destroy();
40  buffers.Remove(this);
41  }
42 
44  bool IsReady() const {
45  return texture != 0 && buffer != 0;
46  }
47 
49  bool IsFunctional() const;
50 
52  Texture GetTexture() const {
53  return texture;
54  }
55 
57  void Use();
58 
60  void RenderToScreen();
61 
63  static void UpdateSizes();
64 
69  static bool HardwareSupport;
70 
71  private:
72 #ifdef OPENGL
73  Texture texture = 0;
74  uint32_t buffer = 0;
75  uint32_t depth = 0;
76 #endif
77 
78  //this is used to resize buffer on a geometry change.
80  };
81 } }
glDeleteRenderbuffers
PFNGLDELETERENDERBUFFERS glDeleteRenderbuffers
Definition: OpenGL.cpp:81
Gorgon::Window::GetMinimumRequiredSize
static Geometry::Size GetMinimumRequiredSize()
Returns the minimum size required to fit any window inside.
Definition: WindowManager.cpp:14
Gorgon::GL::FrameBuffer::UpdateSizes
static void UpdateSizes()
Updates the size of all framebuffers.
Definition: FrameBuffer.cpp:34
Gorgon::GL::FrameBuffer::operator=
FrameBuffer & operator=(const FrameBuffer &)=delete
Gorgon::GL::FrameBuffer::Resize
friend void Resize(const Geometry::Size &size)
Resizes the active context.
Definition: OpenGL.cpp:273
glGenFramebuffers
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers
Definition: OpenGL.cpp:76
glFramebufferRenderbuffer
PFNGLFRAMEBUFFERRENDERBUFFER glFramebufferRenderbuffer
Definition: OpenGL.cpp:80
OpenGL.h
Gorgon::Graphics::ColorMode::RGBA
@ RGBA
32bit red, green, blue and alpha channel image. Red component is in the lowest byte order and
Gorgon::GL::FrameBuffer::FrameBuffer
FrameBuffer(bool depth)
Generates a frame buffer.
Definition: FrameBuffer.h:26
Gorgon::GL::FrameBuffer::FrameBuffer
FrameBuffer(const FrameBuffer &)=delete
Gorgon::GL::GenerateEmptyTexture
Texture GenerateEmptyTexture(const Geometry::Size &size, Graphics::ColorMode mode)
This function generates a texture from the given image data.
Definition: OpenGL.cpp:154
glBindRenderbuffer
PFNGLBINDRENDERBUFFER glBindRenderbuffer
Definition: OpenGL.cpp:77
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Geometry::basic_Size
This class represents a 2D geometric size.
Definition: Size.h:23
Gorgon::GL::FrameBuffer::HardwareSupport
static bool HardwareSupport
Whether hardware supports frame buffers.
Definition: FrameBuffer.h:69
glDeleteFramebuffers
PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers
Definition: OpenGL.cpp:74
Gorgon::GL::FrameBuffer::IsFunctional
bool IsFunctional() const
Returns if the frame buffer is fully functional.
Definition: FrameBuffer.cpp:61
Gorgon::GL::FrameBuffer::Use
void Use()
Begin using this frame buffer.
Definition: FrameBuffer.cpp:65
Gorgon::GL::FrameBuffer::~FrameBuffer
~FrameBuffer()
Definition: FrameBuffer.h:38
glFramebufferTexture2D
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D
Definition: OpenGL.cpp:75
Gorgon::Containers::Collection
Collection is a container for reference typed objects.
Definition: Collection.h:21
Gorgon::GL::FrameBuffer::IsReady
bool IsReady() const
Returns if the frame buffer ready.
Definition: FrameBuffer.h:44
Gorgon::GL::FrameBuffer::GetTexture
Texture GetTexture() const
Returns the texture of this buffer.
Definition: FrameBuffer.h:52
Gorgon::GL::DestroyTexture
void DestroyTexture(Texture texture)
Destroys the given texture.
Definition: OpenGL.cpp:213
Gorgon::GL::ResizeTexture
void ResizeTexture(Texture texture, const Geometry::Size &size, Graphics::ColorMode mode)
Resizes the given texture to the specified size.
Definition: OpenGL.cpp:169
Gorgon::GL::FrameBuffer
This is a frame buffer object that can be used for render to texture tasks.
Definition: FrameBuffer.h:13
Gorgon::GL::FrameBuffer::Generate
void Generate(bool depth)
Generates a frame buffer.
Definition: FrameBuffer.cpp:7
glRenderbufferStorage
PFNGLRENDERBUFFERSTORAGE glRenderbufferStorage
Definition: OpenGL.cpp:78
Gorgon::GL::RenderToScreen
void RenderToScreen()
Stops rendering to a texture and start rendering to a buffer.
Definition: OpenGL.cpp:221
Gorgon::GL::FrameBuffer::FrameBuffer
FrameBuffer()
Does not perform any action, allows late generation of buffers.
Definition: FrameBuffer.h:21
Gorgon::GL::FrameBuffer::Destroy
void Destroy()
Destroys the frame buffer.
Definition: FrameBuffer.cpp:46
glBindFramebuffer
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer
Definition: OpenGL.cpp:72
Gorgon::GL::FrameBuffer::RenderToScreen
void RenderToScreen()
Stop using this buffer and render to screen instead.
Definition: FrameBuffer.cpp:71
glDrawBuffers
PFNGLDRAWBUFFERSPROC glDrawBuffers
Definition: OpenGL.cpp:23
Gorgon::GL::log
Gorgon::Utils::Logger log
The logger that is used for GL operations. Default is unset and will not log anything....
Definition: Shader.cpp:19
FrameBuffer.h
glGenRenderbuffers
PFNGLGENRENDERBUFFERS glGenRenderbuffers
Definition: OpenGL.cpp:79