Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
framebuffer.hpp
Go to the documentation of this file.
1
10
11#ifndef FOOLSENGINE_FRAMEBUFFER_H
12#define FOOLSENGINE_FRAMEBUFFER_H
13
14#include <vector>
15#include <memory>
16
17#include <GL/glew.h>
18#include <glm/glm.hpp>
19
20#include "texture.hpp"
22
23namespace ToyMaker {
24
25 class Framebuffer;
26
34 class RBO {
35 public:
42 inline static std::unique_ptr<RBO> create(const glm::vec2& dimensions) {
43 return std::unique_ptr<RBO>{ new RBO{dimensions} };
44 }
45
49 ~RBO();
50
56 inline GLuint getID() const { return mID; }
57
63 void resize(const glm::vec2& dimensions);
64 private:
70 RBO(const glm::vec2& dimensions);
71
76 GLuint mID;
77 };
78
88 class Framebuffer : public Resource<Framebuffer> {
89 public:
100 GLuint framebuffer,
101 glm::vec2 dimensions,
102 GLuint nColorAttachments,
103 const std::vector<std::shared_ptr<Texture>>& colorBuffers,
104 std::unique_ptr<RBO> rbo
105 );
106
111 ~Framebuffer() override;
112
113 /* copy constructor */
114 Framebuffer(const Framebuffer& other);
115 /* move constructor */
116 Framebuffer(Framebuffer&& other);
117 /* copy assignment operator */
118 Framebuffer& operator=(const Framebuffer& other);
119 /* move assignment operator */
120 Framebuffer& operator=(Framebuffer&& other);
121
128 std::size_t addTargetColorBufferHandle(std::shared_ptr<Texture> colorBufferHandle);
129
136 std::vector<std::shared_ptr<const Texture>> getTargetColorBufferHandles() const;
137
143 const std::vector<std::shared_ptr<Texture>>& getTargetColorBufferHandles();
144
151 bool hasAttachedRBO() const;
152
161 bool hasOwnRBO() const;
162
168 RBO& getOwnRBO();
169
175 void attachRBO(RBO& rbo);
176
181 void detachRBO();
182
187 void bind();
188
194 glm::u16vec2 getDimensions() const { return mDimensions; }
195
200 void unbind();
201
207 inline static std::string getResourceTypeName() { return "Framebuffer"; }
208
209 private:
214 GLuint mID {};
215
220 std::unique_ptr<RBO> mOwnRBO {};
221
227
232 glm::vec2 mDimensions {};
233
238 std::vector<std::shared_ptr<Texture>> mTextureHandles {};
239
244 bool mHasAttachedRBO { false };
245
251 void attachRBO_(RBO& rbo);
252
257 void detachRBO_();
258
263 void destroyResource();
264
269 void releaseResource();
270
276 void copyResource(const Framebuffer& other);
277
283 void stealResource(Framebuffer& other);
284 };
285
291 class FramebufferFromDescription: public ResourceConstructor<Framebuffer, FramebufferFromDescription> {
292 public:
300
309 static std::string getResourceConstructorName() { return "fromDescription"; }
310
311 private:
318 std::shared_ptr<IResource> createResource(const nlohmann::json& methodParams) override;
319 };
320}
321
322#endif
FramebufferFromDescription()
Constructs a new FramebufferFromDescription object.
Definition framebuffer.hpp:297
static std::string getResourceConstructorName()
Get the resource constructor type string associated with this constructor.
Definition framebuffer.hpp:309
std::shared_ptr< IResource > createResource(const nlohmann::json &methodParams) override
The method actually responsible for the creation of a framebuffer with this constructor.
Definition framebuffer.cpp:207
A wrapper class over OpenGL framebuffers.
Definition framebuffer.hpp:88
bool hasOwnRBO() const
Answers whether an RBO description was specified when creating this framebuffer.
Definition framebuffer.cpp:87
void attachRBO_(RBO &rbo)
Attaches an RBO associated with another Framebuffer to this object.
Definition framebuffer.cpp:100
void detachRBO()
Detaches any RBOs currently attached to this framebuffer.
Definition framebuffer.cpp:108
void copyResource(const Framebuffer &other)
Copies resources associated with another framebuffer.
Definition framebuffer.cpp:149
bool hasAttachedRBO() const
Answers whether this framebuffer has an RBO attached.
Definition framebuffer.cpp:83
void releaseResource()
Releases resources associated with this framebuffer, allowing other object(s) to manage them instead.
Definition framebuffer.cpp:142
void detachRBO_()
Unbinds any RBO currently attached to this framebuffer.
Definition framebuffer.cpp:113
void bind()
Makes this framebuffer the currently active framebuffer in this OpenGL context.
Definition framebuffer.cpp:126
GLuint mID
The ID corresponding to this framebuffer.
Definition framebuffer.hpp:214
std::vector< std::shared_ptr< Texture > > mTextureHandles
All color buffers associated with this framebuffer, owned by this framebuffer.
Definition framebuffer.hpp:238
~Framebuffer() override
Destroys the framebuffer object.
Definition framebuffer.cpp:71
void stealResource(Framebuffer &other)
Steals resources associated with another framebuffer.
Definition framebuffer.cpp:197
std::vector< std::shared_ptr< const Texture > > getTargetColorBufferHandles() const
Returns a vector of handles to this framebuffer's color buffers.
Definition framebuffer.cpp:118
std::size_t addTargetColorBufferHandle(std::shared_ptr< Texture > colorBufferHandle)
Attaches a new color buffer to this framebuffer.
Definition framebuffer.cpp:75
std::unique_ptr< RBO > mOwnRBO
The RBO owned by this framebuffer, if such a one exists.
Definition framebuffer.hpp:220
static std::string getResourceTypeName()
Gets the resource type string associated with the Framebuffer resource.
Definition framebuffer.hpp:207
Framebuffer(GLuint framebuffer, glm::vec2 dimensions, GLuint nColorAttachments, const std::vector< std::shared_ptr< Texture > > &colorBuffers, std::unique_ptr< RBO > rbo)
Assuming an allocated OpenGL framebuffer already exists, constructs a Framebuffer object and hands ov...
Definition framebuffer.cpp:31
RBO & getOwnRBO()
Gets the RBO owned by this framebuffer.
Definition framebuffer.cpp:91
glm::vec2 mDimensions
The dimensions, in pixels, for textures attached to this framebuffer.
Definition framebuffer.hpp:232
void unbind()
Unbind this framebuffer (or in other words, bind the default framebuffer)
Definition framebuffer.cpp:129
GLuint mNColorAttachments
The number of color attachments active on this framebuffer when render is called.
Definition framebuffer.hpp:226
bool mHasAttachedRBO
Tracks whether an RBO was attached to this framebuffer (including ones that aren't owned by it).
Definition framebuffer.hpp:244
glm::u16vec2 getDimensions() const
Gets the dimensions specified for this framebuffer.
Definition framebuffer.hpp:194
void attachRBO(RBO &rbo)
Attaches the RBO (of possibly another framebuffer) to this framebuffer object.
Definition framebuffer.cpp:95
void destroyResource()
Destroys resources associated with this framebuffer.
Definition framebuffer.cpp:133
Wrapper class over OpenGL RBOs.
Definition framebuffer.hpp:34
void resize(const glm::vec2 &dimensions)
Deletes previously allocated RBO buffer and allocates a new one.
Definition framebuffer.cpp:21
GLuint getID() const
Gets the ID associated with this RBO.
Definition framebuffer.hpp:56
RBO(const glm::vec2 &dimensions)
Constructs a new RBO object.
Definition framebuffer.cpp:16
GLuint mID
The ID of the RBO.
Definition framebuffer.hpp:76
~RBO()
Destroys the RBO object.
Definition framebuffer.cpp:27
static std::unique_ptr< RBO > create(const glm::vec2 &dimensions)
Creates a new RBO.
Definition framebuffer.hpp:42
ResourceConstructor(int explicitlyInitializeMe)
Definition resource_database.hpp:491
Resource(int explicitlyInitializeMe)
Definition resource_database.hpp:389
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
Headers relating to resources and their management for a given project.
Header containing definitions of classes and functions related to loading and using Texture resources...