#pragma once

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

#include "crArray.h"
#include "crStruct.h"

// GL_LINES batch — the bound program picks the space: world (line3d.vert, view from the
// GraphicsUniforms UBO) or screen (vertex_color.vert, u_projection set by the caller)
class crBatchedLines3D
{
private:
    // interleaved vertex stream — must match line3d.vert locations 0..1
    struct LineVertex
    {
        float3 pos;
        color4 color;
    };

    static constexpr int32_t INITIAL_RESERVE = 4096;

    crArray<LineVertex> _verts;

    GLuint _vao = 0;
    GLuint _vbo = 0;

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

    void Begin();
    void Line( float3 a, float3 b, color4 color );
    void Flush( GLuint program, bool depthTest );
    void ClearUnusedMemory();   // release CPU array + GPU buffer storage — for batches that go dormant (toggle off)
};
