aboutsummaryrefslogtreecommitdiff
path: root/APEX_1.4/module/iofx/src/RenderVolumeImpl.cpp
blob: 4138d30ed9e647f1586f0fd93f47b2db722440ed (plain) (blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright (c) 2008-2015, NVIDIA CORPORATION.  All rights reserved.
 *
 * NVIDIA CORPORATION and its licensors retain all intellectual property
 * and proprietary rights in and to this software, related documentation
 * and any modifications thereto.  Any use, reproduction, disclosure or
 * distribution of this software and related documentation without an express
 * license agreement from NVIDIA CORPORATION is strictly prohibited.
 */


#include "Apex.h"

#include "RenderVolumeImpl.h"
#include "ModuleIofxImpl.h"
#include "IofxAssetImpl.h"
#include "IofxActorImpl.h"
#include "IofxScene.h"
#include "SceneIntl.h"

#include "PsArray.h"

namespace nvidia
{
namespace iofx
{

RenderVolumeImpl::RenderVolumeImpl(IofxScene& scene, const PxBounds3& b, uint32_t priority, bool allIofx)
	: mPriority(priority)
	, mAllIofx(allIofx)
	, mPendingDelete(false)
	, mScene(scene)
{
	setOwnershipBounds(b);

	mScene.mAddedRenderVolumesLock.lock();
	mScene.mAddedRenderVolumes.pushBack(this);
	mScene.mAddedRenderVolumesLock.unlock();
}

RenderVolumeImpl::~RenderVolumeImpl()
{
	mLock.lockWriter();
	while (mIofxActors.size())
	{
		IofxActor* iofx = mIofxActors.popBack();
		iofx->release();
	}
	mLock.unlockWriter();
}

void RenderVolumeImpl::destroy()
{
	if (!mPendingDelete)
	{
		mPendingDelete = true;

		mScene.mDeletedRenderVolumesLock.lock();
		mScene.mDeletedRenderVolumes.pushBack(this);
		mScene.mDeletedRenderVolumesLock.unlock();
	}
}

void RenderVolumeImpl::release()
{
	if (!mPendingDelete)
	{
		mScene.mModule->releaseRenderVolume(*this);
	}
}

bool RenderVolumeImpl::addIofxAsset(IofxAsset& iofx)
{
	WRITE_ZONE();
	if (mAllIofx || mPendingDelete)
	{
		return false;
	}

	mLock.lockWriter();
	mIofxAssets.pushBack(&iofx);
	mLock.unlockWriter();
	return true;
}

bool RenderVolumeImpl::addIofxActor(IofxActor& iofx)
{
	if (mPendingDelete)
	{
		return false;
	}

	mLock.lockWriter();
	mIofxActors.pushBack(&iofx);
	mLock.unlockWriter();
	return true;
}

bool RenderVolumeImpl::removeIofxActor(const IofxActor& iofx)
{
	bool res = false;
	mLock.lockWriter();
	for (uint32_t i = 0 ; i < mIofxActors.size() ; i++)
	{
		if (mIofxActors[ i ] == &iofx)
		{
			mIofxActors.replaceWithLast(i);
			res = true;
			break;
		}
	}
	mLock.unlockWriter();
	return res;
}

void RenderVolumeImpl::setPosition(const PxVec3& pos)
{
	WRITE_ZONE();
	PxVec3 ext = mOwnershipBounds.getExtents();
	mOwnershipBounds = physx::PxBounds3(pos - ext, pos + ext);
}

PxBounds3 RenderVolumeImpl::getBounds() const
{
	READ_ZONE();
	if (mPendingDelete)
	{
		return PxBounds3::empty();
	}

	PxBounds3 b = PxBounds3::empty();
	nvidia::Array<IofxActor*>::ConstIterator i;
	for (i = mIofxActors.begin() ; i != mIofxActors.end() ; i++)
	{
		b.include((*i)->getBounds());
	}

	return b;
}

// Callers must acquire render lock for thread safety
bool RenderVolumeImpl::affectsIofxAsset(const IofxAsset& iofx) const
{
	READ_ZONE();
	if (mPendingDelete)
	{
		return false;
	}

	if (mAllIofx)
	{
		return true;
	}

	nvidia::Array<IofxAsset*>::ConstIterator i;
	for (i = mIofxAssets.begin() ; i != mIofxAssets.end() ; i++)
	{
		if (&iofx == *i)
		{
			return true;
		}
	}

	return false;
}

}
} // namespace nvidia