Example #1
0
BOOL DRIVERCC EndScene(void)
{
	HRESULT		Result;

	if (!AppInfo.lpD3DDevice)
		return FALSE;

	if(AppInfo.RenderingIsOK)
	{
		// Flush everything one last time...
		PCache_FlushWorldPolys();
		PCache_FlushMiscPolys();

		Result = AppInfo.lpD3DDevice->EndScene();

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

		if (!Main_ShowBackBuffer())
			return FALSE;
	}
	return TRUE;
}
Example #2
0
BOOL DRIVERCC EndModels(void)
{
	RenderMode = RENDER_NONE;

	if(AppInfo.RenderingIsOK)
	{
		PCache_FlushWorldPolys();
		PCache_FlushMiscPolys();

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

	}
	return TRUE;
}
Example #3
0
//====================================================================================
//	PCache_InsertMiscPoly
//====================================================================================
BOOL PCache_InsertMiscPoly(DRV_TLVertex *Verts, int32 NumVerts, geRDriver_THandle *THandle, uint32 Flags)
{
	int32			Mip;
	geFloat			ZRecip, u, v, ScaleU, ScaleV, InvScale;
	Misc_Poly		*pCachePoly;
	DRV_TLVertex	*pVerts;
	PCache_Vert		*pD3DVerts;
	int32			i, SAlpha;

	if ((MiscCache.NumVerts + NumVerts) >= MAX_MISC_POLY_VERTS)
	{
		// If the cache is full, we must flush it before going on...
		PCache_FlushMiscPolys();
	}
	else if (MiscCache.NumPolys+1 >= MAX_MISC_POLYS)
	{
		// If the cache is full, we must flush it before going on...
		PCache_FlushMiscPolys();
	}

	Mip = GetMipLevel(Verts, NumVerts, (geFloat)THandle->Width, (geFloat)THandle->Height, THandle->NumMipLevels-1);

	// Store info about this poly in the cache
	pCachePoly = &MiscCache.Polys[MiscCache.NumPolys];

	pCachePoly->THandle = THandle;
	pCachePoly->Flags = Flags;
	pCachePoly->FirstVert = MiscCache.NumVerts;
	pCachePoly->NumVerts = NumVerts;
	pCachePoly->MipLevel = Mip;
	pCachePoly->SortKey = ((THandle - TextureHandles)<<4)+Mip;

	// Get scale value for vertices
	//TCache_GetUVInvScale(Bitmap, Mip, &InvScale);
	InvScale = 1.0f / (geFloat)((1<<THandle->Log));

	// Convert them to take account that the vertices are allready from 0 to 1
	ScaleU = (geFloat)THandle->Width * InvScale;
	ScaleV = (geFloat)THandle->Height * InvScale;

	// Precompute the alpha value...
	SAlpha = ((int32)Verts->a)<<24;

	// Get a pointer to the original polys verts
	pVerts = Verts;
	// Get a pointer into the world verts
	pD3DVerts = &MiscCache.Verts[MiscCache.NumVerts];

	for (i=0; i< NumVerts; i++)
	{
		ZRecip = 1/(pVerts->z);

		pD3DVerts->x = pVerts->x;
		pD3DVerts->y = pVerts->y;

		pD3DVerts->z = (1.0f - ZRecip);		// ZBUFFER
		pD3DVerts->rhw = ZRecip;
		
		u = pVerts->u * ScaleU;
		v = pVerts->v * ScaleV;

		pD3DVerts->uv[0].u = u;
		pD3DVerts->uv[0].v = v;

		pD3DVerts->color = SAlpha | ((int32)pVerts->r<<16) | ((int32)pVerts->g<<8) | (int32)pVerts->b;

		if (AppInfo.FogEnable && !(Flags & DRV_RENDER_POLY_NO_FOG) ) // poly fog
		{
			DWORD	FogVal;
			geFloat	Val;

			Val = pVerts->z;

			if (Val > AppInfo.FogEnd)
				Val = AppInfo.FogEnd;

			FogVal = (DWORD)((AppInfo.FogEnd-Val)/(AppInfo.FogEnd-AppInfo.FogStart)*255.0f);
		
			if (FogVal < 0)
				FogVal = 0;
			else if (FogVal > 255)
				FogVal = 255;
		
			pD3DVerts->specular = (FogVal<<24);		// Alpha component in specular is the fog value (0...255)
		}
		else
			pD3DVerts->specular = 0;

		pVerts++;
		pD3DVerts++;
	}
	
	// Update globals about the misc poly cache
	MiscCache.NumVerts += NumVerts;
	MiscCache.NumPolys++;

	return TRUE;
}