💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.6 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_GL_VERTEX_ARRAY_HPP
  20. #define ANTKEEPER_GL_VERTEX_ARRAY_HPP
  21. #include <cstdint>
  22. #include <unordered_map>
  23. #include "gl/vertex-attribute.hpp"
  24. namespace gl {
  25. class rasterizer;
  26. class vertex_buffer;
  27. /**
  28. * Vertex array object (VAO), which describes how vertex attributes are stored in vertex buffer objects (VBOs).
  29. *
  30. * @see gl::vertex_attribute
  31. * @see gl::vertex_buffer
  32. */
  33. class vertex_array
  34. {
  35. public:
  36. /// Vertex attribute binding location type.
  37. typedef std::uint_fast32_t attribute_location_type;
  38. /// Maps vertex attribute to binding locations.
  39. typedef std::unordered_map<attribute_location_type, vertex_attribute> attribute_map_type;
  40. /// Constructs a vertex array.
  41. vertex_array();
  42. /// Destructs a vertex array.
  43. ~vertex_array();
  44. vertex_array(const vertex_array&) = delete;
  45. vertex_array& operator=(const vertex_array&) = delete;
  46. /**
  47. * Binds a vertex attribute to the vertex array.
  48. *
  49. * @param location Location to which the vertex attribute should be bound.
  50. * @param attribute Vertex attribute to bind.
  51. *
  52. * @except std::invalid_argument Cannot bind vertex attribute that has a null vertex buffer.
  53. * @except std::invalid_argument Cannot bind vertex attribute that has an unsupported number of components.
  54. */
  55. void bind(attribute_location_type location, const vertex_attribute& attribute);
  56. /**
  57. * Unbinds a vertex attribute from the vertex array.
  58. *
  59. * @param location Location of the vertex attribute to unbind.
  60. *
  61. * @except std::invalid_argument Non-existent vertex attribute cannot be unbound.
  62. */
  63. void unbind(attribute_location_type location);
  64. /// Returns a const reference to the map of vertex attributes bound to this vertex array.
  65. const attribute_map_type& get_attributes() const;
  66. private:
  67. friend class rasterizer;
  68. attribute_map_type attributes;
  69. std::uint_fast32_t gl_array_id;
  70. };
  71. } // namespace gl
  72. #endif // ANTKEEPER_GL_VERTEX_ARRAY_HPP