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
Public Types | Static Public Member Functions | Static Private Member Functions | List of all members
engine::graphics::OpenGL Class Reference

This class serves as the OpenGL interface for your app, since the engine doesn't directly link OpenGL to the app executable. More...

#include <OpenGL.hpp>

Public Types

using ShaderProgramId = uint32_t
 

Static Public Member Functions

template<typename TResult , typename... TOpenGLArgs, typename... Args>
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.
 
static int32_t shader_type_to_opengl_type (resources::ShaderType type)
 Converts resources::ShaderType to the OpenGL shader type enum.
 
static uint32_t generate_texture (const std::filesystem::path &path, bool flip_uvs)
 Loads the texture from path into the OpenGL context.
 
static int32_t texture_format (int32_t number_of_channels)
 Get texture format for a number_of_channels.
 
static uint32_t init_skybox_cube ()
 Initializes the cube Vertex Array Object used for skybox drawing. Caches the vao result.
 
static bool shader_compiled_successfully (uint32_t shader_id)
 Check if the shader with the shader_id compiled successfully.
 
static uint32_t compile_shader (const std::string &shader_source, resources::ShaderType shader_type)
 Compiles the shader from source.
 
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, back.jpg, up.jpg, down.jpg, left.jpg, down.jpg. They can be of the other extension as well, but the function will assign each texture to the appropriate side of the cubemap based on the texture file name.
 
static void enable_depth_testing ()
 Enables depth testing.
 
static void disable_depth_testing ()
 Disables depth testing.
 
static void clear_buffers ()
 Clears GL_DEPTH_BUFFER_BIT, GL_COLOR_BUFFER_BIT, and GL_STENCIL_BUFFER_BIT.
 
static std::string get_compilation_error_message (uint32_t shader_id)
 Retrieve the shader compilation error log message.
 

Static Private Member Functions

static void assert_no_error (std::source_location location)
 Throws util::OpenGLError if an OpenGL error occurred. Used internally.
 

Detailed Description

This class serves as the OpenGL interface for your app, since the engine doesn't directly link OpenGL to the app executable.

Any OpenGL additional direct OpenGL calls you need should be added here.

Member Typedef Documentation

◆ ShaderProgramId

Member Function Documentation

◆ call()

template<typename TResult , typename... TOpenGLArgs, typename... Args>
static TResult engine::graphics::OpenGL::call ( std::source_location  location,
TResult(*)(TOpenGLArgs...)  glfun,
Args...  args 
)
inlinestatic

Performs a checked OpenGL call. If the OpenGL call fails, it throws util::OpenGLError.

Parameters
locationSource location of where the call was made.
glfunOpenGL function to call.
argsOpenGL function arguments.
Returns
Return value if the glfun has it, otherwise void.

◆ shader_type_to_opengl_type()

int32_t engine::graphics::OpenGL::shader_type_to_opengl_type ( resources::ShaderType  type)
static

Converts resources::ShaderType to the OpenGL shader type enum.

Returns
GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, GL_GEOMETRY_SHADER

◆ generate_texture()

uint32_t engine::graphics::OpenGL::generate_texture ( const std::filesystem::path &  path,
bool  flip_uvs 
)
static

Loads the texture from path into the OpenGL context.

Parameters
pathpath to a texture file.
flip_uvsflip_uvs on load.
Returns
OpenGL id of a texture object.

◆ texture_format()

int32_t engine::graphics::OpenGL::texture_format ( int32_t  number_of_channels)
static

Get texture format for a number_of_channels.

Parameters
number_of_channelsthat the texture has.
Returns
GL_RED, GL_RGB, GL_RGBA for the number_of_channels=[1,3,4] respectively.

◆ init_skybox_cube()

uint32_t engine::graphics::OpenGL::init_skybox_cube ( )
static

Initializes the cube Vertex Array Object used for skybox drawing. Caches the vao result.

Returns
VAO of the cube used for skybox drawing.

◆ shader_compiled_successfully()

bool engine::graphics::OpenGL::shader_compiled_successfully ( uint32_t  shader_id)
static

Check if the shader with the shader_id compiled successfully.

Returns
true if the shader compilation succeeded, false otherwise.

◆ compile_shader()

uint32_t engine::graphics::OpenGL::compile_shader ( const std::string &  shader_source,
resources::ShaderType  shader_type 
)
static

Compiles the shader from source.

Parameters
shader_sourcesource code for the shader
shader_typethe type of the shader to create1
Returns
OpenGL context object of the shader.

◆ load_skybox_textures()

uint32_t engine::graphics::OpenGL::load_skybox_textures ( const std::filesystem::path &  path,
bool  flip_uvs = false 
)
static

Loads the skybox textures from the path. Make sure that images are named: front.jpg, back.jpg, up.jpg, down.jpg, left.jpg, down.jpg. They can be of the other extension as well, but the function will assign each texture to the appropriate side of the cubemap based on the texture file name.

Parameters
pathdirectory in which cubemap textures are located.
flip_uvswheater to flip_uvs on texture loading.
Returns
OpenGL id to the cubemap texture

◆ enable_depth_testing()

void engine::graphics::OpenGL::enable_depth_testing ( )
static

Enables depth testing.

◆ disable_depth_testing()

void engine::graphics::OpenGL::disable_depth_testing ( )
static

Disables depth testing.

◆ clear_buffers()

void engine::graphics::OpenGL::clear_buffers ( )
static

Clears GL_DEPTH_BUFFER_BIT, GL_COLOR_BUFFER_BIT, and GL_STENCIL_BUFFER_BIT.

◆ get_compilation_error_message()

std::string engine::graphics::OpenGL::get_compilation_error_message ( uint32_t  shader_id)
static

Retrieve the shader compilation error log message.

Parameters
shader_idShader id for which the compilation failed.
Returns
shader compilation error message.

◆ assert_no_error()

void engine::graphics::OpenGL::assert_no_error ( std::source_location  location)
staticprivate

Throws util::OpenGLError if an OpenGL error occurred. Used internally.

Parameters
locationSource location from where the OpenGL call was made.

The documentation for this class was generated from the following files: