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
14#include <glad/glad.h> // OpenGL driver
15
16#include <expected>
17#include <string>
18
19#define check_error() gl::_check_error(__FILE__, __LINE__)
20
21namespace brenta
22{
23
29class gl : public subsystem
30{
31public:
32
33 class config;
34 class builder;
35
36 static const std::string subsystem_name;
37 static const gl::config default_config;
38 static gl::config init_config;
39
40 // Subsystem interface
41 std::expected<void, subsystem::error> initialize() override;
42 std::expected<void, subsystem::error> terminate() override;
43 std::string name() override;
44 bool is_initialized() override;
45
46 // Constructors / destructors
47 gl() = default;
48 ~gl() = default;
49
50 // Member functions
51
52 static gl &instance();
53
58 static void set_poligon_mode(GLboolean enable);
59
70 static void set_viewport(int x, int y, int width, int height);
71
82 static void set_color(float r, float g, float b, float a);
83
93 static void draw_arrays(GLenum mode, int first, int count);
94
106 static void draw_elements(GLenum mode, int count, GLenum type,
107 const void *indices);
108
114 static void clear();
115
116 static void bind_vertex_array(unsigned int n);
117
125 static GLenum _check_error(const char *file, int line);
126
127private:
128
129 static bool initialized;
130
131};
132
134{
135public:
136 bool enable_blending;
137 bool enable_cull_face;
138 bool enable_multisample;
139 bool enable_depth_test;
140};
141
143{
144private:
145
146 gl::config conf = gl::default_config;
147
148public:
149
150 builder() = default;
151 ~builder() = default;
152
153 builder &blending();
154 builder &cull_face();
155 builder &multisample();
156 builder &depth_test();
157
158 subsystem &build() override;
159
160};
161
162} // namespace brenta
OpenGL helper functions.
Definition gl.hpp:30
static void set_color(float r, float g, float b, float a)
Set Clear Color.
Definition gl.cpp:155
static GLenum _check_error(const char *file, int line)
Check OpenGL error.
Definition gl.cpp:180
static void clear()
Clear.
Definition gl.cpp:175
std::string name() override
Returns the name of the sybsystem.
Definition gl.cpp:116
static void set_poligon_mode(GLboolean enable)
Set Poligon Mode.
Definition gl.cpp:130
static void draw_elements(GLenum mode, int count, GLenum type, const void *indices)
Draw Elements.
Definition gl.cpp:165
bool is_initialized() override
Returns true if the subsystem is initialized.
Definition gl.cpp:121
static void set_viewport(int x, int y, int width, int height)
Set Viewport.
Definition gl.cpp:150
static void draw_arrays(GLenum mode, int first, int count)
Draw Arrays.
Definition gl.cpp:160
Builder interface.
Definition subsystem.hpp:49
Subsystem interface.
Definition subsystem.hpp:22