void HSVSpriteBatch::draw_sprite(CL_GraphicContext &gc, const CL_Rectf &dest, const CL_Rect &src, const CL_Texture &texture, float hue_offset)
{
	gc.set_batcher(this);
	if (current_texture != texture)
	{
		flush(gc);
		current_texture = texture;
	}

	positions[fill_position+0] = CL_Vec2f(dest.left, dest.top);
	positions[fill_position+1] = CL_Vec2f(dest.right, dest.top);
	positions[fill_position+2] = CL_Vec2f(dest.left, dest.bottom);
	positions[fill_position+3] = CL_Vec2f(dest.right, dest.top);
	positions[fill_position+4] = CL_Vec2f(dest.left, dest.bottom);
	positions[fill_position+5] = CL_Vec2f(dest.right, dest.bottom);

	tex1_coords[fill_position+0] = CL_Vec2f(src.left/256.f, src.top/256.f);
	tex1_coords[fill_position+1] = CL_Vec2f(src.right/256.f, src.top/256.f);
	tex1_coords[fill_position+2] = CL_Vec2f(src.left/256.f, src.bottom/256.f);
	tex1_coords[fill_position+3] = CL_Vec2f(src.right/256.f, src.top/256.f);
	tex1_coords[fill_position+4] = CL_Vec2f(src.left/256.f, src.bottom/256.f);
	tex1_coords[fill_position+5] = CL_Vec2f(src.right/256.f, src.bottom/256.f);

	for (int i=0; i<6; i++)
		hue_offsets[fill_position+i] = hue_offset;

	fill_position += 6;

	if (fill_position == num_vertices)
		flush(gc);
}
int CL_RenderBatch3D::set_batcher_active(CL_GraphicContext &gc)
{
	if (use_glyph_program != false)
	{
		gc.flush_batcher();
		use_glyph_program = false;
	}

	if (position == 0 || position+6 > max_vertices)
		gc.flush_batcher();
	gc.set_batcher(this);
	return 4;
}
int CL_RenderBatch3D::set_batcher_active(CL_GraphicContext &gc, const CL_Texture &texture, bool glyph_program, const CL_Colorf &new_constant_color)
{
	if (use_glyph_program != glyph_program || constant_color != new_constant_color)
	{
		gc.flush_batcher();
		use_glyph_program = glyph_program;
		constant_color = new_constant_color;
	}

	int texindex = -1;
	for (int i = 0; i < num_current_textures; i++)
	{
		if (current_textures[i] == texture)
		{
			texindex = i;
			break;
		}
	}
	if (texindex == -1 && num_current_textures < max_textures)
	{
		texindex = num_current_textures;
		current_textures[num_current_textures++] = texture;
		tex_sizes[texindex] = CL_Sizef((float)current_textures[texindex].get_width(), (float)current_textures[texindex].get_height());
	}

	if (position == 0 || position+6 > max_vertices || texindex == -1)
	{
		gc.flush_batcher();
		texindex = 0;
		current_textures[texindex] = texture;
		num_current_textures = 1;
		tex_sizes[texindex] = CL_Sizef((float)current_textures[texindex].get_width(), (float)current_textures[texindex].get_height());
	}
	gc.set_batcher(this);
	return texindex;
}