Ability to resize render targets.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m48s

This commit is contained in:
2024-10-06 00:01:06 -04:00
parent b4c29315f4
commit 5f367efc28
7 changed files with 148 additions and 48 deletions

View File

@@ -8,18 +8,29 @@ namespace JGL {
class RenderTarget;
}
//TODO copy constructor for this. Copying this as it is and then that copy going out of scope will crash the program as it sits.
class JGL::RenderTarget {
private:
Color4 clear_color{0,0,0,0};
/// "Size" in this sense is the "Renderable Area" because OpenGL textures behave strangely if they're not square.
Vector2 size{0, 0};
bool using_depth = false;
bool texture_created_by_us = false;
GLuint framebuffer_object = 0;
GLuint depth_buffer = 0;
Texture* texture = nullptr;
void Erase();
public:
static GLuint GetActiveGLFramebufferHandle();
static void SetActiveGLRenderTarget(const RenderTarget& render_target);
/** Change the size of the renderable area of the Render Target.
* If the new size is larger than the non-renderable area the texture will be resized to fit. */
/// @param new_size new size in px.
/// @param clear whether or not the data currently in the RenderTarget is to be kept.
/// @note Clearing the FBO on Resize is *much* faster than keeping the data because we don't have to read back.
void Resize(const Vector2& new_size);
public:
[[nodiscard]] Vector2 GetDimensions() const;
[[nodiscard]] Texture* GetJGLTexture() const;
@@ -30,10 +41,9 @@ public:
/// Get the data back from the FBO. This is *not* async friendly.
[[nodiscard]] std::vector<GLfloat> GetData() const;
public:
/// Create a render target for a texture that already exists. For decals.
explicit RenderTarget(const Texture& texture, const Color4& clear_color = Colors::Black, bool use_depth = false);
/// Create a render target for a texture that already exists. For adding to an existing texture.
explicit RenderTarget(const Texture* texture, const Color4& clear_color = Colors::Black, bool use_depth = false);
/// Create a Render Target with a brand new texture. Want to render JGL elements onto a texture and display it as a sprite?
explicit RenderTarget(const Vector2& size, const Color4& clear_color = Colors::Black, bool use_depth = false);
void Erase();
~RenderTarget();
};

View File

@@ -23,8 +23,12 @@ namespace JGL {
CLAMP_TO_BORDER = 3 //Effectively the same as clamp_to_edge
};
//TODO copy constructor for this. Copying this as it is and then that copy going out of scope will crash the program as it sits.
/// Represents texture data loaded on the GPU. Contains a handle that can be passed to OpenGL draw calls.
class Texture {
private:
void Erase();
protected:
GLuint texture_handle = 0;
Vector2 texture_size = {0, 0};
@@ -38,9 +42,11 @@ namespace JGL {
/// Load a texture from a file,
explicit Texture(const std::string& file, TextureFilteringMode filtering_mode = TextureFilteringMode::BILINEAR, TextureWrappingMode wrapping_mode = TextureWrappingMode::CLAMP_TO_EDGE);
Texture(const std::string& file, const TextureFlag& flags, TextureFilteringMode filtering_mode = TextureFilteringMode::BILINEAR, TextureWrappingMode wrapping_mode = TextureWrappingMode::CLAMP_TO_EDGE);
Texture(SoftwareTexture* software_texture, const Vector2& size, const TextureFormat& format, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode);
/* Initialize a texture filled with trash data
this is primarily for the RenderTarget */
explicit Texture(const Vector2& size);
~Texture();
public:
[[nodiscard]] GLuint GetGLTextureHandle() const;
[[nodiscard]] Vector2 GetDimensions() const;
@@ -51,7 +57,6 @@ namespace JGL {
[[nodiscard]] std::vector<Color4> GetPixelData() const;
void SetTextureHandle(GLuint handle);
void Erase();
};
}

View File

@@ -20,6 +20,7 @@ private:
void load(const GLuint* data, const long& size);
void SetData(void* data, const long& length);
void UpdateData(void* data, const long& offset, const long& length);
void Erase();
public:
VRamList(const GLuint* data, const long& length);
VRamList(const GLfloat* data, const long& length);
@@ -43,8 +44,6 @@ public:
[[nodiscard]] std::vector<GLfloat> GetDataF() const;
[[nodiscard]] std::vector<GLuint> GetDataUI() const;
[[nodiscard]] bool IsFloatArray() const;
/// Deallocate the vram the vbo took up.
void Erase();
/** Replace the data of an existing VBO in it's entirety. Must be same type.
* "length" refers to the number of elements in data. Not the number of bytes. */
void SetData(const GLfloat* data, const long& length);