#pragma once

#if defined( __EMSCRIPTEN__ ) || defined( __ANDROID__ )
#include <GLES3/gl3.h>
#else
#include <glad/glad.h>
#endif

#include "crStruct.h"

// camera-facing billboard quads (particles) — one shared unit quad instanced per billboard, expanded
// toward the eye in the vertex shader (BILLBOARD program); drawn additive in the transparent phase
// (depth read, no write). the fragment shader samples an atlas region (uvRect) per billboard.
// pure GPU front-end: the caller (crParticleSystem) owns the instance array and passes it to Flush
class crBatchedBillboards
{
public:
    // per-instance stream — must match billboard.vert locations 2..6
    struct BillboardInstance
    {
        float3 pos;      // world center
        float  size;     // world diameter
        color4 color;
        float2 uvMin;    // atlas region — read as one vec4 (uvMin.xy, uvMax.zw)
        float2 uvMax;
        float2 cosSin;   // in-plane rotation (the quad spins, the uv stays — the image rotates)
    };

private:
    GLuint _vao         = 0;
    GLuint _quadVbo     = 0;
    GLuint _instanceVbo = 0;

public:
    void Init();
    void Cleanup();

    void Flush( GLuint program, GLuint texture, const BillboardInstance* instances, int32_t count );   // one instanced draw; additive, depth read-only
};
