mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:37:47 +00:00
LibGL: Refactor TextureNameAllocator to a more general NameAllocator
This functionality can also be used for other types of objects.
This commit is contained in:
parent
9a0bb8212a
commit
892006218a
7 changed files with 67 additions and 61 deletions
35
Userland/Libraries/LibGL/NameAllocator.cpp
Normal file
35
Userland/Libraries/LibGL/NameAllocator.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibGL/NameAllocator.h>
|
||||
|
||||
namespace GL {
|
||||
|
||||
void NameAllocator::allocate(GLsizei count, GLuint* names)
|
||||
{
|
||||
for (auto i = 0; i < count; ++i) {
|
||||
if (!m_free_names.is_empty()) {
|
||||
names[i] = m_free_names.top();
|
||||
m_free_names.pop();
|
||||
} else {
|
||||
// We're out of free previously allocated names. Let's allocate a new contiguous amount from the
|
||||
// last known texture name
|
||||
names[i] = m_last_id++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NameAllocator::free(GLuint name)
|
||||
{
|
||||
m_free_names.push(name);
|
||||
}
|
||||
|
||||
bool NameAllocator::has_allocated_name(GLuint name) const
|
||||
{
|
||||
return name < m_last_id && !m_free_names.contains_slow(name);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue