RenderTarget GetData
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 2m11s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 2m11s
Async GetData is todo
This commit is contained in:
@@ -27,6 +27,8 @@ public:
|
||||
[[nodiscard]] GLuint GetGLFramebufferObjectHandle() const;
|
||||
[[nodiscard]] GLuint GetGLDepthBufferHandle() const;
|
||||
[[nodiscard]] Color4 GetClearColor() const;
|
||||
/// 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);
|
||||
|
@@ -42,10 +42,9 @@ public:
|
||||
/// Get list data back from the GPU. This is *very* slow.
|
||||
/// It's not recommended you use this in your normal rendering routines.
|
||||
template <typename T>
|
||||
[[nodiscard]] std::vector<T> GetListData() const {
|
||||
[[nodiscard]] std::vector<T> GetData() const {
|
||||
GLenum buffer_type;
|
||||
GLint current_buffer = 0;
|
||||
|
||||
if constexpr (std::is_same<T, GLfloat>::value)
|
||||
buffer_type = GL_ARRAY_BUFFER,
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, ¤t_buffer);
|
||||
|
@@ -91,3 +91,14 @@ JGL::RenderTarget::RenderTarget(const Vector2& size, const Color4& clear_color,
|
||||
this->clear_color = clear_color;
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
std::vector<GLfloat> JGL::RenderTarget::GetData() const {
|
||||
std::vector<GLfloat> data(GetDimensions().x * GetDimensions().y * 4);
|
||||
GLuint current_fbo = GetActiveGLFramebufferHandle();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_object);
|
||||
glReadPixels(0, 0, GetDimensions().x, GetDimensions().y, GL_RGBA, GL_FLOAT, data.data());
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
|
||||
return data;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user