#include "rendernode_forward.h"
#include "../renderapi.h"
#include "../window.h"
#include "object/camera/camera.h"
#include "../asset/model.h"
#include "asset/asset_manager.h"
namespace engineapi {
	RenderNodeForwardRendering::RenderNodeForwardRendering() 
		:RenderNode(RENDER_FORWARD_RENDERING)
	{
		mSky = AssetManager::GetSingletonPtr()->LoadAsset<Model>("assets/models/SkyBoxMesh.ply", Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG);
		//skyBoxMaterial = new Material(new Shader(Resources::GetAssetFullPath("Shaders/SkyBox.zxshader", true), FrameBufferType::Normal));


		//drawCommandID = RenderAPI::GetSingletonPtr()->AllocateDrawCommand(CommandType::ForwardRendering);
	}
	RenderNodeForwardRendering::~RenderNodeForwardRendering()
	{
	}
	void RenderNodeForwardRendering::Render(Camera& camera)
	{
		auto renderAPI = RenderAPI::GetSingletonPtr();
		auto window = Window::GetSingletonPtr();
		uint32_t width, height;
		window->GetSize(width, height);
		// 切换到主FBO
		//FBOManager::GetInstance()->SwitchFBO("Forward");
		// ViewPort设置为窗口大小
		renderAPI->SetViewPort(width, height);
		mContext->UsePass(mType);
		mContext->UseContext();
	}
	void RenderNodeForwardRendering::RenderSkyBox(Camera& camera)
	{
		// 先转3x3再回4x4，把相机位移信息去除
		Matrix4 mat_V = Matrix4(Matrix3(camera.GetViewMatrix()));
		Matrix4 mat_P = camera.GetProjectionMatrix();

		mSky->Use();
		//skyBoxMaterial->Use();
		//skyBoxMaterial->SetMatrix("ENGINE_View", mat_V);
		//skyBoxMaterial->SetMatrix("ENGINE_Projection", mat_P);
		//skyBoxMaterial->SetCubeMap("_Skybox", SceneManager::GetInstance()->GetCurScene()->skyBox->GetID(), 0);

		//RenderAPI::GetInstance()->Draw(skyBox->VAO);
	}
	void RenderNodeForwardRendering::RenderBatches(const map<uint32_t, vector<MeshRenderer*>>& batchs)
	{

	}
}
