-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTerrainMesh.h
More file actions
108 lines (86 loc) · 2.86 KB
/
TerrainMesh.h
File metadata and controls
108 lines (86 loc) · 2.86 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright © 2008-2012 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#ifndef __TERRAINMESH_H__
#define __TERRAINMESH_H__
#include "glew.h"
#include "TerrainPatchID.h"
#include <deque>
// Include GLM
#include <glm/glm.hpp>
static const uint32_t NUM_SIDES = 6;
// fwd decl'
class TerrainPatch;
class TerrainPatchContext;
#ifdef _DEBUG
class CGLquad;
class CGLcube;
#endif
struct SSplitRequestDescription {
SSplitRequestDescription(const glm::vec3 &v0_,
const glm::vec3 &v1_,
const glm::vec3 &v2_,
const glm::vec3 &v3_,
const glm::vec3 &cn,
const uint32_t depth_,
const TerrainPatchID &patchID_)
: v0(v0_), v1(v1_), v2(v2_), v3(v3_), centroid(cn), depth(depth_), patchID(patchID_)
{
}
const glm::vec3 v0;
const glm::vec3 v1;
const glm::vec3 v2;
const glm::vec3 v3;
const glm::vec3 centroid;
const uint32_t depth;
const TerrainPatchID patchID;
};
struct SSplitResult {
struct SSplitResultData {
SSplitResultData(const GLuint texID_, const glm::vec3 &v0_, const glm::vec3 &v1_, const glm::vec3 &v2_, const glm::vec3 &v3_, const TerrainPatchID &patchID_) :
texID(texID_), v0(v0_), v1(v1_), v2(v2_), v3(v3_), patchID(patchID_)
{
}
const GLuint texID;
const glm::vec3 v0;
const glm::vec3 v1;
const glm::vec3 v2;
const glm::vec3 v3;
const TerrainPatchID patchID;
};
SSplitResult(const int32_t face_, const uint32_t depth_) : face(face_), depth(depth_)
{
}
void addResult(const GLuint tex, const glm::vec3 &v0_, const glm::vec3 &v1_, const glm::vec3 &v2_, const glm::vec3 &v3_, const TerrainPatchID &patchID_)
{
data.push_back(SSplitResultData(tex, v0_, v1_, v2_, v3_, patchID_));
assert(data.size()<=4);
}
const int32_t face;
const uint32_t depth;
std::deque<SSplitResultData> data;
};
class TerrainMesh
{
private:
void BuildFirstPatches();
static const uint32_t NUM_PATCHES = 6;
TerrainPatch* mGeoPatches[NUM_PATCHES];
TerrainPatchContext* mGeoPatchContext;
static const uint32_t MAX_SPLIT_REQUESTS = 128;
std::deque<SSplitRequestDescription*> mSplitRequestDescriptions;
std::deque<SSplitResult*> mSplitResult;
public:
TerrainMesh();
~TerrainMesh();
void Update(const glm::vec3 &campos);
void Render(const glm::mat4 &ViewMatrix, const glm::mat4 &ModelMatrix, const glm::mat4 &MVP);
bool AddSplitRequest(SSplitRequestDescription *desc);
void ProcessSplitRequests();
void ProcessSplitResults();
size_t GetNumberOfHeightmapGenerators() const;
size_t GetCurrentHeightmapProgIndex() const;
void Reset(const size_t newGeneratorIndex);
size_t GetNumSplitRequestsPending() const { return mSplitRequestDescriptions.size(); }
size_t GetNumSplitResultsPending() const { return mSplitResult.size(); }
};
#endif //__TERRAINMESH_H__