1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:47:35 +00:00

LibGL: Add Texture Name Allocation

Texture names can now be allocated via
`glGenTextures` and deallocated via `glDeleteTextures`.
This commit is contained in:
Jesse Buhagiar 2021-05-10 07:52:39 +10:00 committed by Ali Mohammad Pur
parent 8a69e6714e
commit 21dff6d40b
8 changed files with 118 additions and 0 deletions

View file

@ -0,0 +1,33 @@
/*
* 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++;
}
}
}
void TextureNameAllocator::free(GLsizei count, const GLuint* textures)
{
size_t tex_array_index = 0;
while (count-- > 0)
m_free_texture_names.push(textures[tex_array_index++]);
}
}