// © 2026, CGVR MPA Course
#pragma once

#include <glad/glad.h>

#include <cuda_runtime.h>
#include <cuda_gl_interop.h>

struct CudaGLImage;

/**
 * Render Mode for Jump Flooding Result
 */
enum JFARenderMode {
    Voronoi,
    Distance,
    Dilation,
    VoronoiBF,
    VoronoiDiff
};

/**
 * Implements the Jump Flooding Algorithm (JFA).
 */
class JumpFlooding {
public:
    /**
     * Represents "a pixel" during calculating the Jump Flooding Algorithm (JFA).
     */
    struct Seed {
        int x;
        int y;
        uchar4 color;
        int valid;
    };

    /**
     * Initializes the ping pong images with the given resolution.
     */
    JumpFlooding(int width, int height);

    /**
     * Destructor
     */
    ~JumpFlooding();

    /**
     * Performs the Jump Flooding Algorithm and renders the desired output.
     *
     * @param inputImage        A simple RGBA 8-bit input image.
     * @param outputImage       The output image (converted to an RGBA image)
     * @param
     * @param maxIterations     Maximal interations of the jump flooding algorithms.
     */
    void compute(CudaGLImage& inputImage, CudaGLImage& outputImage, JFARenderMode mode, int maxIterations = 99, float renderModeParam = 20);

private:
    int width = 0;
    int height = 0;

    // Ping Pong Images:
    Seed* ping = nullptr;
    Seed* pong = nullptr;
};
