
// StrokingBufferState.hpp - GPU buffers for arc length for paths

#ifndef __StrokingBufferState_hpp__
#define __StrokingBufferState_hpp__

#include <GL/glew.h>
#ifdef __APPLE__
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
# ifdef _WIN32
#  include <windows.h>  // for wglGetProcAddress
# else
#  include <GL/glx.h>  // for glXGetProcAddress
# endif
#endif

// XXX this should move to polar/gpu/GPUStrokeTessellator.hpp eventually
class StrokingBufferState {
    static const GLuint max_links = 524288;   // size of link_ubo
    static const GLuint max_segments = 524288;  // size of segment_distance_ubo & segment_add_ops_ubo

    friend struct PathDrawState;  // needs access to max_links & max_segments

    enum  {
        global_binding_index = 0,
        link_binding_index = 1,
        segment_distance_binding_index = 2,
        segment_add_ops_binding_index = 3,
        NUM_BUFFERS = 4
    };

    GLuint ubo[NUM_BUFFERS];

    GLuint& global_ubo;
    GLuint& link_ubo;
    GLuint& segment_distance_ubo;
    GLuint& segment_add_ops_ubo;

    unsigned int next_distance_offset;

public:
    StrokingBufferState();
    void resetBuffers();
    void init();
    void resetNextDistanceOffset();
    void bind();
    void dumpBuffers(size_t links);
    void advanceNextDistanceOffset(size_t num_links);
    unsigned int nextDistanceOffset();
};

#endif // __StrokingBufferState_hpp__
