#include "TerrainBlock.h"

TerrainBlock::TerrainBlock(TerrainBlockData& data, scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
	: ISceneNode(parent, mgr, id)
	, m_data(data)
{
}


TerrainBlock::~TerrainBlock()
{
}


void TerrainBlock::OnRegisterSceneNode()
{
	if (IsVisible)
		SceneManager->registerNodeForRendering(this);

	ISceneNode::OnRegisterSceneNode();
}

void TerrainBlock::render()
{
	video::IVideoDriver* driver = SceneManager->getVideoDriver();

	driver->setMaterial(m_data.material());
	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
	driver->drawVertexPrimitiveList(
		m_data.vertices(), 
		m_data.VERTEX_COUNT, 
		m_data.indices(), 
		m_data.PRIMITIVE_COUNT,
		video::EVT_STANDARD, 
		scene::EPT_TRIANGLES, 
		video::EIT_16BIT);
}
