
// StrokingBufferState_global.cpp - global state for GPU buffers for arc length for paths 

#include <stdio.h>
#include <assert.h>

#include "StrokingBufferState.hpp"
#include "StrokingBufferState_global.hpp"

static StrokingBufferState* stroking_buffer_state = NULL;

void establishArcLengthBuffers()
{
    if (!stroking_buffer_state) {
        stroking_buffer_state = new StrokingBufferState;
        stroking_buffer_state->init();
    }
}

void bindArcLengthBuffers()
{
    establishArcLengthBuffers();
    stroking_buffer_state->bind();
}

void resetArcLengthBuffers()
{
    if (stroking_buffer_state) {
        stroking_buffer_state->resetBuffers();
    }
}

void dumpArcLengthBuffers(size_t links)
{
    if (stroking_buffer_state) {
        stroking_buffer_state->dumpBuffers(links);
    } else {
        printf("stroking_buffer_state not allocated\n");
    }
}

int nextDistanceOffsetOfArcLengthBuffers()
{
    assert(stroking_buffer_state);
    return stroking_buffer_state->nextDistanceOffset();
}

void advanceNextDistanceOffsetOfArcLengthBuffers(size_t links)
{
    assert(stroking_buffer_state);
    stroking_buffer_state->advanceNextDistanceOffset(links);
}
