💿🐜 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.

141 lines
3.8 KiB

  1. /*
  2. * Copyright (C) 2023 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_RASTERIZER_HPP
  20. #define ANTKEEPER_GL_RASTERIZER_HPP
  21. #include <cstddef>
  22. namespace gl {
  23. class framebuffer;
  24. class vertex_array;
  25. class shader_program;
  26. enum class drawing_mode;
  27. enum class element_array_type;
  28. /**
  29. * Interface to the OpenGL state and drawing functions.
  30. */
  31. class rasterizer
  32. {
  33. public:
  34. /**
  35. * Creates a rasterizer. Warning: This must be called after an OpenGL context has been created.
  36. */
  37. rasterizer();
  38. /// Destroys a rasterizer.
  39. ~rasterizer();
  40. /**
  41. * This should be called when the window associated with the OpenGL context is resized, and will effectively changed the reported dimensions of the default framebuffer.
  42. */
  43. void context_resized(int width, int height);
  44. /**
  45. * Sets the active framebuffer.
  46. *
  47. * @param framebuffer Framebuffer to use.
  48. */
  49. void use_framebuffer(const framebuffer& framebuffer);
  50. /**
  51. * Sets the color to be used when the color buffer of a framebuffer is cleared.
  52. *
  53. * @param r Red color component.
  54. * @param g Green color component.
  55. * @param b Blue color component.
  56. * @param a Alpha color component.
  57. */
  58. void set_clear_color(float r, float g, float b, float a);
  59. /**
  60. * Sets the depth value to be used when the depth buffer of a framebuffer is cleared.
  61. *
  62. * @param depth Depth value.
  63. */
  64. void set_clear_depth(float depth);
  65. /**
  66. * Sets the stencil value to be used when the stencil buffer of a framebuffer is cleared.
  67. *
  68. * @param s Stencil value.
  69. */
  70. void set_clear_stencil(int s);
  71. /**
  72. * Clears the buffers attached to a framebuffer.
  73. *
  74. * @param color Specifies whether the color buffer should be cleared.
  75. * @param depth Specifies whether the depth buffer should be cleared.
  76. * @param stencil Specifies whether the stencil buffer should be cleared.
  77. */
  78. void clear_framebuffer(bool color, bool depth, bool stencil);
  79. /**
  80. * Sets the active viewport.
  81. *
  82. * @param x X-coordinate of the viewport.
  83. * @param y Y-coordinate of the viewport.
  84. * @param width Width of the viewport.
  85. * @param height Height of the viewport.
  86. */
  87. void set_viewport(int x, int y, int width, int height);
  88. /**
  89. * Binds a shader program.
  90. *
  91. * @param program Shader program to bind.
  92. */
  93. void use_program(const shader_program& program);
  94. /**
  95. *
  96. */
  97. void draw_arrays(const vertex_array& vao, drawing_mode mode, std::size_t offset, std::size_t count);
  98. void draw_arrays_instanced(const vertex_array& vao, drawing_mode mode, std::size_t offset, std::size_t count, std::size_t instance_count);
  99. /**
  100. *
  101. */
  102. void draw_elements(const vertex_array& vao, drawing_mode mode, std::size_t offset, std::size_t count, element_array_type type);
  103. /**
  104. * Returns the default framebuffer associated with the OpenGL context of a window.
  105. */
  106. const framebuffer& get_default_framebuffer() const;
  107. private:
  108. framebuffer* default_framebuffer;
  109. const framebuffer* bound_framebuffer;
  110. const vertex_array* bound_vao;
  111. const shader_program* bound_shader_program;
  112. };
  113. inline const framebuffer& rasterizer::get_default_framebuffer() const
  114. {
  115. return *default_framebuffer;
  116. }
  117. } // namespace gl
  118. #endif // ANTKEEPER_GL_RASTERIZER_HPP