Josh's Graphics Library
RenderTarget.h
Go to the documentation of this file.
1#pragma once
2#include <glad/glad.h>
3#include <Color4.hpp>
4#include <Colors.hpp>
5#include <JGL/types/Enums.h>
6#include <J3ML/LinearAlgebra/Vector2.hpp>
7
8namespace JGL {
9 class RenderTarget;
10 class Texture; // Forward declare.
11}
12
14private:
15 Color4 clear_color{0,0,0,0};
17 Vector2 size{0, 0};
18 bool using_depth = false;
19 bool texture_created_by_us = false;
20 GLuint framebuffer_object = 0;
21 GLuint depth_buffer = 0;
22 const Texture* texture = nullptr;
24 GLuint msaa_framebuffer_object = 0;
25 GLuint msaa_depth_buffer = 0;
26 GLuint msaa_render_buffer = 0;
27 void Erase();
28public:
29 static GLuint GetActiveGLFramebufferHandle();
31
34 void Resize(const Vector2& new_size);
35 void SetMSAAEnabled(MSAA_SAMPLE_RATE sample_rate);
39 void Blit() const;
40
42 static void Blit(const RenderTarget& source, RenderTarget* destination);
43 [[nodiscard]] bool TextureCreatedByRenderTarget() const;
44public:
45 [[nodiscard]] Vector2 GetDimensions() const;
46 [[nodiscard]] MSAA_SAMPLE_RATE GetMSAASampleRate() const;
50 [[nodiscard]] bool MSAAEnabled() const;
51 [[nodiscard]] const Texture* GetJGLTexture() const;
52 [[nodiscard]] GLuint GetGLTextureHandle() const;
53 [[nodiscard]] GLuint GetGLFramebufferObjectHandle() const;
54 [[nodiscard]] GLuint GetGLDepthBufferHandle() const;
55 [[nodiscard]] Color4 GetClearColor() const;
57 [[nodiscard]] std::vector<GLfloat> GetData() const;
58public:
60 RenderTarget(const RenderTarget& rhs);
62 explicit RenderTarget(const Texture* texture, const Color4& clear_color = Colors::Black);
64 explicit RenderTarget(const Vector2& size, const Color4& clear_color = Colors::Black, bool use_depth = false, MSAA_SAMPLE_RATE sample_rate = MSAA_SAMPLE_RATE::MSAA_NONE);
66};
JGL::RenderTarget * render_target
Definition: JGL.cpp:14
Definition: RenderTarget.h:13
Color4 GetClearColor() const
Definition: RenderTarget.cpp:50
bool TextureCreatedByRenderTarget() const
Definition: RenderTarget.cpp:207
void SetMSAAEnabled(MSAA_SAMPLE_RATE sample_rate)
Definition: RenderTarget.cpp:219
RenderTarget(const RenderTarget &rhs)
Copy constructor. Will always set "texture_created_by_us" to true and use our own texture to avoid me...
Definition: RenderTarget.cpp:334
GLuint GetGLTextureHandle() const
Definition: RenderTarget.cpp:10
~RenderTarget()
Definition: RenderTarget.cpp:201
GLuint GetGLDepthBufferHandle() const
Definition: RenderTarget.cpp:18
MSAA_SAMPLE_RATE GetMSAASampleRate() const
Definition: RenderTarget.cpp:211
void Blit() const
If you're using raw OpenGL commands to draw to this outside of J2D or J3D don't forget to do this.
Definition: RenderTarget.cpp:276
std::vector< GLfloat > GetData() const
Get the data back from the FBO. This is not async friendly.
Definition: RenderTarget.cpp:127
static void SetActiveGLRenderTarget(const RenderTarget &render_target)
Definition: RenderTarget.cpp:28
Vector2 GetDimensions() const
Definition: RenderTarget.cpp:33
bool MSAAEnabled() const
Returns whether or not MSAA is enabled, If it is and you're not using J2D || J3D Begin / End,...
Definition: RenderTarget.cpp:215
void Resize(const Vector2 &new_size)
Change the size of the renderable area of the Render Target.
Definition: RenderTarget.cpp:138
GLuint GetGLFramebufferObjectHandle() const
Definition: RenderTarget.cpp:14
const Texture * GetJGLTexture() const
Definition: RenderTarget.cpp:6
static GLuint GetActiveGLFramebufferHandle()
Definition: RenderTarget.cpp:22
Represents texture data loaded on the GPU. Contains a handle that can be passed to OpenGL draw calls.
Definition: Texture.h:27
OpenGL Wrapper for rendering 2D & 3D graphics in both a 2D and 3D context.
Definition: JGL.h:31
MSAA_SAMPLE_RATE
Definition: Enums.h:37