Ejemplo n.º 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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 3
0
//====================================================================================
//	RenderWorldPolys
//====================================================================================
static BOOL RenderWorldPolys(int32 RenderMode)
{
	World_Poly			*pPoly;
	int32				i;

	if(!AppInfo.RenderingIsOK)
	{
		return	TRUE;
	}
	switch (RenderMode)
	{	
		case RENDER_WORLD_POLYS_NORMAL:
		{
			AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );

			// Set the default state for the normal poly render mode for the world
			D3DBlendEnable(TRUE);
			D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
			
			// Get the first poly in the sorted list
			SortWorldPolysByHandle();
			
			for (i=0; i< WorldCache.NumPolys; i++)
			{
				pPoly = WorldCache.SortedPolys[i];

				if (pPoly->Flags & DRV_RENDER_CLAMP_UV)
					D3DTexWrap(0, FALSE);
				else
					D3DTexWrap(0, TRUE);

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

				World_PolyPrepVerts(pPoly, PREP_WORLD_VERTS_NORMAL, 0, 0);

				D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
			}
			
			break;
		}
		
		case RENDER_WORLD_POLYS_LMAP:
		{
			AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0);

			D3DTexWrap(0, FALSE);

			D3DBlendEnable(TRUE);
			D3DBlendFunc (D3DBLEND_DESTCOLOR, D3DBLEND_ZERO);

			pPoly = WorldCache.Polys;
			BOOL	Dynamic = 0;

			for (i=0; i< WorldCache.NumPolys; i++, pPoly++)
			{

				if (!pPoly->LInfo)
					continue;

				// Call the engine to set this sucker up, because it's visible...
				D3DDRV.SetupLightmap(pPoly->LInfo, &Dynamic);

				if (!SetupLMap(0, pPoly->LInfo, 0, Dynamic))
					return GE_FALSE;

				World_PolyPrepVerts(pPoly, PREP_WORLD_VERTS_LMAP, 0, 0);

				D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
				
				if (pPoly->LInfo->RGBLight[1])
				{
					AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE);

					D3DBlendFunc (D3DBLEND_ONE, D3DBLEND_ONE);				// Change to a fog state

					// For some reason, some cards can't upload data to the same texture twice, and have it take.
					// So we force Fog maps to use a different slot than the lightmap was using...
					pPoly->LInfo->THandle->MipData[0].Slot = NULL;

					if (!SetupLMap(0, pPoly->LInfo, 1, 1))	// Dynamic is 1, because fog is always dynamic
						return GE_FALSE;

					D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
		
					D3DBlendFunc (D3DBLEND_DESTCOLOR, D3DBLEND_ZERO);		// Restore state

					if (AppInfo.FogEnable)
						AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , TRUE);
				}
			}
			break;
		}

		case RENDER_WORLD_POLYS_SINGLE_PASS:
		{
			// Setup texture stage states
			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);
									 
			AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 );
			AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
			AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); 
			AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_MODULATE );
			AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
			AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );
			//AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG2 );
			AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );

			// Setup frame buffer blend modes
			D3DBlendEnable(TRUE);
			D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);

			// Set the default state for the normal poly render mode for the world
			D3DTexWrap(TSTAGE_0, TRUE);
			D3DTexWrap(TSTAGE_1, FALSE);

			// Sort the list for front back operation to get the least number of world texture misses
			SortWorldPolysByHandle();
			
			// Reset non lightmaps faces to 0
			WorldCache.NumPolys2 = 0;

			for (i=0; i< WorldCache.NumPolys; i++)
			{
				BOOL	Dynamic = 0;

				pPoly = WorldCache.SortedPolys[i];

				if (!pPoly->LInfo)
				{
					// Put gouraud only polys in a seperate list, and render last
					WorldCache.SortedPolys2[WorldCache.NumPolys2++] = pPoly;
					continue;
				}

				if (pPoly->Flags & DRV_RENDER_CLAMP_UV)
					D3DTexWrap(TSTAGE_0, FALSE);
				else
					D3DTexWrap(TSTAGE_0, TRUE);

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

				// Call the engine to set this sucker up, because it's visible...
				D3DDRV.SetupLightmap(pPoly->LInfo, &Dynamic);

				if (!SetupLMap(TSTAGE_1, pPoly->LInfo, 0, Dynamic))
					return GE_FALSE;
					
				// Prep the verts for a lightmap and texture map
				World_PolyPrepVerts(pPoly, PREP_WORLD_VERTS_SINGLE_PASS, TSTAGE_0, TSTAGE_1);

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

				// Draw the texture
				D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);

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

				// Render any fog maps
				if (pPoly->LInfo->RGBLight[1])
				{
					D3DBlendFunc (D3DBLEND_ONE, D3DBLEND_ONE);				// Change to a fog state

				#if (TSTAGE_0 == 0)
					AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
					AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

					AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
				#else
					AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
					AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
				#endif

					// For some reason, some cards can't upload data to the same texture twice, and have it take.
					// So we force Fog maps to use a different slot other than what the lightmap was using...
					pPoly->LInfo->THandle->MipData[0].Slot = NULL;

					if (!SetupLMap(TSTAGE_1, pPoly->LInfo, 1, 1))	// Dynamic is 1, because fog is always dynamic
						return GE_FALSE;

					D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);
	
					// Restore states to the last state before f*g map
				#if (TSTAGE_0 == 0)
					AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
					AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE);
	
					AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_MODULATE );
				#else
					AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_MODULATE );
					AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG2 );
				#endif

					D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
				}
				
				
			}
			
			// Setup for any non-lightmaped faces faces, turn tmu1 off
		#if (TSTAGE_0 == 0)
			AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
			AppInfo.lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
		#else
			AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
			AppInfo.lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
		#endif

			// Render all the faces without lightmaps
			for (i=0; i< WorldCache.NumPolys2; i++)
			{
				BOOL	Dynamic = 0;

				pPoly = WorldCache.SortedPolys2[i];

				if (pPoly->Flags & DRV_RENDER_CLAMP_UV)
					D3DTexWrap(TSTAGE_0, FALSE);
				else
					D3DTexWrap(TSTAGE_0, TRUE);

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

				// Prep verts as if there was no lightmap
				World_PolyPrepVerts(pPoly, PREP_WORLD_VERTS_NORMAL, TSTAGE_0, TSTAGE_1);

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

				// Draw the texture
				D3DTexturedPoly(&WorldCache.Verts[pPoly->FirstVert], pPoly->NumVerts);

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

			break;						 
		}

		default:
			return FALSE;
	}


	return TRUE;
}