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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include "UnityPrefix.h"
#include "CullResults.h"
#include "ShadowCulling.h"//@TODO: Remove
#include "UmbraBackwardsCompatibility.h"
CullResults::CullResults() : shadowCullData(NULL), treeSceneNodes(kMemTempAlloc), treeBoundingBoxes(kMemTempAlloc)
{
}
CullResults::~CullResults()
{
Umbra::Visibility* umbra = sceneCullingOutput.umbraVisibility;
if (umbra != NULL)
{
int* clusterBuffer = (int*)umbra->getOutputClusters()->getPtr();
UNITY_FREE(kMemTempAlloc, clusterBuffer);
Umbra::IndexList* outputObjects = umbra->getOutputObjects();
Umbra::OcclusionBuffer* outputBuffer = umbra->getOutputBuffer();
Umbra::IndexList* outputCluster = umbra->getOutputClusters();
UNITY_DELETE(outputObjects, kMemTempAlloc);
UNITY_DELETE(outputBuffer, kMemTempAlloc);
UNITY_DELETE(outputCluster, kMemTempAlloc);
UNITY_DELETE(umbra, kMemTempAlloc);
}
DestroyCullingOutput(sceneCullingOutput);
UNITY_DELETE(shadowCullData, kMemTempAlloc);
}
void InitIndexList (IndexList& list, size_t count)
{
int* array = (int*)UNITY_MALLOC (kMemTempAlloc, count * sizeof(int));
list = IndexList (array, 0, count);
}
void DestroyIndexList (IndexList& list)
{
UNITY_FREE(kMemTempAlloc, list.indices);
list.indices = NULL;
}
void CreateCullingOutput (const RendererCullData* rendererCullData, CullingOutput& cullingOutput)
{
for(int i=0;i<kVisibleListCount;i++)
InitIndexList(cullingOutput.visible[i], rendererCullData[i].rendererCount);
}
void DestroyCullingOutput (CullingOutput& cullingOutput)
{
for (int i=0;i<kVisibleListCount;i++)
DestroyIndexList (cullingOutput.visible[i]);
}
void CullResults::Init (const UmbraTomeData& tomeData, const RendererCullData* rendererCullData)
{
CreateCullingOutput(rendererCullData, sceneCullingOutput);
if (tomeData.tome != NULL)
{
size_t staticCount = rendererCullData[kStaticRenderers].rendererCount;
Assert(staticCount == 0 || staticCount == UMBRA_TOME_METHOD(tomeData, getObjectCount()));
size_t clusterCount = UMBRA_TOME_METHOD(tomeData, getClusterCount());
int* clusterArray = (int*)UNITY_MALLOC(kMemTempAlloc, clusterCount * sizeof(int));
Umbra::IndexList* staticList = UNITY_NEW(Umbra::IndexList (sceneCullingOutput.visible[kStaticRenderers].indices, staticCount), kMemTempAlloc);
Umbra::OcclusionBuffer* occlusionBuffer = UNITY_NEW(Umbra::OcclusionBuffer, kMemTempAlloc);
Umbra::Visibility* umbraVisibility = UNITY_NEW(Umbra::Visibility(staticList, occlusionBuffer), kMemTempAlloc);
Umbra::IndexList* clusterList = UNITY_NEW(Umbra::IndexList (clusterArray, clusterCount), kMemTempAlloc);
umbraVisibility->setOutputClusters(clusterList);
sceneCullingOutput.umbraVisibility = umbraVisibility;
}
else
{
sceneCullingOutput.umbraVisibility = NULL;
}
}
|