Serenity Operating System
1/*
2 * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <LibGL/NameAllocator.h>
8
9namespace GL {
10
11void NameAllocator::allocate(GLsizei count, GLuint* names)
12{
13 for (auto i = 0; i < count; ++i) {
14 if (!m_free_names.is_empty()) {
15 names[i] = m_free_names.top();
16 m_free_names.pop();
17 } else {
18 // We're out of free previously allocated names. Let's allocate a new contiguous amount from the
19 // last known id
20 names[i] = m_last_id++;
21 }
22 }
23}
24
25void NameAllocator::free(GLuint name)
26{
27 m_free_names.push(name);
28}
29
30bool NameAllocator::has_allocated_name(GLuint name) const
31{
32 return name < m_last_id && !m_free_names.contains_slow(name);
33}
34
35}