Esempio n. 1
0
HRESULT CPainter::DrawSprite(GUITextureElement* pElement, RECT *prcDest, float depth)
{
	// no need to draw complete transparent element
	if (pElement == NULL || pElement->TextureColor.a == 0)
		return S_OK;
	HRESULT hr = S_OK;

	TextureEntity* pTexture = pElement->GetTexture();
	if (pTexture == NULL)
		return E_FAIL;

	RECT rcTexture;
	pElement->GetRect(&rcTexture);

	RECT rcScreen = *prcDest;

	if (pTexture->SurfaceType == TextureEntity::SysMemoryTexture)
	{
//#ifdef USE_DIRECTX_RENDERER
//		POINT pt = { rcScreen.left, rcScreen.top };
//		hr = CGlobals::GetRenderDevice()->UpdateSurface(((TextureEntityDirectX*)pTexture)->GetSurface(), &rcTexture, guiroot->GetGUIState().pBackSurface, &pt);
//#endif
	}
	else
	{
		if (pTexture->GetTexture() != 0)
		{
			if (RectWidth(rcTexture) != 0 || RectHeight(rcTexture) != 0)
			{
				float fScaleX = Math::Abs((float)RectWidth(rcScreen) / (RectWidth(rcTexture)));
				float fScaleY = Math::Abs((float)RectHeight(rcScreen) / (RectHeight(rcTexture)));

				Matrix4 matTransform(Matrix4::IDENTITY);
				matTransform.setScale(Vector3(fScaleX, fScaleY, 0.f));
				matTransform._43 = depth;
				SetSpriteTransform(&matTransform);

				Vector3 vPos((float)rcScreen.left, (float)rcScreen.top, 0.f);

				vPos.x /= fScaleX;
				vPos.y /= fScaleY;
				
				hr = engine->DrawQuad(pTexture, &rcTexture, NULL, &vPos, pElement->TextureColor);
			}
			else
				hr = E_FAIL;
		}
		else
		{
			if (pTexture->IsPending() && state)
				state->AddPendingAsset(1);
		}
	}

	return hr;
}
Esempio n. 2
0
HRESULT CPainter::DrawSprite(GUITextureElement* pElement, RECT *prcDest, Matrix4 matTransform, float depth)
{
	// no need to draw complete transparent element
	if (pElement == NULL || pElement->TextureColor.a == 0)
		return S_OK;

	TextureEntity* pTexture = pElement->GetTexture();
	if (pTexture == NULL)
		return E_FAIL;

	RECT rcTexture;
	pElement->GetRect(&rcTexture);

	RECT rcScreen = *prcDest;

	if (pTexture->SurfaceType == TextureEntity::SysMemoryTexture)
	{
		return DrawSprite(pElement, prcDest, depth);
	}

	if (pTexture->GetTexture() != 0)
	{
		if (RectWidth(rcTexture) != 0 || RectHeight(rcTexture) != 0)
		{
			float fScaleX = Math::Abs((float)RectWidth(rcScreen) / (RectWidth(rcTexture)));
			float fScaleY = Math::Abs((float)RectHeight(rcScreen) / (RectHeight(rcTexture)));

			matTransform._11 *= fScaleX;
			matTransform._22 *= fScaleY;
			matTransform._43 = depth;

			SetSpriteTransform(&matTransform);

			Vector3 vPos((float)rcScreen.left, (float)rcScreen.top, 0.f);

			vPos.x /= fScaleX;
			vPos.y /= fScaleY;
			return engine->DrawQuad(pTexture, &rcTexture, NULL, &vPos, pElement->TextureColor);
		}
		else
			return E_FAIL;
	}
	else
	{
		if (pTexture->IsPending() && state)
			state->AddPendingAsset(1);
	}
	return S_OK;
}
Esempio n. 3
0
// TODO: find a way to release reference to the textures
TextureEntity* CParaWorldAsset::GetDefaultTexture(int nTextureID)
{
	static TextureEntity* s_default_textures[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
	PE_ASSERT(nTextureID < 10 && nTextureID >= 0);

	TextureEntity* tex = s_default_textures[nTextureID];
	if (tex)
	{
		return tex;
	}
	else
	{
		// create the texture if it is not assigned before. 
		char sName[2];
		sName[0] = '0' + nTextureID;
		sName[1] = '\0';
		tex = LoadTexture(sName, "Texture/whitedot.png", TextureEntity::StaticTexture);
		//tex->SetState(AssetEntity::ASSET_STATE_LOCAL);
		tex->LoadAsset();
		s_default_textures[nTextureID] = tex;
	}
	return tex;
}
Esempio n. 4
0
//
// TextureComposeTask
//
bool ParaEngine::TextureComposeTask::UpdateToStaticTexture(CRenderTarget* pRenderTarget, Color colorKey)
{
	ImageEntity* image = pRenderTarget->NewImage(true, colorKey);
	bool res = false;
	if (image)
	{
		if (image->IsValid())
		{
			TextureEntity* pTexture = GetTexture();
			if (pTexture)
			{
				if (pTexture->LoadFromImage(image, D3DFMT_DXT3))
					res = true;
				else
				{
					OUTPUT_LOG("warning: failed to save render target to static texture : %s\n", m_name.c_str());
				}
			}
		}
		SAFE_DELETE(image);
	}
	return res;
}
void ParaEngine::CFaceLayers::OnTaskCompleted()
{
	for (int i = 0; i < CFS_TOTAL_NUM; ++i)
	{
		const FaceTextureComponent& component = m_layers[i];

		// load the component texture
		if (component.name.empty())
			continue;

		TextureEntity* pTextureEntity = NULL;
		AssetFileEntry* pEntry = CAssetManifest::GetSingleton().GetFile(component.name);
		if (pEntry)
			pTextureEntity = CGlobals::GetAssetManager()->LoadTexture(pEntry->GetLocalFileName(), pEntry->GetLocalFileName());
		else
			pTextureEntity = CGlobals::GetAssetManager()->LoadTexture(component.name, component.name);

		if (pTextureEntity)
		{
			pTextureEntity->UnloadAsset();
		}
	}
}
Esempio n. 6
0
bool CParaWorldAsset::UnloadAssetByKeyName(const string& keyname)
{
	string sFileExt = CParaFile::GetFileExtension(keyname);
	if(sFileExt == "dds" || sFileExt == "png")
	{
		TextureEntity* pEntity = (TextureEntity*) GetTextureManager().get(keyname);
		if(pEntity && (pEntity->GetState()==AssetEntity::ASSET_STATE_FAILED_TO_LOAD || pEntity->IsLoaded()))
		{
			pEntity->UnloadAsset();
			pEntity->SetLocalFileName("");
			if(pEntity->GetState()==AssetEntity::ASSET_STATE_FAILED_TO_LOAD)
				pEntity->SetState(AssetEntity::ASSET_STATE_NORMAL);
			return true;
		}
	}

	else if(sFileExt == "x" || sFileExt == "xml")
	{
		{
			MeshEntity* pEntity = (MeshEntity*) GetMeshManager().get(keyname);
			if(pEntity && pEntity->IsLoaded())
			{
				pEntity->UnloadAsset();
				pEntity->SetLocalFileName("");
				return true;
			}
		}
		{
			ParaXEntity* pEntity = (ParaXEntity*) GetParaXManager().get(keyname);
			if(pEntity && pEntity->IsLoaded())
			{
				pEntity->UnloadAsset();
				pEntity->SetLocalFileName("");
				return true;
			}
		}
	}
#ifdef USE_DIRECTX_RENDERER
	else if(sFileExt == "iges")
	{
		CadModel* pCadModel = (CadModel*) m_CadModelManager.get(keyname);
		if(pCadModel && pCadModel->IsLoaded())
		{
			pCadModel->UnloadAsset();
			pCadModel->SetLocalFileName("");
			return true;
		}
	}
#endif
	return false;
}
void ParaEngine::CSkinLayers::OnTaskCompleted()
{
	int nSize = (int)m_layers.size();
	for (int i = 0; i < nSize; ++i)
	{
		CharTextureComponent &component = m_layers[i];
		const CharRegionCoords &coords = CCharCustomizeSysSetting::regions[component.region];

		// load the component texture
		if (component.name.empty())
			continue;
		string componentfilename = component.name;
		AssetFileEntry* pEntry = CAssetManifest::GetSingleton().GetFile(componentfilename);
		if (pEntry)
			componentfilename = pEntry->GetLocalFileName();

		TextureEntity* pTextureEntity = CGlobals::GetAssetManager()->LoadTexture(componentfilename, componentfilename);

		if (pTextureEntity)
		{
			pTextureEntity->UnloadAsset();
		}
	}
}
Esempio n. 8
0
TextureEntity* CParaWorldAsset::LoadTexture(const string&  sIdentifier, const string&  fileName, TextureEntity::_SurfaceType nSurfaceType)
{
	string sFileName;
	CParaFile::ToCanonicalFilePath(sFileName, fileName, false);
	CPathReplaceables::GetSingleton().DecodePath(sFileName, sFileName);

	if (fileName[0] == '<')
	{
		//////////////////////////////////////////////////////////////////////////
		// 
		// HTML renderer textures, the file is of the following format <html>[name#]initial page url[;clip size]
		// e.g. "<html>www.paraengine.com"  , "<html>No1#www.paraengine.com". 
		// where key name is "<html>" and "<html>No1", and initial URL is www.paraengine
		//
		//////////////////////////////////////////////////////////////////////////
		if ((fileName[1] == 'h') && (fileName[2] == 't') && (fileName[3] == 'm') && (fileName[4] == 'l') && (fileName[5] == '>'))
		{

			string sInitURL;
			string sKeyName;
			int nPos = (int)sFileName.find_first_of("#./\\:");
			if (nPos > 0 && sFileName[nPos] == '#')
			{
				sInitURL = sFileName.substr(nPos + 1);
				sKeyName = sFileName.substr(0, nPos);
			}
			else
			{
				sInitURL = sFileName.substr(6);
				sKeyName = "<html>";
			}
			pair<TextureEntity*, bool> res = GetTextureManager().CreateEntity(sIdentifier, sKeyName);
			if (res.first != NULL)
			{
				TextureEntity* pNewEntity = res.first;
				// contains the initial url.
				pNewEntity->SetLocalFileName(sInitURL.c_str());
				pNewEntity->SurfaceType = TextureEntity::HTMLTexture;
			}
			return res.first;
		}
		return NULL;
	}

	pair<TextureEntity*, bool> res = GetTextureManager().CreateEntity(sIdentifier, sFileName);
	if (res.second == true)
	{
		TextureEntity* pNewEntity = res.first;
		pNewEntity->SetAsyncLoad(IsAsyncLoading());
		bool bIsRemoteFile = false;
		{
			//////////////////////////////////////////////////////////////////////////
			// 
			// if the file name ends with  _a{0-9}{0-9}{0-9}.dds, it will be regarded as a texture sequence. 
			// and the nSurfaceType will be ignored and forced to TextureSequence 
			//
			//////////////////////////////////////////////////////////////////////////

			int nSize = (int)fileName.size();
			int nTotalTextureSequence = -1;

			if (nSize > 9)
			{
				if (fileName[nSize - 8] == 'a' && fileName[nSize - 9] == '_')
				{
					nTotalTextureSequence = 0;
					for (int i = 0; i < 3; ++i)
					{
						char s = fileName[nSize - 5 - i];
						if (s >= '0' && s <= '9')
						{
							nTotalTextureSequence += (int)(s - '0')*(int)pow((long double)10, i);
						}
						else
						{
							nTotalTextureSequence = -1;
							break;
						}
					}
				}
				// it is a remote file if the filename starts with "http:", or "https:" or "ftp:"
				bIsRemoteFile = ((fileName[0] == 'h' && fileName[1] == 't' && fileName[2] == 't' && fileName[3] == 'p' && (fileName[4] == ':' || fileName[5] == ':')) ||
					(fileName[0] == 'f' && fileName[1] == 't' && fileName[2] == 'p' && fileName[3] == ':'));
			}
			if (!bIsRemoteFile && nTotalTextureSequence > 0)
				nSurfaceType = TextureEntity::TextureSequence;

			//////////////////////////////////////////////////////////////////////////
			// 
			// if the file name ends with  .swf or flv, it will be regarded as a flash texture. 
			// and the nSurfaceType will be ignored and forced to FlashTexture
			//
			//////////////////////////////////////////////////////////////////////////
			if (nSize > 4)
			{
				if ((((fileName[nSize - 3] == 's') && (fileName[nSize - 2] == 'w') && (fileName[nSize - 1] == 'f'))) ||
					((fileName[nSize - 3] == 'f') && (fileName[nSize - 2] == 'l') && (fileName[nSize - 1] == 'v')))
				{
					nSurfaceType = TextureEntity::FlashTexture;
				}
			}
		}

		pNewEntity->SurfaceType = nSurfaceType;
		if (bIsRemoteFile)
		{
			// set as remote file
			pNewEntity->SetState(AssetEntity::ASSET_STATE_REMOTE);
			// remote file only applies to static texture. FlashTexture automatically support remote streaming, and TextureSequence can not be remote. 
			if (nSurfaceType == TextureEntity::StaticTexture)
			{
				// we will delay loading http texture, until it is used for the first time. 
				TextureEntity::TextureInfo* pInfo = (TextureEntity::TextureInfo*) (pNewEntity->GetTextureInfo());
				if (pInfo)
				{
					// TRICKY code LXZ: 2008.3.6: this works around a bug where an HTTP texture is used in a GUI control, where the GUI control can not correctly determine the image size. 
					// by setting negative size, the GUI control will try to retrieve the size of image the next time it is called. 
					pInfo->m_height = -1;
					pInfo->m_width = -1;
				}

				// this new version uses local Resource store. 
				string sCode = "ParaAsset.GetRemoteTexture(\"";
				sCode += sFileName;
				sCode += "\");";
				CGlobals::GetNPLRuntime()->GetMainRuntimeState()->DoString(sCode.c_str(), (int)sCode.size());
			}
			else
			{
				OUTPUT_LOG("warning: http remote texture %s must be static texture type, but we got type=%d \n", fileName.c_str(), nSurfaceType);
			}
		}
	}
	return res.first;
}
Esempio n. 9
0
bool ModelRenderPass::init_FX(CParaXModel *m, SceneState* pSceneState,CParameterBlock* pMaterialParams)
{
	if(m->showGeosets[geoset] == false || indexCount == 0)
		return false;
	Vector4 ocol(1,1,1,m->m_trans);
	Vector4 ecol(0,0,0,0);

	// Emissive colors
	if (color!=-1) {
		// TODO: non-local provider?
		Vector3 c = m->colors[color].color.getValue(m->m_CurrentAnim);
		float o = m->colors[color].opacity.getValue(m->m_CurrentAnim);
		ocol.w *= o;
		if (unlit) {
			ocol.x = c.x; ocol.y = c.y; ocol.z = c.z;
		} else {
			ocol.x = ocol.y = ocol.z = 0;
		}
		ecol = Vector4(c, ocol.w);
	}


	// opacity
	if (opacity!=-1) {
		ocol.w *= m->transparency[opacity].trans.getValue(m->m_CurrentAnim);
	}

	float materialAlpha = 1.f;
	bool nozwrite_ = nozwrite;
	if(pMaterialParams != NULL)
	{
		CParameter* pParams = pMaterialParams->GetParameter("g_opacity");
		if(pParams)
			materialAlpha = (float)(*pParams);
		pParams = pMaterialParams->GetParameter("zwrite");
		if (pParams && (bool)(*pParams) == false)
			nozwrite_ = true;
	}
	ocol.w *= materialAlpha;

	// if the opacity or Emissive color is 0, we should not draw this pass. 
	if(( (ocol.w > 0) && (color==-1 || (ecol.w > 0)) ) == false)
		return false;

	/// Set the texture
	TextureEntity* bindtex = NULL;
	if (m->specialTextures[tex]==-1) 
		bindtex = m->textures[tex].get();
	else 
	{
		bindtex = m->replaceTextures[m->specialTextures[tex]];
		// use default texture if replaceable texture is not specified. 
		if(bindtex == 0)
			bindtex = m->textures[tex].get();
	}

	// do not render for NULL textures, possibly because the texture is not fully loaded. 
	if (!bindtex || bindtex->GetTexture() == 0)
		return false;

	if(pSceneState->IsIgnoreTransparent() && (blendmode == BM_ADDITIVE || blendmode == BM_ALPHA_BLEND || blendmode == BM_ADDITIVE_ALPHA
		|| materialAlpha < 1))
	{
		return false;
	}

	RenderDevicePtr pd3dDevice = CGlobals::GetRenderDevice();
	CEffectFile* pEffect = CGlobals::GetEffectManager()->GetCurrentEffectFile();
	PE_ASSERT(pEffect!=0);
	if (!pSceneState->IsShadowPass())
	{
		// blend mode
		switch (blendmode) {
		case BM_TRANSPARENT: // 1
			pEffect->EnableAlphaTesting(true);
			break;
		case BM_ALPHA_BLEND: // 2
			pEffect->EnableAlphaBlending(true);
			break;
		case BM_ADDITIVE: // 3
			pEffect->EnableAlphaBlending(true);
			pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
			pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
			break;
		case BM_ADDITIVE_ALPHA: // 4
			pEffect->EnableAlphaBlending(true);
			pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
			pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
			break;
		default: // BM_OPAQUE
			// default to OPAQUE
			// Note 2009.8.9: enable alpha test is enabled even for opaque character
			// pEffect->EnableAlphaBlending(false);
			// pEffect->EnableAlphaTesting(false);
			break;
		}

		if (nozwrite_) {
			CGlobals::GetEffectManager()->EnableZWrite(false);
		}

		if (!cull) {
			CGlobals::GetEffectManager()->SetCullingMode(false);
		}

		/*
		if(opacity != -1)
		{
		pEffect->setFloat(CEffectFile::k_opacity, ocol.w);
		}
		*/

		// color
		if (blendmode <= 1 && ocol.w<0.999f)
		{
			blendmode |= BM_TEMP_FORCEALPHABLEND;
			pEffect->EnableAlphaBlending(true);
			pEffect->setFloat(CEffectFile::k_opacity, ocol.w);
		}
		else if (opacity != -1)
		{
			pEffect->setFloat(CEffectFile::k_opacity, ocol.w);
		}

		if (color != -1)
		{
			Vector3 color_(ecol.x, ecol.y, ecol.z);
			pEffect->setParameter(CEffectFile::k_emissiveMaterialColor, &color_);
		}

		if (unlit) {
			pEffect->EnableSunLight(false);
		}

		if (texanim != -1) {

			//if(m->animTexRGB)
			//pEffect->setParameter(CEffectFile::k_bBoolean7,(const float*)&Vector4(1,0,0,0));

			const TextureAnim& texAnim = m->texanims[texanim];
			//OUTPUT_LOG("UV off: %f  %f\n", texAnim.tval.x, texAnim.tval.y);
			// it will interpolate between interval 1/30 second, hence when implementing blinking eye animation, make sure that the animation is still all right with intepolation on 1/30 texture UV animation. 
			Vector4 v(texAnim.tval.x, texAnim.tval.y, 0.f, 0.f);
			pEffect->setParameter(CEffectFile::k_ConstVector0, &v);
			//pEffect->setParameter(CEffectFile::k_ConstVector0, (const float*)&Vector4(0.00000f,0.242f, 0.f, 0.f));
		}

		if (GetCategoryId() > 0)
		{
			Vector4 v((float)GetCategoryId(), 0.f, 0.f, 0.f);
			pEffect->setParameter(CEffectFile::k_ConstVector1, &v);
		}

		if (pEffect->isParameterUsed(CEffectFile::k_transitionFactor) && pMaterialParams != NULL)
		{

			CParameter* pParams = pMaterialParams->GetParameter("transitionFactor");
			if (pParams)
				pEffect->setFloat(CEffectFile::k_transitionFactor, (float)(*pParams));
		}
	}
	else
	{
		if (blendmode == BM_TRANSPARENT)
			pEffect->EnableAlphaTesting(true);
	}
	
	/// Set the texture
	pEffect->setTexture(0, bindtex);

	if(is_rigid_body)
	{
		Matrix4 mat, mat1;
		mat1 = m->bones[(m->m_origVertices[m->m_indices[m_nIndexStart]+GetVertexStart(m)]).bones[0]].mat;
		mat = mat1 * CGlobals::GetWorldMatrixStack().SafeGetTop();
		CGlobals::GetWorldMatrixStack().push(mat);
		pEffect->applyWorldMatrices();
	}

	return true;
}
Esempio n. 10
0
bool ModelRenderPass::init(CParaXModel *m, SceneState* pSceneState)
{
	if(m->showGeosets[geoset] == false)
		return false;
	Vector4 ocol(1,1,1,m->m_trans);
	Vector4 ecol(0,0,0,0);

	// Emissive colors
	if (color!=-1) {
		// TODO: non-local provider?
		Vector3 c = m->colors[color].color.getValue(m->m_CurrentAnim);
		float o = m->colors[color].opacity.getValue(m->m_CurrentAnim);
		ocol.w *= o;
		if (unlit) {
			ocol.x = c.x; ocol.y = c.y; ocol.z = c.z;
		} else {
			ocol.x = ocol.y = ocol.z = 0;
		}
		ecol = Vector4(c, ocol.w);
	}

	// opacity
	if (opacity!=-1) {
		// TODO: non-local provider?
		ocol.w *= m->transparency[opacity].trans.getValue(m->m_CurrentAnim);
	}

	if(( (ocol.w > 0) && (color==-1 || (ecol.w > 0)) ) == false)
		return false;

	/// Set the texture
	TextureEntity* bindtex = NULL;
	if (m->specialTextures[tex]==-1) 
		bindtex = m->textures[tex].get();
	else 
	{
		bindtex = m->replaceTextures[m->specialTextures[tex]];
		// use default texture if replaceable texture is not specified. 
		if(bindtex == 0)
			bindtex = m->textures[tex].get();
	}
#ifdef USE_DIRECTX_RENDERER
	LPDIRECT3DTEXTURE9 pTex = NULL;
	if(bindtex)
		pTex = bindtex->GetTexture();

	// do not render for NULL textures, possibly because the texture is not fully loaded. 
	if(pTex==NULL)
		return false;

	if(pSceneState->IsIgnoreTransparent() && (blendmode == BM_ADDITIVE || blendmode == BM_ALPHA_BLEND || blendmode == BM_ADDITIVE_ALPHA))
	{
		return false;
	}

	LPDIRECT3DDEVICE9 pd3dDevice = CGlobals::GetRenderDevice();
	// blend mode
	switch (blendmode) {
	case BM_TRANSPARENT: // 1
		pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
		break;
	case BM_ALPHA_BLEND: // 2
		pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		break;
	case BM_ADDITIVE: // 3
		pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);	
		pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
		pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
		break;
	case BM_ADDITIVE_ALPHA: // 4
		pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);	
		pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
		break;
	default: // BM_OPAQUE
		// default to OPAQUE
		//pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		//pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); 
		break;
	}

	if (nozwrite) {
		CGlobals::GetEffectManager()->EnableZWrite(false);
	}

	if (!cull) {
		CGlobals::GetEffectManager()->SetCullingMode(false);
	}

	pd3dDevice->SetTexture(0, pTex);

	if (unlit) {
		pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
	}

	if (texanim!=-1) {
		// it will interpolate between interval 1/30 second, hence when implementing blinking eye animation, make sure that the animation is still all right with interpolation on 1/30 texture UV animation. 
		//// Set up the matrix for the desired transformation.
		Matrix4 texMat;
		const TextureAnim& texAnim = m->texanims[texanim];
		
		// interesting that it uses _31 and _32 instead of _41, _42 for the UV translation.
		texMat = Matrix4::IDENTITY;
		texMat._31 = texAnim.tval.x;
		texMat._32 = texAnim.tval.y;
		pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, 	D3DTTFF_COUNT2);
		pd3dDevice->SetTransform( D3DTS_TEXTURE0, texMat.GetConstPointer() );
		//pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
	}

	// color
	if (blendmode<=1 && ocol.w<0.99f) 
	{
		pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	}

	// TODO: how to programmatically set alpha to ocol.w in fixed function ? right now, it is either on or off. 
	//if(opacity != -1)
	//{
	//	/*pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_BLENDFACTORALPHA );
	//	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	//	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
	//	
	//	pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, (DWORD)(LinearColor(1.f, 1.f, 1.f, ocol.w)));*/

	//	ParaMaterial mtrl;
	//	ZeroMemory( &mtrl, sizeof(mtrl) );

	//	// if a material is used, SetRenderState must be used
	//	// vertex color = light diffuse color * material diffuse color
	//	mtrl.Diffuse.r = 1.f;
	//	mtrl.Diffuse.g = 1.f;
	//	mtrl.Diffuse.b = 1.f;
	//	mtrl.Diffuse.a = ocol.w;

	//	/*mtrl.Emissive.r = 1.0f;
	//	mtrl.Emissive.g = 1.0f;
	//	mtrl.Emissive.b = 1.0f;*/
	//	
	//	pd3dDevice->SetMaterial( &mtrl );

	//	pd3dDevice->SetRenderState(D3DRS_COLORVERTEX, TRUE);
	//	
	//	pd3dDevice->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
	//	pd3dDevice->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);

	//	//pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
	//	// pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
	//}

#ifdef TODO
	/// TODO: set texture addressing
	if (swrap) {

	}
	if (twrap) {

	}
	if (useenvmap) {
		// environment mapping
		// TODO: this is not implemented yet.
	}
#endif

	if(is_rigid_body)
	{
		Matrix4 mat, mat1;
		mat1 = m->bones[(m->m_origVertices[m->m_indices[m_nIndexStart]+GetVertexStart(m)]).bones[0]].mat;
		mat = mat1 * CGlobals::GetWorldMatrixStack().SafeGetTop();
		CGlobals::GetWorldMatrixStack().push(mat);
		pd3dDevice->SetTransform(D3DTS_WORLD, mat.GetConstPointer());
	}
#endif
	return true;
}
Esempio n. 11
0
	//---------------------------------------------------------------------------------------------------------
	void ForwardPipelineSystem::OnFrameworkEntry( float time, BohgeEngine::Framework& framework )
	{
		m_pRenderQueueOrderMap = NEW QueueOrderMap();
		m_pLightRenderArray = NEW LightRenderArray();
		IMaterialSystem::Instance()->SetPipelienType(
			PipelineProperty::PLT_FORWARD_SINGLE_LIGHT,
			PipelineProperty::APT_LIGHTING_ALL
			| PipelineProperty::APT_UNIVERSAL_DEPTH
			| PipelineProperty::APT_UNIVERSAL_POST_EFFECT );
		{
			m_pMainRenderTarget = NEW RenderTargetEntity;
			m_pMainRenderTarget->ListenResizeview();
			m_pMainRenderTarget->SetJobType( IJob::JT_SYNCHRONOUS );
			m_pMainRenderTarget->PushMetadata(
				RenderTargetDependResolutionMetadata(
					RenderTargetProperty::RT_RENDER_TARGET_MAIN,
					RenderTargetProperty::ST_SWAP_A,
					GlobalDefine::Color_Gray,
					framework.GetConfig().GetViewSize(),
					framework.GetConfig().GetResolution()
				));
			m_pMainRenderTarget->CreateResource();
		}

		{
			m_pOriginalColorDepthStencil = NEW RenderTargetEntity;
			m_pOriginalColorDepthStencil->ListenResizeview();
			m_pOriginalColorDepthStencil->SetJobType( IJob::JT_SYNCHRONOUS );
			m_pOriginalColorDepthStencil->PushMetadata(
				RenderTargetDependResolutionMetadata(
				RenderTargetProperty::RT_RENDER_TARGET_2D,
				RenderTargetProperty::ST_SWAP_A,
				GlobalDefine::Color_Black,
				framework.GetConfig().GetViewSize(),
				framework.GetConfig().GetResolution()
				));
			TextureEntity* tex = m_pOriginalColorDepthStencil->MakeTextureAttachment( RenderTargetProperty::TA_COLOR_0 );
			tex->PushMetadata( 
				TextureBufferMetadata( 
						framework.GetConfig().GetResolution(),
						TextureProperty::TT_TEXTURE2D,
						TextureProperty::TU_STATIC,
						TextureProperty::PF_R8G8B8A8, 1, false,
						TextureProperty::TW_CLAMP_TO_EDGE,
						TextureProperty::TW_CLAMP_TO_EDGE,
						TextureProperty::TF_NEAREST,
						TextureProperty::TF_NEAREST,
						NULL ) );
			tex = m_pOriginalColorDepthStencil->MakeTextureAttachment( RenderTargetProperty::TA_DEPTH_STENCIL );
			tex->PushMetadata( 
				TextureBufferMetadata( 
					framework.GetConfig().GetResolution(),
					TextureProperty::TT_TEXTURE2D,
					TextureProperty::TU_STATIC,
					TextureProperty::PF_DEPTH24_STENCIL8, 1, false,
					TextureProperty::TW_CLAMP_TO_EDGE,
					TextureProperty::TW_CLAMP_TO_EDGE,
					TextureProperty::TF_NEAREST,
					TextureProperty::TF_NEAREST,
					NULL ) );
			m_pOriginalColorDepthStencil->CreateResource();
		}

		{
			m_pPreviousSceneColor[0] = NEW RenderTargetEntity;
			m_pPreviousSceneColor[0]->ListenResizeview();
			m_pPreviousSceneColor[0]->SetJobType( IJob::JT_SYNCHRONOUS );
			m_pPreviousSceneColor[0]->PushMetadata(
				RenderTargetDependResolutionMetadata(
				RenderTargetProperty::RT_RENDER_TARGET_2D,
				RenderTargetProperty::ST_SWAP_A,
				GlobalDefine::Color_Black,
				framework.GetConfig().GetViewSize(),
				framework.GetConfig().GetResolution()
				));
			TextureEntity* tex = m_pPreviousSceneColor[0]->MakeTextureAttachment( RenderTargetProperty::TA_COLOR_0 );
			tex->PushMetadata( 
				TextureBufferMetadata( 
					framework.GetConfig().GetResolution(),
					TextureProperty::TT_TEXTURE2D,
					TextureProperty::TU_STATIC,
					TextureProperty::PF_R8G8B8A8, 1, false,
					TextureProperty::TW_CLAMP_TO_EDGE,
					TextureProperty::TW_CLAMP_TO_EDGE,
					TextureProperty::TF_NEAREST,
					TextureProperty::TF_NEAREST,
					NULL ) );
			m_pPreviousSceneColor[0]->CreateResource();
		}

		{
			m_pPreviousSceneColor[1] = NEW RenderTargetEntity;
			m_pPreviousSceneColor[1]->ListenResizeview();
			m_pPreviousSceneColor[1]->SetJobType( IJob::JT_SYNCHRONOUS );
			m_pPreviousSceneColor[1]->PushMetadata(
				RenderTargetDependResolutionMetadata(
					RenderTargetProperty::RT_RENDER_TARGET_2D,
					RenderTargetProperty::ST_SWAP_B,
					GlobalDefine::Color_Black,
					framework.GetConfig().GetViewSize(),
					framework.GetConfig().GetResolution()
				));
			TextureEntity* tex = m_pPreviousSceneColor[1]->MakeTextureAttachment( RenderTargetProperty::TA_COLOR_0 );
			tex->PushMetadata( 
				TextureBufferMetadata( 
				framework.GetConfig().GetResolution(),
				TextureProperty::TT_TEXTURE2D,
				TextureProperty::TU_STATIC,
				TextureProperty::PF_R8G8B8A8, 1, false,
				TextureProperty::TW_CLAMP_TO_EDGE,
				TextureProperty::TW_CLAMP_TO_EDGE,
				TextureProperty::TF_NEAREST,
				TextureProperty::TF_NEAREST,
				NULL ) );
			m_pPreviousSceneColor[1]->CreateResource();
		}
		{
			m_pRenderObject = NEW RenderObjectEntity();
			m_pRenderObject->SetJobType( IJob::JT_SYNCHRONOUS );
			m_pRenderObject->PushMetadata(
				RenderObjectMeshMetadate( 
					RenderObjectProperty::RM_TRIANGLES,
					QuadVertexMetadata( BufferObjectProperty::MU_STATIC ),
					QuadIndicesMetadata( BufferObjectProperty::MU_STATIC ) )
				);
			m_pRenderObject->PushMetadata( RenderObjectMaterialMetadata( PathMetadata( DefaultAsset::ImageBlitMaterial ) ) );
			m_pRenderObject->CreateResource();
		}
	}
Esempio n. 12
0
HRESULT CPainter::DrawSprite(GUITextureElement* pElement, RECT *prcDest, int n, float depth)
{
	// no need to draw complete transparent element
	if (pElement == NULL || pElement->TextureColor.a == 0)
		return S_OK;
	n = n % 4;

	TextureEntity* pTexture = pElement->GetTexture();
	if (pTexture == NULL)
		return E_FAIL;

	RECT rcTexture;
	pElement->GetRect(&rcTexture);

	RECT rcScreen = *prcDest;

	if (pTexture->SurfaceType == TextureEntity::SysMemoryTexture)
	{
		return DrawSprite(pElement, prcDest, depth);
	}

	if (pTexture->GetTexture() != 0)
	{
		if (RectWidth(rcTexture) != 0 || RectHeight(rcTexture) != 0)
		{
			float fScaleX;
			float fScaleY;
			Vector3 vCenter((float)RectWidth(rcTexture) / 2, (float)RectHeight(rcTexture) / 2, 0.f);
			Matrix4 matTransform;
			switch (n) {
			case 0:
				fScaleX = (float)RectWidth(rcScreen) / RectWidth(rcTexture);
				fScaleY = (float)RectHeight(rcScreen) / RectHeight(rcTexture);
				matTransform = Matrix4::IDENTITY;
				break;
			case 1:
			case -3:
				fScaleX = (float)RectWidth(rcScreen) / RectHeight(rcTexture);
				fScaleY = (float)RectHeight(rcScreen) / RectWidth(rcTexture);
				ParaMatrixRotationZ(&matTransform, (float)3.1415926536 / 2);
				break;
			case 2:
			case -2:
				fScaleX = (float)RectWidth(rcScreen) / RectWidth(rcTexture);
				fScaleY = (float)RectHeight(rcScreen) / RectHeight(rcTexture);
				ParaMatrixRotationZ(&matTransform, (float)3.1415926536 / 2);
				break;
			case 3:
			case -1:
				fScaleX = (float)RectWidth(rcScreen) / RectHeight(rcTexture);
				fScaleY = (float)RectHeight(rcScreen) / RectWidth(rcTexture);
				ParaMatrixRotationZ(&matTransform, (float)-3.1415926536 / 2);
				break;
			}
			fScaleX = Math::Abs(fScaleX);
			fScaleY = Math::Abs(fScaleY);
			matTransform._41 = (float)rcScreen.left + (float)RectWidth(rcScreen) / 2; matTransform._42 = (float)rcScreen.top + (float)RectHeight(rcScreen) / 2;
			matTransform._11 *= fScaleX;
			matTransform._21 *= fScaleX;
			matTransform._22 *= fScaleY;
			matTransform._12 *= fScaleY;
			matTransform._43 = depth;

			SetSpriteTransform(&matTransform);

			return engine->DrawQuad(pTexture, &rcTexture, &vCenter, NULL, pElement->TextureColor);
		}
		else
			return E_FAIL;
	}
	else
	{
		if (pTexture->IsPending() && state)
			state->AddPendingAsset(1);
	}
	return S_OK;
}
Esempio n. 13
0
HRESULT CPainter::DrawSprite(GUITextureElement* pElement, RECT *prcDest, const Vector2& vRotOrigin, float fRadian, const Vector2* vScaling, const Vector2* vTranslation, const DWORD* dwColorMask, float depth)
{
	// no need to draw complete transparent element
	if (pElement == NULL || pElement->TextureColor.a == 0)
		return S_OK;
	HRESULT hr = S_OK;

	TextureEntity* pTexture = pElement->GetTexture();
	if (pTexture == NULL)
		return E_FAIL;

	RECT rcTexture;
	pElement->GetRect(&rcTexture);

	RECT rcScreen = *prcDest;

	if (pTexture->SurfaceType == TextureEntity::SysMemoryTexture)
	{
//#ifdef USE_DIRECTX_RENDERER
//		POINT pt = { rcScreen.left, rcScreen.top };
//		hr = guiroot->m_stateGUI.pd3dDevice->UpdateSurface(((TextureEntityDirectX*)pTexture)->GetSurface(), &rcTexture, guiroot->GetGUIState().pBackSurface, &pt);
//#endif
	}
	else
	{
		if (pTexture->GetTexture() != 0)
		{
			if (RectWidth(rcTexture) != 0 || RectHeight(rcTexture) != 0)
			{
				float fScaleX = Math::Abs((float)RectWidth(rcScreen) / RectWidth(rcTexture));
				float fScaleY = Math::Abs((float)RectHeight(rcScreen) / RectHeight(rcTexture));
				if (vScaling)
				{
					fScaleX *= vScaling->x;
					fScaleY *= vScaling->y;
				}

				//////////////////////////////////////////
				// the following code can do rotation: LiXizhi 2007.9.28
				//////////////////////////////////////////
				Matrix4 matTransform;
				Vector2 vPos((float)rcScreen.left, (float)rcScreen.top);
				if (vScaling || vTranslation || fRadian != 0.f)
				{
					vPos -= vRotOrigin;
					ParaMatrixTransformation2D(&matTransform, NULL, 0.0, vScaling, NULL, fRadian, vTranslation);
					vPos = vPos * matTransform;
					vPos += vRotOrigin;
				}

				// out, scaling center, scaling rotation, scaling, rotation center, rotation, translation
				Vector2 vScale(fScaleX, fScaleY);
				ParaMatrixTransformation2D(&matTransform, NULL, 0.0, &vScale, NULL, fRadian, &vPos);
				matTransform._43 = depth;

				SetSpriteTransform(&matTransform);
				Color dwColor;
				if (dwColorMask == 0)
					dwColor = pElement->TextureColor;
				else
				{
					LinearColor colorMask(*dwColorMask);
					colorMask.a *= pElement->TextureColor.a;
					colorMask.r *= pElement->TextureColor.r;
					colorMask.g *= pElement->TextureColor.g;
					colorMask.b *= pElement->TextureColor.b;
					dwColor = colorMask;
				}
				
				hr = engine->DrawQuad(pTexture, &rcTexture, NULL, NULL, dwColor);
			}
			else
				hr = E_FAIL;
		}
		else
		{
			if (pTexture->IsPending() && state)
				state->AddPendingAsset(1);
		}
	}
	return hr;
}
Esempio n. 14
0
void FBXParser::FillParaXModelData(CParaXModel *pMesh, const aiScene *pFbxScene)
{
	pMesh->m_objNum.nVertices = m_vertices.size();
	pMesh->m_objNum.nBones = m_bones.size();
	pMesh->m_objNum.nTextures = m_textures.size();
	pMesh->m_objNum.nAnimations = m_bones.size() > 0 ? m_anims.size() : 0;
	pMesh->m_objNum.nIndices = m_indices.size();
	pMesh->m_header.minExtent = m_minExtent;
	pMesh->m_header.maxExtent = m_maxExtent;
	pMesh->m_vNeckYawAxis = m_modelInfo.m_vNeckYawAxis;
	pMesh->m_vNeckPitchAxis = m_modelInfo.m_vNeckPitchAxis;
	pMesh->initVertices(m_vertices.size(), &(m_vertices[0]));
	pMesh->initIndices(m_indices.size(), &(m_indices[0]));

	if (m_bones.size() > 0)
	{
		pMesh->bones = new ParaEngine::Bone[m_bones.size()];
		for (int i = 0; i < (int)m_bones.size(); ++i)
		{
			m_bones[i].RemoveRedundentKeys();
			pMesh->bones[i] = m_bones[i];
			if (m_bones[i].nBoneID > 0)
				pMesh->m_boneLookup[m_bones[i].nBoneID] = i;
			else if (m_bones[i].IsAttachment())
			{
				// TODO: pivot point
				pMesh->NewAttachment(true, m_bones[i].GetAttachmentId(), i, Vector3::ZERO);
			}
		}
	}

	if (m_anims.size() > 0 && m_bones.size() > 0)
	{
		pMesh->anims = new ModelAnimation[m_anims.size()];
		memcpy(pMesh->anims, &(m_anims[0]), sizeof(ModelAnimation)*m_anims.size());
		pMesh->animBones = true;
		pMesh->animated = true;
	}
	else
	{
		pMesh->animBones = false;
		pMesh->animated = false;
	}

	if (m_textures.size() > 0)
	{
		pMesh->textures = new asset_ptr<TextureEntity>[m_textures.size()];
		for (int i = 0; i < (int)m_textures.size(); i++)
		{
			if (m_textureContentMapping.find(m_textures[i]) != m_textureContentMapping.end())
			{
				int nSize = m_textureContentMapping[m_textures[i]].size();
				if (nSize > 0)
				{
					TextureEntity *texEntity = CGlobals::GetAssetManager()->GetTextureManager().NewEntity(m_textures[i]);
					char* bufferCpy = new char[nSize];
					memcpy(bufferCpy, m_textureContentMapping[m_textures[i]].c_str(), nSize);
					texEntity->SetRawData(bufferCpy, nSize);
					pMesh->textures[i] = texEntity;
				}
			}
			else if (CParaFile::DoesAssetFileExist(m_textures[i].GetFileName().c_str()))
			{
				pMesh->textures[i] = CGlobals::GetAssetManager()->LoadTexture("", m_textures[i], TextureEntity::StaticTexture);
			}
			// for replaceable textures
			if (m_textures[i].nIsReplaceableIndex > 0 && i < 32)
			{
				pMesh->specialTextures[i] = m_textures[i].nIsReplaceableIndex;
			}
		}
	}

	if (pMesh->geosets.size() > 0)
	{
		pMesh->showGeosets = new bool[pMesh->geosets.size()];
		memset(pMesh->showGeosets, true, pMesh->geosets.size()*sizeof(bool));
	}
	pMesh->m_radius = (m_maxExtent - m_minExtent).length() / 2;

	AddDefaultColors(pMesh);
	AddDefaultTransparency(pMesh);

	pMesh->m_RenderMethod = pMesh->HasAnimation() ? CParaXModel::SOFT_ANIM : CParaXModel::NO_ANIM;

	// only enable bmax model, if there are vertex color channel.
	if (m_beUsedVertexColor)
		pMesh->SetBmaxModel();
}
Esempio n. 15
0
void CDirectMouse::SetCursorFromFile(const char *szCursor, int XHotSpot, int YHotSpot)
{
	HRESULT hr = E_FAIL;
	
	//OUTPUT_LOG("SetCursorFromFile: %s\r\n", szCursor==0?"none":szCursor);

	if (szCursor==NULL || szCursor[0] == '\0') {
		szCursor=m_szCursorName.c_str();
		if (m_szCursorName.size()==0) {
			return;
		}
	}
	else
	{
		if(m_szCursorName == szCursor && ((XHotSpot<0 || m_XHotSpot == XHotSpot) && (YHotSpot<0 || m_YHotSpot == YHotSpot)))
		{
			return;
		}
		else
		{
			if(XHotSpot>=0)
				m_XHotSpot = XHotSpot;
			if(YHotSpot>=0)
				m_YHotSpot = YHotSpot;
		}
	}
	LPDIRECT3DDEVICE9 pD3dDevice = CGlobals::GetRenderDevice();
	if(pD3dDevice == NULL)
		return;

	// cursor file is loaded from memory to increase speed when cursor images changes frequently.
	string keyName = szCursor;
	keyName = "cursor:" + keyName;

	TextureEntity* pCursor = (TextureEntity*) CGlobals::GetAssetManager()->GetTextureManager().get(keyName);
	if(pCursor == 0)
	{
		pCursor = CGlobals::GetAssetManager()->LoadTexture(keyName, keyName, TextureEntity::SysMemoryTexture);
		if(pCursor)
		{
			pCursor->SetTextureInfo(TextureEntity::TextureInfo(32, 32, TextureEntity::TextureInfo::FMT_A8R8G8B8, TextureEntity::TextureInfo::TYPE_UNKNOWN));
			pCursor->SetLocalFileName(szCursor);
		}
	}

	if(pCursor)
	{
		LPDIRECT3DSURFACE9 pCursorSurface = ((TextureEntityDirectX*)pCursor)->GetSurface();
		if (pCursorSurface) 
		{
			if(SUCCEEDED(hr = pD3dDevice->SetCursorProperties( m_XHotSpot,m_YHotSpot, pCursorSurface))) 
			{
				// Set the device cursor
				m_szCursorName=szCursor;

				if (m_bShowCursor)
					ForceShowCursor(true);
			}
			else
			{
				OUTPUT_LOG("Load cursor from file failed\n");
			}
		}
		else
		{
			// cursor is not fully loaded yet, simply ignore it. 
			m_szCursorName="";
			hr = S_OK;
		}
	}
	
	if(FAILED(hr))
	{
		//OUTPUT_LOG("Failed loading cursor texture\n %s\n we shall load the default cursor instead\n", szCursor);
		// Set the cursor name as if it is the real cursor
		m_szCursorName=szCursor;
	}
	return;
}