예제 #1
0
//=====================================================================================
//	SetupTexture
//=====================================================================================
geBoolean SetupTexture(int32 Stage, geRDriver_THandle *THandle, int32 MipLevel)
{
#ifdef D3D_MANAGE_TEXTURES
	D3DSetTexture(Stage, THandle->MipData[MipLevel].Texture);
	return GE_TRUE;
#else
	THandle_MipData		*MipData;

	MipData = &THandle->MipData[MipLevel];
	
	if (!SetupMipData(MipData))
	{
		MipData->Flags |= THANDLE_UPDATE;		// Force an upload
		CacheInfo.TexMisses++;
	}

	if (MipData->Flags & THANDLE_UPDATE)
	{
		HRESULT					Error;
		LPDIRECTDRAWSURFACE4	Surface;

		Surface = D3DCache_SlotGetSurface(MipData->Slot);

		Error = Surface->BltFast(0, 0, MipData->Surface, NULL, DDBLTFAST_WAIT);

		if (Error != DD_OK)
		{
			if(Error==DDERR_SURFACELOST)
			{
				if (!D3DMain_RestoreAllSurfaces())
					return FALSE;
			}
			else
			{
				D3DMain_Log("SetupTexture: System to Video cache Blt failed.\n %s", D3DErrorToString(Error));
				return GE_FALSE;
			}
		}
	}

	MipData->Flags &= ~THANDLE_UPDATE;

	D3DCache_SlotSetLRU(MipData->Slot, CurrentLRU);
	D3DSetTexture(Stage, D3DCache_SlotGetTexture(MipData->Slot));

	return GE_TRUE;
#endif
}
예제 #2
0
/***************************************************************************\
  Blits one surface to another.
\**************************************************************************/
int IMR_DirectXInterface::Blit(LPDIRECTDRAWSURFACE4 Source, LPDIRECTDRAWSURFACE4 Target)
{
RECT Dest;
HRESULT ddrval;
DDSURFACEDESC2 SourceDesc, TargetDesc;
int BltX, BltY;

// Make sure DirectDraw is active:
if (!Flags.DirectDrawActive)
    {
    IMR_SetErrorText("IMR_DirectXInterface::Blit(): Interface not initialized!");
    return IMRERR_NOTREADY;
     }

// Make sure we have surfaces:
if (!Source || !Target)
    {
    IMR_SetErrorText("IMR_DirectXInterface::Blit(): NULL surface(s) specified!");
    return IMRERR_NODATA;
     }

// Get a surface descriptor for the surfaces:
TargetDesc.dwSize = sizeof(TargetDesc);
Target->GetSurfaceDesc(&TargetDesc);
SourceDesc.dwSize = sizeof(SourceDesc);
Source->GetSurfaceDesc(&SourceDesc);

// Now find the blit coords:
BltX = (TargetDesc.dwWidth / 2) - (SourceDesc.dwWidth / 2);
BltY = (TargetDesc.dwHeight / 2) - (SourceDesc.dwHeight / 2);

// Blit the surface:
ddrval = Target->BltFast(BltX, BltY, Source, NULL, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);

// If we lost the surface, return failure:
if (ddrval == DDERR_SURFACELOST)
    {
    Restore(Source);
    Restore(Target);
    IMR_SetErrorText("IMR_DirectXInterface::Blit(): Lost surface!");
    return IMRERR_DIRECTX;
     }

// Return ok:
return IMR_OK;
 }
예제 #3
0
//=====================================================================================
//	SetupLMap
//=====================================================================================
geBoolean SetupLMap(int32 Stage, DRV_LInfo *LInfo, int32 LNum, geBoolean Dynamic)
{
#ifdef D3D_MANAGE_TEXTURES
	#ifdef USE_TPAGES
	{
		geRDriver_THandle		*THandle;

		THandle = LInfo->THandle;

		if (Dynamic)
			THandle->Flags |= THANDLE_UPDATE;

		if (!THandle->Block)
		{
			THandle->Block = TPage_MgrFindOptimalBlock(TPageMgr, CurrentLRU);
			THandle->Flags |= THANDLE_UPDATE;
			TPage_BlockSetUserData(THandle->Block, THandle);
			assert(THandle->Block);
		}
		else if (TPage_BlockGetUserData(THandle->Block) != THandle)
		{
			// Find another block
			THandle->Block = TPage_MgrFindOptimalBlock(TPageMgr, CurrentLRU);
			assert(THandle->Block);

			THandle->Flags |= THANDLE_UPDATE;
			TPage_BlockSetUserData(THandle->Block, THandle);
		}

		if (THandle->Flags & THANDLE_UPDATE)
			FillLMapSurface2(LInfo, LNum);

		TPage_BlockSetLRU(THandle->Block, CurrentLRU);
		D3DSetTexture(Stage, TPage_BlockGetTexture(THandle->Block));
	
		if (Dynamic)
			THandle->Flags |= THANDLE_UPDATE;
		else
			THandle->Flags &= ~THANDLE_UPDATE;

		return GE_TRUE;
	}
	#else
	{
		geRDriver_THandle		*THandle;

		THandle = LInfo->THandle;

		if (Dynamic)
			THandle->MipData[0].Flags |= THANDLE_UPDATE;

		if (THandle->MipData[0].Flags & THANDLE_UPDATE)
			FillLMapSurface(LInfo, LNum);

		D3DSetTexture(Stage, THandle->MipData[0].Texture);
	
		if (Dynamic)
			THandle->MipData[0].Flags |= THANDLE_UPDATE;
		else
			THandle->MipData[0].Flags &= ~THANDLE_UPDATE;

		return GE_TRUE;
	}
	#endif

#else
	geRDriver_THandle	*THandle;
	THandle_MipData		*MipData;

	THandle = LInfo->THandle;
	MipData = &THandle->MipData[0];

	if (Dynamic)
		MipData->Flags |= THANDLE_UPDATE;

	if (!SetupMipData(MipData))
	{
		MipData->Flags |= THANDLE_UPDATE;		// Force an upload
		CacheInfo.LMapMisses++;
	}

	if (MipData->Flags & THANDLE_UPDATE)
	{
		HRESULT					Error;
		LPDIRECTDRAWSURFACE4	Surface;

		assert(MipData->Slot);
		
		Surface = D3DCache_SlotGetSurface(MipData->Slot);

		assert(Surface);
		assert(THandle->Log < MAX_LMAP_LOG_SIZE);
		assert(SystemToVideo[THandle->Log].Surface);

		LoadLMapFromSystem(LInfo, THandle->Log, LNum);

		Error = Surface->BltFast(0, 0, SystemToVideo[THandle->Log].Surface, NULL, DDBLTFAST_WAIT);
		//Error = Surface->BltFast(0, 0, SystemToVideo[THandle->Log].Surface, NULL, 0);
		//Error = Surface->Blt(NULL, SystemToVideo[THandle->Log].Surface, NULL, DDBLT_WAIT, NULL);
		//Error = Surface->Blt(NULL, SystemToVideo[THandle->Log].Surface, NULL, 0, NULL);
		
		if (Error != DD_OK)
		{
			if(Error==DDERR_SURFACELOST)
			{
				if (!D3DMain_RestoreAllSurfaces())
					return GE_FALSE;
			}
			else
			{
				D3DMain_Log("SetupTexture: System to Video cache Blt failed.\n %s", D3DErrorToString(Error));
				return GE_FALSE;
			}
		}
	}

	if (Dynamic)		// If it was dynmamic, force an update for one more frame
		MipData->Flags |= THANDLE_UPDATE;
	else
		MipData->Flags &= ~THANDLE_UPDATE;

	D3DCache_SlotSetLRU(MipData->Slot, CurrentLRU);
	D3DSetTexture(Stage, D3DCache_SlotGetTexture(MipData->Slot));

	return GE_TRUE;
#endif
}