matf-rg-engine 1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
Loading...
Searching...
No Matches
OpenGL.hpp
Go to the documentation of this file.
1
6#ifndef OPENGL_HPP
7#define OPENGL_HPP
8#include <cstdint>
9#include <filesystem>
11
12namespace engine::resources {
13 class Skybox;
14}
15
27#define CHECKED_GL_CALL(func, ...) engine::graphics::OpenGL::call(std::source_location::current(), func, __VA_ARGS__)
28
29namespace engine::graphics {
36 class OpenGL {
37 public:
38 using ShaderProgramId = uint32_t;
39
49 template<typename TResult, typename... TOpenGLArgs, typename... Args>
50 static TResult call(std::source_location location, TResult (*glfun)(TOpenGLArgs...), Args... args) {
51 // @formatter:off
52 if constexpr (!std::is_same_v<TResult, void>) {
53 auto result = glfun(std::forward<Args>(args)...);
54 #ifndef NDEBUG
55 assert_no_error(location);
56 #endif
57 return result;
58 } else {
59 glfun(std::forward<Args>(args)...);
60 #ifndef NDEBUG
61 assert_no_error(location);
62 #endif
63 }
64 // @formatter:on
65 }
66
72
80 static uint32_t generate_texture(const std::filesystem::path &path, bool flip_uvs);
81
87 static int32_t texture_format(int32_t number_of_channels);
88
93 static uint32_t init_skybox_cube();
94
99 static bool shader_compiled_successfully(uint32_t shader_id);
100
107 static uint32_t compile_shader(const std::string &shader_source,
108 resources::ShaderType shader_type);
109
119 static uint32_t load_skybox_textures(const std::filesystem::path &path, bool flip_uvs = false);
120
124 static void enable_depth_testing();
125
129 static void disable_depth_testing();
130
134 static void clear_buffers();
135
141 static std::string get_compilation_error_message(uint32_t shader_id);
142
143 private
144 :
149 static void assert_no_error(std::source_location location);
150 };
151}
152#endif //OPENGL_HPP
Defines the Shader class that serves as an abstraction over OpenGL shaders.
This class serves as the OpenGL interface for your app, since the engine doesn't directly link OpenGL...
Definition OpenGL.hpp:36
static bool shader_compiled_successfully(uint32_t shader_id)
Check if the shader with the shader_id compiled successfully.
Definition OpenGL.cpp:80
static int32_t shader_type_to_opengl_type(resources::ShaderType type)
Converts resources::ShaderType to the OpenGL shader type enum.
Definition OpenGL.cpp:13
static void enable_depth_testing()
Enables depth testing.
Definition OpenGL.cpp:165
static TResult call(std::source_location location, TResult(*glfun)(TOpenGLArgs...), Args... args)
Performs a checked OpenGL call. If the OpenGL call fails, it throws util::OpenGLError.
Definition OpenGL.hpp:50
static int32_t texture_format(int32_t number_of_channels)
Get texture format for a number_of_channels.
Definition OpenGL.cpp:50
static void clear_buffers()
Clears GL_DEPTH_BUFFER_BIT, GL_COLOR_BUFFER_BIT, and GL_STENCIL_BUFFER_BIT.
Definition OpenGL.cpp:173
static void disable_depth_testing()
Disables depth testing.
Definition OpenGL.cpp:169
static uint32_t generate_texture(const std::filesystem::path &path, bool flip_uvs)
Loads the texture from path into the OpenGL context.
Definition OpenGL.cpp:22
static void assert_no_error(std::source_location location)
Throws util::OpenGLError if an OpenGL error occurred. Used internally.
Definition OpenGL.cpp:120
static std::string get_compilation_error_message(uint32_t shader_id)
Retrieve the shader compilation error log message.
Definition OpenGL.cpp:95
uint32_t ShaderProgramId
Definition OpenGL.hpp:38
static uint32_t init_skybox_cube()
Initializes the cube Vertex Array Object used for skybox drawing. Caches the vao result.
Definition OpenGL.cpp:59
static uint32_t compile_shader(const std::string &shader_source, resources::ShaderType shader_type)
Compiles the shader from source.
Definition OpenGL.cpp:86
static uint32_t load_skybox_textures(const std::filesystem::path &path, bool flip_uvs=false)
Loads the skybox textures from the path. Make sure that images are named: front.jpg,...
Definition OpenGL.cpp:130
Definition Camera.hpp:12
Definition GraphicsController.hpp:14
ShaderType
The type of the shader.
Definition Shader.hpp:19