Brenta Engine 1.2
Loading...
Searching...
No Matches
gl.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6//
7// Helper functions to interact with OpenGL.
8//
9
10#pragma once
11
12#include <brenta/subsystem.hpp>
13#include <brenta/color.hpp>
14
15#include <glad/glad.h> // OpenGL driver
16
17#include <expected>
18#include <string>
19
20#define check_error() Gl::_check_error(__FILE__, __LINE__)
21
22namespace brenta
23{
24
25//
26// OpenGL helper functions
27// -----------------------
28//
29// This class contains static helper functions to interact with OpenGL.
30//
31class Gl : public Subsystem
32{
33public:
34
35 class Config;
36 class Builder;
37
38 static const GLboolean True;
39 static const GLboolean False;
40
41 enum Type {
42 Byte = GL_BYTE,
43 UnsignedByte = GL_UNSIGNED_BYTE,
44 Short = GL_SHORT,
45 UnsignedShort = GL_UNSIGNED_SHORT,
46 Int = GL_INT,
47 UnsignedInt = GL_UNSIGNED_INT,
48 Float = GL_FLOAT,
49 };
50
51 // Subsystem interface
52 static const std::string subsystem_name;
53 std::expected<void, Subsystem::Error> initialize() override;
54 std::expected<void, Subsystem::Error> terminate() override;
55 std::string name() override;
56 bool is_initialized() override;
57
58 // Member functions
59
60 static Gl &instance();
61
62 static int get_num_channels(GLenum color_format);
63 static int get_bytes_per_channel(GLenum type);
64 static void set_poligon_mode(GLboolean enable);
65 static void set_viewport(int x, int y, int width, int height);
66 static void set_color(const Color &color);
67 static void draw_arrays(GLenum mode, int first, int count);
68 static void draw_elements(GLenum mode, int count, GLenum type,
69 const void *indices);
70 static void clear();
71
72 static GLenum _check_error(const char *file, int line);
73
74private:
75
76 static bool initialized;
77 static Gl::Config init_config;
78
79 // Private constructors / destructors for singleton
80 Gl() = default;
81 ~Gl() = default;
82
83};
84
86{
87public:
88 bool enable_blending = false;
89 bool enable_backface_culling = false;
90 bool enable_multisample = false;
91 bool enable_depth_test = false;
92};
93
95{
96private:
97
98 Gl::Config conf = {};
99
100public:
101
102 Builder() = default;
103 ~Builder() = default;
104
105 Builder &blending();
106 Builder &backface_culling();
107 Builder &multisample();
108 Builder &depth_test();
109
110 Subsystem &build() override;
111
112};
113
114} // namespace brenta