$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
trail_renderer.c File Reference
#include "trail_renderer.h"
#include "gl_common.h"
#include "log.h"
#include "nbody.h"
#include "profiler.h"
#include "shader.h"
#include "utils.h"
#include <cglm/vec3.h>
#include <math.h>
#include <string.h>
Include dependency graph for trail_renderer.c:

Enumerations

enum  { MAX_TRAIL_VERTICES = NBODY_MAX_BODIES * ((TRAIL_MAX_POINTS * 2) + 4) }
 

Functions

static void ring_push (TrailRing *ring, const double pos[3], float timestamp)
 
static void ring_get (const TrailRing *ring, int age, vec3 out)
 
static float ring_get_timestamp (const TrailRing *ring, int age)
 
bool trail_renderer_init (TrailRenderer *trail, int body_count)
 Initializes trail renderer resources. More...
 
void trail_renderer_set_color (TrailRenderer *trail, int body_index, const vec3 color)
 Sets the trail color for a specific body. More...
 
void trail_renderer_cleanup (TrailRenderer *trail)
 Releases all GPU resources. More...
 
void trail_renderer_clear (TrailRenderer *trail)
 Clears all recorded trail data (e.g., on simulation reset). More...
 
void trail_renderer_record (TrailRenderer *trail, const NBodySim *sim, float delta_time)
 Records current positions from the simulation. More...
 
static int build_ribbon (const TrailRing *ring, const vec3 color, const vec3 cam_pos, float body_radius, float hdr_intensity, float max_width, float current_time, float trail_duration, TrailVertex *out)
 
void trail_renderer_draw (TrailRenderer *trail, mat4 view, mat4 proj, vec3 cam_pos)
 Builds ribbon geometry and renders all trails. More...
 
float trail_renderer_get_duration (const TrailRenderer *trail)
 Returns the current trail duration in seconds. More...
 
void trail_renderer_set_duration (TrailRenderer *trail, float duration)
 Sets the trail duration in seconds (clamped to valid range). More...
 

Variables

static const float EPSILON = 1e-6F
 
static const float MIN_BODY_RADIUS = 0.3F
 
static const float HALF = 0.5F
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MAX_TRAIL_VERTICES 

Function Documentation

◆ build_ribbon()

static int build_ribbon ( const TrailRing *  ring,
const vec3  color,
const vec3  cam_pos,
float  body_radius,
float  hdr_intensity,
float  max_width,
float  current_time,
float  trail_duration,
TrailVertex *  out 
)
static
Here is the call graph for this function:

◆ ring_get()

static void ring_get ( const TrailRing *  ring,
int  age,
vec3  out 
)
static

◆ ring_get_timestamp()

static float ring_get_timestamp ( const TrailRing *  ring,
int  age 
)
static

◆ ring_push()

static void ring_push ( TrailRing *  ring,
const double  pos[3],
float  timestamp 
)
static

◆ trail_renderer_cleanup()

void trail_renderer_cleanup ( TrailRenderer *  tr)

Releases all GPU resources.

Parameters
trPointer to the trail renderer.
Here is the call graph for this function:

◆ trail_renderer_clear()

void trail_renderer_clear ( TrailRenderer *  tr)

Clears all recorded trail data (e.g., on simulation reset).

Parameters
trPointer to the trail renderer.

◆ trail_renderer_draw()

void trail_renderer_draw ( TrailRenderer *  tr,
mat4  view,
mat4  proj,
vec3  cam_pos 
)

Builds ribbon geometry and renders all trails.

Must be called while the HDR framebuffer is active (before post-process). Sets up additive blending and depth-read-no-write internally.

Parameters
trPointer to the trail renderer.
viewView matrix.
projProjection matrix.
cam_posCamera world position.
Here is the call graph for this function:

◆ trail_renderer_get_duration()

float trail_renderer_get_duration ( const TrailRenderer *  trail)

Returns the current trail duration in seconds.

◆ trail_renderer_init()

bool trail_renderer_init ( TrailRenderer *  tr,
int  body_count 
)

Initializes trail renderer resources.

Parameters
trPointer to the trail renderer.
body_countNumber of bodies to track.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ trail_renderer_record()

void trail_renderer_record ( TrailRenderer *  tr,
const NBodySim *  sim,
float  delta_time 
)

Records current positions from the simulation.

Should be called every frame. Internally rate-limits sampling.

Parameters
trPointer to the trail renderer.
simPointer to the N-body simulation.
delta_timeFrame delta time.
Here is the call graph for this function:

◆ trail_renderer_set_color()

void trail_renderer_set_color ( TrailRenderer *  tr,
int  body_index,
const vec3  color 
)

Sets the trail color for a specific body.

Parameters
trPointer to the trail renderer.
body_indexBody index.
colorHDR emissive color (values > 1.0 are valid for bloom).

◆ trail_renderer_set_duration()

void trail_renderer_set_duration ( TrailRenderer *  trail,
float  duration 
)

Sets the trail duration in seconds (clamped to valid range).

Variable Documentation

◆ EPSILON

const float EPSILON = 1e-6F
static

◆ HALF

const float HALF = 0.5F
static

◆ MIN_BODY_RADIUS

const float MIN_BODY_RADIUS = 0.3F
static