// Level init, shutdown void CPixelVisibilitySystem::LevelInitPreEntity() { bool fastqueries = HasFastQueries(); // printf("\n ** fast queries: %s **", fastqueries?"true":"false" ); m_hwCanTestGlows = r_dopixelvisibility.GetBool() && fastqueries && engine->GetDXSupportLevel() >= 80; if ( m_hwCanTestGlows ) { CMatRenderContextPtr pRenderContext( materials ); OcclusionQueryObjectHandle_t query = pRenderContext->CreateOcclusionQueryObject(); if ( query != INVALID_OCCLUSION_QUERY_OBJECT_HANDLE ) { pRenderContext->DestroyOcclusionQueryObject( query ); } else { m_hwCanTestGlows = false; } } m_pProxyMaterial = materials->FindMaterial("engine/occlusionproxy", TEXTURE_GROUP_CLIENT_EFFECTS); m_pProxyMaterial->IncrementReferenceCount(); m_pDrawMaterial = materials->FindMaterial("engine/occlusionproxy_countdraw", TEXTURE_GROUP_CLIENT_EFFECTS); m_pDrawMaterial->IncrementReferenceCount(); m_freeQueriesList = m_queryList.CreateList(); m_activeSetsList = m_setList.CreateList(); m_freeSetsList = m_setList.CreateList(); }
//----------------------------------------------------------------------------- // Material precache //----------------------------------------------------------------------------- void CHLClient::PrecacheMaterial( const char *pMaterialName ) { bool bFound; IMaterial *pMaterial = materials->FindMaterial( pMaterialName, &bFound ); if ( bFound && pMaterial ) { pMaterial->IncrementReferenceCount(); m_CachedMaterials.AddToTail( pMaterial ); } }
//----------------------------------------------------------------------------- // Set the material to draw //----------------------------------------------------------------------------- void CMaterialViewPanel::SetMaterial( IMaterial *pMaterial ) { if (m_pMaterial) { m_pMaterial->DecrementReferenceCount(); } m_pMaterial = pMaterial; if (m_pMaterial) { m_pMaterial->IncrementReferenceCount(); } InvalidateLayout(); }
// Level init, shutdown void CPixelVisibilitySystem::LevelInitPreEntity() { m_hwCanTestGlows = r_dopixelvisibility.GetBool() && engine->GetDXSupportLevel() >= 80; if ( m_hwCanTestGlows ) { unsigned short query = materials->CreateOcclusionQueryObject(); if ( query != INVALID_OCCLUSION_QUERY_OBJECT_HANDLE ) { materials->DestroyOcclusionQueryObject( query ); } else { m_hwCanTestGlows = false; } } m_pProxyMaterial = materials->FindMaterial("engine/occlusionproxy", TEXTURE_GROUP_CLIENT_EFFECTS); m_pProxyMaterial->IncrementReferenceCount(); m_pDrawMaterial = materials->FindMaterial("engine/occlusionproxy_countdraw", TEXTURE_GROUP_CLIENT_EFFECTS); m_pDrawMaterial->IncrementReferenceCount(); m_freeQueriesList = m_queryList.CreateList(); m_activeSetsList = m_setList.CreateList(); m_freeSetsList = m_setList.CreateList(); }
//----------------------------------------------------------------------------- // Purpose: Attach the jetpack bar to the main panel //----------------------------------------------------------------------------- void CHudEMP::Init( void ) { if ( !m_pEMPIcon ) { m_pEMPIcon = materials->FindMaterial( "Hud/emp/emp_damage", TEXTURE_GROUP_VGUI ); assert( m_pEMPIcon ); m_pEMPIcon->IncrementReferenceCount(); m_pFrameVar = m_pEMPIcon->FindVar( "$frame", NULL, false ); m_nNumFrames = m_pEMPIcon->GetNumAnimationFrames(); } SetPos( HUDEMP_LEFT, HUDEMP_TOP ); SetSize( HUDEMP_WIDTH, HUDEMP_HEIGHT ); vgui::Panel *pParent = GetClientModeNormal()->GetViewport(); SetParent(pParent); }
void UpdateFullScreenDepthTexture( void ) { if( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_b() ) return; ITexture *pDepthTex = GetFullFrameDepthTexture(); CMatRenderContextPtr pRenderContext( materials ); if( IsX360() ) { pRenderContext->CopyRenderTargetToTextureEx( pDepthTex, -1, NULL, NULL ); } else { pRenderContext->CopyRenderTargetToTextureEx( pDepthTex, 0, NULL, NULL ); } pRenderContext->SetFullScreenDepthTextureValidityFlag( true ); if( r_depthoverlay.GetBool() ) { IMaterial *pMaterial = materials->FindMaterial( "debug/showz", TEXTURE_GROUP_OTHER, true ); pMaterial->IncrementReferenceCount(); IMaterialVar *BaseTextureVar = pMaterial->FindVar( "$basetexture", NULL, false ); IMaterialVar *pDepthInAlpha = NULL; if( IsPC() ) { pDepthInAlpha = pMaterial->FindVar( "$ALPHADEPTH", NULL, false ); pDepthInAlpha->SetIntValue( 1 ); } BaseTextureVar->SetTextureValue( pDepthTex ); pRenderContext->OverrideDepthEnable( true, false ); //don't write to depth, or else we'll never see translucents pRenderContext->DrawScreenSpaceQuad( pMaterial ); pRenderContext->OverrideDepthEnable( false, true ); pMaterial->DecrementReferenceCount(); } }
void CASW_Background_Movie::SetCurrentMovie( const char *szFilename ) { if ( Q_strcmp( m_szCurrentMovie, szFilename ) ) { #ifdef ASW_BINK_MOVIES if ( m_nBIKMaterial != BIKMATERIAL_INVALID ) { // FIXME: Make sure the m_pMaterial is actually destroyed at this point! g_pBIK->DestroyMaterial( m_nBIKMaterial ); m_nBIKMaterial = BIKMATERIAL_INVALID; m_nTextureID = -1; } char szMaterialName[ MAX_PATH ]; Q_snprintf( szMaterialName, sizeof( szMaterialName ), "BackgroundBIKMaterial%i", g_pBIK->GetGlobalMaterialAllocationNumber() ); m_nBIKMaterial = bik->CreateMaterial( szMaterialName, szFilename, "GAME", BIK_LOOP ); #else if ( m_nAVIMaterial != AVIMATERIAL_INVALID ) { // FIXME: Make sure the m_pMaterial is actually destroyed at this point! g_pAVI->DestroyAVIMaterial( m_nAVIMaterial ); m_nAVIMaterial = AVIMATERIAL_INVALID; m_nTextureID = -1; } char szMaterialName[ MAX_PATH ]; static int g_nGlobalAVIAllocationCount = 0; Q_snprintf( szMaterialName, sizeof( szMaterialName ), "BackgroundAVIMaterial%i", g_nGlobalAVIAllocationCount++ ); m_nAVIMaterial = g_pAVI->CreateAVIMaterial( szMaterialName, szFilename, "GAME" ); m_flStartTime = gpGlobals->realtime; IMaterial *pMaterial = avi->GetMaterial( m_nAVIMaterial ); pMaterial->IncrementReferenceCount(); #endif Q_snprintf( m_szCurrentMovie, sizeof( m_szCurrentMovie ), "%s", szFilename ); } }
bool CEngineSprite::Init( const char *pName ) { m_VideoMaterial = NULL; for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[ i ] = NULL; } m_width = m_height = m_numFrames = 1; Assert( g_pVideo != NULL ); if ( g_pVideo != NULL && g_pVideo->LocateVideoSystemForPlayingFile( pName ) != VideoSystem::NONE ) { m_VideoMaterial = g_pVideo->CreateVideoMaterial( pName, pName, "GAME", VideoPlaybackFlags::DEFAULT_MATERIAL_OPTIONS, VideoSystem::DETERMINE_FROM_FILE_EXTENSION, false ); if ( m_VideoMaterial == NULL ) return false; IMaterial *pMaterial = m_VideoMaterial->GetMaterial(); m_VideoMaterial->GetVideoImageSize( &m_width, &m_height ); m_numFrames = m_VideoMaterial->GetFrameCount(); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } else { char pTemp[MAX_PATH]; char pMaterialName[MAX_PATH]; char pMaterialPath[MAX_PATH]; Q_StripExtension( pName, pTemp, sizeof(pTemp) ); Q_strlower( pTemp ); Q_FixSlashes( pTemp, '/' ); // Check to see if this is a UNC-specified material name bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/'; if ( !bIsUNC ) { Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) ); Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS ); } else { Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) ); } Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) ); Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) ); KeyValues *kv = new KeyValues( "vmt" ); if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) ) { Warning( "Unable to load sprite material %s!\n", pMaterialPath ); return false; } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) { m_material[i] = NULL; continue; } Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName, i ); KeyValues *pMaterialKV = kv->MakeCopy(); pMaterialKV->SetInt( "$spriteRenderMode", i ); m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV ); m_material[ i ]->IncrementReferenceCount(); } kv->deleteThis(); m_width = m_material[0]->GetMappingWidth(); m_height = m_material[0]->GetMappingHeight(); m_numFrames = m_material[0]->GetNumAnimationFrames(); } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) continue; if ( !m_material[i] ) return false; } IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache ); m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT; IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache ); Vector origin, originVarValue; if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) ) { origin[0] = -m_width * 0.5f; origin[1] = m_height * 0.5f; } else { originVar->GetVecValue( &originVarValue[0], 3 ); origin[0] = -m_width * originVarValue[0]; origin[1] = m_height * originVarValue[1]; } up = origin[1]; down = origin[1] - m_height; left = origin[0]; right = m_width + origin[0]; return true; }
bool CEngineSprite::Init( const char *pName ) { m_hAVIMaterial = AVIMATERIAL_INVALID; m_hBIKMaterial = BIKMATERIAL_INVALID; m_width = m_height = m_numFrames = 1; const char *pExt = Q_GetFileExtension( pName ); bool bIsAVI = pExt && !Q_stricmp( pExt, "avi" ); #if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 ) bool bIsBIK = pExt && !Q_stricmp( pExt, "bik" ); #endif if ( bIsAVI && IsPC() ) { m_hAVIMaterial = avi->CreateAVIMaterial( pName, pName, "GAME" ); if ( m_hAVIMaterial == AVIMATERIAL_INVALID ) return false; IMaterial *pMaterial = avi->GetMaterial( m_hAVIMaterial ); avi->GetFrameSize( m_hAVIMaterial, &m_width, &m_height ); m_numFrames = avi->GetFrameCount( m_hAVIMaterial ); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } #if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 ) else if ( bIsBIK ) { m_hBIKMaterial = bik->CreateMaterial( pName, pName, "GAME" ); if ( m_hBIKMaterial == BIKMATERIAL_INVALID ) return false; IMaterial *pMaterial = bik->GetMaterial( m_hBIKMaterial ); bik->GetFrameSize( m_hBIKMaterial, &m_width, &m_height ); m_numFrames = bik->GetFrameCount( m_hBIKMaterial ); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } #endif else { char pTemp[MAX_PATH]; char pMaterialName[MAX_PATH]; char pMaterialPath[MAX_PATH]; Q_StripExtension( pName, pTemp, sizeof(pTemp) ); Q_strlower( pTemp ); Q_FixSlashes( pTemp, '/' ); // Check to see if this is a UNC-specified material name bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/'; if ( !bIsUNC ) { Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) ); Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS ); } else { Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) ); } Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) ); Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) ); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = NULL; } KeyValues *kv = new KeyValues( "vmt" ); if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) ) { Warning( "Unable to load sprite material %s!\n", pMaterialPath ); return false; } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) { continue; } // strip possible materials/ Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName + ( bIsUNC ? 0 : 10 ), i ); KeyValues *pMaterialKV = kv->MakeCopy(); pMaterialKV->SetInt( "$spriteRenderMode", i ); m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV ); m_material[i]->IncrementReferenceCount(); } kv->deleteThis(); m_width = m_material[0]->GetMappingWidth(); m_height = m_material[0]->GetMappingHeight(); m_numFrames = m_material[0]->GetNumAnimationFrames(); } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) continue; if ( !m_material[i] ) return false; } IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache ); m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT; IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache ); Vector origin, originVarValue; if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) ) { origin[0] = -m_width * 0.5f; origin[1] = m_height * 0.5f; } else { originVar->GetVecValue( &originVarValue[0], 3 ); origin[0] = -m_width * originVarValue[0]; origin[1] = m_height * originVarValue[1]; } up = origin[1]; down = origin[1] - m_height; left = origin[0]; right = m_width + origin[0]; return true; }
//----------------------------------------------------------------------------- // Draws all the debugging info //----------------------------------------------------------------------------- void CDebugViewRender::Draw2DDebuggingInfo(const CViewSetup &view) { if (IsX360() && IsRetail()) return; // HDRFIXME: Assert NULL rendertarget if (mat_yuv.GetInt() && (engine->GetDXSupportLevel() >= 80)) { IMaterial *pMaterial; pMaterial = materials->FindMaterial("debug/yuv", TEXTURE_GROUP_OTHER, true); if (!IsErrorMaterial(pMaterial)) { pMaterial->IncrementReferenceCount(); DrawScreenEffectMaterial(pMaterial, view.x, view.y, view.width, view.height); pMaterial->DecrementReferenceCount(); } } if (mat_hsv.GetInt() && (engine->GetDXSupportLevel() >= 90)) { IMaterial *pMaterial; pMaterial = materials->FindMaterial("debug/hsv", TEXTURE_GROUP_OTHER, true); if (!IsErrorMaterial(pMaterial)) { pMaterial->IncrementReferenceCount(); DrawScreenEffectMaterial(pMaterial, view.x, view.y, view.width, view.height); pMaterial->DecrementReferenceCount(); } } // Draw debugging lightmaps if (mat_showlightmappage.GetInt() != -1) { CLightmapDebugView clientView(assert_cast<CViewRender *>(::view)); clientView.Setup(view); clientView.Draw(); } if (cl_drawshadowtexture.GetInt()) { int nSize = cl_shadowtextureoverlaysize.GetInt(); g_pClientShadowMgr->RenderShadowTexture(nSize, nSize); } const char *pDrawMaterial = cl_drawmaterial.GetString(); if (pDrawMaterial && pDrawMaterial[0]) { RenderMaterial(pDrawMaterial); } if (mat_showwatertextures.GetBool()) { OverlayWaterTextures(); } if (mat_showcamerarendertarget.GetBool()) { float w = mat_wateroverlaysize.GetFloat(); float h = mat_wateroverlaysize.GetFloat(); OverlayCameraRenderTarget("debug/debugcamerarendertarget", 0, 0, w, h); } if (mat_showframebuffertexture.GetBool()) { // HDRFIXME: Get rid of these rendertarget sets assuming that the assert at the top of this function is true. CMatRenderContextPtr pRenderContext(materials); pRenderContext->PushRenderTargetAndViewport(NULL); OverlayFrameBufferTexture(0); OverlayFrameBufferTexture(1); pRenderContext->PopRenderTargetAndViewport(); } const char *pDrawTexture = mat_drawTexture.GetString(); if (pDrawTexture && pDrawTexture[0]) { OverlayShowTexture(pDrawTexture, mat_drawTextureScale.GetFloat()); } if (r_flashlightdrawdepth.GetBool()) { shadowmgr->DrawFlashlightDepthTexture(); } }