#include "renderer2d.h"
#include "renderer.h"
#include "shader.h"
#include "skip.h"

#include <stdlib.h>

#include "gl.h"

struct vert {
	f32 x, y, z;
};

static void r_enter(struct sw_window *win, void *data);
static void r_exit(struct sw_window *win, void *data);

struct sw_renderer2d *sw_renderer2d_create() {
	struct sw_renderer2d *ren;
	char *frag, *vert;

	ren = malloc(sizeof(struct sw_renderer2d));
	ren->renderer = sw_renderer_create(ren, r_enter, r_exit);

	frag = sw_skip_get_string(sw_skip_self, "renderer2d_frag.glsl");
	vert = sw_skip_get_string(sw_skip_self, "renderer2d_vert.glsl");

	ren->shader = sw_shaderprogram_create((u8 *)vert, 0, (u8 *)frag, 0, 0);

	return ren;
}

static void r_enter(struct sw_window *win, void *data) {
	struct sw_renderer2d *ren;

	(void)win;

	ren = data;
	sw_shaderprogram_use(ren->shader);

	glBegin(GL_TRIANGLES);

	glVertex2i(0, 0);
	glVertex2i(1, 0);
	glVertex2i(0, 1);

	glEnd();
}

static void r_exit(struct sw_window *win, void *data) {
	(void)win;
	(void)data;
}
