Beispiel #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);
}
Beispiel #2
0
void
shader_defaultblend() {
	if (RS->blendchange) {
		rs_commit();
		RS->blendchange = 0;
		render_setblend(RS->R, BLEND_ONE, BLEND_ONE_MINUS_SRC_ALPHA);
	}
}
Beispiel #3
0
void
shader_blend(int m1, int m2) {
	if (m1 != GL_ONE || m2 != GL_ONE_MINUS_SRC_ALPHA) {
		rs_commit();
		RS->blendchange = 1;
		glBlendFunc(m1,m2);
	}
}
Beispiel #4
0
void
shader_defaultblend() {
	if (RS->blendchange) {
		rs_commit();
		RS->blendchange = 0;
		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	}
}
Beispiel #5
0
void
shader_program(int n) {
	if (RS->current_program != n) {
		rs_commit();
		RS->current_program = n;
		glUseProgram(RS->program[n].prog);
	}
}
Beispiel #6
0
void
shader_texture(int id) {
	if (RS->tex != id) {
		rs_commit();
		RS->tex = (GLuint)id;
		glBindTexture(GL_TEXTURE_2D, id);
	}
}
Beispiel #7
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);
	}
}
Beispiel #8
0
void
shader_blend(int m1, int m2) {
	if (m1 != BLEND_GL_ONE || m2 != BLEND_GL_ONE_MINUS_SRC_ALPHA) {
		rs_commit();
		RS->blendchange = 1;
		enum BLEND_FORMAT src = blend_mode(m1);
		enum BLEND_FORMAT dst = blend_mode(m2);
		render_setblend(RS->R, src, dst);
	}
}
Beispiel #9
0
void
shader_st(int prog, float x, float y, float scale) {
	rs_commit();
    shader_program(prog);
    struct program *p = &RS->program[prog];

    if (!p || p->st == -1)
        return;

    glUniform4f(p->st, scale, scale, x, y);
}
Beispiel #10
0
void 
shader_setuniform(int prog, int index, enum UNIFORM_FORMAT t, float *v) {
	rs_commit();
	struct program * p = &RS->program[prog];
	assert(index >= 0 && index < p->uniform_number);
	struct uniform *u = &p->uniform[index];
	assert(t == u->type);
	int n = shader_uniformsize(t);
	memcpy(p->uniform_value + u->offset, v, n * sizeof(float));
	p->reset_uniform = true;
	p->uniform_change[index] = true;
}
Beispiel #11
0
void
shader_program(int n, struct material *m) {
	struct program *p = &RS->program[n];
	if (RS->current_program != n || p->reset_uniform || m) {
		rs_commit();
	}
	if (RS->current_program != n) {
		RS->current_program = n;
		render_shader_bind(RS->R, p->prog);
		p->material = NULL;
		apply_uniform(p);
	} else if (p->reset_uniform) {
		apply_uniform(p);
	}
	if (m) {
		material_apply(n, m);
	}
}
Beispiel #12
0
void 
shader_drawbuffer(struct render_buffer * rb, float tx, float ty, float scale) {
	rs_commit();
	int glid = texture_glid(rb->texid);
	if (glid == 0)
		return;
	shader_texture(glid);
	shader_program(PROGRAM_RENDERBUFFER);
	RS->drawcall++;
	glBindBuffer(GL_ARRAY_BUFFER, rb->vbid);

	float sx = scale;
	float sy = scale;
	screen_trans(&sx, &sy);
	screen_trans(&tx, &ty);
	struct program *p = &RS->program[RS->current_program];
	glUniform4f(p->st, sx, sy, tx, ty);

	renderbuffer_commit(rb);
}
Beispiel #13
0
void 
shader_flush() {
	rs_commit();
}
Beispiel #14
0
void
shader_draw(const struct vertex_pack vb[4], uint32_t color, uint32_t additive) {
	if (renderbuffer_add(&RS->vb, vb, color, additive)) {
		rs_commit();
	}
}