From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Terrain/DetailRenderer.h | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Runtime/Terrain/DetailRenderer.h (limited to 'Runtime/Terrain/DetailRenderer.h') diff --git a/Runtime/Terrain/DetailRenderer.h b/Runtime/Terrain/DetailRenderer.h new file mode 100644 index 0000000..2e11fe2 --- /dev/null +++ b/Runtime/Terrain/DetailRenderer.h @@ -0,0 +1,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 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 ,memory_pool > > DetailList; + + PPtr 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 -- cgit v1.1-26-g67d0