Pioneer
Loading...
Searching...
No Matches
GeoPatch.h
Go to the documentation of this file.
1// Copyright © 2008-2023 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;
38struct SSplitResultData;
39
40class GeoPatch {
41public:
43 const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_,
44 const int depth, const GeoPatchID &ID_);
45
46 ~GeoPatch();
47
48 inline void NeedToUpdateVBOs()
49 {
50 m_needUpdateVBOs = (nullptr != m_heights);
51 }
52
53 void UpdateVBOs(Graphics::Renderer *renderer);
54
55 int GetChildIdx(const GeoPatch *child) const
56 {
57 for (int i = 0; i < NUM_KIDS; i++) {
58 if (m_kids[i].get() == child) return i;
59 }
60 abort();
61 return -1;
62 }
63
64 // in patch surface coords, [0,1]
65 inline vector3d GetSpherePoint(const double x, const double y) const
66 {
67 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();
68 }
69
70 void Render(Graphics::Renderer *r, const vector3d &campos, const matrix4x4d &modelView, const Graphics::Frustum &frustum);
71
72 inline bool canBeMerged() const
73 {
74 bool merge = true;
75 if (m_kids[0]) {
76 for (int i = 0; i < NUM_KIDS; i++) {
77 merge &= m_kids[i]->canBeMerged();
78 }
79 }
80 merge &= !(m_HasJobRequest);
81 return merge;
82 }
83
84 void LODUpdate(const vector3d &campos, const Graphics::Frustum &frustum);
85
86 void RequestSinglePatch();
88 void ReceiveHeightmap(const SSingleSplitResult *psr);
89 void ReceiveHeightResult(const SSplitResultData &data);
91
92 inline bool HasHeightData() const { return (m_heights.get() != nullptr); }
93
94private:
95 static const int NUM_KIDS = 4;
96
98 const vector3d m_v0, m_v1, m_v2, m_v3;
99 std::unique_ptr<double[]> m_heights;
100 std::unique_ptr<vector3f[]> m_normals;
101 std::unique_ptr<Color3ub[]> m_colors;
102 std::unique_ptr<Graphics::MeshObject> m_patchMesh;
103 std::unique_ptr<GeoPatch> m_kids[NUM_KIDS];
104 GeoPatch *m_parent;
105 GeoSphere *m_geosphere;
106 double m_roughLength;
107 vector3d m_clipCentroid, m_centroid;
108 double m_clipRadius;
109 Sint32 m_depth;
110 bool m_needUpdateVBOs;
111
112 const GeoPatchID m_PatchID;
113 Job::Handle m_job;
114 bool m_HasJobRequest;
115#ifdef DEBUG_BOUNDING_SPHERES
116 std::unique_ptr<Graphics::Drawables::Sphere3D> m_boundsphere;
117#endif
118};
119
120#endif /* _GEOPATCH_H */
Definition GeoPatchJobs.h:258
Definition GeoPatchContext.h:18
Definition GeoPatchID.h:9
Definition GeoPatch.h:40
vector3d GetSpherePoint(const double x, const double y) const
Definition GeoPatch.h:65
void UpdateVBOs(Graphics::Renderer *renderer)
Definition GeoPatch.cpp:84
void Render(Graphics::Renderer *r, const vector3d &campos, const matrix4x4d &modelView, const Graphics::Frustum &frustum)
Definition GeoPatch.cpp:263
void NeedToUpdateVBOs()
Definition GeoPatch.h:48
bool canBeMerged() const
Definition GeoPatch.h:72
void ReceiveJobHandle(Job::Handle job)
Definition GeoPatch.cpp:463
void ReceiveHeightmaps(SQuadSplitResult *psr)
Definition GeoPatch.cpp:399
~GeoPatch()
Definition GeoPatch.cpp:73
void RequestSinglePatch()
Definition GeoPatch.cpp:388
void LODUpdate(const vector3d &campos, const Graphics::Frustum &frustum)
Definition GeoPatch.cpp:320
void ReceiveHeightResult(const SSplitResultData &data)
Definition GeoPatch.cpp:443
bool HasHeightData() const
Definition GeoPatch.h:92
void ReceiveHeightmap(const SSingleSplitResult *psr)
Definition GeoPatch.cpp:432
int GetChildIdx(const GeoPatch *child) const
Definition GeoPatch.h:55
Definition GeoSphere.h:29
Definition Frustum.h:17
Definition Renderer.h:44
Definition JobQueue.h:39
Definition RefCounted.h:36
Definition GeoPatchJobs.h:170
Definition GeoPatchJobs.h:213
vector3 Normalized() const
Definition vector3.h:125
Definition Background.h:14
Definition GeoPatchJobs.h:127