Pioneer
GeoPatch.h
Go to the documentation of this file.
1// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#ifndef _GEOPATCH_H
5#define _GEOPATCH_H
6
7#include <SDL_stdinc.h>
8
9#include "Color.h"
10#include "GeoPatchID.h"
11#include "JobQueue.h"
12#include "RefCounted.h"
13#include "matrix4x4.h"
14#include "vector3.h"
15#include <deque>
16#include <memory>
17
18//#define DEBUG_BOUNDING_SPHERES
19
20#ifdef DEBUG_BOUNDING_SPHERES
21#include "graphics/Drawables.h"
22namespace Graphics {
23 class RenderState;
24}
25#endif
26
27namespace Graphics {
28 class Renderer;
29 class Frustum;
30 class MeshObject;
31} // namespace Graphics
32
33class GeoPatchContext;
34class GeoSphere;
35class BasePatchJob;
38
39class GeoPatch {
40public:
42 const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_,
43 const int depth, const GeoPatchID &ID_);
44
45 ~GeoPatch();
46
47 inline void NeedToUpdateVBOs()
48 {
49 m_needUpdateVBOs = (nullptr != m_heights);
50 }
51
52 void UpdateVBOs(Graphics::Renderer *renderer);
53
54 int GetChildIdx(const GeoPatch *child) const
55 {
56 for (int i = 0; i < NUM_KIDS; i++) {
57 if (m_kids[i].get() == child) return i;
58 }
59 abort();
60 return -1;
61 }
62
63 // in patch surface coords, [0,1]
64 inline vector3d GetSpherePoint(const double x, const double y) const
65 {
66 return (m_v0 + x * (1.0 - y) * (m_v1 - m_v0) + x * y * (m_v2 - m_v0) + (1.0 - x) * y * (m_v3 - m_v0)).Normalized();
67 }
68
69 void Render(Graphics::Renderer *r, const vector3d &campos, const matrix4x4d &modelView, const Graphics::Frustum &frustum);
70
71 inline bool canBeMerged() const
72 {
73 bool merge = true;
74 if (m_kids[0]) {
75 for (int i = 0; i < NUM_KIDS; i++) {
76 merge &= m_kids[i]->canBeMerged();
77 }
78 }
79 merge &= !(m_HasJobRequest);
80 return merge;
81 }
82
83 void LODUpdate(const vector3d &campos, const Graphics::Frustum &frustum);
84
85 void RequestSinglePatch();
87 void ReceiveHeightmap(const SSingleSplitResult *psr);
89
90 inline bool HasHeightData() const { return (m_heights.get() != nullptr); }
91
92private:
93 static const int NUM_KIDS = 4;
94
96 const vector3d m_v0, m_v1, m_v2, m_v3;
97 std::unique_ptr<double[]> m_heights;
98 std::unique_ptr<vector3f[]> m_normals;
99 std::unique_ptr<Color3ub[]> m_colors;
100 std::unique_ptr<Graphics::MeshObject> m_patchMesh;
101 std::unique_ptr<GeoPatch> m_kids[NUM_KIDS];
102 GeoPatch *m_parent;
103 GeoSphere *m_geosphere;
104 double m_roughLength;
105 vector3d m_clipCentroid, m_centroid;
106 double m_clipRadius;
107 Sint32 m_depth;
108 bool m_needUpdateVBOs;
109
110 const GeoPatchID m_PatchID;
111 Job::Handle m_job;
112 bool m_HasJobRequest;
113#ifdef DEBUG_BOUNDING_SPHERES
114 std::unique_ptr<Graphics::Drawables::Sphere3D> m_boundsphere;
115#endif
116};
117
118#endif /* _GEOPATCH_H */
Definition: GeoPatchJobs.h:258
Definition: GeoPatchContext.h:18
Definition: GeoPatchID.h:9
Definition: GeoPatch.h:39
vector3d GetSpherePoint(const double x, const double y) const
Definition: GeoPatch.h:64
void UpdateVBOs(Graphics::Renderer *renderer)
Definition: GeoPatch.cpp:78
void Render(Graphics::Renderer *r, const vector3d &campos, const matrix4x4d &modelView, const Graphics::Frustum &frustum)
Definition: GeoPatch.cpp:257
void NeedToUpdateVBOs()
Definition: GeoPatch.h:47
bool canBeMerged() const
Definition: GeoPatch.h:71
void ReceiveJobHandle(Job::Handle job)
Definition: GeoPatch.cpp:441
void ReceiveHeightmaps(SQuadSplitResult *psr)
Definition: GeoPatch.cpp:387
GeoPatch(const RefCountedPtr< GeoPatchContext > &_ctx, GeoSphere *gs, const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const int depth, const GeoPatchID &ID_)
Definition: GeoPatch.cpp:32
~GeoPatch()
Definition: GeoPatch.cpp:67
void RequestSinglePatch()
Definition: GeoPatch.cpp:376
void LODUpdate(const vector3d &campos, const Graphics::Frustum &frustum)
Definition: GeoPatch.cpp:308
bool HasHeightData() const
Definition: GeoPatch.h:90
void ReceiveHeightmap(const SSingleSplitResult *psr)
Definition: GeoPatch.cpp:426
int GetChildIdx(const GeoPatch *child) const
Definition: GeoPatch.h:54
Definition: GeoSphere.h:29
Definition: Frustum.h:17
Definition: Renderer.h:44
Definition: JobQueue.h:39
Definition: GeoPatchJobs.h:170
Definition: GeoPatchJobs.h:213
vector3 Normalized() const
Definition: vector3.h:121
Definition: Background.h:14