mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-30 19:22:14 +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
51
irr/src/OpenGL/VBO.cpp
Normal file
51
irr/src/OpenGL/VBO.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
// Copyright (C) 2024 sfan5
|
||||
// This file is part of the "Irrlicht Engine".
|
||||
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||
|
||||
#include "VBO.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <mt_opengl.h>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace video
|
||||
{
|
||||
|
||||
void OpenGLVBO::upload(const void *data, size_t size, size_t offset,
|
||||
GLenum usage, bool mustShrink)
|
||||
{
|
||||
bool newBuffer = false;
|
||||
if (!m_name) {
|
||||
GL.GenBuffers(1, &m_name);
|
||||
if (!m_name)
|
||||
return;
|
||||
newBuffer = true;
|
||||
} else if (size > m_size || mustShrink) {
|
||||
// note: mustShrink && offset > 0 is forbidden
|
||||
newBuffer = size != m_size;
|
||||
}
|
||||
|
||||
GL.BindBuffer(GL_ARRAY_BUFFER, m_name);
|
||||
|
||||
if (newBuffer) {
|
||||
assert(offset == 0);
|
||||
GL.BufferData(GL_ARRAY_BUFFER, size, data, usage);
|
||||
m_size = size;
|
||||
} else {
|
||||
GL.BufferSubData(GL_ARRAY_BUFFER, offset, size, data);
|
||||
}
|
||||
|
||||
GL.BindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void OpenGLVBO::destroy()
|
||||
{
|
||||
if (m_name)
|
||||
GL.DeleteBuffers(1, &m_name);
|
||||
m_name = 0;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue