Cogs.Core
RenderBlockCulling.h
1#pragma once
2
3#include "RenderBlock.h"
4
5#include "ClipmapParameterCalculation.h"
6
7namespace Cogs
8{
9 static bool intersect(const Cogs::Geometry::Frustum & frustum, const BoundingBox & box)
10 {
11 return Cogs::Geometry::contains(frustum, box) != 0;
12 }
13
14 static void cullRenderBlocks(const RenderBlock * blocks,
15 bool * visible,
16 const size_t count,
17 const RenderLevel & renderLevel,
18 const ViewVolume & viewVolume,
19 const Vector3d cullOrigin,
20 const float heightExaggeration,
21 const float worldScaleX,
22 const float worldScaleY)
23 {
24 // Scales raster
25 const Vector2 worldScale = Vector2(worldScaleX, worldScaleY);
26 const Vector2 offset = Vector2(static_cast<float>(cullOrigin.x), static_cast<float>(cullOrigin.y));
27 const float offsetZ = static_cast<float>(cullOrigin.z);
28
29 for (size_t i = 0; i < count; ++i) {
30 const RenderBlock & block = blocks[i];
31
32 const Vector2 min = block.min * worldScale + offset;
33 const Vector2 max = block.max * worldScale + offset;
34
35 const float minZ = offsetZ + (renderLevel.terrainLevel->isHeight ? renderLevel.terrainLevel->minZ * heightExaggeration : -1.0f);
36 const float maxZ = offsetZ + (renderLevel.terrainLevel->isHeight ? renderLevel.terrainLevel->maxZ * heightExaggeration : 1.0f);
37
38 const BoundingBox bbox = { Vector3(min, minZ), Vector3(max, maxZ) };
39
40 // Store culling result, override visibility to always true for degenerate mesh.
41 visible[i] = block.mesh->width == -1 || intersect(viewVolume.frustum, bbox);
42 };
43 }
44}
Contains all Cogs related functionality.
Definition: FieldSetter.h:23