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

#ifndef OPENGLFRAMEBUFFER_H
#define OPENGLFRAMEBUFFER_H
#include <Hazel/Core/Log.h>
#include <Hazel/Renderer/FrameBuffer.h>


namespace Hazel
{
    class OpenGLFrameBuffer : public FrameBuffer
    {
    public:
        OpenGLFrameBuffer(const FrameBufferSpecification& spec);
        virtual ~OpenGLFrameBuffer();

        void Bind() override;
        void UnBind() override;

        virtual const FrameBufferSpecification& GetSpecification() const override { return m_Specification; }
        virtual uint32_t GetColorAttachmentID(const uint32_t index = 0) const override {
            if (index > m_ColorAttachments.size())
            {
                HZ_CORE_ERROR("Attempting to access color attachment that is out-of-bounds");
            }
            return m_ColorAttachments[index];
        }

        virtual void ClearAttachment(uint32_t attachmentIndex, int value) override;
        virtual int ReadPixel(uint32_t attachmentIndex, int x, int y) override;
        virtual void Resize(uint32_t width, uint32_t height) override;
        virtual uint32_t GetColorAttachmentRendererID(const uint32_t index = 0) const override { return m_ColorAttachments[index]; }

        void Invalidata();

    private:
        uint32_t m_RendererID = 0;
        FrameBufferSpecification m_Specification;

        std::vector<FrameBufferTextureSpecification> m_ColorAttachmentsSpecifications;
        FrameBufferTextureSpecification m_DepthAttachmentSpecification = FrameBufferTextureFormat::NONE;

        std::vector<uint32_t> m_ColorAttachments;
        uint32_t m_DepthAttachment = 0;
    };
}

#endif //OPENGLFRAMEBUFFER_H
