Ejemplo n.º 1
0
void 
shader_drawbuffer(struct render_buffer * rb, float tx, float ty, float scale) {
	rs_commit();

	RID glid = texture_glid(rb->texid);
	if (glid == 0)
		return;
	shader_texture(glid, 0);
	render_set(RS->R, VERTEXBUFFER, rb->vbid, 0);

	float sx = scale;
	float sy = scale;
	screen_trans(&sx, &sy);
	screen_trans(&tx, &ty);
	float v[4] = { sx, sy, tx, ty };

	// we should call shader_adduniform to add "st" uniform first
	shader_setuniform(PROGRAM_RENDERBUFFER, 0, UNIFORM_FLOAT4, v);

	shader_program(PROGRAM_RENDERBUFFER, NULL);
	RS->drawcall++;

	renderbuffer_commit(rb);

	render_set(RS->R, VERTEXBUFFER, RS->vertex_buffer, 0);
}
Ejemplo n.º 2
0
void
shader_init() {
	if (RS) return;

	struct render_state * rs = (struct render_state *) malloc(sizeof(*rs));
	memset(rs, 0 , sizeof(*rs));

	struct render_init_args RA;
	// todo: config these args
	RA.max_buffer = 128;
	RA.max_layout = 4;
	RA.max_target = 128;
	RA.max_texture = 256;
	RA.max_shader = MAX_PROGRAM;

	int rsz = render_size(&RA);
	rs->R = (struct render *)malloc(rsz);
	rs->R = render_init(&RA, rs->R, rsz);
	texture_initrender(rs->R);
	screen_initrender(rs->R);
	label_initrender(rs->R);
	lsprite_initrender(rs->R);
	renderbuffer_initrender(rs->R);

	rs->current_program = -1;
	rs->blendchange = 0;
	render_setblend(rs->R, BLEND_ONE, BLEND_ONE_MINUS_SRC_ALPHA);

	uint16_t idxs[6 * MAX_COMMBINE];
	int i;
	for (i=0;i<MAX_COMMBINE;i++) {
		idxs[i*6] = i*4;
		idxs[i*6+1] = i*4+1;
		idxs[i*6+2] = i*4+2;
		idxs[i*6+3] = i*4;
		idxs[i*6+4] = i*4+2;
		idxs[i*6+5] = i*4+3;
	}
	
	rs->index_buffer = render_buffer_create(rs->R, INDEXBUFFER, idxs, 6 * MAX_COMMBINE, sizeof(uint16_t));
	rs->vertex_buffer = render_buffer_create(rs->R, VERTEXBUFFER, NULL,  4 * MAX_COMMBINE, sizeof(struct vertex));

	struct vertex_attrib va[4] = {
		{ "position", 0, 2, sizeof(float), BUFFER_OFFSET(vp.vx) },
		{ "texcoord", 0, 2, sizeof(uint16_t), BUFFER_OFFSET(vp.tx) },
		{ "color", 0, 4, sizeof(uint8_t), BUFFER_OFFSET(rgba) },
		{ "additive", 0, 4, sizeof(uint8_t), BUFFER_OFFSET(add) },
	};
	rs->layout = render_register_vertexlayout(rs->R, sizeof(va)/sizeof(va[0]), va);
	render_set(rs->R, VERTEXLAYOUT, rs->layout, 0);
	render_set(rs->R, INDEXBUFFER, rs->index_buffer, 0);
	render_set(rs->R, VERTEXBUFFER, rs->vertex_buffer, 0);

	RS = rs;
}
Ejemplo n.º 3
0
void
shader_reset() {
	struct render_state *rs = RS;
	render_state_reset(rs->R);
	render_setblend(rs->R, BLEND_ONE, BLEND_ONE_MINUS_SRC_ALPHA);
	if (RS->current_program != -1) {
		render_shader_bind(rs->R, RS->program[RS->current_program].prog);
	}
	render_set(rs->R, VERTEXLAYOUT, rs->layout, 0);
	render_set(rs->R, TEXTURE, RS->tex[0], 0);
	render_set(rs->R, INDEXBUFFER, RS->index_buffer,0);
	render_set(rs->R, VERTEXBUFFER, RS->vertex_buffer,0);
}
Ejemplo n.º 4
0
static int		while_ft(t_env env)
{
	while (1)
	{
		ft_putendl("\nMake your play :");
		get_next_line(0, &env.set);
		if (valid_play(env.set, env.x))
		{
			if (!(env.pos = compute_play(ft_atoi(env.set) - 1,\
							&env, env.y - 1, '1')))
				ft_putendl("you cannot put this here");
			else
			{
				render_set(env.x, env.y, &env);
				env.check = winning_play(&env, ft_atoi(env.set) - 1,\
						env.pos, '1');
				if (env.check == 4)
					return (player_victory("\nHuman player won"));
			}
			if (ft_ia_turn(&env))
				return (player_victory("\nComputer won"));
		}
		else
			ft_putendl("\nInvalid move. Try again");
	}
	return (0);
}
Ejemplo n.º 5
0
void
shader_texture(int id, int channel) {
	assert(channel < MAX_TEXTURE_CHANNEL);
	if (RS->tex[channel] != id) {
		rs_commit();
		RS->tex[channel] = id;
		render_set(RS->R, TEXTURE, id, channel);
	}
}
Ejemplo n.º 6
0
const char*
texture_active_rt(int id) {
	if (id < 0 || id >= POOL.count)
		return "Invalid rt id";
	struct texture *tex = &POOL.tex[id];

	render_set(R, TARGET, tex->fb, 0);

	return NULL;
}
Ejemplo n.º 7
0
int				main(int ac, char **av)
{
	t_env		env;

	if (ac != 3)
		return (0);
	if (!(env.game = init_board(ft_atoi(av[1]), ft_atoi(av[2]), &env)))
		return (0);
	srand (time(NULL));
	env.start = rand() % 2 + 1;
	if (env.start == 2)
		play_IA_first(&env);
	render_set(env.x, env.y, &env);
	if (!while_ft(env))
		return (free_tabs(&env));
	return (0);
}