//
// Asura_Chunk_RenderSettings.cpp
//
// Created by Richard Rice - 01/07/04
// 
// Copyright (C) 2004 Rebellion, All Rights Reserved.
//

#include "Core/Asura.h"
#include "ChunkSystem/Asura_Chunk_RenderSettings.h"

#include "Core/Asura_String.h"
#include "ChunkSystem/Asura_Chunk_Stream.h"
#include "ChunkSystem/Asura_SaveBlock.h"
#include "FileAccess/Asura_FileAccess.h"
#include "Rendering/Asura_Render.h"



#define ASURA_CHUNK_RENDERSETTINGS_VERSION 0

bool Asura_Chunk_RenderSettings::Process (Asura_Chunk_Stream& xStream) const
{
	// Is this the correct version?

	if (Version > ASURA_CHUNK_RENDERSETTINGS_VERSION)
	{
		Asura_Assertf	(false, ("Unknown chunk version %d for render settings",Version));
		return			(false);
	}

	else
	{
		Asura_String	xReflectanceName;


		// Read the data before using it...
		xStream >> xReflectanceName;

		// SM3 doesn't use this
#ifndef ASURA_TARGET_SM3
		Asura_Render::SetReflectanceMapName	(xReflectanceName.GetString());
#endif //#ifndef ASURA_TARGET_SM3
		return								(true);
	}
}

bool Asura_Chunk_RenderSettings::Process(Asura_Handle iFileHandle) const
{
	Asura_Chunk_File_Stream	xStream (iFileHandle);


	// Call the other process function...

	return	(Process(xStream));
}

#ifdef ASURA_TOOLS
void Asura_Chunk_RenderSettings::Create (Asura_Chunk_Stream& xStream)
{
	Asura_String xReflectanceName = Asura_Render::GetReflectanceMapName();


	// Write the data...

	xStream.WriteChunk_Start	(ASURA_CHUNK_RENDERSETTINGS, ASURA_CHUNK_RENDERSETTINGS_VERSION, 0);

	xStream << xReflectanceName;

	xStream.WriteChunk_End	();
}

void Asura_Chunk_RenderSettings::Create(Asura_SaveBlock* pxSaveBlock)
{
	Asura_Chunk_SaveBlock_Stream	xStream (pxSaveBlock);


	// Call the other version...

	Create	(xStream);
}

#endif // ASURA_TOOLS
