예제 #1
0
파일: shader.c 프로젝트: 1414648814/ejoy2d
int 
material_size(int prog) {
	if (prog < 0 || prog >= MAX_PROGRAM)
		return 0;
	struct program *p = &RS->program[prog];
	if (p->uniform_number == 0 && p->texture_number == 0) {
		return 0;
	}
	struct uniform * lu = &p->uniform[p->uniform_number-1];
	int total = lu->offset + shader_uniformsize(lu->type);
	return sizeof(struct material) + (total-1) * sizeof(float);
}
예제 #2
0
파일: shader.c 프로젝트: 1414648814/ejoy2d
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;
}
예제 #3
0
파일: shader.c 프로젝트: 158466322/ejoy2d
int 
material_setuniform(struct material *m, int index, int n, const float *v) {
	struct program * p = m->p;
	assert(index >= 0 && index < p->uniform_number);
	struct uniform * u = &p->uniform[index];
	if (shader_uniformsize(u->type) != n) {
		return 1;
	}
	memcpy(m->uniform + u->offset, v, n * sizeof(float));
	m->uniform_enable[index] = true;
	return 0;
}
예제 #4
0
파일: shader.c 프로젝트: 1414648814/ejoy2d
int 
shader_adduniform(int prog, const char * name, enum UNIFORM_FORMAT t) {
	// reset current_program
	assert(prog >=0 && prog < MAX_PROGRAM);
	shader_program(prog, NULL);
	struct program * p = &RS->program[prog];
	assert(p->uniform_number < MAX_UNIFORM);
	int loc = render_shader_locuniform(RS->R, name);
	int index = p->uniform_number++;
	struct uniform * u = &p->uniform[index];
	u->loc = loc;
	u->type = t;
	if (index == 0) {
		u->offset = 0;
	} else {
		struct uniform * lu = &p->uniform[index-1];
		u->offset = lu->offset + shader_uniformsize(lu->type);
	}
	if (loc < 0)
		return -1;
	return index;
}