mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37: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:
parent
8a69e6714e
commit
21dff6d40b
8 changed files with 118 additions and 0 deletions
33
Userland/Libraries/LibGL/Tex/NameAllocator.cpp
Normal file
33
Userland/Libraries/LibGL/Tex/NameAllocator.cpp
Normal 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++]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue