1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 19:57:36 +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:
cflip 2022-11-13 15:04:55 -07:00 committed by Andreas Kling
parent 9a0bb8212a
commit 892006218a
7 changed files with 67 additions and 61 deletions

View file

@ -1,30 +0,0 @@
/*
* 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(GLuint texture)
{
m_free_texture_names.push(texture);
}
}

View file

@ -1,26 +0,0 @@
/*
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Stack.h>
#include <LibGL/GL/gl.h>
namespace GL {
class TextureNameAllocator {
public:
TextureNameAllocator() = default;
void allocate(GLsizei count, GLuint* textures);
void free(GLuint texture);
private:
Stack<GLuint, 512> m_free_texture_names;
GLuint m_last_texture_id { 1 };
};
}