summaryrefslogtreecommitdiff
path: root/src/systems/terrain.h
blob: a65ecec32e8b663a6ef26ac15a168621ab180cb3 (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
/**
 * @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

PUB Heightmap Heightmap_FromImage(str8 filepath);
PUB Heightmap Heightmap_FromPerlin(/* TODO: perlin noise generation parameters */);

// --- 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);