示例#1
0
//============================================================================================
//	THandle_Create
//============================================================================================
geRDriver_THandle *DRIVERCC THandle_Create(int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat)
{
	geRDriver_THandle	*THandle;

	THandle = FindTextureHandle();

	if (!THandle)
	{
		SetLastDrvError(DRV_ERROR_GENERIC, "D3DDRV:THandle_Create:  Out of texture handles.\n");
		return NULL;
	}

	THandle->PixelFormat = *PixelFormat;

	if (PixelFormat->Flags & RDRIVER_PF_3D)
	{
		// Get the pixel format desc for this thandle
		if (!SetupCurrent3dDesc(PixelFormat->PixelFormat))
			return NULL;

		if (!Create3DTHandle(THandle, Width, Height, NumMipLevels, PixelFormat))
			return NULL;

		CacheNeedsUpdate = GE_TRUE;
	}
	else if (PixelFormat->Flags & RDRIVER_PF_LIGHTMAP)
	{
		// Get the pixel format desc for this thandle
		if (!SetupCurrent3dDesc(PixelFormat->PixelFormat))
			return NULL;

		if (!CreateLightmapTHandle(THandle, Width, Height, NumMipLevels, PixelFormat))
			return NULL;

		CacheNeedsUpdate = GE_TRUE;
	}
	else if (PixelFormat->Flags & RDRIVER_PF_2D)
	{
		// 2d surfaces are always this format for now
		memcpy(&CurrentSurfDesc, &AppInfo.ddSurfFormat, sizeof(DDSURFACEDESC2));

		if (!Create2DTHandle(THandle, Width, Height, NumMipLevels, PixelFormat))
			return NULL;
	}

	return THandle;
}
// Create a new texture handle...
geRDriver_THandle *DRIVERCC THandle_Create(int32 Width, int32 Height, int32 NumMipLevels, 
										   const geRDriver_PixelFormat *PixelFormat)
{
	geRDriver_THandle	*THandle;	
	GLubyte				Log;

	
	THandle = FindTextureHandle();

	if (!THandle)
	{
		SetLastDrvError(DRV_ERROR_GENERIC, "OGL_THandleCreate: No more handles left.");
		gllog("ERROR:  OGL_THandleCreate: No more handles left.\n");
		goto ExitWithError;
	}

	if(PixelFormat->Flags & RDRIVER_PF_3D)
	{
		char errMsg[64];

		if(Width > maxTextureSize)
		{
			sprintf(errMsg, "OGL_THandleCreate: Width > GL_MAX_TEXTURE_SIZE (%d)", maxTextureSize);
			SetLastDrvError(DRV_ERROR_GENERIC, errMsg);
			gllog("%s\n", errMsg);
			goto ExitWithError;
		}

		if (Height > maxTextureSize)
		{
			sprintf(errMsg, "OGL_THandleCreate: Height > GL_MAX_TEXTURE_SIZE (%d)", maxTextureSize);
			SetLastDrvError(DRV_ERROR_GENERIC, errMsg);
			gllog("%s\n", errMsg);
			goto ExitWithError;
		}
	}

	THandle->MipLevels			= NumMipLevels;
	THandle->Width				= Width;
	THandle->Height				= Height;
	THandle->PixelFormat		= *PixelFormat;
	THandle->Flags				= 0;
	
	Log							= (uint8)GetLog(Width, Height);
	
	if(THandle->PixelFormat.Flags & RDRIVER_PF_2D)
	{
		THandle->PaddedWidth = SnapToPower2(THandle->Width);
		THandle->PaddedHeight = SnapToPower2(THandle->Height);
	}
	else if(THandle->PixelFormat.Flags & RDRIVER_PF_3D)
	{
		THandle->InvScale = 1.0f / (GLfloat)((1<<Log));
	}
	else
	{
		// Must be a lightmap
		THandle->Flags |= THANDLE_UPDATE_LM;
		THandle->InvScale = 1.0f / (GLfloat)((1<<Log)<<4);	
	}

	// Init an OpenGL texture object to hold this texture
	glGenTextures(1, &(THandle->TextureID));

	return THandle;
		
	ExitWithError:
	{
		return NULL;
	}
}