TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
8 / 8
100.0%
Branches:
5 / 6
83.3%
Functions:
2 / 2
100.0%

layers/kernels/noise_relief.h
Line Branch Exec Source
1 /// @file
2 /// @brief The kernel of `NoiseRelief`; a kernel header for C++ and Slang.
3 #pragma once
4
5 #include "terraingen/layers/kernels/cell.h"
6 #include "terraingen/noise/noise_layers.h"
7
8 #ifndef __SLANG__
9 #include "terraingen/gpu/program.h"
10
11 #include <vector>
12 #endif
13
14 namespace terraingen {
15
16 /// The enabled layers of a noise relief, in order.
17 struct NoiseReliefKernel {
18 NoiseLayers layers; ///< Only enabled layers, so every `enabled` flag is set.
19 };
20
21 #ifdef __SLANG__
22 /// A cell's height after the noise relief: `height` plus the stacked layers at `position`.
23 inline float ApplyCell(NoiseReliefKernel kernel, float height, CellPosition position) {
24 return height + EvaluateNoiseLayers(position.x, position.y, kernel.layers);
25 }
26 #else
27 /// A cell's height after the noise relief: `height` plus the stacked layers at `position`. The
28 /// same stack as on the GPU, taken by reference so no cell copies the block.
29 74605001 inline float ApplyCell(const NoiseReliefKernel& kernel, float height, CellPosition position) {
30 return height +
31 74605001 EvaluateNoiseLayers(position.x, position.y, kernel.layers.layers, kernel.layers.count);
32 }
33
34 static_assert(sizeof(NoiseReliefKernel) == 420, "NoiseReliefKernel must match its std430 layout");
35
36 /// The compiled forms of the noise relief kernel.
37 template <> KernelProgram CompiledKernel<NoiseReliefKernel>();
38
39 /// The kernel of `layers`, at most `kMaxNoiseLayers`, keeping the enabled ones in order; skipping
40 /// a disabled layer leaves the stack as it was, so the heights are the same.
41 293 inline NoiseReliefKernel MakeNoiseReliefKernel(const std::vector<NoiseLayer>& layers) {
42 293 NoiseReliefKernel kernel;
43
2/2
✓ Branch 5 taken 323 times.
✓ Branch 6 taken 293 times.
616 for (const NoiseLayer& layer : layers) {
44
3/4
✓ Branch 0 taken 321 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 321 times.
✗ Branch 3 not taken.
323 if (layer.enabled && kernel.layers.count < kMaxNoiseLayers) {
45 321 kernel.layers.layers[kernel.layers.count++] = layer;
46 }
47 }
48 293 return kernel;
49 }
50 #endif
51
52 } // namespace terraingen
53