Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
mnd::GraphicsAPI Class Reference

OpenGL 3.3 Core Profile abstraction layer. More...

#include <GraphicsAPI.h>

Public Member Functions

bool Init ()
 Set up initial OpenGL state (depth test, face culling, etc.).
 
std::shared_ptr< ShaderProgramCreateShaderProgram (const std::string &vertexSource, const std::string &fragmentSource)
 Compile vertex + fragment GLSL source and link into a program.
 
const std::shared_ptr< ShaderProgram > & GetDefaultShaderProgram ()
 Returns the built-in default shader (Blinn-Phong + diffuse texture).
 
GLuint CreateVertexBuffer (const std::vector< float > &vertices)
 Upload a flat array of floats to a new GPU vertex buffer.
 
GLuint CreateIndexBuffer (const std::vector< uint32_t > &indices)
 Upload a flat array of u32 indices to a new GPU index buffer.
 
void SetClearColor (float r, float g, float b, float a)
 Set the colour that glClear() fills the framebuffer with.
 
void ClearBuffers ()
 Clear the colour and depth buffers ready for the next frame.
 
void BindShaderProgram (ShaderProgram *shaderProgram)
 Bind a compiled shader program to the current GL state.
 
void BindMaterial (Material *material)
 Upload all material parameters as uniforms to the active shader.
 
void BindMesh (Mesh *mesh)
 Bind the mesh's VAO so the next draw call uses its geometry.
 
void UnbindMesh (Mesh *mesh)
 
void DrawMesh (Mesh *mesh)
 Issue a draw call for the bound mesh.
 

Detailed Description

OpenGL 3.3 Core Profile abstraction layer.

Responsibilities:

  • Initialise default render state (depth test, blending …).
  • Compile and link GLSL programs via CreateShaderProgram().
  • Allocate VBO / IBO objects on the GPU.
  • Bind materials and meshes to the current GL state before draw calls.

Definition at line 40 of file GraphicsAPI.h.

Member Function Documentation

◆ BindMaterial()

void mnd::GraphicsAPI::BindMaterial ( Material material)

Upload all material parameters as uniforms to the active shader.

Parameters
materialMaterial whose float / texture params are applied.

Definition at line 196 of file GraphicsAPI.cpp.

Referenced by mnd::RenderQueue::Draw().

◆ BindMesh()

void mnd::GraphicsAPI::BindMesh ( Mesh mesh)

Bind the mesh's VAO so the next draw call uses its geometry.

Parameters
meshMesh whose VAO/VBO/EBO layout is activated.

Definition at line 207 of file GraphicsAPI.cpp.

Referenced by mnd::RenderQueue::Draw(), and mnd::ParticleSystem::Render().

◆ BindShaderProgram()

void mnd::GraphicsAPI::BindShaderProgram ( ShaderProgram shaderProgram)

Bind a compiled shader program to the current GL state.

Parameters
shaderProgramThe program to activate; must not be nullptr.

Definition at line 185 of file GraphicsAPI.cpp.

◆ ClearBuffers()

void mnd::GraphicsAPI::ClearBuffers ( )

Clear the colour and depth buffers ready for the next frame.

Definition at line 180 of file GraphicsAPI.cpp.

Referenced by mnd::Engine::Run().

◆ CreateIndexBuffer()

GLuint mnd::GraphicsAPI::CreateIndexBuffer ( const std::vector< uint32_t > &  indices)

Upload a flat array of u32 indices to a new GPU index buffer.

Parameters
indicesTriangle list indices into the vertex buffer.
Returns
GL handle to the created EBO.

Definition at line 164 of file GraphicsAPI.cpp.

◆ CreateShaderProgram()

std::shared_ptr< ShaderProgram > mnd::GraphicsAPI::CreateShaderProgram ( const std::string &  vertexSource,
const std::string &  fragmentSource 
)

Compile vertex + fragment GLSL source and link into a program.

Parameters
vertexSourceGLSL source string for the vertex stage.
fragmentSourceGLSL source string for the fragment stage.
Returns
Shared pointer to the linked ShaderProgram.

Definition at line 18 of file GraphicsAPI.cpp.

References kShaderInfoLogSize, LOG_ERROR, and LOG_INFO.

Referenced by GetDefaultShaderProgram(), mnd::ParticleSystem::Init(), and mnd::Material::Load().

◆ CreateVertexBuffer()

GLuint mnd::GraphicsAPI::CreateVertexBuffer ( const std::vector< float > &  vertices)

Upload a flat array of floats to a new GPU vertex buffer.

Parameters
verticesInterleaved vertex data (position, normal, UV, …).
Returns
GL handle to the created VBO.

Definition at line 153 of file GraphicsAPI.cpp.

◆ DrawMesh()

void mnd::GraphicsAPI::DrawMesh ( Mesh mesh)

Issue a draw call for the bound mesh.

Uses indexed drawing (glDrawElements) when the mesh has an EBO, otherwise falls back to glDrawArrays.

Parameters
meshThe mesh to draw (must already be bound via BindMesh).

Definition at line 229 of file GraphicsAPI.cpp.

Referenced by mnd::RenderQueue::Draw().

◆ GetDefaultShaderProgram()

const std::shared_ptr< ShaderProgram > & mnd::GraphicsAPI::GetDefaultShaderProgram ( )

Returns the built-in default shader (Blinn-Phong + diffuse texture).

Loaded once during Init(). Materials that do not specify their own shader fall back to this program.

Definition at line 72 of file GraphicsAPI.cpp.

References CreateShaderProgram().

◆ Init()

bool mnd::GraphicsAPI::Init ( )

Set up initial OpenGL state (depth test, face culling, etc.).

Returns
true on success.

Definition at line 12 of file GraphicsAPI.cpp.

Referenced by mnd::OpenGLRendererBackend::Init().

◆ SetClearColor()

void mnd::GraphicsAPI::SetClearColor ( float  r,
float  g,
float  b,
float  a 
)

Set the colour that glClear() fills the framebuffer with.

Parameters
r,g,b,aLinear RGBA components in [0, 1].

Definition at line 175 of file GraphicsAPI.cpp.

Referenced by mnd::Engine::Run().

◆ UnbindMesh()

void mnd::GraphicsAPI::UnbindMesh ( Mesh mesh)

Definition at line 218 of file GraphicsAPI.cpp.

Referenced by mnd::RenderQueue::Draw().


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