blob: 890cb90ba7e3726ff0939061707f7154b9a52756 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/**
* @file terrain.h
* @brief
*/
#pragma once
/*
Future:
- Chunked terrain
- Dynamic LOD
*/
#include "defines.h"
#include "maths_types.h"
#include "mem.h"
#include "ral.h"
#include "render.h"
#include "str.h"
typedef struct Heightmap {
Str8 filepath;
u32x2 size;
void* image_data;
bool is_uploaded;
} Heightmap;
typedef struct Terrain_Storage Terrain_Storage;
// --- Public API
PUB bool Terrain_Init(Terrain_Storage* storage);
PUB void Terrain_Shutdown(Terrain_Storage* storage);
PUB void Terrain_Run(Terrain_Storage* storage); // NOTE: For now it renders directly to main framebuffer
/** @brief Sets the active heightmap to be rendered and collided against. */
PUB Heightmap Terrain_LoadHeightmap(Heightmap hmap, bool free_on_upload);
PUB Heightmap Heightmap_FromImage(Str8 filepath);
PUB Heightmap Heightmap_FromPerlin(/* TODO: perlin noise generation parameters */);
PUB bool Terrain_IsActive(); // checks whether we have a loaded heightmap and it's being rendered
// --- Internal
// TODO: void terrain_system_render_hmap(renderer* rend, terrain_state* state);
/** @brief Get the height (the Y component) for a vertex at a particular coordinate in the heightmap
*/
f32 Heightmap_HeightXZ(Heightmap* hmap, f32 x, f32 z);
/** @brief Calculate the normal vector of a vertex at a particular coordinate in the heightmap */
Vec3 Heightmap_NormalXZ(Heightmap* hmap, f32 x, f32 z);
/** @brief Generate the `geometry_data` for a heightmap ready to be uploaded to the GPU */
Geometry geo_heightmap(arena* a, Heightmap heightmap);
|