bool C_CFPlayer::OnPostInternalDrawModel( ClientModelRenderInfo_t *pInfo ) { CMatRenderContextPtr pRenderContext( materials ); pRenderContext->DepthRange(0.0f, 1.0f); return BaseClass::OnPostInternalDrawModel(pInfo); }
void OverlayCameraRenderTarget(const char *pszMaterialName, float flX, float flY, float w, float h) { float offsetS = (0.5f / 256.0f); float offsetT = (0.5f / 256.0f); IMaterial *pMaterial; pMaterial = materials->FindMaterial(pszMaterialName, TEXTURE_GROUP_OTHER, true); if (!IsErrorMaterial(pMaterial)) { CMatRenderContextPtr pRenderContext(materials); pRenderContext->Bind(pMaterial); IMesh* pMesh = pRenderContext->GetDynamicMesh(true); CMeshBuilder meshBuilder; meshBuilder.Begin(pMesh, MATERIAL_QUADS, 1); meshBuilder.Position3f(flX, flY, 0.0f); meshBuilder.TexCoord2f(0, 0.0f + offsetS, 0.0f + offsetT); meshBuilder.AdvanceVertex(); meshBuilder.Position3f(flX + w, flY, 0.0f); meshBuilder.TexCoord2f(0, 1.0f + offsetS, 0.0f + offsetT); meshBuilder.AdvanceVertex(); meshBuilder.Position3f(flX + w, flY + h, 0.0f); meshBuilder.TexCoord2f(0, 1.0f + offsetS, 1.0f + offsetT); meshBuilder.AdvanceVertex(); meshBuilder.Position3f(flX, flY + h, 0.0f); meshBuilder.TexCoord2f(0, 0.0f + offsetS, 1.0f + offsetT); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); } }
void CGlowOverlay::DrawOverlays( bool bCacheFullSceneState ) { VPROF("CGlowOverlay::DrawOverlays()"); CMatRenderContextPtr pRenderContext( materials ); bool bClippingEnabled = pRenderContext->EnableClipping( true ); unsigned short iNext; for( unsigned short i=g_GlowOverlaySystem.m_GlowOverlays.Head(); i != g_GlowOverlaySystem.m_GlowOverlays.InvalidIndex(); i = iNext ) { iNext = g_GlowOverlaySystem.m_GlowOverlays.Next( i ); CGlowOverlay *pOverlay = g_GlowOverlaySystem.m_GlowOverlays[i]; if( !pOverlay->m_bActivated ) continue; if( pOverlay->Update() ) { pRenderContext->EnableClipping( ((pOverlay->m_bInSky) ? (false):(bClippingEnabled)) ); //disable clipping in skybox, restore clipping to pre-existing state when not in skybox (it may be off as well) pOverlay->Draw( bCacheFullSceneState ); } else { delete pOverlay; } } pRenderContext->EnableClipping( bClippingEnabled ); //restore clipping to original state }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_PropCombineBall::DrawMotionBlur( void ) { float color[3]; Vector vecDir = GetAbsOrigin() - m_vecLastOrigin; float speed = VectorNormalize( vecDir ); speed = clamp( speed, 0, 32 ); float stepSize = MIN( ( speed * 0.5f ), 4.0f ); Vector spawnPos = GetAbsOrigin(); Vector spawnStep = -vecDir * stepSize; float base = RemapValClamped( speed, 4, 32, 0.0f, 1.0f ); CMatRenderContextPtr pRenderContext( materials ); pRenderContext->Bind( m_pBlurMaterial ); // Draw the motion blurred trail for ( int i = 0; i < 8; i++ ) { spawnPos += spawnStep; color[0] = color[1] = color[2] = base * ( 1.0f - ( (float) i / 12.0f ) ); DrawHalo( m_pBlurMaterial, spawnPos, m_flRadius, color ); } }
int C_Hairball::DrawModel( int flags ) { if ( !m_pMaterial ) return 0; CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); for ( int iHair=0; iHair < m_nHairs; iHair++ ) { CSimplePhysics::CNode *pBase = &m_Nodes[iHair * m_nNodesPerHair]; CBeamSegDraw beamDraw; beamDraw.Start( pRenderContext, m_nNodesPerHair-1, m_pMaterial ); for ( int i=0; i < m_nNodesPerHair; i++ ) { BeamSeg_t seg; seg.m_vPos = pBase[i].m_vPredicted; seg.m_vColor.Init( 0, 0, 0 ); seg.m_flTexCoord = 0; static float flHairWidth = 1; seg.m_flWidth = flHairWidth; seg.m_flAlpha = 0; beamDraw.NextSeg( &seg ); } beamDraw.End(); } return 1; }
//----------------------------------------------------------------------------- // Purpose: Sets view parameters for level overview mode // Input : *rect - //----------------------------------------------------------------------------- void CViewRender::SetUpOverView() { static int oldCRC = 0; m_View.m_bOrtho = true; float aspect = (float)m_View.width/(float)m_View.height; int size_y = 1024.0f * cl_leveloverview.GetFloat(); // scale factor, 1024 = OVERVIEW_MAP_SIZE int size_x = size_y * aspect; // standard screen aspect m_View.origin.x -= size_x / 2; m_View.origin.y += size_y / 2; m_View.m_OrthoLeft = 0; m_View.m_OrthoTop = -size_y; m_View.m_OrthoRight = size_x; m_View.m_OrthoBottom = 0; m_View.angles = QAngle( 90, 90, 0 ); // simple movement detector, show position if moved int newCRC = m_View.origin.x + m_View.origin.y + m_View.origin.z; if ( newCRC != oldCRC ) { Msg( "Overview: scale %.2f, pos_x %.0f, pos_y %.0f\n", cl_leveloverview.GetFloat(), m_View.origin.x, m_View.origin.y ); oldCRC = newCRC; } CMatRenderContextPtr pRenderContext( materials ); pRenderContext->ClearColor4ub( 0, 255, 0, 255 ); // render->DrawTopView( true ); }
void CReplayRenderer::LayoffFrame( int nFrame ) { VPROF_BUDGET( "CReplayRenderer::LayoffFrame", VPROF_BUDGETGROUP_REPLAY ); // FIXME: This is somewhat of a hack to get layoff working again // We're rendering into the full preview size, but stretching down to the actual size Rect_t srcRect; srcRect.x = 0; srcRect.y = 0; srcRect.width = m_RenderParams.m_Settings.m_nWidth; srcRect.height = m_RenderParams.m_Settings.m_nHeight; Rect_t dstRect; dstRect.x = 0; dstRect.y = 0; dstRect.width = m_RenderParams.m_Settings.m_nWidth; dstRect.height = m_RenderParams.m_Settings.m_nHeight; #ifdef TRACE_REPLAY_STATE_MACHINE Msg( "laying off movie frame %i\n", nFrame ); #endif CMatRenderContextPtr pRenderContext( materials ); // pRenderContext->ReadPixelsAndStretch( &srcRect, &dstRect, (unsigned char*)m_pLayoffBuf, // IMAGE_FORMAT_BGRA8888, dstRect.width * ImageLoader::SizeInBytes( IMAGE_FORMAT_BGRA8888 ) ); pRenderContext->ReadPixels( 0, 0, (int) m_RenderParams.m_Settings.m_nWidth, (int) m_RenderParams.m_Settings.m_nHeight, (unsigned char*)m_pLayoffBuf, IMAGE_FORMAT_BGRA8888 ); static ConVarRef mat_queue_mode( "mat_queue_mode" ); // Encode the frame #ifdef REPLAY_RECORDING_ENABLE if ( m_RenderParams.m_bExportRaw ) { CUtlBuffer bufOut; if ( TGAWriter::WriteToBuffer( (unsigned char *)m_pLayoffBuf, bufOut, m_RenderParams.m_Settings.m_nWidth, m_RenderParams.m_Settings.m_nHeight, IMAGE_FORMAT_BGRA8888, IMAGE_FORMAT_RGB888 ) ) { // Format filename and write the TGA CFmtStr fmtFilename( "%sFrame_%04i.tga", m_fmtTgaRenderDirName.Access(), m_iTgaFrame++ ); if ( !g_pFullFileSystem->WriteFile( fmtFilename.Access(), NULL, bufOut ) ) { Warning( "Couldn't write bitmap data snapshot to file %s.\n", fmtFilename.Access() ); } } } else if ( m_pMovieMaker ) { // can't run in any other mode Assert( mat_queue_mode.GetInt() == 0 ); VPROF_BUDGET( "CReplayRenderer::LayoffFrame - AppendVideoFrame", VPROF_BUDGETGROUP_REPLAY ); m_pMovieMaker->AppendVideoFrame( m_pLayoffBuf ); } #endif }
//----------------------------------------------------------------------------- // Sets a default env_cubemap for rendering materials w/ specularity //----------------------------------------------------------------------------- void CSceneViewerApp::InitDefaultEnvCubemap( ) { // Deal with the default cubemap CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); ITexture *pCubemapTexture = g_pMaterialSystem->FindTexture( "editor/cubemap", NULL, true ); m_DefaultEnvCubemap.Init( pCubemapTexture ); pRenderContext->BindLocalCubemap( pCubemapTexture ); }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- void CDmeDrawSettings::DrawDag( CDmeDag *pDag ) { if ( !pDag ) return; CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); m_IsAMaterialBound = false; if ( !Shaded() ) { BindWireframe(); } else if ( GetGrayShade() ) { BindGray(); } pDag->Draw( this ); m_IsAMaterialBound = false; if ( GetWireframeOnShaded() ) { if ( Shaded() ) { VMatrix m; pRenderContext->GetMatrix( MATERIAL_PROJECTION, &m ); /* Extract the near and far clipping plane values from projection matrix float c = m[ 2 ][ 2 ]; float d = m[ 2 ][ 3 ]; const float near = d / ( c - 1.0f ); const float far = d / ( c + 1.0f ); */ const float zBias = 0.00025; m[ 2 ][ 2 ] += zBias; m[ 2 ][ 3 ] += zBias; pRenderContext->MatrixMode( MATERIAL_PROJECTION ); pRenderContext->PushMatrix(); pRenderContext->LoadMatrix( m ); BindWireframeOnShaded(); PushDrawType(); SetDrawType( CDmeDrawSettings::DRAW_WIREFRAME ); pDag->Draw( this ); PopDrawType(); pRenderContext->MatrixMode( MATERIAL_PROJECTION ); pRenderContext->PopMatrix(); } } }
void CColorCorrectionMgr::RemoveColorCorrection( ClientCCHandle_t h ) { if ( h != INVALID_CLIENT_CCHANDLE ) { CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); ColorCorrectionHandle_t ccHandle = (ColorCorrectionHandle_t)h; pRenderContext->RemoveLookup( ccHandle ); } }
void DrawSmokeFogOverlay() { if(g_SmokeFogOverlayAlpha == 0 || !g_pSmokeFogMaterial || !materials) return; // Hard-coded for now.. g_SmokeFogOverlayColor.Init( 0.3, 0.3, 0.3 ); CMatRenderContextPtr pRenderContext( materials ); pRenderContext->MatrixMode( MATERIAL_PROJECTION ); pRenderContext->LoadIdentity(); pRenderContext->Ortho( 0, 0, 1, 1, -99999, 99999 ); pRenderContext->MatrixMode( MATERIAL_VIEW ); pRenderContext->LoadIdentity(); pRenderContext->MatrixMode( MATERIAL_MODEL ); pRenderContext->LoadIdentity(); IMesh* pMesh = pRenderContext->GetDynamicMesh( false, NULL, NULL, g_pSmokeFogMaterial ); CMeshBuilder meshBuilder; static float dist = 10; Vector vColor = g_SmokeFogOverlayColor; vColor.x = MIN(MAX(vColor.x, 0), 1); vColor.y = MIN(MAX(vColor.y, 0), 1); vColor.z = MIN(MAX(vColor.z, 0), 1); float alpha = MIN(MAX(g_SmokeFogOverlayAlpha, 0), 1); meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); meshBuilder.Position3f( 0, 0, dist ); meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( 0, 1, dist ); meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( 1, 1, dist ); meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( 1, 0, dist ); meshBuilder.Color4f( vColor.x, vColor.y, vColor.z, alpha ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
void CTextureSystem::RebindDefaultCubeMap() { // rebind with the default cubemap if ( m_pCubemapTexture ) { CMatRenderContextPtr pRenderContext( MaterialSystemInterface() ); pRenderContext->BindLocalCubemap( m_pCubemapTexture ); } }
//----------------------------------------------------------------------------- // Purpose: Draw our special effects //----------------------------------------------------------------------------- void C_WeaponStunStick::DrawFirstPersonEffects( void ) { Vector vecOrigin; QAngle vecAngles; float color[3]; float scale; CMatRenderContextPtr pRenderContext( materials ); IMaterial *pMaterial = materials->FindMaterial( STUNSTICK_GLOW_MATERIAL_NOZ, NULL, false ); // FIXME: Needs to work with new IMaterial system! pRenderContext->Bind( pMaterial ); // Find where we are in the fade float fadeAmount = RemapValClamped( gpGlobals->curtime, m_flFadeTime, m_flFadeTime + FADE_DURATION, 1.0f, 0.1f ); // Get bright when swung if ( InSwing() ) { color[0] = color[1] = color[2] = 0.4f; scale = 22.0f; } else { color[0] = color[1] = color[2] = 0.4f * fadeAmount; scale = 20.0f; } if ( color[0] > 0.0f ) { // Draw an all encompassing glow around the entire head UTIL_GetWeaponAttachment( this, m_BeamCenterAttachment, vecOrigin, vecAngles ); DrawHalo( pMaterial, vecOrigin, scale, color ); } // Draw bright points at each attachment location for ( int i = 0; i < (NUM_BEAM_ATTACHMENTS*2)+1; i++ ) { if ( InSwing() ) { color[0] = color[1] = color[2] = random->RandomFloat( 0.05f, 0.5f ); scale = random->RandomFloat( 4.0f, 5.0f ); } else { color[0] = color[1] = color[2] = random->RandomFloat( 0.05f, 0.5f ) * fadeAmount; scale = random->RandomFloat( 4.0f, 5.0f ) * fadeAmount; } if ( color[0] > 0.0f ) { UTIL_GetWeaponAttachment( this, i, vecOrigin, vecAngles ); DrawHalo( pMaterial, vecOrigin, scale, color ); } } }
//----------------------------------------------------------------------------- // Purpose: // Input : pMaterial - // source - // color - //----------------------------------------------------------------------------- void DrawHaloOriented( const Vector& source, float scale, float const *color, float roll ) { Vector point, screen; CMatRenderContextPtr pRenderContext( materials ); IMesh* pMesh = pRenderContext->GetDynamicMesh(); CMeshBuilder meshBuilder; meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); // Transform source into screen space ScreenTransform( source, screen ); Vector right, up; float sr, cr; SinCos( roll, &sr, &cr ); for ( int i = 0; i < 3; i++ ) { right[i] = CurrentViewRight()[i] * cr + CurrentViewUp()[i] * sr; up[i] = CurrentViewRight()[i] * -sr + CurrentViewUp()[i] * cr; } meshBuilder.Color3fv (color); meshBuilder.TexCoord2f (0, 0, 1); VectorMA (source, -scale, up, point); VectorMA (point, -scale, right, point); meshBuilder.Position3fv (point.Base()); meshBuilder.AdvanceVertex(); meshBuilder.Color3fv (color); meshBuilder.TexCoord2f (0, 0, 0); VectorMA (source, scale, up, point); VectorMA (point, -scale, right, point); meshBuilder.Position3fv (point.Base()); meshBuilder.AdvanceVertex(); meshBuilder.Color3fv (color); meshBuilder.TexCoord2f (0, 1, 0); VectorMA (source, scale, up, point); VectorMA (point, scale, right, point); meshBuilder.Position3fv (point.Base()); meshBuilder.AdvanceVertex(); meshBuilder.Color3fv (color); meshBuilder.TexCoord2f (0, 1, 1); VectorMA (source, -scale, up, point); VectorMA (point, scale, right, point); meshBuilder.Position3fv (point.Base()); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
//----------------------------------------------------------------------------- // Debugging aid to display a texture //----------------------------------------------------------------------------- static void OverlayShowTexture( const char* textureName, float scale ) { bool foundVar; IMaterial *pMaterial; IMaterialVar *BaseTextureVar; ITexture *pTex; float x, y, w, h; // ___error is created in code in CMaterialSystem::CreateDebugMaterials() pMaterial = materials->FindMaterial( "___error", TEXTURE_GROUP_OTHER, true ); BaseTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false ); if (!foundVar) return; CMatRenderContextPtr pRenderContext( materials ); if ( textureName && textureName[0] ) { pTex = materials->FindTexture( textureName, TEXTURE_GROUP_OTHER, false ); BaseTextureVar->SetTextureValue( pTex ); w = pTex->GetActualWidth() * scale; h = pTex->GetActualHeight() * scale; } else { w = h = 64.0f * scale; } // Center relative to current viewport int nViewportX, nViewportY, nViewportWidth, nViewportHeight; pRenderContext->GetViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight ); x = ( nViewportWidth - w ) * 0.5f; y = ( nViewportHeight - h ) * 0.5f; pRenderContext->Bind( pMaterial ); IMesh* pMesh = pRenderContext->GetDynamicMesh( true ); CMeshBuilder meshBuilder; meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); meshBuilder.Position3f( x, y, 0.0f ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x+w, y, 0.0f ); meshBuilder.TexCoord2f( 0, 1.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x+w, y+h, 0.0f ); meshBuilder.TexCoord2f( 0, 1.0f, 1.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x, y+h, 0.0f ); meshBuilder.TexCoord2f( 0, 0.0f, 1.0f ); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
//----------------------------------------------------------------------------- // Setup lighting //----------------------------------------------------------------------------- static void SetupLighting( int lightingCombination, Vector &lightOffset ) { CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); if( lightingCombination == 0 ) { g_pStudioRender->SetLocalLights( 0, NULL ); pRenderContext->SetAmbientLight( 1.0, 1.0, 1.0 ); static Vector white[6] = { Vector( 1.0, 1.0, 1.0 ), Vector( 1.0, 1.0, 1.0 ), Vector( 1.0, 1.0, 1.0 ), Vector( 1.0, 1.0, 1.0 ), Vector( 1.0, 1.0, 1.0 ), Vector( 1.0, 1.0, 1.0 ), }; g_pStudioRender->SetAmbientLightColors( white ); } else { pRenderContext->SetAmbientLight( 0.0f, 0.0f, 0.0f ); static Vector black[6] = { Vector( 0.0, 0.0, 0.0 ), Vector( 0.0, 0.0, 0.0 ), Vector( 0.0, 0.0, 0.0 ), Vector( 0.0, 0.0, 0.0 ), Vector( 0.0, 0.0, 0.0 ), Vector( 0.0, 0.0, 0.0 ), }; g_pStudioRender->SetAmbientLightColors( black ); int lightID; LightDesc_t lightDescs[MAX_LIGHTS]; for( lightID = 0; lightID < MAX_LIGHTS; lightID++ ) { int lightType = g_LightCombinations[lightingCombination][lightID]; lightDescs[lightID] = g_TestLights[lightType][lightID]; lightDescs[lightID].m_Position += lightOffset; } // Feed disabled lights through? if( g_LightCombinations[lightingCombination][1] == MATERIAL_LIGHT_DISABLE ) { g_pStudioRender->SetLocalLights( 1, lightDescs ); } else { g_pStudioRender->SetLocalLights( MAX_LIGHTS, lightDescs ); } } }
void CReplayRenderer::BeginRenderingSample( int nSample, int x, int y, int nWidth, int nHeight, float fTonemapScale ) { // Always start on ping-pong buffer zero if ( nSample == 0 ) { m_nCurrentPingPong = 0; } CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); pRenderContext->PushRenderTargetAndViewport( m_AccumBuffSample, x, y, nWidth, nHeight ); }
//----------------------------------------------------------------------------- // Purpose: // Input : pMaterial - // source - // color - //----------------------------------------------------------------------------- void DrawHalo(IMaterial* pMaterial, const Vector& source, float scale, float const* color, float flHDRColorScale ) { static unsigned int nHDRColorScaleCache = 0; Vector point, screen; if( pMaterial ) { IMaterialVar *pHDRColorScaleVar = pMaterial->FindVarFast( "$hdrcolorscale", &nHDRColorScaleCache ); if( pHDRColorScaleVar ) { pHDRColorScaleVar->SetFloatValue( flHDRColorScale ); } } CMatRenderContextPtr pRenderContext( materials ); IMesh* pMesh = pRenderContext->GetDynamicMesh( ); CMeshBuilder meshBuilder; meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); // Transform source into screen space ScreenTransform( source, screen ); meshBuilder.Color3fv (color); meshBuilder.TexCoord2f (0, 0, 1); VectorMA (source, -scale, CurrentViewUp(), point); VectorMA (point, -scale, CurrentViewRight(), point); meshBuilder.Position3fv (point.Base()); meshBuilder.AdvanceVertex(); meshBuilder.Color3fv (color); meshBuilder.TexCoord2f (0, 0, 0); VectorMA (source, scale, CurrentViewUp(), point); VectorMA (point, -scale, CurrentViewRight(), point); meshBuilder.Position3fv (point.Base()); meshBuilder.AdvanceVertex(); meshBuilder.Color3fv (color); meshBuilder.TexCoord2f (0, 1, 0); VectorMA (source, scale, CurrentViewUp(), point); VectorMA (point, scale, CurrentViewRight(), point); meshBuilder.Position3fv (point.Base()); meshBuilder.AdvanceVertex(); meshBuilder.Color3fv (color); meshBuilder.TexCoord2f (0, 1, 1); VectorMA (source, -scale, CurrentViewUp(), point); VectorMA (point, scale, CurrentViewRight(), point); meshBuilder.Position3fv (point.Base()); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- int C_BaseViewModel::InternalDrawModel( int flags ) { CMatRenderContextPtr pRenderContext( materials ); if ( ShouldFlipViewModel() ) pRenderContext->CullMode( MATERIAL_CULLMODE_CW ); int ret = BaseClass::InternalDrawModel( flags ); pRenderContext->CullMode( MATERIAL_CULLMODE_CCW ); return ret; }
CPixelVisibilityQuery::~CPixelVisibilityQuery() { CMatRenderContextPtr pRenderContext( materials ); if ( m_queryHandle != INVALID_OCCLUSION_QUERY_OBJECT_HANDLE ) { pRenderContext->DestroyOcclusionQueryObject( m_queryHandle ); } if ( m_queryHandleCount != INVALID_OCCLUSION_QUERY_OBJECT_HANDLE ) { pRenderContext->DestroyOcclusionQueryObject( m_queryHandleCount ); } }
//----------------------------------------------------------------------------- // Purpose: Renders the connecting lines between the keyframes // Input : pRender - //----------------------------------------------------------------------------- void CMapKeyFrame::Render3D( CRender3D *pRender ) { if ( m_bRebuildPath ) { if (GetAnimator() != NULL) { GetAnimator()->RebuildPath(); } } // only draw if we have a valid connection if ( m_pNextKeyFrame && m_flSpeed > 0 ) { // only draw if we haven't already been drawn this frame if ( GetRenderFrame() != pRender->GetRenderFrame() ) { pRender->PushRenderMode( RENDER_MODE_WIREFRAME ); SetRenderFrame( pRender->GetRenderFrame() ); Vector o1, o2; GetOrigin( o1 ); m_pNextKeyFrame->GetOrigin( o2 ); CMeshBuilder meshBuilder; CMatRenderContextPtr pRenderContext( MaterialSystemInterface() ); IMesh *pMesh = pRenderContext->GetDynamicMesh(); // draw connecting line going from green to red meshBuilder.Begin( pMesh, MATERIAL_LINE_STRIP, MAX_LINE_POINTS ); // start point meshBuilder.Color3f( 0, 1.0f, 0 ); meshBuilder.Position3f( o1[0], o1[1], o1[2] ); meshBuilder.AdvanceVertex(); for ( int i = 0; i < MAX_LINE_POINTS; i++ ) { float red = (float)(i+1) / (float)MAX_LINE_POINTS; meshBuilder.Color3f( red, 1.0f - red, 0 ); meshBuilder.Position3f( m_LinePoints[i][0], m_LinePoints[i][1], m_LinePoints[i][2] ); meshBuilder.AdvanceVertex(); } meshBuilder.End(); pMesh->Draw(); pRender->PopRenderMode(); } } }
//----------------------------------------------------------------------------- // Debugging aid to display a texture //----------------------------------------------------------------------------- static void OverlayShowTexture( const char* textureName, float scale ) { bool foundVar; IMaterial *pMaterial; IMaterialVar *BaseTextureVar; ITexture *pTex; float x, y, w, h; // screen safe x = 32; y = 32; pMaterial = materials->FindMaterial( "___debug", TEXTURE_GROUP_OTHER, true ); BaseTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false ); if (!foundVar) return; CMatRenderContextPtr pRenderContext( materials ); if ( textureName && textureName[0] ) { pTex = materials->FindTexture( textureName, TEXTURE_GROUP_OTHER, false ); BaseTextureVar->SetTextureValue( pTex ); w = pTex->GetActualWidth() * scale; h = pTex->GetActualHeight() * scale; } else { w = h = 64.0f * scale; } pRenderContext->Bind( pMaterial ); IMesh* pMesh = pRenderContext->GetDynamicMesh( true ); CMeshBuilder meshBuilder; meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); meshBuilder.Position3f( x, y, 0.0f ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x+w, y, 0.0f ); meshBuilder.TexCoord2f( 0, 1.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x+w, y+h, 0.0f ); meshBuilder.TexCoord2f( 0, 1.0f, 1.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x, y+h, 0.0f ); meshBuilder.TexCoord2f( 0, 0.0f, 1.0f ); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
//----------------------------------------------------------------------------- // Purpose: // Input : flags - // Output : int //----------------------------------------------------------------------------- int C_PropCombineBall::DrawModel( int flags ) { if ( !m_bEmit ) return 0; // Make sure our materials are cached if ( !InitMaterials() ) { //NOTENOTE: This means that a material was not found for the combine ball, so it may not render! AssertOnce( 0 ); return 0; } // Draw the flickering overlay DrawFlicker(); // Draw the motion blur from movement if ( m_bHeld || m_bLaunched ) { DrawMotionBlur(); } // Draw the model if we're being held if ( m_bHeld ) { QAngle angles; VectorAngles( -CurrentViewForward(), angles ); // Always orient towards the camera! SetAbsAngles( angles ); BaseClass::DrawModel( flags ); } else { float color[3]; color[0] = color[1] = color[2] = 1.0f; float sinOffs = 1.0f * sin( gpGlobals->curtime * 25 ); float roll = SpawnTime(); // Draw the main ball body CMatRenderContextPtr pRenderContext( materials ); pRenderContext->Bind( m_pBodyMaterial, (C_BaseEntity*) this ); DrawHaloOriented( GetAbsOrigin(), m_flRadius + sinOffs, color, roll ); } m_vecLastOrigin = GetAbsOrigin(); return 1; }
//----------------------------------------------------------------------------- // Purpose: // Input : frame - // x - // y - // *prcSubRect - //----------------------------------------------------------------------------- void CEngineSprite::DrawFrameOfSize( int frame, int x, int y, int iWidth, int iHeight, const wrect_t *prcSubRect ) { // FIXME: If we ever call this with AVIs, need to have it call GetTexCoordRange and make that work Assert( !IsAVI() && !IsBIK() ); float fLeft = 0; float fRight = 1; float fTop = 0; float fBottom = 1; if ( prcSubRect ) { AdjustSubRect( this, frame, &fLeft, &fRight, &fTop, &fBottom, &iWidth, &iHeight, prcSubRect ); } if ( giScissorTest && !Scissor( x, y, iWidth, iHeight, fLeft, fTop, fRight, fBottom ) ) return; SetFrame( frame ); CMatRenderContextPtr pRenderContext( materials ); IMesh* pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, GetMaterial() ); CMeshBuilder meshBuilder; meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); float color[3]; GetHUDSpriteColor( color ); meshBuilder.Color3fv( color ); meshBuilder.TexCoord2f( 0, fLeft, fTop ); meshBuilder.Position3f( x, y, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Color3fv( color ); meshBuilder.TexCoord2f( 0, fRight, fTop ); meshBuilder.Position3f( x + iWidth, y, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Color3fv( color ); meshBuilder.TexCoord2f( 0, fRight, fBottom ); meshBuilder.Position3f( x + iWidth, y + iHeight, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Color3fv( color ); meshBuilder.TexCoord2f( 0, fLeft, fBottom ); meshBuilder.Position3f( x, y + iHeight, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
void CColorCorrectionMgr::SetResetable( ClientCCHandle_t h, bool bResetable ) { // NOTE: Setting stuff to be not resettable doesn't work when in queued mode // because the logic that sets m_nActiveWeightCount to 0 in ResetColorCorrectionWeights // is no longer valid when stuff is not resettable. Assert( bResetable || !g_pMaterialSystem->GetThreadMode() == MATERIAL_SINGLE_THREADED ); if ( h != INVALID_CLIENT_CCHANDLE ) { CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); ColorCorrectionHandle_t ccHandle = (ColorCorrectionHandle_t)h; pRenderContext->SetResetable( ccHandle, bResetable ); } }
void CColorCorrectionMgr::ResetColorCorrectionWeights() { VPROF_("ResetColorCorrectionWeights", 2, VPROF_BUDGETGROUP_OTHER_UNACCOUNTED, false, 0); // FIXME: Where should I put this? It needs to happen prior to SimulateEntities() // which is where the client thinks for c_colorcorrection + c_colorcorrectionvolumes // update the color correction weights. CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); pRenderContext->ResetLookupWeights(); m_nActiveWeightCount = 0; m_bHaveExclusiveWeight = false; m_flExclusiveWeight = 0.0f; m_colorCorrectionWeights.RemoveAll(); }
void CReplayRenderer::ClearToBlack( CTextureReference &buf, int x, int y, int nWidth, int nHeight ) { CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); // Bind the resolving material AccumParams_t accParms = { m_AccumBuffSample, m_AccumBuffSample, 0.0f, true }; // true to clear to black pRenderContext->Bind( m_FourSampleResolveMatRef, &accParms ); // Render black quad to the layoff result pRenderContext->PushRenderTargetAndViewport( buf, x, y, nWidth, nHeight ); DrawResolvingQuad( nWidth, nHeight ); pRenderContext->PopRenderTargetAndViewport(); }
void CGlowObjectManager::RenderGlowEffects( const CViewSetup *pSetup, int nSplitScreenSlot ) { if ( glow_outline_effect_enable.GetBool() ) { CMatRenderContextPtr pRenderContext( materials ); int nX, nY, nWidth, nHeight; pRenderContext->GetViewport( nX, nY, nWidth, nHeight ); PIXEvent _pixEvent( pRenderContext, "EntityGlowEffects" ); ApplyEntityGlowEffects( pSetup, nSplitScreenSlot, pRenderContext, glow_outline_effect_width.GetFloat(), nX, nY, nWidth, nHeight ); } }
void FX_DrawLine( const Vector &start, const Vector &end, float scale, IMaterial *pMaterial, const color32 &color ) { Vector lineDir, viewDir; //Get the proper orientation for the line VectorSubtract( end, start, lineDir ); VectorSubtract( end, CurrentViewOrigin(), viewDir ); Vector cross = lineDir.Cross( viewDir ); VectorNormalize( cross ); CMatRenderContextPtr pRenderContext( materials ); //Bind the material IMesh* pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, pMaterial ); CMeshBuilder meshBuilder; Vector tmp; meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); VectorMA( start, -scale, cross, tmp ); meshBuilder.Position3fv( tmp.Base() ); meshBuilder.TexCoord2f( 0, 1.0f, 1.0f ); meshBuilder.Color4ub( color.r, color.g, color.b, color.a ); meshBuilder.Normal3fv( cross.Base() ); meshBuilder.AdvanceVertex(); VectorMA( start, scale, cross, tmp ); meshBuilder.Position3fv( tmp.Base() ); meshBuilder.TexCoord2f( 0, 0.0f, 1.0f ); meshBuilder.Color4ub( color.r, color.g, color.b, color.a ); meshBuilder.Normal3fv( cross.Base() ); meshBuilder.AdvanceVertex(); VectorMA( end, scale, cross, tmp ); meshBuilder.Position3fv( tmp.Base() ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.Color4ub( color.r, color.g, color.b, color.a ); meshBuilder.Normal3fv( cross.Base() ); meshBuilder.AdvanceVertex(); VectorMA( end, -scale, cross, tmp ); meshBuilder.Position3fv( tmp.Base() ); meshBuilder.TexCoord2f( 0, 1.0f, 0.0f ); meshBuilder.Color4ub( color.r, color.g, color.b, color.a ); meshBuilder.Normal3fv( cross.Base() ); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
//----------------------------------------------------------------------------- // main application //----------------------------------------------------------------------------- void CVsVGuiWindow::PaintWindow() { if ( m_nCurrentTick == m_nLastRenderedTick || !g_pVGui->IsRunning() ) { ValidateRect( m_hWnd, NULL ); return; } m_nCurrentTick = m_nLastRenderedTick; vgui::VPANEL root = g_pVGuiSurface->GetEmbeddedPanel(); g_pVGuiSurface->Invalidate( root ); RECT windowRect; CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); ::GetClientRect( m_hWnd, &windowRect ); g_pMaterialSystem->SetView( m_hWnd ); pRenderContext->Viewport( 0, 0, windowRect.right, windowRect.bottom ); float flStartTime = Plat_FloatTime(); pRenderContext->ClearColor4ub( 76, 88, 68, 255 ); pRenderContext->ClearBuffers( true, true ); g_pMaterialSystem->BeginFrame( 0 ); // draw from the main panel down if ( m_hMainPanel.Get() ) { int w, h; m_hMainPanel->GetSize( w, h ); if ( w != windowRect.right || h != windowRect.bottom ) { m_hMainPanel->SetBounds( 0, 0, windowRect.right, windowRect.bottom ); m_hMainPanel->Repaint(); } g_pVGuiSurface->RestrictPaintToSinglePanel( m_hMainPanel->GetVPanel() ); g_pVGuiSurface->PaintTraverseEx( root, true ); g_pVGuiSurface->RestrictPaintToSinglePanel( 0 ); } g_pMaterialSystem->EndFrame(); g_pMaterialSystem->SwapBuffers(); g_pMaterialSystem->SetView( NULL ); ValidateRect( m_hWnd, NULL ); m_flRenderDelayTime = Plat_FloatTime() - flStartTime; m_flRenderDelayTime = max( m_flRenderDelayTime, 0.015f ); }