Exemple #1
0
BOOL DRIVERCC BeginScene(BOOL Clear, BOOL ClearZ, RECT *WorldRect)
{
	HRESULT	Result;

	CurrentLRU++;

	if (!AppInfo.lpD3DDevice)
	{
		D3DMain_Log("BeginScene:  No D3D Device!.");
		return FALSE;
	}

	// Make sure we clear the cache info structure...
	memset(&CacheInfo, 0, sizeof(DRV_CacheInfo));

	if (!THandle_CheckCache())
		return GE_FALSE;

	//	Watch for inactive app or minimize
	if(AppInfo.RenderingIsOK)
	{
		if (!Main_ClearBackBuffer(Clear, ClearZ))
		{
			D3DMain_Log("D3DClearBuffers failed.");
			return FALSE;
		}
		
		D3DDRV.NumRenderedPolys = 0;
		
		Result = AppInfo.lpD3DDevice->BeginScene();

		if (Result != D3D_OK)
		{
			D3DMain_Log("BeginScene:  D3D BeginScene Failed.\n%s.", D3DErrorToString(Result));
			return FALSE;
		}

		D3DBilinearFilter(D3DFILTER_LINEAR, D3DFILTER_LINEAR);
		D3DPolygonMode (D3DFILL_SOLID);
		
		D3DZWriteEnable (TRUE);
		D3DZEnable(TRUE);
		D3DZFunc(D3DCMP_LESSEQUAL);

		D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
		D3DBlendEnable(TRUE);

		if (AppInfo.FogEnable)
		{
			AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , TRUE);
			AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR , ((DWORD)AppInfo.FogR<<16)|((DWORD)AppInfo.FogG<<8)|(DWORD)AppInfo.FogB);
		}
		else
		{
			AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , FALSE);
		}
	}

	return TRUE;
}
Exemple #2
0
//====================================================================================
//	PCache_FlushMiscPolys
//====================================================================================
BOOL PCache_FlushMiscPolys(void)
{
	int32				i;
	Misc_Poly			*pPoly;

	if (!MiscCache.NumPolys)
		return TRUE;

	if (!THandle_CheckCache())
		return GE_FALSE;

	// Set the render states
	if (AppInfo.CanDoMultiTexture)
	{
		AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
		AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
		D3DSetTexture(1, NULL);		// Reset texture stage 1
	}
	
	  AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0);
	  AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	  AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
	  AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
	  AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	  AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
	  AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE);
	  D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
	  D3DBlendEnable(TRUE);

	// Sort the polys by handle
	SortMiscPolysByHandle();

	for (i=0; i< MiscCache.NumPolys; i++)
	{
		pPoly = MiscCache.SortedPolys[i];

		if (pPoly->Flags & DRV_RENDER_NO_ZMASK)		// We are assuming that this is not going to change all that much
			D3DZEnable(FALSE);
		else
			D3DZEnable(TRUE);

		if (pPoly->Flags & DRV_RENDER_NO_ZWRITE)	// We are assuming that this is not going to change all that much
			D3DZWriteEnable(FALSE);	
		else
			D3DZWriteEnable(TRUE);
									  
		if (pPoly->Flags & DRV_RENDER_CLAMP_UV)
			D3DTexWrap(0, FALSE);
		else
			D3DTexWrap(0, TRUE);

		if (!SetupTexture(0, pPoly->THandle, pPoly->MipLevel))
			return GE_FALSE;

		if ( (pPoly->Flags & DRV_RENDER_POLY_NO_FOG) && AppInfo.FogEnable) // poly fog
			AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , FALSE);

		D3DTexturedPoly(&MiscCache.Verts[pPoly->FirstVert], pPoly->NumVerts);

		if ( (pPoly->Flags & DRV_RENDER_POLY_NO_FOG) && AppInfo.FogEnable) // poly fog
			AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , TRUE);
	}

	// Turn z stuff back on...
	D3DZWriteEnable (TRUE);
	D3DZEnable(TRUE);
	
	MiscCache.NumPolys = 0;
	MiscCache.NumVerts = 0;

#ifdef SUPER_FLUSH
	AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);
	AppInfo.lpD3DDevice->EndScene();
	AppInfo.lpD3DDevice->BeginScene();
#endif

	return TRUE;
}