NameAllocator.cpp 791 B

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