Kohi Game Engine
geometry_system.h File Reference

The geometry system is responsible for loading and unloading geometry, as well as reference counting. More...

Go to the source code of this file.

Data Structures

struct  geometry_system_config
 The geometry system configuration. More...
 
struct  geometry_config
 Represents the configuration for a geometry. More...
 

Macros

#define DEFAULT_GEOMETRY_NAME   "default"
 The name of the default geometry. More...
 

Typedefs

typedef struct geometry_system_config geometry_system_config
 The geometry system configuration. More...
 
typedef struct geometry_config geometry_config
 Represents the configuration for a geometry. More...
 

Functions

b8 geometry_system_initialize (u64 *memory_requirement, void *state, void *config)
 Initializes the geometry system. Should be called twice; once to get the memory requirement (passing state=0), and a second time passing an allocated block of memory to actually initialize the system. More...
 
void geometry_system_shutdown (void *state)
 Shuts down the geometry system. More...
 
KAPI geometrygeometry_system_acquire_by_id (u32 id)
 Acquires an existing geometry by id. More...
 
KAPI geometrygeometry_system_acquire_from_config (geometry_config config, b8 auto_release)
 Registers and acquires a new geometry using the given config. More...
 
KAPI void geometry_system_config_dispose (geometry_config *config)
 Frees resources held by the provided configuration. More...
 
KAPI void geometry_system_release (geometry *geometry)
 Releases a reference to the provided geometry. More...
 
KAPI geometrygeometry_system_get_default (void)
 Obtains a pointer to the default geometry. More...
 
KAPI geometrygeometry_system_get_default_2d (void)
 Obtains a pointer to the default geometry. More...
 
KAPI geometry_config geometry_system_generate_plane_config (f32 width, f32 height, u32 x_segment_count, u32 y_segment_count, f32 tile_x, f32 tile_y, const char *name, const char *material_name)
 Generates configuration for plane geometries given the provided parameters. NOTE: vertex and index arrays are dynamically allocated and should be freed upon object disposal. Thus, this should not be considered production code. More...
 
KAPI geometry_config geometry_system_generate_cube_config (f32 width, f32 height, f32 depth, f32 tile_x, f32 tile_y, const char *name, const char *material_name)
 

Detailed Description

The geometry system is responsible for loading and unloading geometry, as well as reference counting.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2022-01-11

Macro Definition Documentation

◆ DEFAULT_GEOMETRY_NAME

#define DEFAULT_GEOMETRY_NAME   "default"

The name of the default geometry.

Typedef Documentation

◆ geometry_config

Represents the configuration for a geometry.

◆ geometry_system_config

The geometry system configuration.

Function Documentation

◆ geometry_system_acquire_by_id()

KAPI geometry* geometry_system_acquire_by_id ( u32  id)

Acquires an existing geometry by id.

Parameters
idThe geometry identifier to acquire by.
Returns
A pointer to the acquired geometry or nullptr if failed.

◆ geometry_system_acquire_from_config()

KAPI geometry* geometry_system_acquire_from_config ( geometry_config  config,
b8  auto_release 
)

Registers and acquires a new geometry using the given config.

Parameters
configThe geometry configuration.
auto_releaseIndicates if the acquired geometry should be unloaded when its reference count reaches 0.
Returns
A pointer to the acquired geometry or nullptr if failed.

◆ geometry_system_config_dispose()

KAPI void geometry_system_config_dispose ( geometry_config config)

Frees resources held by the provided configuration.

Parameters
configA pointer to the configuration to be disposed.

◆ geometry_system_generate_cube_config()

KAPI geometry_config geometry_system_generate_cube_config ( f32  width,
f32  height,
f32  depth,
f32  tile_x,
f32  tile_y,
const char *  name,
const char *  material_name 
)
Parameters
width
height
depth
tile_x
tile_y
name
material_name
Returns
geometry_config

◆ geometry_system_generate_plane_config()

KAPI geometry_config geometry_system_generate_plane_config ( f32  width,
f32  height,
u32  x_segment_count,
u32  y_segment_count,
f32  tile_x,
f32  tile_y,
const char *  name,
const char *  material_name 
)

Generates configuration for plane geometries given the provided parameters. NOTE: vertex and index arrays are dynamically allocated and should be freed upon object disposal. Thus, this should not be considered production code.

Parameters
widthThe overall width of the plane. Must be non-zero.
heightThe overall height of the plane. Must be non-zero.
x_segment_countThe number of segments along the x-axis in the plane. Must be non-zero.
y_segment_countThe number of segments along the y-axis in the plane. Must be non-zero.
tile_xThe number of times the texture should tile across the plane on the x-axis. Must be non-zero.
tile_yThe number of times the texture should tile across the plane on the y-axis. Must be non-zero.
nameThe name of the generated geometry.
material_nameThe name of the material to be used.
Returns
A geometry configuration which can then be fed into geometry_system_acquire_from_config().

◆ geometry_system_get_default()

KAPI geometry* geometry_system_get_default ( void  )

Obtains a pointer to the default geometry.

Returns
A pointer to the default geometry.

◆ geometry_system_get_default_2d()

KAPI geometry* geometry_system_get_default_2d ( void  )

Obtains a pointer to the default geometry.

Returns
A pointer to the default geometry.

◆ geometry_system_initialize()

b8 geometry_system_initialize ( u64 memory_requirement,
void *  state,
void *  config 
)

Initializes the geometry system. Should be called twice; once to get the memory requirement (passing state=0), and a second time passing an allocated block of memory to actually initialize the system.

Parameters
memory_requirementA pointer to hold the memory requirement as it is calculated.
stateA block of memory to hold the state or, if gathering the memory requirement, 0.
configThe configuration (geometry_system_config) for this system.
Returns
True on success; otherwise false.

◆ geometry_system_release()

KAPI void geometry_system_release ( geometry geometry)

Releases a reference to the provided geometry.

Parameters
geometryThe geometry to be released.

◆ geometry_system_shutdown()

void geometry_system_shutdown ( void *  state)

Shuts down the geometry system.

Parameters
stateThe state block of memory.