Ejemplo n.º 1
0
/**
 * @brief Export all the faces for one particular lightmap (day or night)
 * @param path The path to write the files into
 * @param name The name of the map to export the lightmap for
 * @param day @c true to export the day lightmap data, @c false to export the night lightmap data
 */
static void ExportLightmap (const char* path, const char* name, bool day)
{
	const int lightmapIndex = day ? 1 : 0;
	const byte* bspLightBytes = curTile->lightdata[lightmapIndex];
	const byte quant = *bspLightBytes;
	const int scale = 1 << quant;

	for (int i = 0; i < curTile->numfaces; i++) {
		const dBspSurface_t* face = &curTile->faces[i];
		const byte* lightmap = bspLightBytes + face->lightofs[lightmapIndex];
		vec2_t texSize;

		CalcTextureSize(face, texSize, scale);

		/* write a tga image out */
		if (Vector2NotEmpty(texSize)) {
			char filename[MAX_QPATH];
			Com_sprintf(filename, sizeof(filename), "%s/%s_lightmap_%04d%c.tga", path, name, i, day ? 'd' : 'n');
			Com_Printf("Writing %s (%.0fx%.0f)\n", filename, texSize[0], texSize[1]);
			WriteTGA24(filename, lightmap, texSize[0], texSize[1], 0);
			Com_sprintf(filename, sizeof(filename), "%s/%s_direction_%04d%c.tga", path, name, i, day ? 'd' : 'n');
			Com_Printf("Writing %s (%.0fx%.0f)\n", filename, texSize[0], texSize[1]);
			WriteTGA24(filename, lightmap, texSize[0], texSize[1], 3);
		}
	}
}
	virtual void InitRHI()
	{
		TextureCubeRHI = RHICreateTextureCube(Size, Format, NumMips, 0, NULL);
		TextureRHI = TextureCubeRHI;

		if (SourceData)
		{
			check(SourceData->Num() > 0);

			const int32 BlockBytes = GPixelFormats[Format].BlockBytes;
			int32 MipBaseIndex = 0;

			for (int32 MipIndex = 0; MipIndex < NumMips; MipIndex++)
			{
				const int32 MipSize = 1 << (NumMips - MipIndex - 1);
				const int32 CubeFaceBytes = MipSize * MipSize * BlockBytes;

				for (int32 CubeFace = 0; CubeFace < CubeFace_MAX; CubeFace++)
				{
					uint32 DestStride = 0;
					uint8* DestBuffer = (uint8*)RHILockTextureCubeFace(TextureCubeRHI, CubeFace, 0, MipIndex, RLM_WriteOnly, DestStride, false);

					// Handle DestStride by copying each row
					for (int32 Y = 0; Y < MipSize; Y++)
					{
						uint8* DestPtr = ((uint8*)DestBuffer + Y * DestStride);
						const int32 SourceIndex = MipBaseIndex + CubeFace * CubeFaceBytes + Y * MipSize * BlockBytes;
						const uint8* SourcePtr = &(*SourceData)[SourceIndex];
						FMemory::Memcpy(DestPtr, SourcePtr, MipSize * BlockBytes);
					}

					RHIUnlockTextureCubeFace(TextureCubeRHI, CubeFace, 0, MipIndex, false);
				}

				MipBaseIndex += CubeFaceBytes * CubeFace_MAX;
			}

			if (!GIsEditor)
			{
				// Toss the source data now that we've created the cubemap
				// Note: can't do this if we ever use this texture resource in the editor and want to save the data later
				DEC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory,SourceData->GetAllocatedSize());
				SourceData->Empty();
			}
		}

		// Create the sampler state RHI resource.
		FSamplerStateInitializerRHI SamplerStateInitializer
		(
			SF_Trilinear,
			AM_Clamp,
			AM_Clamp,
			AM_Clamp
		);
		SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer);

		INC_MEMORY_STAT_BY(STAT_ReflectionCaptureTextureMemory,CalcTextureSize(Size,Size,Format,NumMips) * 6);
	}
Ejemplo n.º 3
0
const uint8* FDDSLoadHelper::GetDDSDataPointer(ECubeFace Face) const
{
	uint32 SliceSize = CalcTextureSize(DDSHeader->dwWidth, DDSHeader->dwHeight, ComputePixelFormat(), ComputeMipMapCount());

	const uint8* Ptr = (const uint8*)DDSHeader + sizeof(FDDSFileHeader);

	// jump over the not requested slices / cube map sides
	Ptr += SliceSize * Face;

	return Ptr;
}
	virtual void ReleaseRHI()
	{
		DEC_MEMORY_STAT_BY(STAT_ReflectionCaptureTextureMemory,CalcTextureSize(Size,Size,Format,NumMips) * 6);
		TextureCubeRHI.SafeRelease();
		FTexture::ReleaseRHI();
	}