GL.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Vector.h>
  8. #ifdef AK_OS_MACOS
  9. # define GL_SILENCE_DEPRECATION
  10. # include <OpenGL/OpenGL.h>
  11. # include <OpenGL/gl3.h>
  12. #else
  13. # include <GL/gl.h>
  14. #endif
  15. #include <LibGfx/Forward.h>
  16. #include <LibGfx/Rect.h>
  17. namespace AccelGfx::GL {
  18. enum class ShaderType {
  19. Vertex,
  20. Fragment,
  21. };
  22. struct Shader {
  23. GLuint id;
  24. };
  25. struct Program {
  26. GLuint id;
  27. };
  28. struct VertexAttribute {
  29. GLint id;
  30. };
  31. struct Uniform {
  32. GLint id;
  33. };
  34. struct Texture {
  35. GLuint id;
  36. Optional<Gfx::IntSize> size;
  37. };
  38. struct Buffer {
  39. GLuint id;
  40. };
  41. struct VertexArray {
  42. GLuint id;
  43. };
  44. struct Framebuffer {
  45. GLuint fbo_id;
  46. GL::Texture texture;
  47. };
  48. void set_viewport(Gfx::IntRect);
  49. enum class BlendFactor {
  50. Zero,
  51. One,
  52. OneMinusSrcAlpha,
  53. SrcAlpha,
  54. };
  55. void enable_blending(BlendFactor source, BlendFactor destination, BlendFactor source_alpha, BlendFactor destination_alpha);
  56. void read_pixels(Gfx::IntRect, Gfx::Bitmap&);
  57. Shader create_shader(ShaderType type, char const* source);
  58. Program create_program(Shader const& vertex_shader, Shader const& fragment_shader);
  59. void use_program(Program const&);
  60. VertexAttribute get_attribute_location(Program const&, char const* name);
  61. Uniform get_uniform_location(Program const&, char const* name);
  62. void delete_program(Program const&);
  63. Texture create_texture();
  64. void bind_texture(Texture const&);
  65. void upload_texture_data(Texture& texture, Gfx::Bitmap const& bitmap);
  66. void delete_texture(Texture const&);
  67. void set_uniform(Uniform const& uniform, int);
  68. void set_uniform(Uniform const& uniform, float, float);
  69. void set_uniform(Uniform const& uniform, float, float, float, float);
  70. void set_vertex_attribute(VertexAttribute const& attribute, u32 offset, int number_of_components);
  71. enum class ScalingMode {
  72. Nearest,
  73. Linear,
  74. };
  75. void set_texture_scale_mode(ScalingMode);
  76. void clear_color(Gfx::Color const&);
  77. enum class DrawPrimitive {
  78. Triangles,
  79. TriangleFan,
  80. };
  81. void draw_arrays(DrawPrimitive, size_t count);
  82. Buffer create_buffer();
  83. void bind_buffer(Buffer const&);
  84. void upload_to_buffer(Buffer const&, Span<float> values);
  85. void delete_buffer(Buffer const&);
  86. VertexArray create_vertex_array();
  87. void bind_vertex_array(VertexArray const&);
  88. void delete_vertex_array(VertexArray const&);
  89. Framebuffer create_framebuffer(Gfx::IntSize);
  90. void bind_framebuffer(Framebuffer const& framebuffer);
  91. void delete_framebuffer(Framebuffer const& framebuffer);
  92. void enable_scissor_test(Gfx::IntRect);
  93. void disable_scissor_test();
  94. }