DRW: Add DRW_UNIFORM_FLOAT_COPY and DRW_UNIFORM_BOOL_COPY.
And also use a union instead of forcing the cast to void*.
This commit is contained in:
parent
10b9c86c80
commit
ef49a587d4
|
@ -371,6 +371,8 @@ void DRW_shgroup_uniform_mat3(DRWShadingGroup *shgroup, const char *name, const
|
|||
void DRW_shgroup_uniform_mat4(DRWShadingGroup *shgroup, const char *name, const float (*value)[4]);
|
||||
/* Store value instead of referencing it. */
|
||||
void DRW_shgroup_uniform_int_copy(DRWShadingGroup *shgroup, const char *name, const int value);
|
||||
void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value);
|
||||
void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value);
|
||||
|
||||
/* Passes */
|
||||
DRWPass *DRW_pass_create(const char *name, DRWState state);
|
||||
|
|
|
@ -157,11 +157,13 @@ typedef struct DRWCall {
|
|||
/* Used by DRWUniform.type */
|
||||
typedef enum {
|
||||
DRW_UNIFORM_BOOL,
|
||||
DRW_UNIFORM_BOOL_COPY,
|
||||
DRW_UNIFORM_SHORT_TO_INT,
|
||||
DRW_UNIFORM_SHORT_TO_FLOAT,
|
||||
DRW_UNIFORM_INT,
|
||||
DRW_UNIFORM_INT_COPY,
|
||||
DRW_UNIFORM_FLOAT,
|
||||
DRW_UNIFORM_FLOAT_COPY,
|
||||
DRW_UNIFORM_TEXTURE,
|
||||
DRW_UNIFORM_TEXTURE_PERSIST,
|
||||
DRW_UNIFORM_TEXTURE_REF,
|
||||
|
@ -171,7 +173,13 @@ typedef enum {
|
|||
|
||||
struct DRWUniform {
|
||||
DRWUniform *next; /* single-linked list */
|
||||
const void *value;
|
||||
union {
|
||||
/* For reference or array/vector types. */
|
||||
const void *pvalue;
|
||||
/* Single values. */
|
||||
float fvalue;
|
||||
int ivalue;
|
||||
};
|
||||
int location;
|
||||
char type; /* DRWUniformType */
|
||||
char length; /* cannot be more than 16 */
|
||||
|
|
|
@ -78,10 +78,24 @@ static void drw_shgroup_uniform_create_ex(DRWShadingGroup *shgroup, int loc,
|
|||
DRWUniform *uni = BLI_mempool_alloc(DST.vmempool->uniforms);
|
||||
uni->location = loc;
|
||||
uni->type = type;
|
||||
uni->value = value;
|
||||
uni->length = length;
|
||||
uni->arraysize = arraysize;
|
||||
|
||||
switch (type) {
|
||||
case DRW_UNIFORM_INT_COPY:
|
||||
uni->ivalue = *((int *)value);
|
||||
break;
|
||||
case DRW_UNIFORM_BOOL_COPY:
|
||||
uni->ivalue = (int)*((bool *)value);
|
||||
break;
|
||||
case DRW_UNIFORM_FLOAT_COPY:
|
||||
uni->fvalue = *((float *)value);
|
||||
break;
|
||||
default:
|
||||
uni->pvalue = value;
|
||||
break;
|
||||
}
|
||||
|
||||
BLI_LINKS_PREPEND(shgroup->uniforms, uni);
|
||||
}
|
||||
|
||||
|
@ -214,9 +228,20 @@ void DRW_shgroup_uniform_mat4(DRWShadingGroup *shgroup, const char *name, const
|
|||
/* Stores the int instead of a pointer. */
|
||||
void DRW_shgroup_uniform_int_copy(DRWShadingGroup *shgroup, const char *name, const int value)
|
||||
{
|
||||
drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_INT_COPY, SET_INT_IN_POINTER(value), 1, 1);
|
||||
drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_INT_COPY, &value, 1, 1);
|
||||
}
|
||||
|
||||
void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value)
|
||||
{
|
||||
drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_BOOL_COPY, &value, 1, 1);
|
||||
}
|
||||
|
||||
void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value)
|
||||
{
|
||||
drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT_COPY, &value, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
|
@ -914,58 +914,61 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
|
|||
drw_stencil_set(shgroup->stencil_mask);
|
||||
|
||||
/* Binding Uniform */
|
||||
/* Don't check anything, Interface should already contain the least uniform as possible */
|
||||
for (DRWUniform *uni = shgroup->uniforms; uni; uni = uni->next) {
|
||||
switch (uni->type) {
|
||||
case DRW_UNIFORM_SHORT_TO_INT:
|
||||
val = (int)*((short *)uni->value);
|
||||
GPU_shader_uniform_vector_int(
|
||||
shgroup->shader, uni->location, uni->length, uni->arraysize, &val);
|
||||
break;
|
||||
case DRW_UNIFORM_INT_COPY:
|
||||
val = GET_INT_FROM_POINTER(uni->value);
|
||||
val = (int)*((short *)uni->pvalue);
|
||||
GPU_shader_uniform_vector_int(
|
||||
shgroup->shader, uni->location, uni->length, uni->arraysize, &val);
|
||||
break;
|
||||
case DRW_UNIFORM_SHORT_TO_FLOAT:
|
||||
fval = (float)*((short *)uni->value);
|
||||
fval = (float)*((short *)uni->pvalue);
|
||||
GPU_shader_uniform_vector(
|
||||
shgroup->shader, uni->location, uni->length, uni->arraysize, (float *)&fval);
|
||||
break;
|
||||
case DRW_UNIFORM_BOOL_COPY:
|
||||
case DRW_UNIFORM_INT_COPY:
|
||||
GPU_shader_uniform_vector_int(
|
||||
shgroup->shader, uni->location, uni->length, uni->arraysize, &uni->ivalue);
|
||||
break;
|
||||
case DRW_UNIFORM_BOOL:
|
||||
case DRW_UNIFORM_INT:
|
||||
GPU_shader_uniform_vector_int(
|
||||
shgroup->shader, uni->location, uni->length, uni->arraysize, (int *)uni->value);
|
||||
shgroup->shader, uni->location, uni->length, uni->arraysize, (int *)uni->pvalue);
|
||||
break;
|
||||
case DRW_UNIFORM_FLOAT_COPY:
|
||||
GPU_shader_uniform_vector(
|
||||
shgroup->shader, uni->location, uni->length, uni->arraysize, &uni->fvalue);
|
||||
break;
|
||||
case DRW_UNIFORM_FLOAT:
|
||||
GPU_shader_uniform_vector(
|
||||
shgroup->shader, uni->location, uni->length, uni->arraysize, (float *)uni->value);
|
||||
shgroup->shader, uni->location, uni->length, uni->arraysize, (float *)uni->pvalue);
|
||||
break;
|
||||
case DRW_UNIFORM_TEXTURE:
|
||||
tex = (GPUTexture *)uni->value;
|
||||
tex = (GPUTexture *)uni->pvalue;
|
||||
BLI_assert(tex);
|
||||
bind_texture(tex, BIND_TEMP);
|
||||
GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
|
||||
break;
|
||||
case DRW_UNIFORM_TEXTURE_PERSIST:
|
||||
tex = (GPUTexture *)uni->value;
|
||||
tex = (GPUTexture *)uni->pvalue;
|
||||
BLI_assert(tex);
|
||||
bind_texture(tex, BIND_PERSIST);
|
||||
GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
|
||||
break;
|
||||
case DRW_UNIFORM_TEXTURE_REF:
|
||||
tex = *((GPUTexture **)uni->value);
|
||||
tex = *((GPUTexture **)uni->pvalue);
|
||||
BLI_assert(tex);
|
||||
bind_texture(tex, BIND_TEMP);
|
||||
GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
|
||||
break;
|
||||
case DRW_UNIFORM_BLOCK:
|
||||
ubo = (GPUUniformBuffer *)uni->value;
|
||||
ubo = (GPUUniformBuffer *)uni->pvalue;
|
||||
bind_ubo(ubo, BIND_TEMP);
|
||||
GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
|
||||
break;
|
||||
case DRW_UNIFORM_BLOCK_PERSIST:
|
||||
ubo = (GPUUniformBuffer *)uni->value;
|
||||
ubo = (GPUUniformBuffer *)uni->pvalue;
|
||||
bind_ubo(ubo, BIND_PERSIST);
|
||||
GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue