Get VBO data back from the GPU.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 7m17s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 7m17s
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector3.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector4.hpp>
|
||||
#include <JGL/logger/logger.h>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace JGL {
|
||||
@@ -11,10 +14,12 @@ namespace JGL {
|
||||
}
|
||||
|
||||
/// A wrapper for VBO, Storing texture coordinates or vertices or indices in vram.
|
||||
/// For J2D, We can't really store the vertices into vram. But we can store the texture coordinates.
|
||||
class JGL::VRamList {
|
||||
private:
|
||||
GLuint list_handle = 0;
|
||||
long size = 0;
|
||||
bool element_array_buffer = false;
|
||||
|
||||
void load(const GLfloat* data, const long& size);
|
||||
void load(const GLuint* data, const long& size);
|
||||
public:
|
||||
@@ -26,5 +31,38 @@ public:
|
||||
VRamList(const GLuint* data, const long& size);
|
||||
public:
|
||||
[[nodiscard]] GLuint GetHandle() const;
|
||||
/// Returns the number of GLfloat or GLuint in the list.
|
||||
[[nodiscard]] long GetSize() const;
|
||||
/// Returns the size of the data in bytes.
|
||||
[[nodiscard]] long GetDataSize() const;
|
||||
[[nodiscard]] bool IsIntegerArray() const;
|
||||
[[nodiscard]] bool IsFloatArray() const;
|
||||
void Erase();
|
||||
|
||||
/// 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 {
|
||||
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);
|
||||
else if constexpr (std::is_same<T, GLuint>::value)
|
||||
buffer_type = GL_ELEMENT_ARRAY_BUFFER,
|
||||
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, ¤t_buffer);
|
||||
else {
|
||||
Logger::Fatal("Typename T must be either GLfloat or GLuint.");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
glBindBuffer(buffer_type, list_handle);
|
||||
std::vector<T> data(size);
|
||||
memcpy(data.data(), (T*) glMapBuffer(buffer_type, GL_READ_ONLY), size * sizeof(T));
|
||||
glUnmapBuffer(buffer_type);
|
||||
glBindBuffer(buffer_type, current_buffer);
|
||||
|
||||
return data;
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user