2021-05-09 18:52:39 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibGL/Tex/NameAllocator.h>
|
|
|
|
|
|
|
|
|
|
namespace GL {
|
|
|
|
|
|
|
|
|
|
void TextureNameAllocator::allocate(GLsizei count, GLuint* textures)
|
|
|
|
|
{
|
|
|
|
|
for (auto i = 0; i < count; ++i) {
|
|
|
|
|
if (!m_free_texture_names.is_empty()) {
|
|
|
|
|
textures[i] = m_free_texture_names.top();
|
|
|
|
|
m_free_texture_names.pop();
|
|
|
|
|
} else {
|
|
|
|
|
// We're out of free previously allocated names. Let's allocate a new contiguous amount from the
|
|
|
|
|
// last known texture name
|
|
|
|
|
textures[i] = m_last_texture_id++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-27 22:45:08 -03:00
|
|
|
void TextureNameAllocator::free(GLuint texture)
|
2021-05-09 18:52:39 -03:00
|
|
|
{
|
2021-11-27 22:45:08 -03:00
|
|
|
m_free_texture_names.push(texture);
|
2021-05-09 18:52:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|