2020-12-31 07:32:16 -08:00
|
|
|
// Copyright © 2008-2021 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>
|
|
|
|
|
2019-10-16 12:10:22 -07:00
|
|
|
#include "Color.h"
|
2019-01-02 08:59:07 -08:00
|
|
|
#include "GeoPatchID.h"
|
|
|
|
#include "JobQueue.h"
|
2019-10-16 12:10:22 -07:00
|
|
|
#include "RefCounted.h"
|
|
|
|
#include "matrix4x4.h"
|
2019-01-02 08:59:07 -08:00
|
|
|
#include "vector3.h"
|
2013-03-10 12:59:08 -07:00
|
|
|
#include <deque>
|
2019-10-16 12:10:22 -07:00
|
|
|
#include <memory>
|
2013-03-10 12:59:08 -07:00
|
|
|
|
2019-05-27 14:03:58 -07:00
|
|
|
//#define DEBUG_BOUNDING_SPHERES
|
|
|
|
|
|
|
|
#ifdef DEBUG_BOUNDING_SPHERES
|
|
|
|
#include "graphics/Drawables.h"
|
|
|
|
namespace Graphics {
|
|
|
|
class RenderState;
|
|
|
|
}
|
|
|
|
#endif
|
2014-10-11 08:24:50 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
namespace Graphics {
|
|
|
|
class Renderer;
|
2019-05-03 17:53:44 -07:00
|
|
|
class Frustum;
|
2019-10-16 12:10:22 -07:00
|
|
|
class VertexBuffer;
|
2019-01-02 08:59:07 -08:00
|
|
|
}
|
2019-05-27 10:47:21 -07:00
|
|
|
|
2013-03-10 12:59:08 -07:00
|
|
|
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
|
|
|
public:
|
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();
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
inline void NeedToUpdateVBOs()
|
|
|
|
{
|
2019-05-27 10:42:54 -07:00
|
|
|
m_needUpdateVBOs = (nullptr != m_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
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
int GetChildIdx(const GeoPatch *child) const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_KIDS; i++) {
|
2019-05-27 10:42:54 -07:00
|
|
|
if (m_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]
|
2019-01-02 08:59:07 -08:00
|
|
|
inline vector3d GetSpherePoint(const double x, const double y) const
|
|
|
|
{
|
2019-05-27 10:42:54 -07:00
|
|
|
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();
|
2013-03-10 12:59:08 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
inline bool canBeMerged() const
|
|
|
|
{
|
2013-04-01 12:28:48 -07:00
|
|
|
bool merge = true;
|
2019-05-27 10:42:54 -07:00
|
|
|
if (m_kids[0]) {
|
2019-01-02 08:59:07 -08:00
|
|
|
for (int i = 0; i < NUM_KIDS; i++) {
|
2019-05-27 10:42:54 -07:00
|
|
|
merge &= m_kids[i]->canBeMerged();
|
2013-04-01 12:28:48 -07:00
|
|
|
}
|
|
|
|
}
|
2019-05-27 10:42:54 -07:00
|
|
|
merge &= !(m_HasJobRequest);
|
2013-04-01 12:28:48 -07:00
|
|
|
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
|
|
|
|
2019-05-27 10:42:54 -07:00
|
|
|
inline bool HasHeightData() const { return (m_heights.get() != nullptr); }
|
|
|
|
private:
|
|
|
|
static const int NUM_KIDS = 4;
|
|
|
|
|
|
|
|
RefCountedPtr<GeoPatchContext> m_ctx;
|
|
|
|
const vector3d m_v0, m_v1, m_v2, m_v3;
|
|
|
|
std::unique_ptr<double[]> m_heights;
|
|
|
|
std::unique_ptr<vector3f[]> m_normals;
|
|
|
|
std::unique_ptr<Color3ub[]> m_colors;
|
|
|
|
std::unique_ptr<Graphics::VertexBuffer> m_vertexBuffer;
|
|
|
|
std::unique_ptr<GeoPatch> m_kids[NUM_KIDS];
|
|
|
|
GeoPatch *m_parent;
|
|
|
|
GeoSphere *m_geosphere;
|
|
|
|
double m_roughLength;
|
|
|
|
vector3d m_clipCentroid, m_centroid;
|
|
|
|
double m_clipRadius;
|
|
|
|
Sint32 m_depth;
|
|
|
|
bool m_needUpdateVBOs;
|
|
|
|
|
|
|
|
const GeoPatchID m_PatchID;
|
|
|
|
Job::Handle m_job;
|
|
|
|
bool m_HasJobRequest;
|
|
|
|
#ifdef DEBUG_BOUNDING_SPHERES
|
|
|
|
std::unique_ptr<Graphics::Drawables::Sphere3D> m_boundsphere;
|
|
|
|
#endif
|
2013-03-10 12:59:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _GEOPATCH_H */
|