print [@

#include <librnd/plugins/lib_hid_gl/draw.h>

extern hidgl_draw_t hidgl_draw_error;
extern hidgl_draw_t hidgl_draw_direct;

@]

if ?libs/gui/gl/vao/presents
then
print [@
extern hidgl_draw_t hidgl_draw_vao;
@]
end

print [@
static hidgl_draw_t *hidgl_draws;

#define DRAW_INSERT(drw) \
	do { \
		drw.next = hidgl_draws; \
		hidgl_draws = &drw; \
	} while(0)

/* create a linked list of all draw backends compiled */
RND_INLINE void hidgl_draw_init_(void)
{
	static int inited = 0;

	if (inited)
		return;
@]

if ?libs/gui/gl/vao/presents
then
print [@
	DRAW_INSERT(hidgl_draw_vao);
@]
end

print [@
	DRAW_INSERT(hidgl_draw_direct);

	inited = 1;
}
@]

print [@

/*** stencil ***/

#include <librnd/plugins/lib_hid_gl/stenc.h>

extern hidgl_stenc_t hidgl_stenc_error;
extern hidgl_stenc_t hidgl_stenc_direct;

@]

if ?libs/gui/gl/fb_attachment/presents
then
print [@
extern hidgl_stenc_t hidgl_stenc_framebuffer;
@]
end

print [@
static hidgl_stenc_t *hidgl_stencs;

#define STENC_INSERT(stc) \
	do { \
		stc.next = hidgl_stencs; \
		hidgl_stencs = &stc; \
	} while(0)

/* create a linked list of all stencil backends compiled */
RND_INLINE void hidgl_stenc_init_(void)
{
	static int inited = 0;

	if (inited)
		return;

	STENC_INSERT(hidgl_stenc_direct);
@]



if ?libs/gui/gl/fb_attachment/presents
then
print [@
	STENC_INSERT(hidgl_stenc_framebuffer);
@]
end


print [@
	inited = 1;
}

@]
