DRW/GWN: Add callId builtin uniform.

This uniforms can be used to have a unique id for each drawcall of a shgrp.
This only works for standard shgroups and is an exception for the outline
drawing.
This commit is contained in:
Clément Foucault 2018-04-16 19:26:54 +02:00
parent 2b0b4133c8
commit dccda1fe43
5 changed files with 11 additions and 0 deletions

View File

@ -36,6 +36,7 @@ typedef enum {
GWN_UNIFORM_COLOR, // vec4 color
GWN_UNIFORM_EYE, // vec3 eye
GWN_UNIFORM_CALLID, // int callId
GWN_UNIFORM_CUSTOM, // custom uniform, not one of the above built-ins

View File

@ -48,6 +48,7 @@ static const char* BuiltinUniform_name(Gwn_UniformBuiltin u)
[GWN_UNIFORM_COLOR] = "color",
[GWN_UNIFORM_EYE] = "eye",
[GWN_UNIFORM_CALLID] = "callId",
[GWN_UNIFORM_CUSTOM] = NULL,
[GWN_NUM_UNIFORMS] = NULL,

View File

@ -222,6 +222,7 @@ struct DRWShadingGroup {
int normalworld;
int orcotexfac;
int eye;
int callid;
uint16_t matflag; /* Matrices needed, same as DRWCall.flag */
#ifndef NDEBUG

View File

@ -498,6 +498,7 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
shgroup->normalworld = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_WORLDNORMAL);
shgroup->orcotexfac = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_ORCO);
shgroup->eye = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_EYE);
shgroup->callid = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_CALLID);
shgroup->matflag = 0;
if (shgroup->modelinverse > -1)

View File

@ -1005,6 +1005,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
}
else {
bool prev_neg_scale = false;
int callid = 0;
for (DRWCall *call = shgroup->calls.first; call; call = call->next) {
/* OPTI/IDEA(clem): Do this preparation in another thread. */
@ -1013,6 +1014,12 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
if ((call->state->flag & DRW_CALL_CULLED) != 0)
continue;
/* XXX small exception/optimisation for outline rendering. */
if (shgroup->callid != -1) {
GPU_shader_uniform_vector_int(shgroup->shader, shgroup->callid, 1, 1, &callid);
callid += 1;
}
/* Negative scale objects */
bool neg_scale = call->state->flag & DRW_CALL_NEGSCALE;
if (neg_scale != prev_neg_scale) {