$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
icosphere.c File Reference
#include "icosphere.h"
#include <cglm/types.h>
#include <cglm/vec3.h>
#include <stdint.h>
#include <stdlib.h>
Include dependency graph for icosphere.c:

Data Structures

struct  EdgeEntry
 
struct  EdgeHash
 

Macros

#define X   0.525731112119133606F
 
#define Z   0.850650808352039932F
 

Enumerations

enum  {
  INITIAL_VEC3_CAPACITY = 128 , INITIAL_UINT_CAPACITY = 256 , ICOSAHEDRON_VERTEX_COUNT = 12 , ICOSAHEDRON_INDEX_COUNT = 60 ,
  INDEX_SHIFT = 32
}
 

Functions

void vec3array_init (Vec3Array *array)
 Initializes a Vec3Array with zeroed fields. More...
 
void vec3array_push (Vec3Array *array, vec3 vertex)
 Appends a vec3 to the array, reallocating if necessary. More...
 
void vec3array_free (Vec3Array *array)
 Frees the internal buffer of a Vec3Array. More...
 
void uintarray_init (UintArray *array)
 Initializes a UintArray with zeroed fields. More...
 
void uintarray_push (UintArray *array, unsigned int value)
 Appends an unsigned int to the array, reallocating if necessary. More...
 
void uintarray_free (UintArray *array)
 Frees the internal buffer of a UintArray. More...
 
static void normalize_vec3 (vec3 vertex, vec3 out)
 
static void edge_hash_init (EdgeHash *hash, size_t capacity)
 
static void edge_hash_free (EdgeHash *hash)
 
static unsigned int get_midpoint (unsigned int point1, unsigned int point2, Vec3Array *vertices, EdgeHash *hash)
 
static void subdivide (Vec3Array *vertices, UintArray *indices, int depth)
 
static void compute_normals (const Vec3Array *vertices, Vec3Array *normals)
 
void icosphere_init (IcosphereGeometry *geom)
 Initializes icosphere geometry buffers. More...
 
void icosphere_generate (IcosphereGeometry *geom, int subdivisions)
 Generates icosphere mesh data for a specified subdivision level. More...
 
void icosphere_free (IcosphereGeometry *geom)
 Frees all dynamic memory in the icosphere container. More...
 

Variables

static const vec3 icosahedron_vertices [ICOSAHEDRON_VERTEX_COUNT]
 
static const unsigned int icosahedron_indices [ICOSAHEDRON_INDEX_COUNT]
 

Macro Definition Documentation

◆ X

#define X   0.525731112119133606F

◆ Z

#define Z   0.850650808352039932F

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
INITIAL_VEC3_CAPACITY 
INITIAL_UINT_CAPACITY 
ICOSAHEDRON_VERTEX_COUNT 
ICOSAHEDRON_INDEX_COUNT 
INDEX_SHIFT 

Function Documentation

◆ compute_normals()

static void compute_normals ( const Vec3Array vertices,
Vec3Array normals 
)
static
Here is the call graph for this function:

◆ edge_hash_free()

static void edge_hash_free ( EdgeHash hash)
static

◆ edge_hash_init()

static void edge_hash_init ( EdgeHash hash,
size_t  capacity 
)
static

◆ get_midpoint()

static unsigned int get_midpoint ( unsigned int  point1,
unsigned int  point2,
Vec3Array vertices,
EdgeHash hash 
)
static
Here is the call graph for this function:

◆ icosphere_free()

void icosphere_free ( IcosphereGeometry geom)

Frees all dynamic memory in the icosphere container.

Parameters
geomPointer to the geometry container.
Here is the call graph for this function:

◆ icosphere_generate()

void icosphere_generate ( IcosphereGeometry geom,
int  subdivisions 
)

Generates icosphere mesh data for a specified subdivision level.

Parameters
geomPointer to the geometry container.
subdivisionsNumber of times to split each triangle face (0-6).
See also
app_settings.h (MAX_SUBDIV)
Here is the call graph for this function:

◆ icosphere_init()

void icosphere_init ( IcosphereGeometry geom)

Initializes icosphere geometry buffers.

Parameters
geomPointer to the geometry container.
Here is the call graph for this function:

◆ normalize_vec3()

static void normalize_vec3 ( vec3  vertex,
vec3  out 
)
static

◆ subdivide()

static void subdivide ( Vec3Array vertices,
UintArray indices,
int  depth 
)
static
Here is the call graph for this function:

◆ uintarray_free()

void uintarray_free ( UintArray array)

Frees the internal buffer of a UintArray.

◆ uintarray_init()

void uintarray_init ( UintArray array)

Initializes a UintArray with zeroed fields.

◆ uintarray_push()

void uintarray_push ( UintArray array,
unsigned int  value 
)

Appends an unsigned int to the array, reallocating if necessary.

◆ vec3array_free()

void vec3array_free ( Vec3Array array)

Frees the internal buffer of a Vec3Array.

◆ vec3array_init()

void vec3array_init ( Vec3Array array)

Initializes a Vec3Array with zeroed fields.

◆ vec3array_push()

void vec3array_push ( Vec3Array array,
vec3  vertex 
)

Appends a vec3 to the array, reallocating if necessary.

Variable Documentation

◆ icosahedron_indices

const unsigned int icosahedron_indices[ICOSAHEDRON_INDEX_COUNT]
static
Initial value:
= {
0, 4, 1, 0, 9, 4, 9, 5, 4, 4, 5, 8, 4, 8, 1, 8, 10, 1, 8, 3,
10, 5, 3, 8, 5, 2, 3, 2, 7, 3, 7, 10, 3, 7, 6, 10, 7, 11, 6, 11,
0, 6, 0, 1, 6, 6, 1, 10, 9, 0, 11, 9, 11, 2, 9, 2, 5, 7, 2, 11}

◆ icosahedron_vertices

const vec3 icosahedron_vertices[ICOSAHEDRON_VERTEX_COUNT]
static
Initial value:
= {
{- 0.525731112119133606F , 0, 0.850650808352039932F }, { 0.525731112119133606F , 0, 0.850650808352039932F }, {- 0.525731112119133606F , 0, - 0.850650808352039932F }, { 0.525731112119133606F , 0, - 0.850650808352039932F }, {0, 0.850650808352039932F , 0.525731112119133606F }, {0, 0.850650808352039932F , - 0.525731112119133606F },
{0, - 0.850650808352039932F , 0.525731112119133606F }, {0, - 0.850650808352039932F , - 0.525731112119133606F }, { 0.850650808352039932F , 0.525731112119133606F , 0}, {- 0.850650808352039932F , 0.525731112119133606F , 0}, { 0.850650808352039932F , - 0.525731112119133606F , 0}, {- 0.850650808352039932F , - 0.525731112119133606F , 0}}