//-----------------------------------------------------------------------------
// Allocate, free standard render target textures
//-----------------------------------------------------------------------------
void CTextureManager::AllocateStandardRenderTargets( )
{
	bool bAllocateFullscreenTexture = ( m_nFlags & MATERIAL_INIT_ALLOCATE_FULLSCREEN_TEXTURE ) != 0;
	bool bAllocateMorphAccumTexture = g_pMorphMgr->ShouldAllocateScratchTextures();

	if ( IsPC() && ( bAllocateFullscreenTexture || bAllocateMorphAccumTexture ) )
	{
		MaterialSystem()->BeginRenderTargetAllocation();

		// A offscreen render target which is the size + format of the back buffer (*not* HDR format!)
		if ( bAllocateFullscreenTexture )
		{
			m_pFullScreenTexture = CreateRenderTargetTexture( "_rt_FullScreen", 1, 1, RT_SIZE_FULL_FRAME_BUFFER_ROUNDED_UP, 
				MaterialSystem()->GetBackBufferFormat(), RENDER_TARGET, TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT, 0 );
			m_pFullScreenTexture->IncrementReferenceCount();
		}

		// This texture is the one we accumulate morph deltas into
		if ( bAllocateMorphAccumTexture )
		{
			g_pMorphMgr->AllocateScratchTextures();
			g_pMorphMgr->AllocateMaterials();
		}

		MaterialSystem()->EndRenderTargetAllocation();
	}
}
Example #2
0
	void Rectangle::CreateShadowTexture() {
		const auto pRenderTarget = sD3DMgr.GetRenderTarget();
		const auto pOldSurface = pRenderTarget->GetRenderTargetSurface();

		uint32 width = static_cast<uint32>(GetWidth());
		uint32 height = static_cast<uint32>(GetHeight());
		m_shadowTexture = pRenderTarget->CreateRenderTargetTexture(width, height);

		if (m_shadowTexture == nullptr)
			throw std::runtime_error("Could not create shadow texture!");

		const auto pSurface = m_shadowTexture->GetObject()->QuerySurface(0);
		pRenderTarget->SetRenderTargetSurface(pSurface, 0, true);

		const auto dimensions = GetDimensions();
		const auto gradientColors = GetGradientColors();
		float4 horizRounding = GetHorizontalRoundings();
		float4 vertRounding = GetVerticalRoundings();

		if (((horizRounding._1 != 0.0f && vertRounding._1 != 0.0f) ||
			 (horizRounding._2 != 0.0f && vertRounding._2 != 0.0f) ||
			 (horizRounding._3 != 0.0f && vertRounding._3 != 0.0f) ||
			 (horizRounding._4 != 0.0f && vertRounding._4 != 0.0f)))
		{
			pRenderTarget->FillRoundedRectangle(
				Utils::Vector2(0.0f, 0.0f),
				dimensions,
				horizRounding,
				vertRounding,
				gradientColors);
		}
		else {
			pRenderTarget->FillRectangle(
				Utils::Vector2(0.0f, 0.0f),
				dimensions,
				gradientColors);
		}

		pRenderTarget->SetRenderTargetSurface(pOldSurface);
		GetGlobalInterface()->ClipStack.Apply();
	}