//
// Created by sfd on 25-5-25.
//

#ifndef FRAMEBUFFER_H
#define FRAMEBUFFER_H
#include <vector>
#include <Hazel/Core/Core.h>

#include "glm/vec2.hpp"


namespace Hazel
{
    enum class FrameBufferTextureFormat
    {
        NONE = 0,

        // Color
        RGBA8,
        RED_INTEGER,

        // Depth/stencil
        DEPTH24STENCIL8,

        // Defaults
        DEPTH = DEPTH24STENCIL8
    };

    struct FrameBufferTextureSpecification
    {
        FrameBufferTextureSpecification() = default;
        FrameBufferTextureSpecification(FrameBufferTextureFormat format)
            : TextureFormat(format)
        {}

        FrameBufferTextureFormat TextureFormat = FrameBufferTextureFormat::NONE;
        // TODO: filtering / warp
    };

    struct FrameBufferAttachmentSpecification
    {
        FrameBufferAttachmentSpecification() = default;
        FrameBufferAttachmentSpecification(const std::initializer_list<FrameBufferTextureSpecification> attachments)
            : Attachments(attachments)
        {}

        std::vector<FrameBufferTextureSpecification> Attachments;
    };

    struct FrameBufferSpecification
    {
        uint32_t Width = 0, Height = 0;
        FrameBufferAttachmentSpecification Attachments;
        uint32_t Samples = 1;

        bool SwapChainTarget = false;
    };


    class HAZEL_API FrameBuffer
    {
    public:
        virtual ~FrameBuffer() = default;
        virtual uint32_t GetColorAttachmentID(uint32_t index = 0) const = 0;

        virtual int ReadPixel(uint32_t attachmentIndex, int x, int y) = 0;

        virtual void ClearAttachment(uint32_t index, int value) = 0;
        virtual uint32_t GetColorAttachmentRendererID(uint32_t index) const = 0;

        // virtual FrameBufferSpecification& GetSpecification() = 0;
        virtual const FrameBufferSpecification& GetSpecification() const = 0;

        virtual void Bind() = 0;
        virtual void UnBind() = 0;

        virtual void Resize(uint32_t width, uint32_t height) = 0;

        static Ref<FrameBuffer> Create(const FrameBufferSpecification& spec);
    };
}


#endif //FRAMEBUFFER_H
