Esempio n. 1
0
CTextureHandle CTexelGenerator::GenerateNormal(bool bInMedias)
{
	for (size_t i = 0; i < m_apMethods.size(); i++)
	{
		CTextureHandle hNormal = m_apMethods[i]->GenerateNormal(bInMedias);
		if (hNormal.IsValid())
			return hNormal;
	}

	return CTextureHandle();
}
Esempio n. 2
0
CTextureHandle CTexelGenerator::GenerateDiffuse(bool bInMedias)
{
	for (size_t i = 0; i < m_apMethods.size(); i++)
	{
		CTextureHandle hTexture = m_apMethods[i]->GenerateDiffuse(bInMedias);
		if (hTexture.IsValid())
			return hTexture;
	}

	return CTextureHandle();
}
Esempio n. 3
0
int CGraphics_Threaded::UnloadTexture(CTextureHandle Index)
{
	if(Index.Id() == m_InvalidTexture.Id())
		return 0;

	if(!Index.IsValid())
		return 0;

	CCommandBuffer::SCommand_Texture_Destroy Cmd;
	Cmd.m_Slot = Index.Id();
	m_pCommandBuffer->AddCommand(Cmd);

	m_aTextureIndices[Index.Id()] = m_FirstFreeTexture;
	m_FirstFreeTexture = Index.Id();
	return 0;
}
Esempio n. 4
0
AABB CLevelEntity::CalculateBoundingBox(CLevelEntity* pThis)
{
	size_t iModel = pThis->GetModelID();
	CModel* pModel = CModelLibrary::GetModel(iModel);

	if (pModel)
		return pModel->m_aabbVisBoundingBox;

	tstring sAABB = pThis->GetParameterValue("BoundingBox");

	AABB aabbBounds = AABB(Vector(-0.5f, -0.5f, -0.5f), Vector(0.5f, 0.5f, 0.5f));

	if (CanUnserializeString_AABB(sAABB))
	{
		aabbBounds = UnserializeString_AABB(sAABB, pThis->GetName(), pThis->m_sClass, "BoundingBox");

		// Center the entity around this bounding box.
		Vector vecGlobalOrigin = aabbBounds.Center();
		aabbBounds.m_vecMins -= vecGlobalOrigin;
		aabbBounds.m_vecMaxs -= vecGlobalOrigin;
	}
	else
	{
		CSaveData* pSaveData = CBaseEntity::FindSaveDataByHandle(tstring("C"+pThis->m_sClass).c_str(), "BoundingBox");
		if (pSaveData && pSaveData->m_bDefault)
			memcpy(&aabbBounds, &pSaveData->m_oDefault, sizeof(aabbBounds));
	}

	if (pThis->m_hMaterialModel.IsValid() && pThis->m_hMaterialModel->m_ahTextures.size())
	{
		CTextureHandle hBaseTexture = pThis->m_hMaterialModel->m_ahTextures[0];

		if (hBaseTexture.IsValid())
		{
			aabbBounds.m_vecMaxs.y *= (float)hBaseTexture->m_iHeight/pThis->m_hMaterialModel->m_iTexelsPerMeter;
			aabbBounds.m_vecMins.y *= (float)hBaseTexture->m_iHeight/pThis->m_hMaterialModel->m_iTexelsPerMeter;

			aabbBounds.m_vecMaxs.z *= (float)hBaseTexture->m_iWidth/pThis->m_hMaterialModel->m_iTexelsPerMeter;
			aabbBounds.m_vecMins.z *= (float)hBaseTexture->m_iWidth/pThis->m_hMaterialModel->m_iTexelsPerMeter;
		}
	}

	aabbBounds.m_vecMins = aabbBounds.m_vecMins * pThis->GetScale();
	aabbBounds.m_vecMaxs = aabbBounds.m_vecMaxs * pThis->GetScale();

	return aabbBounds;
}
Esempio n. 5
0
void CNormalGenerator::SetNormalTexture(size_t iMaterial)
{
	// Materials not loaded yet?
	if (iMaterial >= SMAKWindow()->GetMaterials().size())
		return;

	CMaterialHandle hMaterial = SMAKWindow()->GetMaterials()[iMaterial];

	CShader* pShader = CShaderLibrary::GetShader(hMaterial->m_sShader);
	size_t iDiffuse = pShader->FindTextureByUniform("iDiffuse");
	if (iDiffuse >= hMaterial->m_ahTextures.size())
		return;

	CTextureHandle hDiffuseTexture = hMaterial->m_ahTextures[iDiffuse];

	if (!hDiffuseTexture.IsValid())
		return;

	m_iMaterial = iMaterial;

	// Don't let the listeners know yet, we want to generate the new one first so there is no lapse in displaying.
//	m_bNewNormal2Available = true;

	m_avecTextureTexels.resize(hDiffuseTexture->m_iWidth*hDiffuseTexture->m_iHeight);

	CRenderer::ReadTextureFromGL(hDiffuseTexture, m_avecTextureTexels.data());

	m_iNormal2Width = hDiffuseTexture->m_iWidth;
	m_iNormal2Height = hDiffuseTexture->m_iHeight;

	m_aflLowPassTexels.resize(hDiffuseTexture->m_iWidth*hDiffuseTexture->m_iHeight);
	m_aflMidPassTexels.resize(hDiffuseTexture->m_iWidth*hDiffuseTexture->m_iHeight);
	m_avecNormal2Texels.resize(hDiffuseTexture->m_iWidth*hDiffuseTexture->m_iHeight);

	Setup();

	UpdateNormal2();
}
Esempio n. 6
0
int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureID, int x, int y, int Width, int Height, int Format, const void *pData)
{
	CCommandBuffer::SCommand_Texture_Update Cmd;
	Cmd.m_Slot = TextureID.Id();
	Cmd.m_X = x;
	Cmd.m_Y = y;
	Cmd.m_Width = Width;
	Cmd.m_Height = Height;
	Cmd.m_Format = ImageFormatToTexFormat(Format);

	// calculate memory usage
	int MemSize = Width*Height*ImageFormatToPixelSize(Format);

	// copy texture data
	void *pTmpData = mem_alloc(MemSize, sizeof(void*));
	mem_copy(pTmpData, pData, MemSize);
	Cmd.m_pData = pTmpData;

	//
	m_pCommandBuffer->AddCommand(Cmd);
	return 0;
}
Esempio n. 7
0
void CGraphics_Threaded::TextureSet(CTextureHandle TextureID)
{
	dbg_assert(m_Drawing == 0, "called Graphics()->TextureSet within begin");
	m_State.m_Texture = TextureID.Id();
	m_State.m_Dimension = 2;
}
Esempio n. 8
0
void CToyEditor::ReloadModels()
{
	bool bGenPreviewDistance = false;

	if (!CModelLibrary::GetModel(m_iMeshPreview))
		m_iMeshPreview = ~0;

	tstring sMesh = FindAbsolutePath(GetDirectory(GetToy().m_sFilename) + "/" + GetToy().m_sMesh);
	if (IsFile(sMesh))
	{
		if (m_iMeshPreview != ~0)
		{
			CModel* pMesh = CModelLibrary::GetModel(m_iMeshPreview);
			if (m_bReloadPreview || sMesh != FindAbsolutePath(pMesh->m_sFilename))
			{
				CModelLibrary::ReleaseModel(m_iMeshPreview);
				CModelLibrary::ClearUnreferenced();

				if (GetToy().m_bUseLocalTransforms)
					CModelLibrary::LoadNextSceneWithLocalTransforms();

				m_iMeshPreview = CModelLibrary::AddModel(sMesh);

				bGenPreviewDistance = true;
				m_bReloadPreview = false;
			}
		}
		else
		{
			if (GetToy().m_bUseLocalTransforms)
				CModelLibrary::LoadNextSceneWithLocalTransforms();

			m_iMeshPreview = CModelLibrary::AddModel(sMesh);

			bGenPreviewDistance = true;
			m_bReloadPreview = false;
		}
	}
	else
	{
		if (m_iMeshPreview != ~0)
		{
			CModelLibrary::ReleaseModel(m_iMeshPreview);
			CModelLibrary::ClearUnreferenced();
			m_iMeshPreview = ~0;
		}
	}

	// Enclose this next code section in a scope so that the it variable here doesn't affect later code.
	{
		// Mark all scenes as not necessary.
		for (auto it = m_aFileScenes.begin(); it != m_aFileScenes.end(); it++)
			it->second.bMark = false;
	}

	for (size_t i = 0; i < GetToy().m_aAreas.size(); i++)
	{
		const auto& oArea = GetToy().m_aAreas[i];
		auto it = m_aFileScenes.find(oArea.m_sFilename);

		if (it == m_aFileScenes.end())
		{
			// Couldn't find it. We make one!
			CSceneAreaModelData oModelData;

			oModelData.pScene = std::shared_ptr<CConversionScene>(new CConversionScene());
			CModelConverter c(oModelData.pScene.get());
			if (!c.ReadModel(GetDirectory(GetToy().m_sFilename) + "/" + oArea.m_sFilename))
				continue;

			for (size_t j = 0; j < oModelData.pScene->GetNumMeshes(); j++)
				oModelData.aiModels.push_back(CModelLibrary::AddModel(oModelData.pScene.get(), j));

			for (size_t j = 0; j < oModelData.pScene->GetNumMaterials(); j++)
			{
				auto pMaterial = oModelData.pScene->GetMaterial(j);

				CTextureHandle hDiffuse = CTextureLibrary::AddTexture(pMaterial->GetDiffuseTexture());

				CMaterialHandle hMaterial = CMaterialLibrary::CreateBlankMaterial(oArea.m_sFilename + " : " + pMaterial->GetName());

				hMaterial->SetShader("model");

				if (hDiffuse.IsValid())
					hMaterial->SetParameter("DiffuseTexture", hDiffuse);

				hMaterial->SetParameter("Diffuse", pMaterial->m_vecDiffuse);

				// Hold a handle to the materials so they don't get removed next time the list is cleared.
				oModelData.ahMaterials.push_back(hMaterial);
			}

			oModelData.bMark = true;

			m_aFileScenes[oArea.m_sFilename] = oModelData;
			bGenPreviewDistance = true;
		}
		else
		{
			it->second.bMark = true;
		}
	}

	auto it = m_aFileScenes.begin();

	// Any scene still marked as not necessary gets del taco'd.
	while (it != m_aFileScenes.end())
	{
		if (!it->second.bMark)
		{
			for (size_t i = 0; i < it->second.aiModels.size(); i++)
				CModelLibrary::ReleaseModel(it->second.aiModels[i]);

			m_aFileScenes.erase(it++);
		}
		else
			++it;
	}

	if (bGenPreviewDistance)
	{
		m_flPreviewDistance = 0;

		if (m_iMeshPreview != ~0)
			m_flPreviewDistance = std::max(CModelLibrary::GetModel(m_iMeshPreview)->m_aabbVisBoundingBox.Size().Length()*2, m_flPreviewDistance);

		for (auto it = m_aFileScenes.begin(); it != m_aFileScenes.end(); it++)
		{
			for (size_t i = 0; i < it->second.aiModels.size(); i++)
			{
				CModel* pModel = CModelLibrary::GetModel(it->second.aiModels[i]);
				if (pModel)
					m_flPreviewDistance = std::max(pModel->m_aabbVisBoundingBox.Size().Length()*2, m_flPreviewDistance);
			}
		}
	}

	m_hMaterialPreview.Reset();
	tstring sMaterial = GetToy().m_sMesh;
	if (IsFile(sMaterial))
	{
		// Don't bother with clearing old ones, they'll get flushed eventually.
		CMaterialHandle hMaterialPreview = CMaterialLibrary::AddMaterial(sMaterial);

		if (hMaterialPreview.IsValid())
		{
			m_hMaterialPreview = hMaterialPreview;

			if (m_hMaterialPreview->m_ahTextures.size())
			{
				CTextureHandle hBaseTexture = m_hMaterialPreview->m_ahTextures[0];

				m_flPreviewDistance = (float)(hBaseTexture->m_iHeight + hBaseTexture->m_iWidth)/hMaterialPreview->m_iTexelsPerMeter;
			}
		}
	}

	tstring sPhys = FindAbsolutePath(GetDirectory(GetToy().m_sFilename) + "/" + GetToy().m_sPhys);
	if (IsFile(sPhys))
	{
		if (m_iPhysPreview != ~0)
		{
			CModel* pPhys = CModelLibrary::GetModel(m_iPhysPreview);
			if (sPhys != FindAbsolutePath(pPhys->m_sFilename))
			{
				CModelLibrary::ReleaseModel(m_iPhysPreview);
				CModelLibrary::ClearUnreferenced();
				m_iPhysPreview = CModelLibrary::AddModel(sPhys);
			}
		}
		else
			m_iPhysPreview = CModelLibrary::AddModel(sPhys);
	}
	else
	{
		if (m_iPhysPreview != ~0)
		{
			CModelLibrary::ReleaseModel(m_iPhysPreview);
			CModelLibrary::ClearUnreferenced();
		}
		m_iPhysPreview = ~0;
	}
}