Space Sim
Loading...
Searching...
No Matches
mesh.c File Reference
#include "core/init.h"
#include "utilities/mathf.h"
#include "core/types.h"
#include "mesh/mesh.h"
#include "uthash/uthash.h"
#include "core/camera.h"
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <float.h>

Go to the source code of this file.

Data Structures

struct  ZeroKey
struct  ZeroEntry

Macros

#define ATMOSPHERE_IDX(x, y, o)
#define MAX_ZERO_LIST   100000

Enumerations

enum  FACE { XPOS , XNEG , YPOS , YNEG , ZPOS , ZNEG }

Functions

vec3 cube_pos (FACE face, vec2 uv)
vec3 calc_normal (vec3 a, vec3 b, vec3 c)
float mod289 (float x)
vec4 perm (vec4 x)
vec3 vec3_fract (vec3 x)
vec4 vec4_fract (vec4 x)
float fbm_noise (vec3 p)
float fbm (vec3 p)
float wrap (float x, float size)
vec3 vec3_wrap (vec3 a, float size)
float sample_density (vec3 p)
 Samples a precomputed perlin volume.
float sample_fbm_density (vec3 p)
 Samples a precomputed fbm volume.
float calc_density (vec3 p)
 Copies the exact density function from the GPU to the CPU.
void create_new_planet_mesh (int lod, ivec3 chunk_center, int chunk_id, bool is_parent)
 Creates a mesh for a certain chunk.
bool aabb_in_frustum (ivec3 min, ivec3 max, vec4 planes[6])
void get_view_planes (vec4 planes[6], Camera *cam, vec3 planet_offset, float planet_radius)
 Returns view planes from a camera, used for frustum culling.
int compareJobs (const void *a, const void *b)
int compareFrees (const void *a, const void *b)
int find_current_lod (ivec3 center, ChunkHash **h)
 Finds the highest LOD that we have cached from the current chunk.
bool free_current_parent (int lod, int i)
 Frees the given LOD (as a parent).
bool free_parent (int lod, int i)
 Frees the parent of given LOD.
bool free_child (int lod, int i)
 Frees the child of given LOD.
uint32_t assign_new_uID ()
void init_chunk_data ()
 Initializes and frees old ChunkData and hash tables.
void load_chunks (vec3 planet_origin, float planet_radius)
 Checks all chunks based on new Camera position, building a job list and then executing them based on ChunkScore.
void make_atmosphere_sphere_face (FACE face, int *vcnt, int *icnt)
 Creats a sphere face to be used for atmosphere rendering.
void mesh_atmosphere_sphere ()
 Creates an atmosphere sphere for rendering.

Variables

AuthorityEntry * authority_map = NULL
ChunkHash * hash_table = NULL
bool already_emitted [LODMAX][MAX_CHUNKS]
uint32_t chunk_uID = 0
ZeroEntry * zero_hash_table = NULL
int zero_list_count = 0
ChunkScore * jobs = NULL
ChunkData * job_data = NULL
ChunkScore * frees = NULL
bool replacement_mask [LODMAX][MAX_CHUNKS] = {0}
int generation_id = 0
int emitted_chunks = 0
int emitted_chunk_ids [VERTEX_COUNT_MAX]
int emitted_chunk_lods [VERTEX_COUNT_MAX]
GLsync zero_fence

Data Structure Documentation

◆ ZeroKey

struct ZeroKey

Definition at line 765 of file mesh.c.

Data Fields
int x
int y
int z
int lod

◆ ZeroEntry

struct ZeroEntry

Definition at line 771 of file mesh.c.

Data Fields
ZeroKey key
UT_hash_handle hh

Macro Definition Documentation

◆ MAX_ZERO_LIST

#define MAX_ZERO_LIST   100000

Definition at line 763 of file mesh.c.

Referenced by load_chunks().

Enumeration Type Documentation

◆ FACE

enum FACE
Enumerator
XPOS 
XNEG 
YPOS 
YNEG 
ZPOS 
ZNEG 

Definition at line 16 of file mesh.c.

Function Documentation

◆ cube_pos()

vec3 cube_pos ( FACE face,
vec2 uv )

Definition at line 36 of file mesh.c.

References cube_pos(), vec2::x, XNEG, XPOS, vec2::y, YNEG, YPOS, ZNEG, and ZPOS.

Referenced by cube_pos(), and make_atmosphere_sphere_face().

◆ calc_normal()

vec3 calc_normal ( vec3 a,
vec3 b,
vec3 c )

Definition at line 58 of file mesh.c.

References calc_normal(), vec3::x, vec3::y, and vec3::z.

Referenced by calc_normal(), and make_atmosphere_sphere_face().

◆ mod289()

float mod289 ( float x)

Definition at line 74 of file mesh.c.

References mod289().

◆ perm()

vec4 perm ( vec4 x)

Definition at line 79 of file mesh.c.

References mod289(), perm(), vec4_add(), vec4_mul(), vec4_scale(), vec4::w, vec4::x, vec4::y, and vec4::z.

◆ vec3_fract()

vec3 vec3_fract ( vec3 x)

Definition at line 101 of file mesh.c.

References vec3_fract(), vec3::x, vec3::y, and vec3::z.

Referenced by vec3_fract().

◆ vec4_fract()

vec4 vec4_fract ( vec4 x)

Definition at line 116 of file mesh.c.

References vec4_fract(), vec4::w, vec4::x, vec4::y, and vec4::z.

Referenced by fbm_noise(), and vec4_fract().

◆ fbm_noise()

◆ fbm()

float fbm ( vec3 p)

Definition at line 163 of file mesh.c.

References fbm(), fbm_noise(), vec3_add(), and vec3_scale().

◆ wrap()

float wrap ( float x,
float size )

Definition at line 190 of file mesh.c.

References size, and wrap().

Referenced by vec3_wrap(), and wrap().

◆ vec3_wrap()

vec3 vec3_wrap ( vec3 a,
float size )

Definition at line 202 of file mesh.c.

References size, vec3_wrap(), wrap(), vec3::x, vec3::y, and vec3::z.

Referenced by vec3_wrap().

◆ aabb_in_frustum()

bool aabb_in_frustum ( ivec3 min,
ivec3 max,
vec4 planes[6] )

Definition at line 492 of file mesh.c.

References aabb_in_frustum(), vec3_dot(), vec4::w, ivec3::x, vec4::x, ivec3::y, vec4::y, ivec3::z, and vec4::z.

Referenced by aabb_in_frustum(), and load_chunks().

◆ get_view_planes()

void get_view_planes ( vec4 planes[6],
Camera * cam,
vec3 planet_offset,
float planet_radius )

◆ compareJobs()

int compareJobs ( const void * a,
const void * b )

Definition at line 569 of file mesh.c.

References compareJobs(), and ChunkScore::score.

Referenced by compareJobs(), and load_chunks().

◆ compareFrees()

int compareFrees ( const void * a,
const void * b )

Definition at line 587 of file mesh.c.

References compareFrees(), and ChunkScore::score.

Referenced by compareFrees(), and load_chunks().

◆ assign_new_uID()

uint32_t assign_new_uID ( )

Definition at line 757 of file mesh.c.

References assign_new_uID(), and chunk_uID.

Referenced by assign_new_uID(), and load_chunks().

Variable Documentation

◆ authority_map

AuthorityEntry* authority_map = NULL

Definition at line 617 of file mesh.c.

Referenced by get_current_lod(), init_chunk_data(), and set_current_lod().

◆ hash_table

ChunkHash* hash_table = NULL

◆ already_emitted

bool already_emitted[LODMAX][MAX_CHUNKS]

Definition at line 623 of file mesh.c.

Referenced by free_child(), free_parent(), and load_chunks().

◆ chunk_uID

uint32_t chunk_uID = 0

Definition at line 754 of file mesh.c.

Referenced by assign_new_uID(), and load_chunks().

◆ zero_hash_table

ZeroEntry* zero_hash_table = NULL

Definition at line 778 of file mesh.c.

Referenced by init_chunk_data(), and load_chunks().

◆ zero_list_count

int zero_list_count = 0

Definition at line 779 of file mesh.c.

Referenced by load_chunks().

◆ jobs

ChunkScore* jobs = NULL

Definition at line 782 of file mesh.c.

Referenced by init_chunk_data(), and load_chunks().

◆ job_data

ChunkData* job_data = NULL

Definition at line 783 of file mesh.c.

Referenced by init_chunk_data(), and load_chunks().

◆ frees

ChunkScore* frees = NULL

Definition at line 784 of file mesh.c.

Referenced by init_chunk_data(), and load_chunks().

◆ replacement_mask

bool replacement_mask[LODMAX][MAX_CHUNKS] = {0}

Definition at line 786 of file mesh.c.

Referenced by load_chunks().

◆ generation_id

int generation_id = 0

Definition at line 877 of file mesh.c.

Referenced by load_chunks().

◆ emitted_chunks

int emitted_chunks = 0

Definition at line 879 of file mesh.c.

Referenced by layout(), load_chunks(), and main().

◆ emitted_chunk_ids

int emitted_chunk_ids[VERTEX_COUNT_MAX]

Definition at line 880 of file mesh.c.

Referenced by load_chunks().

◆ emitted_chunk_lods

int emitted_chunk_lods[VERTEX_COUNT_MAX]

Definition at line 881 of file mesh.c.

Referenced by load_chunks().

◆ zero_fence

GLsync zero_fence

Definition at line 884 of file mesh.c.

Referenced by load_chunks().