NameAllocator.cpp 849 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGL/Tex/NameAllocator.h>
  7. namespace GL {
  8. void TextureNameAllocator::allocate(GLsizei count, GLuint* textures)
  9. {
  10. for (auto i = 0; i < count; ++i) {
  11. if (!m_free_texture_names.is_empty()) {
  12. textures[i] = m_free_texture_names.top();
  13. m_free_texture_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 texture name
  17. textures[i] = m_last_texture_id++;
  18. }
  19. }
  20. }
  21. void TextureNameAllocator::free(GLsizei count, const GLuint* textures)
  22. {
  23. size_t tex_array_index = 0;
  24. while (count-- > 0)
  25. m_free_texture_names.push(textures[tex_array_index++]);
  26. }
  27. }