mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 07:05:40 +12:00
Merge pull request #515 from wheremyfoodat/wheremyfoodat-patch-2
Add UBO support to opengl.hpp
This commit is contained in:
commit
79bfb67156
1 changed files with 68 additions and 26 deletions
42
third_party/opengl/opengl.hpp
vendored
42
third_party/opengl/opengl.hpp
vendored
|
@ -485,6 +485,48 @@ namespace OpenGL {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct UniformBuffer {
|
||||||
|
GLuint m_handle = 0;
|
||||||
|
|
||||||
|
void create() {
|
||||||
|
if (m_handle == 0) {
|
||||||
|
glGenBuffers(1, &m_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void createFixedSize(GLsizei size, GLenum usage = GL_DYNAMIC_DRAW) {
|
||||||
|
create();
|
||||||
|
bind();
|
||||||
|
glBufferData(GL_UNIFORM_BUFFER, size, nullptr, usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
UniformBuffer(bool shouldCreate = false) {
|
||||||
|
if (shouldCreate) {
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef OPENGL_DESTRUCTORS
|
||||||
|
~UniformBuffer() { free(); }
|
||||||
|
#endif
|
||||||
|
GLuint handle() const { return m_handle; }
|
||||||
|
bool exists() const { return m_handle != 0; }
|
||||||
|
void bind() const { glBindBuffer(GL_UNIFORM_BUFFER, m_handle); }
|
||||||
|
void free() { glDeleteBuffers(1, &m_handle); }
|
||||||
|
|
||||||
|
// Reallocates the buffer on every call. Prefer the sub version if possible.
|
||||||
|
template <typename UniformType>
|
||||||
|
void buffer(const UniformType& uniformData, GLenum usage = GL_DYNAMIC_DRAW) {
|
||||||
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(uniformData), &uniformData, usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only use if you used createFixedSize
|
||||||
|
template <typename UniformType>
|
||||||
|
void bufferSub(const UniformType& uniformData, int vertCount, GLintptr offset = 0) {
|
||||||
|
glBufferSubData(GL_UNIFORM_BUFFER, offset, sizeof(uniformData), &uniformData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
enum DepthFunc {
|
enum DepthFunc {
|
||||||
Never = GL_NEVER, // Depth test never passes
|
Never = GL_NEVER, // Depth test never passes
|
||||||
Always = GL_ALWAYS, // Depth test always passes
|
Always = GL_ALWAYS, // Depth test always passes
|
||||||
|
|
Loading…
Add table
Reference in a new issue