$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
sphere_sorting.h File Reference

Back-to-front sorting for transparent geometry. More...

#include "instanced_rendering.h"
#include <cglm/cglm.h>
Include dependency graph for sphere_sorting.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SphereSortEntry
 Lightweight proxy for sorting data without moving large structs. More...
 
struct  SphereSorter
 Reusable memory context for sorting operations. More...
 

Functions

void sphere_sorter_init (SphereSorter *sorter, int initial_capacity)
 Allocates internal buffers for the sorter. More...
 
void sphere_sorter_cleanup (SphereSorter *sorter)
 Destroys the sorter context. More...
 
GLuint sphere_sorter_sort_gpu (SphereSorter *sorter, const SphereInstance *instances, int count, const vec3 camera_pos)
 Sorts the array of instances Back-to-Front (descending depth) on GPU. More...
 
GLuint sphere_sorter_sort_cpu (SphereSorter *sorter, const SphereInstance *instances, int count, const vec3 camera_pos)
 Sorts the array of instances Back-to-Front (descending depth) on CPU. More...
 
GLuint sphere_sorter_sort_cpu_radix (SphereSorter *sorter, const SphereInstance *instances, int count, const vec3 camera_pos)
 Sorts the array of instances Back-to-Front (descending depth) using Radix Sort. More...
 

Detailed Description

Back-to-front sorting for transparent geometry.

This module provides an efficient sorting mechanism for sphere instances, which is required for correct alpha blending of billboarded spheres.

Function Documentation

◆ sphere_sorter_cleanup()

void sphere_sorter_cleanup ( SphereSorter sorter)

Destroys the sorter context.

Parameters
sorterPointer to the struct.

◆ sphere_sorter_init()

void sphere_sorter_init ( SphereSorter sorter,
int  initial_capacity 
)

Allocates internal buffers for the sorter.

Parameters
sorterPointer to the struct.
initial_capacityExpected number of instances.
Here is the call graph for this function:

◆ sphere_sorter_sort_cpu()

GLuint sphere_sorter_sort_cpu ( SphereSorter sorter,
const SphereInstance instances,
int  count,
const vec3  camera_pos 
)

Sorts the array of instances Back-to-Front (descending depth) on CPU.

Uses qsort on the host and uploads the result to the SSBO.

Parameters
sorterMemory context.
instancesArray of instances (will be copied and sorted internally).
countActive element count.
camera_posWorld-space viewer position.
Returns
The SSBO handle containing the sorted instances.
Here is the call graph for this function:

◆ sphere_sorter_sort_cpu_radix()

GLuint sphere_sorter_sort_cpu_radix ( SphereSorter sorter,
const SphereInstance instances,
int  count,
const vec3  camera_pos 
)

Sorts the array of instances Back-to-Front (descending depth) using Radix Sort.

Parameters
sorterMemory context.
instancesArray of instances.
countActive element count.
camera_posWorld-space viewer position (for depth).
Returns
The SSBO handle containing the sorted instances.
Here is the call graph for this function:

◆ sphere_sorter_sort_gpu()

GLuint sphere_sorter_sort_gpu ( SphereSorter sorter,
const SphereInstance instances,
int  count,
const vec3  camera_pos 
)

Sorts the array of instances Back-to-Front (descending depth) on GPU.

Uploads instances to an SSBO, sorts them using a compute shader, and prepares them for rendering.

Parameters
sorterMemory context.
instancesPointer to the array of instances to upload.
countActive element count.
camera_posWorld-space viewer position.
Returns
The SSBO handle containing the sorted instances.
Here is the call graph for this function: