summaryrefslogtreecommitdiff
path: root/Runtime/Terrain/DetailRenderer.h
blob: 2e11fe2c3aa8123ecc0741389a2042a1d9ac5c43 (plain)
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
#pragma once
#include "Configuration/UnityConfigure.h"

#if ENABLE_TERRAIN

#include "Runtime/Filters/Mesh/LodMesh.h"
#include "TerrainData.h"
#include "Runtime/Shaders/Material.h"
#include "Runtime/Camera/Camera.h"
#include "Runtime/Utilities/MemoryPool.h"

class DetailPatchRender
{
public:
	Mesh *mesh;
	bool isCulledVisible;
	bool isMeshNull;
	bool inited;
	int lastUsed;
	int x;
	int y;
	
	DetailPatchRender() { inited = false; mesh = NULL; }	
	~DetailPatchRender() { DestroySingleObject (mesh); }
};

class DetailRenderer 
{
public: 
	Material *m_Materials[kDetailRenderModeCount];
	
	DetailRenderer (PPtr<TerrainData> terrain, Vector3f position, int lightmapIndex);
	void Render (Camera *camera, float viewDistance, int layer, float detailDensity);
	void Cleanup ();
	void ReloadAllDetails();
	void ReloadDirtyDetails();

	int GetLightmapIndex() { return m_LightmapIndex; }
	void SetLightmapIndex(int value) { m_LightmapIndex = value; }

private:
	typedef std::map<UInt32,DetailPatchRender, std::less<UInt32> ,memory_pool<std::pair<const UInt32, DetailPatchRender> > > DetailList;

	PPtr<TerrainData> m_Database;
	Vector3f m_TerrainSize;
	UInt8 m_LightmapIndex;

	DetailList m_Patches[kDetailRenderModeCount];
	Vector3f m_Position;
	int m_RenderCount;
	float m_LastTime;

	DetailPatchRender& GrabCachedPatch (int x, int y, int lightmapIndex, DetailRenderMode mode, float density);
};

#endif // ENABLE_TERRAIN