summaryrefslogtreecommitdiff
path: root/Runtime/Terrain/ImposterRenderTexture.h
blob: de7714f9b0d21e7ef2c50c0f6aba298b3689a01b (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
57
58
59
60
61
62
63
64
65
#pragma once
#include "Configuration/UnityConfigure.h"

#if ENABLE_TERRAIN

#include "TreeDatabase.h"
#include "Runtime/Math/Rect.h"
#include <vector>


class RenderTexture;
class Camera;


class ImposterRenderTexture
{
public:
	ImposterRenderTexture(const TreeDatabase& treeDB);
	~ImposterRenderTexture();
		
	const Rectf& GetArea(int index) const {
		return m_Areas[index];
	}	

	RenderTexture* GetTexture() const { return m_Texture; }
	bool GetSupported() const { return m_Supported; }

	void UpdateImposters(const Camera& mainCamera);

	void InvalidateAngles () 
	{
		m_AngleX = std::numeric_limits<float>::infinity();
		m_AngleY = std::numeric_limits<float>::infinity();
	}

	const Matrix4x4f& getCameraOrientation() const { return m_CameraOrientationMatrix; }

	void GetBillboardParams(float& angleFactor, float& offsetFactor) const;
private:
	void UpdateImposter(const Rectf& rect, const TreeDatabase::Prototype& prototype);

private:
	const TreeDatabase&	m_TreeDatabase;

	std::vector<Rectf> m_Areas;
	Camera* m_Camera;
	RenderTexture* m_Texture;
	bool		m_Supported;

	float    m_AngleX;
	float    m_AngleY;

	int 		    m_ImposterHeight;
	int 		    m_MaxImposterSize;

	Matrix4x4f m_CameraOrientationMatrix;

	static void InvalidateRenderTexture(void* userData) {
		((ImposterRenderTexture*)userData)->InvalidateAngles();
	}
};

#endif // ENABLE_TERRAIN