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

137 lines
3.8 KiB

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