forked from pioneerspacesim/pioneer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeoPatchContext.h
75 lines (55 loc) · 1.86 KB
/
GeoPatchContext.h
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
// Copyright © 2008-2018 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#ifndef _GEOPATCHCONTEXT_H
#define _GEOPATCHCONTEXT_H
#include <SDL_stdinc.h>
#include "vector3.h"
#include "Random.h"
#include "galaxy/StarSystem.h"
#include "graphics/Material.h"
#include "graphics/VertexBuffer.h"
#include "terrain/Terrain.h"
#include "GeoPatchID.h"
#include <deque>
// maximumpatch depth
#define GEOPATCH_MAX_DEPTH 15 + (2*Pi::detail.fracmult) //15
namespace Graphics { class Renderer; }
class SystemBody;
class GeoPatch;
class GeoSphere;
class GeoPatchContext : public RefCounted {
private:
static int edgeLen;
static int numTris;
static double frac;
static inline int VBO_COUNT_HI_EDGE() { return 3*(edgeLen-1); }
static inline int VBO_COUNT_MID_IDX() { return (4*3*(edgeLen-3)) + 2*(edgeLen-3)*(edgeLen-3)*3; }
// ^^ serrated teeth bit ^^^ square inner bit
static inline int IDX_VBO_LO_OFFSET(const int i) { return i*sizeof(Uint32)*3*(edgeLen/2); }
static inline int IDX_VBO_HI_OFFSET(const int i) { return (i*sizeof(Uint32)*VBO_COUNT_HI_EDGE())+IDX_VBO_LO_OFFSET(4); }
static RefCountedPtr<Graphics::IndexBuffer> indices;
static int prevEdgeLen;
static void GenerateIndices();
public:
struct VBOVertex
{
vector3f pos;
vector3f norm;
Color4ub col;
vector2f uv;
};
GeoPatchContext(const int _edgeLen) {
edgeLen = _edgeLen + 2; // +2 for the skirt
Init();
}
static void Refresh() {
Init();
}
static void Init();
static inline Graphics::IndexBuffer* GetIndexBuffer() { return indices.Get(); }
static inline int NUMVERTICES() { return edgeLen*edgeLen; }
static inline int GetEdgeLen() { return edgeLen; }
static inline int GetNumTris() { return numTris; }
static inline double GetFrac() { return frac; }
};
#endif /* _GEOPATCHCONTEXT_H */