void SampleApexResourceCallback::releaseResource(const char* nameSpace, const char* name, void* resource)
{
	PX_ASSERT(resource);
	PX_UNUSED(name);
	if (resource)
	{

#if DEBUG_RESOURCE_REQUESTS
		fprintf(gDebugOutput, "free - %s\n", name);
#endif
		if (!strcmp(nameSpace, APEX_MATERIALS_NAME_SPACE))
		{
			SampleFramework::SampleMaterialAsset* asset = static_cast<SampleFramework::SampleMaterialAsset*>(resource);
			m_assetManager.returnAsset(*asset);
		}
		else if (!strcmp(nameSpace, APEX_CUSTOM_VB_NAME_SPACE))
		{
			delete(char*) resource;	// char* allocated above with new
		}
		else if (!strcmp(nameSpace, APEX_COLLISION_GROUP_128_NAME_SPACE))
		{
			PX_ALWAYS_ASSERT();
		}
		else if (!strcmp(nameSpace, APEX_COLLISION_GROUP_64_NAME_SPACE))
		{
			PX_ALWAYS_ASSERT();
		}
		else
		{
			nvidia::apex::Asset* asset = (nvidia::apex::Asset*)resource;
			m_apexSDK->releaseAsset(*asset);
		}
		m_numGets--;
	}
}
void ApexVertexBuffer::copy(uint32_t dstIndex, uint32_t srcIndex, ApexVertexBuffer* srcBufferPtr)
{
	ApexVertexBuffer& srcVB = srcBufferPtr != NULL ? *srcBufferPtr : *this;
	ApexVertexFormat& srcVF = srcVB.mFormat;

	if (mParams->buffers.arraySizes[0] != srcVB.mParams->buffers.arraySizes[0])
	{
		PX_ALWAYS_ASSERT();
		return;
	}

	for (uint32_t i = 0; i < (uint32_t)mParams->buffers.arraySizes[0]; i++)
	{
		RenderDataFormat::Enum dstFormat = mFormat.getBufferFormat(i);
		VertexFormat::BufferID id = mFormat.getBufferID(i);
		const int32_t srcBufferIndex = srcVF.getBufferIndexFromID(id);
		if (srcBufferIndex >= 0)
		{
			RenderDataFormat::Enum srcFormat = srcVF.getBufferFormat((uint32_t)srcBufferIndex);
			NvParameterized::Interface* dstInterface = mParams->buffers.buf[i];
			NvParameterized::Interface* srcInterface = srcVB.mParams->buffers.buf[(uint32_t)srcBufferIndex];
			// BRG: Using PH's reasoning: Technically all those CustomBuffer* classes should have the same struct, so I just use the first one
			BufferU8x1& srcBuffer = *static_cast<BufferU8x1*>(srcInterface);
			BufferU8x1& dstBuffer = *static_cast<BufferU8x1*>(dstInterface);
			PX_ASSERT(dstIndex < (uint32_t)dstBuffer.data.arraySizes[0]);
			PX_ASSERT(srcIndex < (uint32_t)srcBuffer.data.arraySizes[0]);
			copyRenderVertexData(dstBuffer.data.buf, dstFormat, dstIndex, srcBuffer.data.buf, srcFormat, srcIndex);
		}
	}
}
const char* Writer::semanticToString(physx::apex::NxRenderVertexSemantic::Enum semantic)
{
	const char* result = NULL;
	switch (semantic)
	{
#define CASE(_SEMANTIC) case physx::apex::NxRenderVertexSemantic::_SEMANTIC: result = #_SEMANTIC; break
		CASE(POSITION);
		CASE(NORMAL);
		CASE(TANGENT);
		CASE(BINORMAL);
		CASE(COLOR);
		CASE(TEXCOORD0);
		CASE(TEXCOORD1);
		CASE(TEXCOORD2);
		CASE(TEXCOORD3);
		CASE(BONE_INDEX);
		CASE(BONE_WEIGHT);
#undef CASE

	default:
		PX_ALWAYS_ASSERT();
	}

	return result;
}
Пример #4
0
void DefaultCpuDispatcher::flush( PxBaseTask& task, PxI32 targetRef)
{
	// TODO: implement
	PX_ALWAYS_ASSERT();
	PX_UNUSED(task);
	PX_UNUSED(targetRef);
}
void ClothingScene::lockScene()
{
	mSceneLock.lock();

	if (mSceneRunning == 1)
	{
		APEX_INVALID_OPERATION("The scene is running while the scene write lock is being acquired!");
		PX_ALWAYS_ASSERT();
	}
}
void transformRenderBuffer(void* dst, const void* src, RenderDataFormat::Enum format, uint32_t numVertices, const float& op)
{
	switch (format)
	{
		// Put transform handlers here
		HANDLE_TRANSFORM(FLOAT3, float)
		HANDLE_TRANSFORM(BYTE_SNORM3, float)
	default:
		break;
	}

	PX_ALWAYS_ASSERT();	// Unhandled format
}
void ImpactEmitterAsset::initializeAssetNameTable()
{
	/* initialize the exlosion, iofx, and ios asset names to resID tables */
	NxParameterized::Handle eventSetHandle(*mParams);
	int numSets;

	mParams->getParameterHandle("eventSetList", eventSetHandle);
	PX_ASSERT(eventSetHandle.isValid());

	mParams->getArraySize(eventSetHandle, numSets);
	for (int i = 0; i < numSets; i++)
	{
		NxParameterized::Handle ih(*mParams);
		NxParameterized::Interface* eventPtr = 0;

		eventSetHandle.getChildHandle(i, ih);
		PX_ASSERT(ih.isValid());

		mParams->getParamRef(ih, eventPtr);
		PX_ASSERT(eventPtr);

		ApexSimpleString tmpClassName(eventPtr->className());


		if (tmpClassName == "ImpactExplosionEvent")
		{
#if NX_SDK_VERSION_MAJOR == 2
			ImpactExplosionEvent* paramPtr = (ImpactExplosionEvent*)eventPtr;
			mExplosionAssetTracker.addAssetName(paramPtr->parameters().explosionAssetName->name(), false);
#elif NX_SDK_VERSION_MAJOR == 3
			APEX_DEBUG_WARNING("Invalid asset. ImpactExplosionEvent is not supported under PhysX 3.");
			PX_ALWAYS_ASSERT();
#endif
		}
		else if (tmpClassName == "ImpactObjectEvent")
		{
			ImpactObjectEvent* paramPtr = (ImpactObjectEvent*)eventPtr;

			mIofxAssetTracker.addAssetName(paramPtr->parameters().iofxAssetName->name(), false);
			mIosAssetTracker.addAssetName(paramPtr->parameters().iosAssetName->className(),
			                              paramPtr->parameters().iosAssetName->name());
		}
	}
}
void CudaModuleScene::onAfterLaunchApexCudaFunc(const ApexCudaFunc& func, CUstream stream)
{
	if (mCudaProfileSession)
	{
		mCudaProfileSession->onFuncFinish(func.getProfileId(), stream);
	}

#if !CUDA_KERNEL_CHECK_ALWAYS
	if (mSceneIntl.getCudaKernelCheckEnabled())
#endif
	{
		CUresult ret = cuStreamSynchronize(stream);
		if ( CUDA_SUCCESS != ret )
		{
			APEX_INTERNAL_ERROR("Cuda Error %d after launch of func '%s'", ret, func.getName());
			PX_ALWAYS_ASSERT();
		}
	}
}
const char* Writer::semanticToString(physx::apex::NxRenderBoneSemantic::Enum semantic)
{
	const char* result = NULL;
	switch (semantic)
	{
#define CASE(_SEMANTIC) case physx::apex::NxRenderBoneSemantic::_SEMANTIC: result = #_SEMANTIC; break
		CASE(POSE);
		CASE(PREVIOUS_POSE);
#undef CASE

	// if this assert is hit add/remove semantics above to match NxRenderBoneSemantic
	PX_COMPILE_TIME_ASSERT(physx::apex::NxRenderBoneSemantic::NUM_SEMANTICS == 2);

	default:
		PX_ALWAYS_ASSERT();
	}

	return result;
}
void transformRenderBuffer(void* dst, const void* src, RenderDataFormat::Enum format, uint32_t numVertices, const PxMat33& op)
{
	switch (format)
	{
		// Put transform handlers here
		HANDLE_TRANSFORM(FLOAT3, PxMat33)
		HANDLE_TRANSFORM(FLOAT4, PxMat33)
		HANDLE_TRANSFORM(FLOAT4_QUAT, PxMat33)
		HANDLE_TRANSFORM(BYTE_SNORM3, PxMat33)
		HANDLE_TRANSFORM(BYTE_SNORM4, PxMat33)
		HANDLE_TRANSFORM(BYTE_SNORM4_QUATXYZW, PxMat33)
		HANDLE_TRANSFORM(SHORT_SNORM3, PxMat33)
		HANDLE_TRANSFORM(SHORT_SNORM4, PxMat33)
		HANDLE_TRANSFORM(SHORT_SNORM4_QUATXYZW, PxMat33)
	default:
		break;
	}

	PX_ALWAYS_ASSERT();	// Unhandled format
}
Пример #11
0
void Find(const char* root, FileHandler& f, const char** ignoredFiles)
{
	if (!root)
		return;

	// Fix slashes
	char goodRoot[128];
	strcpy(goodRoot, root);
#if defined PX_WINDOWS || defined PX_X360
	for (char* p = goodRoot; *p; ++p)
	{
		if ('/' == *p)
			*p = '\\';
	}
#endif

	physx::DirEntry dentry;
	if (!physx::DirEntry::GetFirstEntry(goodRoot, dentry))
	{
		PX_ALWAYS_ASSERT();
		return;
	}

	for (; !dentry.isDone(); dentry.next())
	{
		const char* filename = dentry.getName();

		if (!filename || 0 == strcmp(".", filename) || 0 == strcmp("..", filename))
			continue;

		bool doSkip = false;
		for (size_t i = 0; ignoredFiles && ignoredFiles[i]; ++i)
		{
			if (0 == strcmp(filename, ignoredFiles[i]))
			{
				doSkip = true;
				break;
			}
		}

		if (doSkip)
			continue;

		char tmp[128];
		physx::string::sprintf_s(tmp, sizeof(tmp), "%s/%s", goodRoot, filename);

#if defined PX_WINDOWS || defined PX_X360
	for (char* p = tmp; *p; ++p)
	{
		if ('/' == *p)
			*p = '\\';
	}
#endif

		if (dentry.isDirectory())
		{
			Find(tmp, f, ignoredFiles);
			continue;
		}

		f.handle(tmp);
	}
}
void ApexVertexBuffer::resize(uint32_t vertexCount)
{
	mParams->vertexCount = vertexCount;

	NvParameterized::Handle handle(*mParams);

	VERIFY_PARAM(mParams->getParameterHandle("buffers", handle));
	int32_t buffersSize = 0;
	VERIFY_PARAM(mParams->getArraySize(handle, buffersSize));

	for (int32_t i = 0; i < buffersSize; i++)
	{
		RenderDataFormat::Enum outFormat = mFormat.getBufferFormat((uint32_t)i);

		NvParameterized::Handle elementHandle(*mParams);
		VERIFY_PARAM(handle.getChildHandle(i, elementHandle));

		NvParameterized::Interface* currentReference = NULL;
		VERIFY_PARAM(mParams->getParamRef(elementHandle, currentReference));

		// BUFFER_FORMAT_ADD This is just a bookmark for places where to add buffer formats
		if (currentReference == NULL && vertexCount > 0)
		{
			const char* className = NULL;

			switch (outFormat)
			{
			case RenderDataFormat::UBYTE1:
			case RenderDataFormat::BYTE_UNORM1:
			case RenderDataFormat::BYTE_SNORM1:
				className = BufferU8x1::staticClassName();
				break;
			case RenderDataFormat::UBYTE2:
			case RenderDataFormat::BYTE_UNORM2:
			case RenderDataFormat::BYTE_SNORM2:
				className = BufferU8x2::staticClassName();
				break;
			case RenderDataFormat::UBYTE3:
			case RenderDataFormat::BYTE_UNORM3:
			case RenderDataFormat::BYTE_SNORM3:
				className = BufferU8x3::staticClassName();
				break;
			case RenderDataFormat::UBYTE4:
			case RenderDataFormat::BYTE_UNORM4:
			case RenderDataFormat::BYTE_SNORM4:
			case RenderDataFormat::R8G8B8A8:
			case RenderDataFormat::B8G8R8A8:
				className = BufferU8x4::staticClassName();
				break;
			case RenderDataFormat::SHORT1:
			case RenderDataFormat::USHORT1:
			case RenderDataFormat::SHORT_UNORM1:
			case RenderDataFormat::SHORT_SNORM1:
			case RenderDataFormat::HALF1:
				className = BufferU16x1::staticClassName();
				break;
			case RenderDataFormat::SHORT2:
			case RenderDataFormat::USHORT2:
			case RenderDataFormat::SHORT_UNORM2:
			case RenderDataFormat::SHORT_SNORM2:
			case RenderDataFormat::HALF2:
				className = BufferU16x2::staticClassName();
				break;
			case RenderDataFormat::SHORT3:
			case RenderDataFormat::USHORT3:
			case RenderDataFormat::SHORT_UNORM3:
			case RenderDataFormat::SHORT_SNORM3:
			case RenderDataFormat::HALF3:
				className = BufferU16x3::staticClassName();
				break;
			case RenderDataFormat::SHORT4:
			case RenderDataFormat::USHORT4:
			case RenderDataFormat::SHORT_UNORM4:
			case RenderDataFormat::SHORT_SNORM4:
			case RenderDataFormat::HALF4:
				className = BufferU16x4::staticClassName();
				break;
			case RenderDataFormat::UINT1:
				className = BufferU32x1::staticClassName();
				break;
			case RenderDataFormat::UINT2:
				className = BufferU32x2::staticClassName();
				break;
			case RenderDataFormat::UINT3:
				className = BufferU32x3::staticClassName();
				break;
			case RenderDataFormat::UINT4:
				className = BufferU32x4::staticClassName();
				break;
			case RenderDataFormat::FLOAT1:
				className = BufferF32x1::staticClassName();
				break;
			case RenderDataFormat::FLOAT2:
				className = BufferF32x2::staticClassName();
				break;
			case RenderDataFormat::FLOAT3:
				className = BufferF32x3::staticClassName();
				break;
			case RenderDataFormat::FLOAT4:
			case RenderDataFormat::R32G32B32A32_FLOAT:
			case RenderDataFormat::B32G32R32A32_FLOAT:
				className = BufferF32x4::staticClassName();
				break;
			default:
				PX_ALWAYS_ASSERT();
				break;
			}

			if (className != NULL)
			{
				currentReference = GetInternalApexSDK()->getParameterizedTraits()->createNvParameterized(className);
			}

			if (currentReference != NULL)
			{
				NvParameterized::Handle arrayHandle(*currentReference);
				VERIFY_PARAM(currentReference->getParameterHandle("data", arrayHandle));
				PX_ASSERT(arrayHandle.isValid());
				VERIFY_PARAM(arrayHandle.resizeArray((int32_t)vertexCount));

				mParams->setParamRef(elementHandle, currentReference);
			}
		}
		else if (vertexCount > 0)
		{
			NvParameterized::Interface* oldReference = currentReference;
			PX_ASSERT(oldReference != NULL);
			currentReference = GetInternalApexSDK()->getParameterizedTraits()->createNvParameterized(oldReference->className());
			if (currentReference != NULL)
			{
				VERIFY_PARAM(currentReference->copy(*oldReference));

				NvParameterized::Handle arrayHandle(*currentReference);
				VERIFY_PARAM(currentReference->getParameterHandle("data", arrayHandle));
				VERIFY_PARAM(arrayHandle.resizeArray((int32_t)vertexCount));
			}
			VERIFY_PARAM(mParams->setParamRef(elementHandle, currentReference));
			oldReference->destroy();
		}
		else if (vertexCount == 0)
		{
			VERIFY_PARAM(mParams->setParamRef(elementHandle, NULL));

			if (currentReference != NULL)
			{
				currentReference->destroy();
			}
		}
	}
}
Пример #13
0
void Writer::writeArray(physx::apex::NxRenderDataFormat::Enum format, unsigned int stride, unsigned int numElements, const void* data, float tolerance, physx::apex::NxRenderVertexSemantic::Enum s)
{
	if (mIsStdout)
	{
		unsigned int maxNumElements = 1000000;

		switch (format)
		{
		case physx::apex::NxRenderDataFormat::USHORT1:
		case physx::apex::NxRenderDataFormat::UINT1:
			maxNumElements = 10;
			break;
		case physx::apex::NxRenderDataFormat::FLOAT2:
			maxNumElements = 3;
			break;
		case physx::apex::NxRenderDataFormat::FLOAT3:
			maxNumElements = 2;
			break;
		case physx::apex::NxRenderDataFormat::FLOAT3x4:
			maxNumElements = 1;
			break;
		default:
			PX_ALWAYS_ASSERT();
		}

		if (maxNumElements < numElements)
		{
			numElements = maxNumElements;
		}
	}

	for (unsigned int i = 0; i < numElements; i++)
	{
		const char* dataSample = ((const char*)data) + stride * i;

		switch (format)
		{
		case physx::apex::NxRenderDataFormat::USHORT1:
		{
			const short* sh = (const short*)dataSample;
			printAndScan("%d ", sh[0]);
		}
		break;
		case physx::apex::NxRenderDataFormat::USHORT2:
		{
			const short* sh = (const short*)dataSample;
			printAndScan("(%d ", sh[0]);
			printAndScan("%d )", sh[1]);
		}
		break;
		case physx::apex::NxRenderDataFormat::USHORT3:
			{
				const short* sh = (const short*)dataSample;
				printAndScan("(%d ", sh[0]);
				printAndScan("%d ", sh[2]);
				printAndScan("%d )", sh[1]);
			}
			break;
		case physx::apex::NxRenderDataFormat::USHORT4:
		{
			const short* sh = (const short*)dataSample;
			printAndScan("(%d ", sh[0]);
			printAndScan("%d ", sh[1]);
			printAndScan("%d ", sh[2]);
			printAndScan("%d )", sh[3]);
		}
		break;
		case physx::apex::NxRenderDataFormat::UINT1:
		{
			const unsigned int* ui = (const unsigned int*)dataSample;
			printAndScan("%d ", ui[0]);
		}
		break;
		case physx::apex::NxRenderDataFormat::FLOAT2:
		{
			const float* fl = (const float*)dataSample;
			printAndScan(tolerance, s, "(%f ", fl[0]);
			printAndScan(tolerance, s, "%f ) ", fl[1]);
		}
		break;
		case physx::apex::NxRenderDataFormat::FLOAT3:
		{
			const physx::PxVec3* vec3 = (const physx::PxVec3*)dataSample;
			printAndScan(tolerance, s, "(%f ", vec3->x);
			printAndScan(tolerance, s, "%f ", vec3->y);
			printAndScan(tolerance, s, "%f ) ", vec3->z);
		}
		break;
		case physx::apex::NxRenderDataFormat::FLOAT4:
		{
			const physx::PxVec4* vec4 = (const physx::PxVec4*)dataSample;
			printAndScan(tolerance, s, "(%f ", vec4->x);
			printAndScan(tolerance, s, "%f ", vec4->y);
			printAndScan(tolerance, s, "%f ", vec4->z);
			printAndScan(tolerance, s, "%f ) ", vec4->w);
		}
		break;
		case physx::apex::NxRenderDataFormat::FLOAT3x4:
		{
			const physx::PxVec3* vec3 = (const physx::PxVec3*)dataSample;
			printAndScan("(");
			for (unsigned int j = 0; j < 4; j++)
			{
				printAndScan(tolerance, s, "%f ", vec3[j].x);
				printAndScan(tolerance, s, "%f ", vec3[j].y);
				printAndScan(tolerance, s, "%f ", vec3[j].z);
			}
			printAndScan(") ");
		}
		break;
		case physx::apex::NxRenderDataFormat::R8G8B8A8:
		case physx::apex::NxRenderDataFormat::B8G8R8A8:
			{
				const unsigned int* ui = (const unsigned int*)dataSample;
				printAndScan("0x%x ", ui[0]);
			}
		break;
		default:
			PX_ALWAYS_ASSERT();
		}
	}
}
void ApexAssetAuthoring::setToolString(const char* /*toolString*/)
{
	PX_ALWAYS_ASSERT();
	APEX_INVALID_OPERATION("Not Implemented.");
}