void Optimizer::TwoPassZbuffer(const CameraParameter& rho, const IlluminationParameter& lamda, MeshPtr mesh, ModelPtr model, bool segment)
{
	int width = model->Rows();
	int height = model->Cols();

	mesh->UpdateVertexNormal();
	shared_ptr<Camera> camera = make_shared<PinholeCamera>(rho, width, height);
	shared_ptr<Camera> light = make_shared<PinholeCamera>(rho, lamda, width, height);
	shared_ptr<Illumination> illumination = make_shared<PhongIllumination>(lamda);

	HardwareRender render(camera, illumination);
	vector<float> depth_map(width*height);
	render.Rendering(mesh, lamda, depth_map);

	HardwareRender render2(light, illumination);
	vector<float> shadow_map(width*height);
	render2.Rendering(mesh, lamda, shadow_map);

	shared_ptr<DepthBuffer> object_depth = nullptr;
	shared_ptr<BoxRaster> raster = nullptr;
	SoftwareRender object_render(camera, illumination, object_depth, raster);
	if (segment)
	{
		object_render.TwoPassZbufferSegment(light, mesh, model, depth_map, shadow_map);
	}
	else
	{
		object_render.TwoPassZbuffer(light, mesh, model, depth_map, shadow_map);
	}
}
void Optimizer::GpuRendering(const CameraParameter& rho,
	const IlluminationParameter& lamda,
	MeshPtr mesh,
	ModelPtr model)
{
	int width = model->Rows();
	int height = model->Cols();

	mesh->UpdateVertexNormal();
	shared_ptr<Camera> camera = make_shared<PinholeCamera>(rho, width, height);
	shared_ptr<Camera> light = make_shared<PinholeCamera>(rho, lamda, ShadowResolution, ShadowResolution);
	shared_ptr<Illumination> illumination = make_shared<PhongIllumination>(lamda);

	//HardwareRender gpu_render(camera, light,illumination);
	HardwareRender gpu_render(camera, illumination);
	gpu_render.RenderingWithBackground(mesh, model, lamda);
	//gpu_render.RenderingWithShadow(mesh, lamda);
}