Beispiel #1
0
ITexture* GLGraphics::GetTexture (const String& name, bool createIfMissing)
{
	ITexture* tex = 0;

	if (name.IsValid())
	{
		mTextures.Lock();
		{
			for (uint i = 0; i < mTextures.GetSize(); ++i)
			{
				tex = mTextures[i];

				if (tex != 0 && tex->GetName() == name)
				{
					mTextures.Unlock();
					return tex;
				}
			}

			if (createIfMissing)
			{
				GLTexture* myTex = new GLTexture(name, this);
				mTextures.Expand() = myTex;
				tex = myTex;
			}
			else tex = 0;
		}
		mTextures.Unlock();
	}
	return tex;
}
void CTextureProxy::OnBind( void *pEntity )
{
	// Bail if no base variable
	if ( !m_pBaseTextureVar )
		return;

	char texture[128];

	if (Q_stricmp(m_szTextureType, "hometeamcrest") == 0 && GetGlobalTeam(TEAM_A)->HasCrest())
		Q_snprintf(texture, sizeof(texture), "%s/%s/teamcrest", TEAMKITS_PATH, GetGlobalTeam(TEAM_A)->GetFolderName());
	else if (Q_stricmp(m_szTextureType, "awayteamcrest") == 0 && GetGlobalTeam(TEAM_B)->HasCrest())
		Q_snprintf(texture, sizeof(texture), "%s/%s/teamcrest", TEAMKITS_PATH, GetGlobalTeam(TEAM_B)->GetFolderName());
	else
		Q_snprintf(texture, sizeof(texture), "%s", m_pDefaultTexture->GetName());

	m_pNewTexture = materials->FindTexture(texture, NULL, true);
		
	m_pBaseTextureVar->SetTextureValue(m_pNewTexture);

	GetMaterial()->RecomputeStateSnapshots();
}
            virtual void ProcessEvent( EFlowEvent evt, SActivationInfo* pActInfo )
            {
                switch ( evt )
                {
                    case eFE_Suspend:
                        pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, false );
                        break;

                    case eFE_Resume:
                        pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, true );
                        break;

                    case eFE_Initialize:
                        break;

                    case eFE_Activate:

                        if ( IsPortActive( pActInfo, EIP_GET ) && !m_pVideo )
                        {
                            m_pVideo = gVideoplayerSystem->GetVideoplayerById( GetPortInt( pActInfo, EIP_VIDEOID ) );
                            pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, true );
                        }

                        else if ( m_pVideo )
                        {
                            // Set changed properties
                            if ( IsPortActive( pActInfo, EIP_VIDEOID ) )
                            {
                                m_pVideo = gVideoplayerSystem->GetVideoplayerById( GetPortInt( pActInfo, EIP_VIDEOID ) );
                            }
                        }

                        break;

                    case eFE_Update:
                        if ( m_pVideo )
                        {
                            ITexture* tex = m_pVideo->GetTexture();

                            if ( tex && m_nID != tex->GetTextureID() )
                            {
                                m_nID = tex->GetTextureID();
                                m_sName = tex->GetName();

                                ActivateOutput( pActInfo, EOP_TEXID, m_nID );
                                ActivateOutput( pActInfo, EOP_TEXNAME, m_sName );
                                ActivateOutput( pActInfo, EOP_CHANGED, true );
                            }
                        }

                        if ( !m_pVideo && m_nID != -1 )
                        {
                            m_nID = -1;
                            m_sName = "";

                            ActivateOutput( pActInfo, EOP_TEXID, m_nID );
                            ActivateOutput( pActInfo, EOP_TEXNAME, m_sName );
                            ActivateOutput( pActInfo, EOP_CHANGED, true );

                            pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, false );
                        }

                        break;
                }
            }
void CPlayerTextureProxy::OnBind( C_BaseEntity *pEnt )
{
	// Bail if no base variable
	if ( !m_pBaseTextureVar )
		return;

	CTeamKitInfo *pKitInfo;
	const char *teamFolder;
	const char *kitFolder;
	int skinIndex;
	int shirtNumber;
	const char *shirtName;
	bool isKeeper;

	ITexture *pDetailTexture;
	CProceduralRegenerator **pProcReg;

	if (dynamic_cast<C_SDKPlayer *>(pEnt))
	{
		C_SDKPlayer *pPl = dynamic_cast<C_SDKPlayer *>(pEnt);

		C_Team *pTeam = GetGlobalTeam(g_PR->GetTeam(pPl->index));

		teamFolder = pTeam->GetFolderName();
		kitFolder = pTeam->GetKitFolderName();
		pKitInfo = pTeam->GetKitInfo();
		skinIndex = g_PR->GetSkinIndex(pPl->index);
		shirtNumber = g_PR->GetShirtNumber(pPl->index);
		shirtName = g_PR->GetShirtName(pPl->index);
		isKeeper = g_PR->GetTeamPosType(pPl->index) == POS_GK;

		int teamIndex = pTeam->GetTeamNumber() - TEAM_A;
		int posIndex = g_PR->GetTeamPosIndex(pPl->index);

		pDetailTexture = materials->FindTexture(VarArgs("models/player/default/detail_%d_%d", teamIndex, posIndex), NULL, true);
		pProcReg = &m_pTextureRegen[teamIndex][posIndex];
	}
	else if (dynamic_cast<C_ReplayPlayer *>(pEnt))
	{
		C_ReplayPlayer *pReplayPl = dynamic_cast<C_ReplayPlayer *>(pEnt);

		C_Team *pTeam = GetGlobalTeam(pReplayPl->m_nTeamNumber);

		teamFolder = pTeam->GetFolderName();
		kitFolder = pTeam->GetKitFolderName();
		pKitInfo = pTeam->GetKitInfo();
		skinIndex = pReplayPl->m_nSkinIndex;
		shirtNumber = pReplayPl->m_nShirtNumber;
		shirtName = pReplayPl->m_szShirtName;
		isKeeper = pReplayPl->m_bIsKeeper;

		int teamIndex = pReplayPl->m_nTeamNumber - TEAM_A;
		int posIndex = pReplayPl->m_nTeamPosIndex;

		pDetailTexture = materials->FindTexture(VarArgs("models/player/default/detail_%d_%d", teamIndex, posIndex), NULL, true);
		pProcReg = &m_pTextureRegen[teamIndex][posIndex];
	}
	else if (dynamic_cast<C_BaseAnimatingOverlay *>(pEnt))
	{
		C_BaseAnimatingOverlay *pPlayerModelPreview = dynamic_cast<C_BaseAnimatingOverlay *>(pEnt);

		CAppearanceSettingPanel *pPanel = (CAppearanceSettingPanel *)iosOptionsMenu->GetPanel()->GetSettingPanel(SETTING_PANEL_APPEARANCE);

		pPanel->GetPlayerTeamInfo(&teamFolder, &kitFolder);
		pKitInfo = CTeamInfo::FindTeamByKitName(VarArgs("%s/%s", teamFolder, kitFolder));
		skinIndex = pPanel->GetPlayerSkinIndex();
		shirtNumber = pPanel->GetPlayerOutfieldShirtNumber();
		shirtName = pPanel->GetPlayerShirtName();
		isKeeper = false;

		pDetailTexture = materials->FindTexture("models/player/default/detail_preview", NULL, true);
		pProcReg = &m_pPreviewTextureRegen;
	}
	else
	{
		return;
	}

	if (!Q_strcmp(m_szTextureType, "shirt") || !Q_strcmp(m_szTextureType, "keepershirt"))
	{
		if (!(*pProcReg))
			*pProcReg = new CProceduralRegenerator();

		pDetailTexture->SetTextureRegenerator(*pProcReg);
		m_pDetailTextureVar->SetTextureValue(pDetailTexture);

		bool needsUpdate;

		if (isKeeper)
			needsUpdate = (*pProcReg)->SetPlayerInfo(shirtName, shirtNumber, pKitInfo->m_KeeperShirtNameColor, pKitInfo->m_nKeeperShirtNameOffset, pKitInfo->m_KeeperShirtNumberColor, pKitInfo->m_nKeeperShirtNumberOffset, true, pKitInfo->m_pFontAtlas);
		else
			needsUpdate = (*pProcReg)->SetPlayerInfo(shirtName, shirtNumber, pKitInfo->m_OutfieldShirtNameColor, pKitInfo->m_nOutfieldShirtNameOffset, pKitInfo->m_OutfieldShirtNumberColor, pKitInfo->m_nOutfieldShirtNumberOffset, false, pKitInfo->m_pFontAtlas);
				
		if (needsUpdate)
			pDetailTexture->Download();
	}

	char texture[128];

	if (Q_stricmp(m_szTextureType, "shirt") == 0)
		Q_snprintf(texture, sizeof(texture), "%s/%s/%s/outfield", TEAMKITS_PATH, teamFolder, kitFolder);
	else if (Q_stricmp(m_szTextureType, "keepershirt") == 0)
		Q_snprintf(texture, sizeof(texture), "%s/%s/%s/keeper", TEAMKITS_PATH, teamFolder, kitFolder);
	else if (Q_stricmp(m_szTextureType, "socks") == 0)
		Q_snprintf(texture, sizeof(texture), "%s/%s/%s/socks", TEAMKITS_PATH, teamFolder, kitFolder);
	else if (Q_stricmp(m_szTextureType, "gksocks") == 0)
		Q_snprintf(texture, sizeof(texture), "%s/%s/%s/gksocks", TEAMKITS_PATH, teamFolder, kitFolder);
	else if (Q_stricmp(m_szTextureType, "skin") == 0)
		Q_snprintf(texture, sizeof(texture), "models/player/skins/skin%d", skinIndex + 1);
	else
		Q_snprintf(texture, sizeof(texture), "%s", m_pTexture->GetName());

	ITexture *pNewTex = materials->FindTexture(texture, NULL, false);

	if (!pNewTex->IsError())
		m_pTexture = pNewTex;

	m_pBaseTextureVar->SetTextureValue(m_pTexture);
		
	GetMaterial()->RecomputeStateSnapshots();
}
void ShaderEditorInterface::OnUpdateSkymask( bool bCombineMode, int x, int y, int w, int h )
{
	SetFramebufferCopyTexOverride( NULL );

	if ( !IsSkymaskAvailable() )
		return;

	//UpdateFramebufferTexture( true );

	ITexture *pSkyMask = GetSkymaskTex();

	if ( IsErrorTexture( pSkyMask ) )
		return;

	static CMaterialReference pMatSkyDraw = NULL;
	static CMaterialReference pMatScreenRestore = NULL;
	static CMaterialReference pMatCombineMasks = NULL;
#ifdef SHADER_EDITOR_DLL_2006
	pMatSkyDraw = materials->FindMaterial( "postprocessing/skymask_fill_0", TEXTURE_GROUP_OTHER );
	pMatCombineMasks = materials->FindMaterial( "postprocessing/skymask_fill_1", TEXTURE_GROUP_OTHER );
	pMatScreenRestore = materials->FindMaterial( "postprocessing/fb_restore", TEXTURE_GROUP_OTHER );
#else
	if ( !pMatSkyDraw )
	{
		pSkyMats[ 0 ] = new KeyValues( "FILL_SKYMASK" );
		pSkyMats[ 0 ]->SetInt( "$COMBINEMODE", 0 );
		pMatSkyDraw.Init( "__sedit_skyfill", TEXTURE_GROUP_CLIENT_EFFECTS, pSkyMats[ 0 ] );
		//pMatSkyDraw->Refresh();
		//pKV->Clear();
		Assert( pMatSkyDraw );
	}
	if ( !pMatScreenRestore )
	{
		pSkyMats[ 1 ] = new KeyValues( "FULLSCREENQUAD_WRITEA" );
		pSkyMats[ 1 ]->SetString( "$BASETEXTURE", GetFBTex()->GetName() );
		pSkyMats[ 1 ]->SetInt( "$COMBINEMODE", 0 );
		pMatScreenRestore.Init( "__sedit_fbrestore", TEXTURE_GROUP_CLIENT_EFFECTS, pSkyMats[ 1 ] );
		//pMatScreenRestore->Refresh();
		//pKV->Clear();
		Assert( pMatScreenRestore );
	}
	if ( !pMatCombineMasks )
	{
		const char *skymaskname = pSkyMask->GetName();
		pSkyMats[ 2 ] = new KeyValues( "FILL_SKYMASK" );
		pSkyMats[ 2 ]->SetString( "$BASETEXTURE", skymaskname );
		pSkyMats[ 2 ]->SetInt( "$COMBINEMODE", 1 );
		pMatCombineMasks.Init( "__sedit_skyfill", TEXTURE_GROUP_CLIENT_EFFECTS, pSkyMats[ 2 ] );
		//pMatCombineMasks->Refresh();
		//pKV->Clear();
		Assert( pMatCombineMasks );
	}
#endif

	// _rt_SEdit_Skymask
	CMatRenderContextPtr pRenderContext( materials );

	IMaterial *pOperation = pMatSkyDraw;
	if ( bCombineMode )
		pOperation = pMatCombineMasks;

	int dest_width = w;
	int dest_height = h;
	float src_x1 = w - 1;
	float src_y1 = h - 1;

#ifdef SHADER_EDITOR_DLL_2006
	Frustum frustum;
	CViewSetup setup;
	setup.angles = _MainView.angles;
	setup.origin = _MainView.origin;
	setup.x = _MainView.x;
	setup.y = _MainView.y;
	setup.width = _MainView.width;
	setup.height = _MainView.height;
	setup.fov = _MainView.fov;
	setup.context = 0;
	setup.m_bOrtho = false;
	setup.m_flAspectRatio = _MainView.m_flAspectRatio;
	setup.m_vUnreflectedOrigin = setup.origin;
	render->Push3DView( setup, 0, false, NULL, frustum );
#endif

	pRenderContext->PushRenderTargetAndViewport( NULL );
	//pRenderContext->Viewport( x, y, w, h );
	//pRenderContext->DepthRange( 0, 1 );
	//MaterialHeightClipMode_t hClipLast = pRenderContext->GetHeightClipMode();
	//pRenderContext->SetHeightClipMode( MATERIAL_HEIGHTCLIPMODE_DISABLE );
	//const bool bEnableClipping = pRenderContext->EnableClipping( false );

#ifndef SHADER_EDITOR_DLL_2006
	UpdateScreenEffectTexture( GetFBTex(), x, y, w, h );
	//pRenderContext->CopyRenderTargetToTexture( GetFBTex() );
#endif

	// do ops
	pRenderContext->DrawScreenSpaceRectangle( pOperation,
		x, y, dest_width, dest_height,
		x, y, src_x1, src_y1,
		w, h );

	// store to mask
	UpdateScreenEffectTexture( pSkyMask, x, y, w, h, true );
	//pRenderContext->CopyRenderTargetToTexture( pSkyMask );

	// restore fb
#ifndef SHADER_EDITOR_DLL_2006
	pRenderContext->DrawScreenSpaceRectangle( pMatScreenRestore,
		x, y, w, h,
		x, y, w - 1, h - 1,
		w, h );
#endif

	//pRenderContext->EnableClipping( bEnableClipping );
	//pRenderContext->SetHeightClipMode( hClipLast );
	pRenderContext->PopRenderTargetAndViewport();

#ifdef SHADER_EDITOR_DLL_2006
	render->PopView( frustum );
#endif
}