UpdateData in VRamList & QOL changes.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m45s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m45s
This commit is contained in:
@@ -34,13 +34,13 @@ namespace JGL {
|
||||
TextureWrappingMode texture_wrapping_mode;
|
||||
void load(SoftwareTexture* software_texture, const Vector2& size, const TextureFormat& format, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode);
|
||||
public:
|
||||
///Load a texture from a file,
|
||||
Texture() = default;
|
||||
/// 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);
|
||||
/* Initialize a texture filled with trash data
|
||||
this is primarily for the RenderTarget */
|
||||
explicit Texture(const Vector2& size);
|
||||
Texture() = default;
|
||||
public:
|
||||
[[nodiscard]] GLuint GetGLTextureHandle() const;
|
||||
[[nodiscard]] Vector2 GetDimensions() const;
|
||||
|
@@ -1,72 +1,64 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <glad/glad.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector2i.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 {
|
||||
class VRamList;
|
||||
}
|
||||
|
||||
/// A wrapper for VBO, Storing texture coordinates or vertices or indices in vram.
|
||||
/// A wrapped for "Vertex Buffer Object" In OpenGL, Store things in VRam.
|
||||
class JGL::VRamList {
|
||||
private:
|
||||
GLuint list_handle = 0;
|
||||
long size = 0;
|
||||
long num_elements = 0;
|
||||
bool element_array_buffer = false;
|
||||
|
||||
void load(const GLfloat* data, const long& size);
|
||||
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);
|
||||
public:
|
||||
VRamList() = default;
|
||||
VRamList(const GLuint* data, const long& size);
|
||||
VRamList(const GLfloat* data, const long& size);
|
||||
VRamList(Vector2* data, const long& size);
|
||||
VRamList(Vector3* data, const long& size);
|
||||
VRamList(Vector4* data, const long& size);
|
||||
VRamList(const GLuint* data, const long& length);
|
||||
VRamList(const GLfloat* data, const long& length);
|
||||
VRamList(Vector2* data, const long& length);
|
||||
VRamList(Vector3* data, const long& length);
|
||||
VRamList(Vector4* data, const long& length);
|
||||
public:
|
||||
[[nodiscard]] GLuint GetHandle() const;
|
||||
/// Returns the number of GLfloat or GLuint in the list.
|
||||
[[nodiscard]] long GetSize() const;
|
||||
/// Returns the number of elements in the list.
|
||||
[[nodiscard]] long GetLength() const;
|
||||
/// Returns the size of the data in bytes.
|
||||
[[nodiscard]] long GetDataSize() const;
|
||||
[[nodiscard]] bool IsIntegerArray() const;
|
||||
[[nodiscard]] size_t GetSize() const;
|
||||
/** Get VBO data back from the GPU. This is *bad* because the CPU is going to wait
|
||||
* for the transfer to finish. Has limited use other than testing. */
|
||||
[[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);
|
||||
void SetData(const Vector2* data, const long& length);
|
||||
void SetData(const Vector3* data, const long& length);
|
||||
void SetData(const Vector4* data, const long& length);
|
||||
|
||||
/// Update the data of an existing VBO. Data would be the same type as the list already is.
|
||||
/// "size" refers to the number of elements in data. Not the number of bytes.
|
||||
void SetData(void* data, const long& size);
|
||||
void SetData(const GLuint* data, const long& length);
|
||||
void SetData(const Vector2i* data, const long& length);
|
||||
|
||||
/* Get VBO data back from the GPU. This is *very* slow because the CPU is going to wait
|
||||
for the transfer to finish. I don't know why you'd want to do this outside of testing reasons.*/
|
||||
template <typename T>
|
||||
[[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);
|
||||
else if constexpr (std::is_same<T, GLuint>::value)
|
||||
buffer_type = GL_ELEMENT_ARRAY_BUFFER,
|
||||
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, ¤t_buffer);
|
||||
else
|
||||
jlog::Fatal("Typename T must be either GLfloat or GLuint.");
|
||||
/** Update only a portion of the data in a VBO. Must be same type.
|
||||
* "length" refers to the number of elements in data. Not the number of bytes.
|
||||
* "offset" refers the number of Typename T into the buffer the data you want to change is.
|
||||
* For ex, offset 0 and length of 1 overwrites the first value. Offset 1 the second etc */
|
||||
void UpdateData(const GLfloat* data, const long& offset, const long& length);
|
||||
void UpdateData(const Vector2* data, const long& offset, const long& length);
|
||||
void UpdateData(const Vector3* data, const long& offset, const long& length);
|
||||
void UpdateData(const Vector4* data, const long& offset, const long& length);
|
||||
|
||||
if ((element_array_buffer && buffer_type == GL_ARRAY_BUFFER) || (!element_array_buffer && buffer_type == GL_ELEMENT_ARRAY_BUFFER))
|
||||
jlog::Fatal("Returning the contents of a VRamList using the incorrect Typename T?");
|
||||
|
||||
glBindBuffer(buffer_type, list_handle);
|
||||
std::vector<T> data(size);
|
||||
memcpy(data.data(), glMapBuffer(buffer_type, GL_READ_ONLY), size * sizeof(T));
|
||||
glUnmapBuffer(buffer_type);
|
||||
glBindBuffer(buffer_type, current_buffer);
|
||||
|
||||
return data;
|
||||
}
|
||||
void UpdateData(const GLuint* data, const long& offset, const long& length);
|
||||
void UpdateData(const Vector2i* data, const long& offset, const long& length);
|
||||
};
|
Reference in New Issue
Block a user