#ifndef RENDER_RENDERER_H
#define RENDER_RENDERER_H
#include <memory>
#include "directional_shadow.h"
#include "ibl_resources.h"

class Shader;
class Scene;
class Graphic;
class IBLBaker;
class SkyboxRenderer;

class Renderer {
public:
    explicit Renderer(Graphic &graphic);
    // void RenderFrame_Old(Scene &scene) const;
    ~Renderer();

    void RenderFrame(Scene &scene) const;

    // [新增] 按 D3D11 face 顺序导入六张图：+X、-X、+Y、-Y、+Z、-Z。
    // 成功后会同步更新天空盒、irradiance、prefiltered cube 和 BRDF LUT。
    [[nodiscard]] bool LoadEnvironmentCube(const std::array<std::filesystem::path, 6> &facePaths);

    // [新增] 从目录自动查找 posx/negx/posy/negy/posz/negz，
    // 扩展名依次尝试 png/jpg/jpeg/bmp/tif/tiff。
    [[nodiscard]] bool LoadEnvironmentCubeDirectory(const std::filesystem::path &directory);

    // IBL 纹理是全局场景资源，而不是每种材质的资源
    [[nodiscard]] bool SetIBLTextures(const TextureCube *irradiance,
                                      const TextureCube *prefilteredEnvironment,
                                      const Texture2D *brdfLut) const;
    void SetIBLIntensity(float intensity) const noexcept;
    void SetIBLRotationRadians(float radians) const noexcept;
    void SetIBLEnabled(bool enabled) const noexcept;

    [[nodiscard]] IBLResources &GetIBLResources() noexcept { return *m_iblResources; }
    [[nodiscard]] const IBLResources &GetIBLResources() const noexcept { return *m_iblResources; }

private:
    Graphic &m_graphic;
    std::unique_ptr<DirectionalShadow> m_directionalShadow;

    std::unique_ptr<IBLResources> m_iblResources; //[add]

    // [新增] 运行时环境资源及其一次性烘焙器。
    std::unique_ptr<IBLBaker> m_iblBaker;
    std::unique_ptr<SkyboxRenderer> m_skyboxRenderer;
    std::unique_ptr<TextureCube> m_environmentCube;
    std::unique_ptr<TextureCube> m_iblIrradianceCube;
    std::unique_ptr<TextureCube> m_iblPrefilteredCube;
    std::unique_ptr<Texture2D> m_iblBrdfLut;

    //todo 暂时由此管理
    Shader *m_VS_ShadowDepth;
};








#endif //RENDER_RENDERER_H
