aboutsummaryrefslogtreecommitdiff
path: root/APEX_1.4/module/iofx/src/IofxActorImpl.cpp
blob: 6996e8808c9283fc4fca5275d1e678500c61dea4 (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
/*
 * 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 "ApexSDKIntl.h"
#include "SceneIntl.h"
#include "IofxActor.h"
#include "IofxActorImpl.h"
#include "IofxSceneCPU.h"
#include "IofxSceneGPU.h"
#include "RenderVolumeImpl.h"
#include "IosObjectData.h"
#include "IofxRenderData.h"

#include "ModuleIofxImpl.h"

namespace nvidia
{
namespace iofx
{

IofxActorImpl::IofxActorImpl(ResID renderResID, IofxScene* iscene, IofxManager& mgr)
	: mRenderResID(renderResID)
	, mIofxScene(iscene)
	, mMgr(mgr)
	, mRenderVolume(NULL) // IOS will set this after creation
	, mSemantics(0)
	, mActiveRenderable(NULL)
{
	//asset.add(*this);

	mResultBounds.setEmpty();
	mResultRange.startIndex = 0;
	mResultRange.objectCount = 0;
	mResultVisibleCount = 0;

	addSelfToContext(*iscene->mApexScene->getApexContext());    // Add self to ApexScene
	addSelfToContext(*iscene);							      // Add self to IofxScene
}

IofxActorImpl::~IofxActorImpl()
{
}

void IofxActorImpl::getLodRange(float& min, float& max, bool& intOnly) const
{
	READ_ZONE();
	PX_UNUSED(min);
	PX_UNUSED(max);
	PX_UNUSED(intOnly);
	APEX_INVALID_OPERATION("not implemented");
}


float IofxActorImpl::getActiveLod() const
{
	READ_ZONE();
	APEX_INVALID_OPERATION("BasicIosActor does not support this operation");
	return -1.0f;
}


void IofxActorImpl::forceLod(float lod)
{
	WRITE_ZONE();
	PX_UNUSED(lod);
	APEX_INVALID_OPERATION("not implemented");
}

void IofxActorImpl::release()
{
	if (mInRelease)
	{
		return;
	}
	mInRelease = true;
	destroy();
}


void IofxActorImpl::destroy()
{
	if (mRenderVolume)
	{
		mRenderVolume->removeIofxActor(*this);
	}

	// Removes self from scenes and IOFX manager
	// should be called after mRenderVolume->removeIofxActor to avoid dead-lock!!!
	ApexActor::destroy();

	for (uint32_t i = 0 ; i < mRenderableArray.size() ; i++)
	{
		IofxRenderableImpl* renderable = mRenderableArray[i];
		if (renderable != NULL)
		{
			renderable->release();
		}
	}
	mRenderableArray.clear();

	delete this;
}

bool IofxActorImpl::prepareRenderables(IosObjectBaseData* obj)
{
	if (mResultRange.objectCount > 0 && obj->renderData->checkSemantics(mSemantics))
	{
		const uint32_t instanceID = obj->renderData->getInstanceID();
		if (mRenderableArray.size() <= instanceID)
		{
			mRenderableArray.resize(instanceID + 1, NULL);
		}
		mActiveRenderable = mRenderableArray[instanceID];
		if (mActiveRenderable == NULL)
		{
			if (mMgr.mIsMesh)
			{
				mActiveRenderable = PX_NEW(IofxMeshRenderable)(mIofxScene, mRenderResID);
			}
			else
			{
				mActiveRenderable = PX_NEW(IofxSpriteRenderable)(mIofxScene, mRenderResID);
			}
			mRenderableArray[instanceID] = mActiveRenderable;
		}

		mActiveRenderable->update(obj->renderData, mResultBounds, mResultRange.startIndex, mResultRange.objectCount, mResultVisibleCount);
		return true;
	}
	else
	{
		mActiveRenderable = NULL;
		return false;
	}
}

IofxRenderable* IofxActorImpl::acquireRenderableReference()
{
	return mActiveRenderable ? mActiveRenderable->incrementReferenceCount() : NULL;
}


}
} // namespace nvidia