Ejemplo n.º 1
0
//-------------------------------------------------------------------------------------------------
bool sdPhysicsSystem::LoadScene(sdMap* pkMap)
{
	if (!m_bInitialized || !pkMap)
		return false;

	sdTerrain* pkTerrain = pkMap->GetTerrain();
	NIASSERT(pkTerrain);

	// 创建空白NxScene
	CreateEmptyScene(pkTerrain->GetTerrainSize());
	NIASSERT(m_pkScene);

	float fTimeStep = 1.f / 60.f;
	m_pkScene->setTiming(fTimeStep, 6, NX_TIMESTEP_FIXED);
	m_pkScene->setUserTriggerReport(m_pkUserTriggerReport);

	NxMaterial* pkDefaultMaterial = m_pkScene->getMaterialFromIndex(0);
	NIASSERT(pkDefaultMaterial);
	pkDefaultMaterial->setRestitution(0.1f);
	pkDefaultMaterial->setStaticFriction(0.5f);
	pkDefaultMaterial->setDynamicFriction(0.5f);

	// 加载地形数据到NxScene
	CreateTerrain(pkTerrain);

	// 加载预生成的物件数据到NxScene
	

	// 生成地形的边界
	CreateTerrainBound(pkTerrain);

	return true;
}
Ejemplo n.º 2
0
//-------------------------------------------------------------------------------------------------
void sdRenderHelper::DisableZTest(NiAVObject* pkAVObject)
{
	NIASSERT(pkAVObject);

	NiProperty* pkProperty = pkAVObject->GetProperty(NiZBufferProperty::GetType());
	if (pkProperty)
	{
		NiZBufferProperty* pkZBufferProperty = (NiZBufferProperty*)(pkProperty);
		NIASSERT(pkZBufferProperty);

		pkZBufferProperty->SetZBufferTest(false);
		pkZBufferProperty->SetZBufferWrite(true);
	}

	if (pkAVObject->IsNode())
	{
		NiNode* pkNode = (NiNode*)pkAVObject;
		NIASSERT(pkNode);

		for (uint ui = 0; ui < pkNode->GetArrayCount(); ++ui)
		{
			NiAVObject* pkChild = pkNode->GetAt(ui);
			if (pkChild)
				DisableZTest(pkChild);
		}
	}
}
Ejemplo n.º 3
0
//-------------------------------------------------------------------------------------------------
bool sdPhysicsSystem::CreateEmptyScene(uint uiSize)
{
	NIASSERT(!m_pkScene);
	NIASSERT(!m_pkControllerManager);

	float fSize = (float)uiSize;
	float fWalkHeight = 4000.f;
	NxBounds3 nxBound;
	nxBound.setCenterExtents(NxVec3(fSize * 0.5f, fSize * 0.5f, 0.f), NxVec3(fSize * 0.5f, fSize * 0.5f, fWalkHeight *0.5f));

	NxSceneDesc nxSceneDesc;
	nxSceneDesc.gravity = NxVec3(0.f, 0.f, -9.8f);
	nxSceneDesc.simType = NX_SIMULATION_SW;
	nxSceneDesc.maxBounds = &nxBound;
	nxSceneDesc.upAxis = 2;							///< Z up
	nxSceneDesc.bpType = NX_BP_TYPE_SAP_MULTI;
	nxSceneDesc.nbGridCellsX = 8u;
	nxSceneDesc.nbGridCellsY = 8u;
	nxSceneDesc.subdivisionLevel = 5;

	m_pkScene = m_pkPhysicsSDK->createScene(nxSceneDesc);
	NIASSERT(m_pkScene);

	m_pkControllerManager = NxCreateControllerManager(m_pkAllocator);
	NIASSERT(m_pkControllerManager);

	return true;
}
Ejemplo n.º 4
0
//-------------------------------------------------------------------------------------------------
void sdQueryOcclusion_DX9::BeginQuery(uint uiOcclusionId)
{
	// Nested BeginQuery/EndQuery pairs are not allowed.
	NIASSERT(m_pvCurApiQuery == NULL);

	// Find corresponging sdQueryOcclusion, or create a new one if it is not existed.
	OcclusionQueryMapItr itr = m_kOcclusionQueryMap.find(uiOcclusionId);
	if (itr == m_kOcclusionQueryMap.end())
	{
		std::pair<OcclusionQueryMapItr, bool> kResult = 
			m_kOcclusionQueryMap.insert(OcclusionQueryPair(uiOcclusionId, sdOcclusionQuery()));
		NIASSERT(kResult.second);

		itr = kResult.first;		
	}

	// DXAPI calling
	sdOcclusionQuery& kOcclusionQuery = itr->second;
	{
		// Create an d3d occlusion query, which means adding an occlusion testing
		// begin marker to the command buffer queue.
		IDirect3DDevice9* d3ddevice = (IDirect3DDevice9*)NiDX9Renderer::GetRenderer()->GetD3DDevice();
		
		IDirect3DQuery9* d3dQuery;
		HRESULT hr = d3ddevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &d3dQuery);
		NIASSERT(S_OK == hr);

		hr = d3dQuery->Issue(D3DISSUE_BEGIN);
		NIASSERT(S_OK == hr);

		m_pvCurApiQuery = d3dQuery;
	}
	kOcclusionQuery.m_akApiQueryVec.push_back(m_pvCurApiQuery);
}
Ejemplo n.º 5
0
//-------------------------------------------------------------------------------------------------
sdMemoryTexture::sdMemoryTexture(LPDIRECT3DTEXTURE9 spD3DTexture)
{
	NIASSERT(spD3DTexture);

	// 获取渲染设备
	NiDX9Renderer* spRenderer = NiDX9Renderer::GetRenderer();
	NIASSERT(spRenderer);

	// 提取格式信息
	D3DSURFACE_DESC kLevelDesc;
	spD3DTexture->GetLevelDesc(0, &kLevelDesc);

	m_uiWidth = kLevelDesc.Width;
	m_uiHeight = kLevelDesc.Height;
	m_uiLevel = spD3DTexture->GetLevelCount();
	m_eFormat = kLevelDesc.Format;

	//
	m_spD3DTexture = spD3DTexture;
	m_spD3DTexture->AddRef();

	// 创建GB纹理对象
	m_spTexture = spRenderer->CreateNiTextureFromD3DTexture(m_spD3DTexture);
	NIASSERT(m_spTexture);
}
Ejemplo n.º 6
0
ENGINE_NAMESPACE_BEGIN_ENGINE
//-------------------------------------------------------------------------------------------------
sdMemoryTexture::sdMemoryTexture(uint uiWidth, uint uiHeight, uint uiLevel, D3DFORMAT eFormat)
{
	// 获取渲染设备
	NiDX9Renderer* spRenderer = NiDX9Renderer::GetRenderer();
	NIASSERT(spRenderer);

	LPDIRECT3DDEVICE9 spD3DDevice = spRenderer->GetD3DDevice();
	NIASSERT(spD3DDevice);

	//
	m_uiWidth = uiWidth;
	m_uiHeight = uiHeight;
	m_uiLevel = uiLevel;
	m_eFormat = eFormat;

	// 创建D3D纹理
	HRESULT hr = D3DXCreateTexture(spD3DDevice, 
		m_uiWidth, m_uiHeight, uiLevel, 
		0,
		eFormat,
		D3DPOOL_SYSTEMMEM,
		&m_spD3DTexture);
	if (FAILED(hr))	
	{
		NIASSERT(0);
		return;
	}
	m_spD3DTexture->AddRef();

	// 创建GB纹理对象
	m_spTexture = spRenderer->CreateNiTextureFromD3DTexture(m_spD3DTexture);
	NIASSERT(m_spTexture);
}
Ejemplo n.º 7
0
//-------------------------------------------------------------------------------------------------
bool sdMRTShadingPass::Initialize(uint uiStaticMeshStencilID, uint uiStaticMeshStencilIDMask, 
	NiRenderedTexture* pkLightTexture, NiRenderedTexture* pkGeomTexture, 
	NiRenderedTexture* pkAlbedoTexture, NiRenderedTexture* pkGlossTexture,
	NiRenderedTexture* pkGlowTexture)
{
	NIASSERT(uiStaticMeshStencilID);
	NIASSERT(uiStaticMeshStencilIDMask);

	NIASSERT(pkLightTexture);
	NIASSERT(pkGeomTexture);
	NIASSERT(pkAlbedoTexture);
	NIASSERT(pkGlossTexture);
	NIASSERT(pkGlowTexture)

	if (m_bInitialized)
	{
		NIASSERT(0);
		return false;
	}

	//
	IRenderDevice* pkRenderDevice = IRenderDevice::GetRenderDevice();
	NIASSERT(pkRenderDevice);

	// 设置模版参数
	m_uiStaticMeshStencilID = uiStaticMeshStencilID;
	m_uiStaticMeshStencilIDMask = uiStaticMeshStencilIDMask;

	// 设置输入纹理
	m_spGeomTexture = pkGeomTexture;
	m_spLightTexture = pkLightTexture;
	m_spAlbedoTexture = pkAlbedoTexture;
	m_spGlossTexture = pkGlossTexture;
	m_spGlowTexture = pkGlowTexture;

	// 初始化材质
	char szMaterialName[64];
	uint uiNum = 8;
	m_kStaticShadingMaterials.resize(uiNum);
	for (uint i = 0; i < uiNum; ++i)
	{
		sprintf(szMaterialName, "MRT3Shading0x%08x", i);
		m_kStaticShadingMaterials[i] = pkRenderDevice->CreateMaterial(szMaterialName);
	}

	// 初始化纹理属性
	m_spTexturingProp  = NiNew NiTexturingProperty;
	NIASSERT(m_spTexturingProp);
	m_spTexturingProp->SetShaderMap(0, NiNew NiTexturingProperty::ShaderMap(m_spLightTexture, 0));
	m_spTexturingProp->SetShaderMap(1, NiNew NiTexturingProperty::ShaderMap(m_spGeomTexture, 0));
	m_spTexturingProp->SetShaderMap(2, NiNew NiTexturingProperty::ShaderMap(m_spAlbedoTexture, 0));
	m_spTexturingProp->SetShaderMap(3, NiNew NiTexturingProperty::ShaderMap(m_spGlossTexture, 0));
	m_spTexturingProp->SetShaderMap(4, NiNew NiTexturingProperty::ShaderMap(m_spGlowTexture, 0));
	m_kPropertyList.AddTail((NiTexturingProperty*)m_spTexturingProp);

	return (m_bInitialized = true);
}
Ejemplo n.º 8
0
//-------------------------------------------------------------------------------------------------
bool sdPhysXQuadSection::Build(sdPhysXSceneMgr* pkPhysXSceneMgr, uint uiOriginX, uint uiOriginY, uint uiSize)
{
	NIASSERT(m_pkPhysXSceneMgr);

	//
	m_pkPhysXSceneMgr = pkPhysXSceneMgr;

	// 起始点
	m_uiOriginX	= uiOriginX;
	m_uiOriginY	= uiOriginY;
	
	//
	uint uiSectionSize = pkPhysXSceneMgr->GetSectionSize();
	uint uiSectionPerSide = uiSize / uiSectionSize;
	NIASSERT((uiSectionPerSide & 0x3) == 0);
	if (uiSize != uiSectionSize)
	{
		// 当前节点为中间节点
		//
		// 递归调用子树
		uint uiChildSize = uiSize / 2;
		uint uiCenterX = uiOriginX + uiChildSize;
		uint uiCenterY = uiOriginY + uiChildSize;

		m_pkQuadNodeChild[E_LT_CHILD] = NiNew sdPhysXQuadSection;
		m_pkQuadNodeChild[E_LT_CHILD]->Build(pkPhysXSceneMgr, uiOriginX, uiCenterY, uiChildSize);

		m_pkQuadNodeChild[E_RT_CHILD] = NiNew sdPhysXQuadSection;
		m_pkQuadNodeChild[E_RT_CHILD]->Build(pkPhysXSceneMgr, uiCenterX, uiCenterY, uiChildSize);

		m_pkQuadNodeChild[E_LB_CHILD] = NiNew sdPhysXQuadSection;
		m_pkQuadNodeChild[E_LB_CHILD]->Build(pkPhysXSceneMgr, uiOriginX, uiOriginY, uiChildSize);

		m_pkQuadNodeChild[E_RB_CHILD] = NiNew sdPhysXQuadSection;
		m_pkQuadNodeChild[E_RB_CHILD]->Build(pkPhysXSceneMgr, uiCenterX, uiOriginX, uiChildSize);

		// 节点ID
		m_usSectionID = INVALID_SECTION_ID;
	}
	else
	{
		// 当前节点为叶子节点
		//
		// 节点ID
		uint uiIndexX = uiOriginX / uiSectionSize;
		uint uiIndexY = uiOriginY / uiSectionSize;
		m_usSectionID = uiIndexY * uiSectionPerSide + uiIndexX;
	}

	return true;
}
Ejemplo n.º 9
0
//-------------------------------------------------------------------------------------------------
void sdResourceSystem::RegisterEvent(sdResourceEvent* pkEvent)
{
	NIASSERT(pkEvent);

	// Event加入TicketEventMap
	sdResourceEventPtr pkResEvent = pkEvent;
	sdResourceEventList* pkResEventList = NULL;
	if (m_kTicketEventMap.GetAt(pkResEvent->GetTicket(), pkResEventList))
	{
		pkResEventList->AddEvent(pkResEvent);
	}
	else
	{
		pkResEventList = NiNew sdResourceEventList;
		pkResEventList->AddEvent(pkResEvent);
		m_kTicketEventMap.SetAt(pkResEvent->GetTicket(), pkResEventList);
	}

	// Event加入ObjectEventMap
	if (m_kObjectEventMap.GetAt(pkResEvent->GetObject(), pkResEventList))
	{
		pkResEventList->AddEvent(pkResEvent);
	}
	else
	{
		pkResEventList = NiNew sdResourceEventList;
		pkResEventList->AddEvent(pkResEvent);
		m_kObjectEventMap.SetAt(pkResEvent->GetObject(), pkResEventList);
	}
}
Ejemplo n.º 10
0
//-------------------------------------------------------------------------------------------------
void sdHeightMap::SetRawHeight(int iX, int iY, float fHeight)
{
	// 溢出则不设置
	if (iX < 0)	return;
	if (iY < 0) return;
	if (iX > (int)m_uiSize)	return;
	if (iY > (int)m_uiSize)	return;

	// 检查并更新高度范围
	const static float fMaxHeightRange = 10000.0f;
	if (fHeight < m_fMinHeight)
	{
		if (m_fMaxHeight - fHeight < fMaxHeightRange)	
			m_fMinHeight = fHeight;
		else 
			return;
	}
	else if (fHeight > m_fMaxHeight)
	{
		if (fHeight - m_fMinHeight < fMaxHeightRange)	
			m_fMaxHeight = fHeight;
		else 
			return;
	}

	// 高度对齐(四舍五入)
	NIASSERT(m_fAlignHeight > 0.0f);
	fHeight = floor(fHeight / m_fAlignHeight + 0.5f) * m_fAlignHeight;

	// 高度保存
	m_pfHeight[iY * m_uiAllocSize + iX] = fHeight;
}
Ejemplo n.º 11
0
//-------------------------------------------------------------------------------------------------
void sdResourceSystem::RaiseEvent(ResourceSystem::sdResource *pkResource)
{
	if (!pkResource)
		return;

	sdResourceEventList* pkTicketEventList = NULL;
	if (m_kTicketEventMap.GetAt(pkResource->GetTicket(), pkTicketEventList))
	{
		const NiTPointerList<sdResourceEventPtr>& kResEvents = pkTicketEventList->GetEvents();
		NiTListIterator kIter = kResEvents.GetHeadPos();
		while (kIter)
		{
			sdResourceEvent* pkResEvent = kResEvents.GetNext(kIter);
			NIASSERT(pkResEvent);

			sdResourceEventList* pkObjectEventList = NULL;
			if (m_kObjectEventMap.GetAt(pkResEvent->GetObject(), pkObjectEventList))
			{
				if (!pkObjectEventList->RemoveEvent(pkResEvent).GetSize())
				{
					NiDelete pkObjectEventList;
					pkObjectEventList = NULL;
					m_kObjectEventMap.RemoveAt(pkResEvent->GetObject());
				}
			}

			if (!pkResource->Ignored())
				(*pkResEvent)(pkResource);	///< Call bacl after remove
		}

		NiDelete pkTicketEventList;
		pkTicketEventList = NULL;
		m_kTicketEventMap.RemoveAt(pkResource->GetTicket());
	}
}
Ejemplo n.º 12
0
//-------------------------------------------------------------------------------------------------
void* sdRenderObjectAlloc::Alloc(uint uiSize)
{
	if (m_uiSize + uiSize > m_uiCapacity)
	{
		if (NULL == m_pkIncreaseChild)
		{
			uint uiCapacity = m_uiIncreaseStep;
			if (uiCapacity < uiSize)
			{
				// 所要求分配对象过大,超出内存增加步长,则增大到所需求的大小
				NIASSERT(0 && "Too big render object size or too small increase step was setting.");
				uiCapacity = uiSize;
			}

			m_pkIncreaseChild = NiNew sdRenderObjectAlloc(uiCapacity, m_uiIncreaseStep);
		}

		return m_pkIncreaseChild->Alloc(uiSize);
	}

	void* pResult = &m_pcBuffer[m_uiSize];
	m_uiSize += uiSize;
	++m_uiNumObject;

	return pResult;
}
Ejemplo n.º 13
0
//-------------------------------------------------------------------------------------------------
void sdQueryOcclusion_DX9::Update()
{
	OcclusionQueryMapItr itr = m_kOcclusionQueryMap.begin();
	OcclusionQueryMapItr itr_end = m_kOcclusionQueryMap.end();
	for (; itr != itr_end; ++itr)
	{
		uint uiOcclusionId = itr->first;
		sdOcclusionQuery& kQuery = itr->second;

		kQuery.m_iResult = 0;
		for (int i = 0; i < (int)m_kOcclusionQueryMap.size(); ++i)
		{
			// DXAPI calling
			DWORD dwNumPixels = 0;
			{
				IDirect3DQuery9* d3dQuery = (IDirect3DQuery9*)kQuery.m_akApiQueryVec[i];
				NIASSERT(d3dQuery);

				// \TODO
				// 1.We may need test passing zero value instead of D#DGETDATA_FLUSH.
				// 2.We may need test calling GetData() as the sequence as queries be created.
				while (S_FALSE == d3dQuery->GetData(&dwNumPixels, sizeof(dwNumPixels), D3DGETDATA_FLUSH));
				//while (S_FALSE == d3dQuery->GetData(&dwNumPixels, sizeof(dwNumPixels), 0));
			}

			kQuery.m_iResult += dwNumPixels;
		}
	}
}
Ejemplo n.º 14
0
//-------------------------------------------------------------------------------------------------
void sdResourceSystem::UnregisterEvent(const void* pkObject)
{
	NIASSERT(pkObject);

	sdResourceEventList* pkObjectEventList = NULL;
	if (m_kObjectEventMap.GetAt(pkObject, pkObjectEventList))
	{
		const NiTPointerList<sdResourceEventPtr>& kResEvents = pkObjectEventList->GetEvents();
		NiTListIterator kIter = kResEvents.GetHeadPos();
		while (kIter)
		{
			sdResourceEvent* pkResEvent = kResEvents.GetNext(kIter);
			NIASSERT(pkResEvent);

			sdResource::ResTicket kResTicket = pkResEvent->GetTicket();

			// 取消加载
			sdResourceGroup* pkResourceGroup = m_kResourceGroupVec[kResTicket >> 28];
			if (pkResourceGroup)
			{
				sdResourcePtr pkResource = pkResourceGroup->RemoveResource(kResTicket);
				if (pkResource)
				{
					pkResource->IgnoreResource();
					pkResource = 0;
				}
			}

			// EventList从TicketEventMap移除
			sdResourceEventList* pkTicketEventList = NULL;
			if (m_kTicketEventMap.GetAt(kResTicket, pkTicketEventList))
			{
				if (!pkTicketEventList->RemoveEvent(pkResEvent).GetSize())
				{
					NiDelete pkTicketEventList;
					pkTicketEventList = NULL;
					m_kTicketEventMap.RemoveAt(kResTicket);
				}
			}
		}

		// EventList从ObjectEventMap移除
		NiDelete pkObjectEventList;
		pkObjectEventList = NULL;
		m_kObjectEventMap.RemoveAt(pkObject);
	}
}
Ejemplo n.º 15
0
//-------------------------------------------------------------------------------------------------
sdKfmResource::~sdKfmResource()
{
	if (m_spActorManager)
	{
		NIASSERT(0);
		::OutputDebugString("RsourceMamager - Memory Leak Detected");
	}
}
Ejemplo n.º 16
0
	//-----------------------------------------------------------------------------
	bool MWorldEditor::Initialize(System::IntPtr hWndPtr)
	{
		m_pkWorldEditor = new sdWorldEditor;
		NIASSERT(m_pkWorldEditor);
		m_pkWorldEditor->Initialize((HWND)hWndPtr.ToPointer());

		return true;
	}
Ejemplo n.º 17
0
//-------------------------------------------------------------------------------------------------
void sdMemoryTexture::UnlockRegion(uint uiLevel)
{
	if (FAILED(m_spD3DTexture->UnlockRect(uiLevel)))
	{
		NIASSERT(0);
		return;
	}
}
Ejemplo n.º 18
0
//-------------------------------------------------------------------------------------------------
sdHeightMap::sdHeightMap(uint uiSize)
: m_pfHeight(NULL)
, m_uiSpacing(1u)
, m_fSpacingDiv(1.f / 1u)
, m_uiSize(uiSize)
, m_uiAllocSize(uiSize + 1)
, m_fMinHeight(0.0f)
, m_fMaxHeight(0.0f)
, m_fAlignHeight(0.05f)
{
	// 检查尺寸
	NIASSERT(efd::IsPowerOf2(uiSize));

	// 创建高度图数据
	m_pfHeight = new float[m_uiAllocSize * m_uiAllocSize];
	NIASSERT(m_pfHeight);
	memset(m_pfHeight, 0, m_uiAllocSize * m_uiAllocSize * sizeof(float));
}
Ejemplo n.º 19
0
//-------------------------------------------------------------------------------------------------
bool sdPhysicsSystem::Initialize()
{
	if (m_bInitialized)
	{
		NIASSERT(0);

		Destroy();
		m_bInitialized = false;
	}

	// 创建内存分配器
	m_pkAllocator = NiNew sdPhysXAllocator;
	NIASSERT(m_pkAllocator);

	// 创建调试输出数据流
	m_pkOutputStream = NiNew sdPhysXOutputStream;
	NIASSERT(m_pkOutputStream);

	// 创建PhysX,初始化参数
	NxSDKCreateError kErrorCode;
	NxPhysicsSDKDesc kDesc;
	m_pkPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, m_pkOutputStream, kDesc, &kErrorCode);
	NIASSERT(m_pkPhysicsSDK);

	m_pkPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.1f);
	m_pkPhysicsSDK->setParameter(NX_BOUNCE_THRESHOLD, -0.5f);
	m_pkPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1.f);
	m_pkPhysicsSDK->setParameter(NX_VISUALIZE_BODY_AXES, 0.2f);
	m_pkPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1.f);
	m_pkPhysicsSDK->setParameter(NX_VISUALIZE_CLOTH_MESH, 1.f);
//	m_pkPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, 1.f);
//	m_pkPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXESS, 1.f);

	// 创建Cook库
	//m_pkCooking = NxGetCookingLib(NX_PHYSICS_SDK_VERSION);
	//NIASSERT(m_pkCooking);
	//m_pkCooking->NxInitCooking();

	//
	m_pkUserTriggerReport = NiNew sdPhysXTriggerReport;
	NIASSERT(m_pkUserTriggerReport);

	return m_bInitialized = true;
}
Ejemplo n.º 20
0
//-------------------------------------------------------------------------------------------------
int sdQueryOcclusion_DX9::GetResult(uint uiOcclusionId)
{
	OcclusionQueryMapItr itr = m_kOcclusionQueryMap.find(uiOcclusionId);
	if (itr == m_kOcclusionQueryMap.end())
		return -1;

	const sdOcclusionQuery& kQuery = itr->second;
	NIASSERT(-1 != kQuery.m_iResult);
	return kQuery.m_iResult;
}
Ejemplo n.º 21
0
//-------------------------------------------------------------------------------------------------
void sdKfmResource::FreeResource(bool bNotify /* = true */)
{
	if (m_spActorManager)
	{
		sdResourceSystem* pkResourceSystem = (sdResourceSystem*)sdResourceSystem::GetResourceSystem();
		NIASSERT(pkResourceSystem);

		sdNifResourcePool* pkNifResourcePool = pkResourceSystem->GetNifResourcePool();
		NIASSERT(pkNifResourcePool);
		if (!m_kChangeNifFileName.empty() && !m_kModelRootName.empty())
			pkNifResourcePool->FreeNifFile(m_kChangeNifFileName);

		m_spActorManager = 0;

		sdKfmResourcePool* pkKfmResourcePool = pkResourceSystem->GetKfmResourcePool();
		NIASSERT(pkKfmResourcePool);
		pkKfmResourcePool->FreeKFMFile(m_kFileName);
	}
}
Ejemplo n.º 22
0
//-------------------------------------------------------------------------------------------------
bool sdKfmResource::LoadResource(bool bMainThreadLoad /* = false */)
{
	//__VLD_THREAD_TRACE_AUTO2(sdKfmResource);

	m_eStatus = E_RES_STATUS_LOADED;

	sdResourceSystem* pkResourceSystem = (sdResourceSystem*)sdResourceSystem::GetResourceSystem();
	NIASSERT(pkResourceSystem);

	sdKfmResourcePool* pkKfmResourcePool = pkResourceSystem->GetKfmResourcePool();
	NIASSERT(pkKfmResourcePool);

	m_spActorManager = pkKfmResourcePool->LoadKfmFile(m_kFileName, m_eUsage, m_bReleaseOnGC, bMainThreadLoad);
	if (!m_spActorManager)
		return false;
	
	if (!m_kChangeNifFileName.empty() && !m_kModelRootName.empty())
	{
		sdNifResourcePool* pkNifResourcePool = pkResourceSystem->GetNifResourcePool();
		NIASSERT(pkNifResourcePool);

		NiNodePtr spNewNifRoot = pkNifResourcePool->LoadNifFile(m_kChangeNifFileName, E_RES_USAGE_NIF_COMMON, bMainThreadLoad);
		if (spNewNifRoot)
		{
			if (m_spActorManager->GetNIFRoot())
			{
				// ¼ì²é
				NiAVObject* pkModelRoot = m_spActorManager->GetNIFRoot()->GetObjectByName(m_kModelRootName.c_str());
				if (pkModelRoot)
				{
					NiKFMTool* spKFMTool = m_spActorManager->GetKFMTool();
					if (spKFMTool)
						spKFMTool->SetModelRoot(m_kModelRootName.c_str());
				}
			}

			m_spActorManager->ChangeNIFRoot((NiNode*)spNewNifRoot);
		}
	}

	return true;
}
Ejemplo n.º 23
0
//-------------------------------------------------------------------------------------------------
void sdQueryOcclusion_DX9::EndQuery()
{
	// Nested BeginQuery/EndQuery pairs are not allowed.
	NIASSERT(m_pvCurApiQuery == NULL);

	// DXAPI calling
	{
		// Add an end marker to the command buffer queue.
		((IDirect3DQuery9*)m_pvCurApiQuery)->Issue(D3DISSUE_END);
	}
}
Ejemplo n.º 24
0
void  MyGUIRenderClick::InitUI(IDirect3DDevice9 * pDevice)
{	

	//m_pDevice = pDevice;
	NiRenderer* pkRenderer = NiRenderer::GetRenderer();
	NIASSERT(pkRenderer);
	if(!pkRenderer) return;

// 	NiTexture::FormatPrefs kPrefs;
// 	const NiRenderTargetGroup* pkRTGroup = pkRenderer->GetDefaultRenderTargetGroup();
// 	const NiPixelFormat* pkPixelFormat = pkRTGroup->GetPixelFormat(0);
// 	if (pkPixelFormat->GetBitsPerPixel() == 16)
// 		kPrefs.m_ePixelLayout = NiTexture::FormatPrefs::HIGH_COLOR_16;
// 	else
// 		kPrefs.m_ePixelLayout = NiTexture::FormatPrefs::TRUE_COLOR_32;
// 
// 	m_spRenderedTexture = NiRenderedTexture::Create(1<<1024, 
// 		1<<1024, pkRenderer, kPrefs);
// 
// 	if(!m_spRenderedTexture)
// 	{
// 		NIASSERT(FALSE && "Cannot create offscreen framebuffer\n");
// 		return ;
// 	}
// 
// 	m_spRenderTargetGroup = NiRenderTargetGroup::Create(
// 		m_spRenderedTexture->GetBuffer(), pkRenderer, true,
// 		true);
// 	if(!m_spRenderTargetGroup)
// 	{
// 		NIASSERT(FALSE && "Cannot create offscreen framebuffer\n");
// 		return ;
// 	}

	//SetRenderTargetGroup(m_spRenderTargetGroup);
	
	efd::Win32PlatformServicePtr spWin32 = m_pInputService->GetServiceManager()->GetSystemServiceAs<efd::Win32PlatformService>();
	EE_ASSERT(spWin32);
	hWnd = spWin32->GetWindowRef();

	create(pDevice);
 //	addResourceLocation(mRootMedia + "/Demos/Demo_Gui");
 //	addResourceLocation(mRootMedia + "/Common/Scene");
 //	addResourceLocation(mRootMedia + "/Common/Wallpapers");
	//addResourceLocation(mRootMedia + "/Demos/Demo_Colour");
	//addResourceLocation(mRootMedia + "/Demos/Demo_ScrollView");   
   
	//getGUI()->load("test.layout");
	MyGUI::VectorWidgetPtr& root = MyGUI::LayoutManager::getInstance().load("test.layout");
	MyGUI::WidgetPtr pWidget = root.at(0)->findWidget("_Main");
	m_pMainWindow = pWidget->castType<MyGUI::Window>(false);
	pWidget = m_pMainWindow->findWidget("Edit");
	m_pEdit = pWidget->castType<MyGUI::Edit>(false);
}
Ejemplo n.º 25
0
//-------------------------------------------------------------------------------------------------
void sdEarlyZPass::Draw()
{
    if (!m_bInitialized || !m_bActived)
        return;

    D3DPERF_BeginEvent(0xff000000, L"EarlyZPass");

    IRenderDevice* pkRenderDevice = IRenderDevice::GetRenderDevice();
    NIASSERT(pkRenderDevice);

    // 清除数据绑定
    pkRenderDevice->ClearVertexBinding();
    pkRenderDevice->ClearTextureBinding();

    // Alpha
    pkRenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,	false);
    pkRenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE,	false);

    // Z
    pkRenderDevice->SetRenderState(D3DRS_ZENABLE,			true);
    pkRenderDevice->SetRenderState(D3DRS_ZWRITEENABLE,		true);
    pkRenderDevice->SetRenderState(D3DRS_ZFUNC,				D3DCMP_LESSEQUAL);

    // Stencil
    if (m_uiStaticMeshStencilID)
    {
        pkRenderDevice->SetRenderState(D3DRS_STENCILENABLE,		true);
        pkRenderDevice->SetRenderState(D3DRS_STENCILFUNC,		D3DCMP_ALWAYS);
        pkRenderDevice->SetRenderState(D3DRS_STENCILFAIL,		D3DSTENCILOP_KEEP);
        pkRenderDevice->SetRenderState(D3DRS_STENCILZFAIL,		D3DSTENCILOP_KEEP);
        pkRenderDevice->SetRenderState(D3DRS_STENCILPASS,		D3DSTENCILOP_REPLACE);
        pkRenderDevice->SetRenderState(D3DRS_STENCILREF,		m_uiStaticMeshStencilID);
        pkRenderDevice->SetRenderState(D3DRS_STENCILWRITEMASK,	m_uiStaticMeshStencilIDMask);
    }
    else
    {
        pkRenderDevice->SetRenderState(D3DRS_STENCILENABLE,		false);
    }

    // 禁用第一个颜色缓存,以获取双倍输出
    // Then the most important one: Disable color output. Get double speed on ROP
    pkRenderDevice->SetRenderState(D3DRS_COLORWRITEENABLE,	0);

    // 绘制
    __super::Draw();

    // 恢复第一个颜色输出
    // Re-enable color output
    uint uiColorChannelMask = D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN |	D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA;
    pkRenderDevice->SetRenderState(D3DRS_COLORWRITEENABLE,	uiColorChannelMask);

    D3DPERF_EndEvent();
}
Ejemplo n.º 26
0
//-------------------------------------------------------------------------------------------------
bool sdEarlyZPass::Initialize(uint uiStaticMeshStencilID, uint uiStaticMeshStencilIDMask)
{
    NIASSERT(uiStaticMeshStencilID & uiStaticMeshStencilIDMask);

    if (m_bInitialized)
    {
        NIASSERT(0);
        return false;
    }

    //
    IRenderDevice* pkRenderDevice = IRenderDevice::GetRenderDevice();
    NIASSERT(pkRenderDevice);

    // 设置模版参数
    m_uiStaticMeshStencilID = uiStaticMeshStencilID;
    m_uiStaticMeshStencilIDMask = uiStaticMeshStencilIDMask;

    // 初始化材质
    m_spSolidMeshZMaterial = pkRenderDevice->CreateMaterial("StaticMesh_Solid_EarlyZ");
    NIASSERT(m_spSolidMeshZMaterial);

    m_spNormalMapAlphaTestZMaterial = pkRenderDevice->CreateMaterial("StaticMesh_NormalMap_EarlyZ");
    NIASSERT(m_spNormalMapAlphaTestZMaterial);

    m_spDiffuseMapAlphaTestZMaterial = pkRenderDevice->CreateMaterial("StaticMesh_DiffuseMap_EarlyZ");
    NIASSERT(m_spDiffuseMapAlphaTestZMaterial);

    return (m_bInitialized = true);
}
Ejemplo n.º 27
0
ENGINE_NAMESPACE_BEGIN_ENGINE
ENGINE_NAMESPACE_BEGIN_RENDERSYSTEM
//-------------------------------------------------------------------------------------------------
sdRenderObjectAlloc::sdRenderObjectAlloc(uint uiCapicaty, uint uiIncreaseStep)
: m_uiCapacity(uiCapicaty)
, m_uiSize(0)
, m_uiNumObject(0)
, m_uiIncreaseStep(uiIncreaseStep)
, m_pkIncreaseChild(NULL)
{
	m_pcBuffer = new char[uiCapicaty];
	NIASSERT(m_pcBuffer);
}
Ejemplo n.º 28
0
ENGINE_NAMESPACE_BEGIN_ENGINE
ENGINE_NAMESPACE_BEGIN_RENDERSYSTEM
//-------------------------------------------------------------------------------------------------
bool sdEarlyZPass::Comparator(sdRenderObject* lhs, sdRenderObject* rhs)
{
    NIASSERT(lhs);
    NIASSERT(rhs);
    NIASSERT(sdRenderObject::E_ROT_STATIC_MESH == lhs->GetType());
    NIASSERT(sdRenderObject::E_ROT_STATIC_MESH == rhs->GetType());

    // 键排序(材质)
    if (lhs->GetType() != rhs->GetType())
        return (uint)lhs->GetType() < (uint)rhs->GetType();

    // 距离排序(由近到远,也许并不必要)
    NiCamera kCamera;
    NiRenderer::GetRenderer()->GetCameraData(kCamera);
    const NiPoint3& kCamPos = kCamera.GetWorldLocation();
    const NiPoint3& kCamDir = kCamera.GetWorldDirection();
    const NiPoint3& lhsPos = lhs->GetMesh()->GetTranslate();
    const NiPoint3& rhsPos = rhs->GetMesh()->GetTranslate();
    return kCamDir.Dot(lhsPos - kCamPos) < kCamDir.Dot(rhsPos - kCamPos);
}
Ejemplo n.º 29
0
//-------------------------------------------------------------------------------------------------
D3DLOCKED_RECT sdMemoryTexture::LockRegion(uint uiLevel, uint uiX, uint uiY, uint uiW, uint uiH)
{
	// 锁定内存纹理
	D3DLOCKED_RECT kD3DLockRect;
	RECT kRect[] = {uiX, uiY, uiX + uiW, uiY + uiH};
	if (FAILED(m_spD3DTexture->LockRect(uiLevel, &kD3DLockRect, kRect, D3DLOCK_NO_DIRTY_UPDATE)))
	{
		NIASSERT(0);

		kD3DLockRect.pBits = 0;
		kD3DLockRect.Pitch = 0;
		return kD3DLockRect;
	}

	m_spD3DTexture->AddDirtyRect(kRect);

	return kD3DLockRect;
}
Ejemplo n.º 30
0
//-------------------------------------------------------------------------------------------------
sdMemoryTexture::~sdMemoryTexture()
{
	//
	NiDX9Renderer* spRenderer = NiDX9Renderer::GetRenderer();
	NIASSERT(spRenderer);

	//
	if (m_spD3DTexture)
	{
		m_spD3DTexture->Release();
		m_spD3DTexture = NULL;
	}

	if (m_spTexture)
	{
		spRenderer->PurgeTexture(m_spTexture);
		m_spTexture = 0;
	}
}