Path Tracing
Loading...
Searching...
No Matches
mesh.hpp File Reference

Loads 3D models through ASSIMP into CPU-side geometry and material data, defines the GPUVertex/GPUTriangle/GPUMaterial layouts shared with the shader. More...

#include <vector>
#include <string>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include "config.hpp"
Include dependency graph for mesh.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  GPUVertex
struct  GPUTriangle
struct  GPUMaterial
struct  CPUTextureSlot
struct  CPUMaterial
struct  MeshBounds
 Loaded mesh bounding box, axis-aligned, used for AABB early rejection Calculated during loadMesh. Used for AABB early rejection for rays that miss the bouding box. More...
struct  GPULight

Macros

#define LIGHT_POINT   0
#define LIGHT_DIRECTIONAL   1
#define LIGHT_SPOT   2

Functions

void recreateBuffer (GLuint &ssbo, GLsizeiptr size_bytes, const void *data, GLenum usage)
 Recreates/Creates a GPU buffer, freeing any previous held handle first. Prevents leaking the old buffer when called repeatedly.
int uploadLights (const vector< GPUTriangle > &triangles, const vector< GPUMaterial > &materials, GLuint &light_ssbo)
int uploadAnalyticLights (const vector< GPULight > &lights, GLuint &light_ssbo)
bool loadMesh (const string &path, vector< GPUTriangle > &triangles, vector< GPUMaterial > &materials, vector< CPUMaterial > &cpu_materials, mat4 transform, MeshBounds *bounds)
 Loads a mesh and calculates its bounding box.
bool uploadMesh (const vector< GPUTriangle > &triangles, const vector< GPUMaterial > &materials, GLuint &tri_ssbo, GLuint &mat_ssbo)
void clearMesh ()
vector< GPUTriangle > makeTestMesh ()
void checkGL (const char *label)
 quick checkpoint to check OpenGL silent error throws. Catches the error and sends it, or it prints an OK check

Variables

Renderer renderer
GLuint light_ssbo
 Mesh light storage to pass emissive triangles.
GLint loc_light_count

Detailed Description

Loads 3D models through ASSIMP into CPU-side geometry and material data, defines the GPUVertex/GPUTriangle/GPUMaterial layouts shared with the shader.

Author
Leonel Matos
See also
globals.glsl for the mirrored std430 structs
Date
2026-09-10

Macro Definition Documentation

◆ LIGHT_DIRECTIONAL

#define LIGHT_DIRECTIONAL   1

◆ LIGHT_POINT

#define LIGHT_POINT   0

◆ LIGHT_SPOT

#define LIGHT_SPOT   2

Function Documentation

◆ checkGL()

void checkGL ( const char * label)
inline

quick checkpoint to check OpenGL silent error throws. Catches the error and sends it, or it prints an OK check

Parameters
label

◆ clearMesh()

void clearMesh ( )

◆ loadMesh()

bool loadMesh ( const string & path,
vector< GPUTriangle > & triangles,
vector< GPUMaterial > & materials,
vector< CPUMaterial > & cpu_materials,
mat4 transform,
MeshBounds * bounds )

Loads a mesh and calculates its bounding box.

Parameters
pathPath to the mesh file (any file format supported by ASSIMP)
trianglesOutput triangle buffer
materialsOutput material buffer
transformTransform matrix applied to all vertices (default: Identity)
boundsOptional output bounding box - nullptr to skip
Returns
true if loaded correctly
See also
MeshBounds, uploadMesh
Bug
don't know if this will work well with spectral rendering
Bug
this is a very incorrect way to force the mirror type, but I don't have metallic/roughness value types, so it is what it is...

◆ makeTestMesh()

vector< GPUTriangle > makeTestMesh ( )

◆ recreateBuffer()

void recreateBuffer ( GLuint & ssbo,
GLsizeiptr size_bytes,
const void * data,
GLenum usage )
inline

Recreates/Creates a GPU buffer, freeing any previous held handle first. Prevents leaking the old buffer when called repeatedly.

Parameters
ssboBuffer handle; deleted if exists, then recreates
size_bytesByte size of the data to upload
dataPointer to source data (can be nullptr to just allocate space)
usageGL usage hint (STATIC_DRAW, DYNAMIC_DRAW...)

◆ uploadAnalyticLights()

int uploadAnalyticLights ( const vector< GPULight > & lights,
GLuint & light_ssbo )

◆ uploadLights()

int uploadLights ( const vector< GPUTriangle > & triangles,
const vector< GPUMaterial > & materials,
GLuint & light_ssbo )

◆ uploadMesh()

bool uploadMesh ( const vector< GPUTriangle > & triangles,
const vector< GPUMaterial > & materials,
GLuint & tri_ssbo,
GLuint & mat_ssbo )

Variable Documentation

◆ light_ssbo

GLuint light_ssbo
extern

Mesh light storage to pass emissive triangles.

◆ loc_light_count

GLint loc_light_count
extern

◆ renderer

Renderer renderer
extern