2019-01-02 01:47:08 -08:00
|
|
|
// Copyright © 2008-2019 Pioneer Developers. See AUTHORS.txt for details
|
2013-03-10 12:59:08 -07:00
|
|
|
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
|
|
|
|
|
|
|
|
#ifndef _GEOPATCH_H
|
|
|
|
#define _GEOPATCH_H
|
|
|
|
|
|
|
|
#include <SDL_stdinc.h>
|
|
|
|
|
|
|
|
#include "vector3.h"
|
|
|
|
#include "Random.h"
|
|
|
|
#include "galaxy/StarSystem.h"
|
2015-12-13 14:05:00 -08:00
|
|
|
#include "graphics/Frustum.h"
|
2013-03-10 12:59:08 -07:00
|
|
|
#include "graphics/Material.h"
|
|
|
|
#include "terrain/Terrain.h"
|
|
|
|
#include "GeoPatchID.h"
|
2013-04-23 15:46:32 -07:00
|
|
|
#include "JobQueue.h"
|
2013-03-10 12:59:08 -07:00
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
|
2014-10-11 08:24:50 -07:00
|
|
|
// #define DEBUG_BOUNDING_SPHERES
|
|
|
|
|
2015-12-13 14:05:00 -08:00
|
|
|
namespace Graphics { class Renderer; }
|
2013-03-10 12:59:08 -07:00
|
|
|
class SystemBody;
|
|
|
|
class GeoPatchContext;
|
|
|
|
class GeoSphere;
|
2013-03-27 14:33:37 -07:00
|
|
|
class BasePatchJob;
|
2013-04-01 07:38:03 -07:00
|
|
|
class SQuadSplitResult;
|
2013-03-27 14:33:37 -07:00
|
|
|
class SSingleSplitResult;
|
2013-03-24 13:55:35 -07:00
|
|
|
|
2013-03-20 13:21:26 -07:00
|
|
|
class GeoPatch {
|
2014-10-11 08:24:50 -07:00
|
|
|
private:
|
2015-12-13 07:04:49 -08:00
|
|
|
static const int NUM_KIDS = 4;
|
2013-03-10 12:59:08 -07:00
|
|
|
|
|
|
|
RefCountedPtr<GeoPatchContext> ctx;
|
|
|
|
const vector3d v0, v1, v2, v3;
|
2013-10-29 04:44:49 -07:00
|
|
|
std::unique_ptr<double[]> heights;
|
|
|
|
std::unique_ptr<vector3f[]> normals;
|
|
|
|
std::unique_ptr<Color3ub[]> colors;
|
2014-03-01 05:04:18 -08:00
|
|
|
std::unique_ptr<Graphics::VertexBuffer> m_vertexBuffer;
|
2013-10-29 04:44:49 -07:00
|
|
|
std::unique_ptr<GeoPatch> kids[NUM_KIDS];
|
2013-03-10 12:59:08 -07:00
|
|
|
GeoPatch *parent;
|
|
|
|
GeoSphere *geosphere;
|
|
|
|
double m_roughLength;
|
|
|
|
vector3d clipCentroid, centroid;
|
|
|
|
double clipRadius;
|
2014-03-01 05:04:18 -08:00
|
|
|
Sint32 m_depth;
|
2013-03-10 12:59:08 -07:00
|
|
|
bool m_needUpdateVBOs;
|
|
|
|
|
|
|
|
const GeoPatchID mPatchID;
|
2014-04-18 08:28:18 -07:00
|
|
|
Job::Handle m_job;
|
2013-04-01 12:28:48 -07:00
|
|
|
bool mHasJobRequest;
|
2014-10-11 08:24:50 -07:00
|
|
|
#ifdef DEBUG_BOUNDING_SPHERES
|
|
|
|
std::unique_ptr<Graphics::Drawables::Sphere3D> m_boundsphere;
|
|
|
|
#endif
|
|
|
|
public:
|
2013-03-10 12:59:08 -07:00
|
|
|
|
2013-06-29 08:44:43 -07:00
|
|
|
GeoPatch(const RefCountedPtr<GeoPatchContext> &_ctx, GeoSphere *gs,
|
|
|
|
const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_,
|
2013-03-10 12:59:08 -07:00
|
|
|
const int depth, const GeoPatchID &ID_);
|
|
|
|
|
|
|
|
~GeoPatch();
|
|
|
|
|
2015-06-15 14:14:22 -07:00
|
|
|
inline void NeedToUpdateVBOs() {
|
2013-10-29 04:44:49 -07:00
|
|
|
m_needUpdateVBOs = (nullptr != heights);
|
2013-03-10 12:59:08 -07:00
|
|
|
}
|
|
|
|
|
2015-06-15 14:14:22 -07:00
|
|
|
void UpdateVBOs(Graphics::Renderer *renderer);
|
2013-03-10 12:59:08 -07:00
|
|
|
|
|
|
|
int GetChildIdx(const GeoPatch *child) const {
|
2013-04-23 14:36:54 -07:00
|
|
|
for (int i=0; i<NUM_KIDS; i++) {
|
2013-10-29 04:44:49 -07:00
|
|
|
if (kids[i].get() == child) return i;
|
2013-03-10 12:59:08 -07:00
|
|
|
}
|
|
|
|
abort();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-29 08:44:43 -07:00
|
|
|
// in patch surface coords, [0,1]
|
2013-03-10 12:59:08 -07:00
|
|
|
inline vector3d GetSpherePoint(const double x, const double y) const {
|
|
|
|
return (v0 + x*(1.0-y)*(v1-v0) + x*y*(v2-v0) + (1.0-x)*y*(v3-v0)).Normalized();
|
|
|
|
}
|
|
|
|
|
2013-06-29 08:44:43 -07:00
|
|
|
void Render(Graphics::Renderer *r, const vector3d &campos, const matrix4x4d &modelView, const Graphics::Frustum &frustum);
|
2013-04-01 07:38:03 -07:00
|
|
|
|
2013-04-01 12:28:48 -07:00
|
|
|
inline bool canBeMerged() const {
|
|
|
|
bool merge = true;
|
2013-10-29 04:44:49 -07:00
|
|
|
if (kids[0]) {
|
2013-04-23 14:36:54 -07:00
|
|
|
for (int i=0; i<NUM_KIDS; i++) {
|
2013-04-01 12:28:48 -07:00
|
|
|
merge &= kids[i]->canBeMerged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
merge &= !(mHasJobRequest);
|
|
|
|
return merge;
|
2013-04-01 07:38:03 -07:00
|
|
|
}
|
|
|
|
|
2015-12-13 14:05:00 -08:00
|
|
|
void LODUpdate(const vector3d &campos, const Graphics::Frustum &frustum);
|
2013-06-29 08:44:43 -07:00
|
|
|
|
2013-03-24 13:55:35 -07:00
|
|
|
void RequestSinglePatch();
|
2013-05-08 11:22:41 -07:00
|
|
|
void ReceiveHeightmaps(SQuadSplitResult *psr);
|
2013-03-24 13:55:35 -07:00
|
|
|
void ReceiveHeightmap(const SSingleSplitResult *psr);
|
2015-07-13 03:34:46 -07:00
|
|
|
void ReceiveJobHandle(Job::Handle job);
|
2014-10-11 08:24:50 -07:00
|
|
|
|
|
|
|
inline bool HasHeightData() const { return (heights.get()!=nullptr); }
|
2013-03-10 12:59:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _GEOPATCH_H */
|