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; }
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; }
//==================================================================================== // PCache_InsertWorldPoly //==================================================================================== BOOL PCache_InsertWorldPoly(DRV_TLVertex *Verts, int32 NumVerts, geRDriver_THandle *THandle, DRV_TexInfo *TexInfo, DRV_LInfo *LInfo, uint32 Flags) { int32 Mip; geFloat ZRecip, DrawScaleU, DrawScaleV; World_Poly *pCachePoly; DRV_TLVertex *pVerts; PCache_TVert *pTVerts; PCache_Vert *pD3DVerts; int32 i; uint32 Alpha; #ifdef _DEBUG if (LInfo) { assert(LInfo->THandle); } #endif if ((WorldCache.NumVerts + NumVerts) >= MAX_WORLD_POLY_VERTS) { // If the cache is full, we must flush it before going on... if (!PCache_FlushWorldPolys()) return GE_FALSE; } else if (WorldCache.NumPolys+1 >= MAX_WORLD_POLYS) { // If the cache is full, we must flush it before going on... if (!PCache_FlushWorldPolys()) return GE_FALSE; } DrawScaleU = 1.0f / TexInfo->DrawScaleU; DrawScaleV = 1.0f / TexInfo->DrawScaleV; Mip = GetMipLevel(Verts, NumVerts, DrawScaleU, DrawScaleV, THandle->NumMipLevels-1); // Get a pointer to the original polys verts pVerts = Verts; // Store info about this poly in the cache pCachePoly = &WorldCache.Polys[WorldCache.NumPolys]; pCachePoly->THandle = THandle; pCachePoly->LInfo = LInfo; pCachePoly->Flags = Flags; pCachePoly->FirstVert = WorldCache.NumVerts; pCachePoly->NumVerts = NumVerts; pCachePoly->ShiftU = TexInfo->ShiftU; pCachePoly->ShiftV = TexInfo->ShiftV; pCachePoly->ScaleU = DrawScaleU; pCachePoly->ScaleV = DrawScaleV; pCachePoly->MipLevel = Mip; // Don't forget the sort key: pCachePoly->SortKey = ((THandle - TextureHandles)<<4)+Mip; // Get a pointer into the world verts pD3DVerts = &WorldCache.Verts[WorldCache.NumVerts]; pTVerts = &WorldCache.TVerts[WorldCache.NumVerts]; if (Flags & DRV_RENDER_ALPHA) Alpha = (uint32)pVerts->a<<24; else Alpha = (uint32)(255<<24); for (i=0; i< NumVerts; i++) { ZRecip = 1.0f/(pVerts->z); pD3DVerts->x = pVerts->x; pD3DVerts->y = pVerts->y; pD3DVerts->z = (1.0f - ZRecip); // ZBUFFER pD3DVerts->rhw = ZRecip; 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; // Store the uv's so the prep pass can use them... pTVerts->u = pVerts->u; pTVerts->v = pVerts->v; pTVerts->Color = Alpha | ((uint32)pVerts->r<<16) | ((uint32)pVerts->g<<8) | (uint32)pVerts->b; pTVerts++; pVerts++; pD3DVerts++; } // Update globals about the world poly cache WorldCache.NumVerts += NumVerts; WorldCache.NumPolys++; return TRUE; }