mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-26 18:21:04 +00:00
OpenGL: encapsulate VBOs into a class
internal only for now but this will be handy
This commit is contained in:
parent
b087e2554f
commit
bb550158fc
6 changed files with 147 additions and 58 deletions
57
irr/src/OpenGL/VBO.h
Normal file
57
irr/src/OpenGL/VBO.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright (C) 2024 sfan5
|
||||
// This file is part of the "Irrlicht Engine".
|
||||
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include <cstddef>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace video
|
||||
{
|
||||
|
||||
class OpenGLVBO
|
||||
{
|
||||
public:
|
||||
/// @note does not create on GL side
|
||||
OpenGLVBO() = default;
|
||||
/// @note does not free on GL side
|
||||
~OpenGLVBO() = default;
|
||||
|
||||
/// @return "name" (ID) of this buffer in GL
|
||||
GLuint getName() const { return m_name; }
|
||||
/// @return does this refer to an existing GL buffer?
|
||||
bool exists() const { return m_name != 0; }
|
||||
|
||||
/// @return size of this buffer in bytes
|
||||
size_t getSize() const { return m_size; }
|
||||
|
||||
/**
|
||||
* Upload buffer data to GL.
|
||||
*
|
||||
* Changing the size of the buffer is only possible when `offset == 0`.
|
||||
* @param data data pointer
|
||||
* @param size number of bytes
|
||||
* @param offset offset to upload at
|
||||
* @param usage usage pattern passed to GL (only if buffer is new)
|
||||
* @param mustShrink force re-create of buffer if it became smaller
|
||||
* @note modifies GL_ARRAY_BUFFER binding
|
||||
*/
|
||||
void upload(const void *data, size_t size, size_t offset,
|
||||
GLenum usage, bool mustShrink = false);
|
||||
|
||||
/**
|
||||
* Free buffer in GL.
|
||||
* @note modifies GL_ARRAY_BUFFER binding
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
GLuint m_name = 0;
|
||||
size_t m_size = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue