Skip to content

Commit

Permalink
fix material apply bug when reset uniform during one drawframe
Browse files Browse the repository at this point in the history
  • Loading branch information
rainfiel committed Aug 11, 2016
1 parent 91d66d7 commit 7396bea
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ struct material {
int texture[MAX_TEXTURE_CHANNEL];
bool uniform_enable[MAX_UNIFORM];
float uniform[1];
bool reset;
};

int
Expand All @@ -445,6 +446,7 @@ material_init(void *self, int size, int prog) {
memset(self, 0, rsz);
struct material * m = (struct material *)self;
m->p = p;
m->reset = false;
int i;
for (i=0;i<MAX_TEXTURE_CHANNEL;i++) {
m->texture[i] = -1;
Expand All @@ -463,6 +465,7 @@ material_setuniform(struct material *m, int index, int n, const float *v) {
}
memcpy(m->uniform + u->offset, v, n * sizeof(float));
m->uniform_enable[index] = true;
m->reset = true;
return 0;
}

Expand All @@ -471,9 +474,10 @@ material_apply(int prog, struct material *m) {
struct program * p = m->p;
if (p != &RS->program[prog])
return;
if (p->material == m) {
if (p->material == m && !m->reset) {
return;
}
m->reset = false;
p->material = m;
p->reset_uniform = true;
int i;
Expand Down Expand Up @@ -502,5 +506,6 @@ material_settexture(struct material *m, int channel, int texture) {
return 1;
}
m->texture[channel] = texture;
m->reset = true;
return 0;
}

0 comments on commit 7396bea

Please sign in to comment.