copy construct RenderTarget.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m36s

This commit is contained in:
2024-10-13 16:37:51 -04:00
parent bb4a80e36d
commit cc504c65ec
4 changed files with 24 additions and 5 deletions

View File

@@ -10,9 +10,6 @@ namespace JGL {
class Texture; // Forward declare.
}
//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.
//If you do copy it you're doing it wrong. But still.
class JGL::RenderTarget {
private:
Color4 clear_color{0,0,0,0};
@@ -59,6 +56,8 @@ public:
/// Get the data back from the FBO. This is *not* async friendly.
[[nodiscard]] std::vector<GLfloat> GetData() const;
public:
/// Copy constructor. Will always set "texture_created_by_us" to true and use our own texture to avoid memleaks.
RenderTarget(const RenderTarget& rhs);
/// 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);
/// Create a Render Target with a brand new texture. Want to render JGL elements onto a texture and display it as a sprite?

View File

@@ -201,9 +201,10 @@ public:
//Draw the Render Target that we just drew all that stuff onto.
auto image3_render_target = image2_render_target;
J2D::Begin();
J2D::DrawSprite(*j2d_render_target, {0, 0}, 0, {0.5, 0.5}, {1,1}, Colors::White);
J2D::DrawSprite(*image2_render_target, {300, 500}, 0, {0.5, 0.5}, {1,1}, Colors::White);
J2D::DrawSprite(*image3_render_target, {300, 500}, 0, {0.5, 0.5}, {1,1}, Colors::White);
J2D::End();
}

View File

@@ -21,7 +21,7 @@ namespace JGL {
CachedFont* CacheFont(const Font& font, u32 size) {
CachedFont* cachedFont;
FT_Set_Pixel_Sizes(font.face, 0, size);
jlog::Debug("Caching font data...");
Logger::Debug("Caching font data...");
GLuint texture_id;
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);

View File

@@ -323,3 +323,22 @@ void JGL::RenderTarget::Blit(const JGL::RenderTarget& source, JGL::RenderTarget*
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, current_draw_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
}
JGL::RenderTarget::RenderTarget(const JGL::RenderTarget& rhs) {
auto* this_render_target = new RenderTarget(rhs.size, rhs.clear_color, rhs.using_depth, rhs.msaa_sample_rate);
RenderTarget::Blit(rhs, this_render_target);
this->clear_color = this_render_target->clear_color;
this->size = this_render_target->size;
this->using_depth = this_render_target->using_depth;
this->texture_created_by_us = true;
this->texture = this_render_target->texture;
this->framebuffer_object = this_render_target->framebuffer_object;
this->depth_buffer = this_render_target->depth_buffer;
this->msaa_sample_rate = this_render_target->msaa_sample_rate;
this->msaa_framebuffer_object = this_render_target->msaa_framebuffer_object;
this->msaa_depth_buffer = this_render_target->msaa_depth_buffer;
this->msaa_render_buffer = this_render_target->msaa_render_buffer;
operator delete(this_render_target);
}