Cleanup: DRW: Remove pointers to materials

This commit is contained in:
2019-05-11 14:42:26 +02:00
parent 2d28df783a
commit ad0e95688d
7 changed files with 43 additions and 55 deletions

View File

@@ -1180,21 +1180,21 @@ void EEVEE_materials_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
}
}
#define ADD_SHGROUP_CALL(shgrp, ob, ma, geom, oedata) \
#define ADD_SHGROUP_CALL(shgrp, ob, geom, oedata) \
do { \
if (oedata) { \
DRW_shgroup_call_object_add_with_callback( \
shgrp, geom, ob, ma, EEVEE_lightprobes_obj_visibility_cb, oedata); \
shgrp, geom, ob, EEVEE_lightprobes_obj_visibility_cb, oedata); \
} \
else { \
DRW_shgroup_call_object_add_ex(shgrp, geom, ob, ma, false); \
DRW_shgroup_call_object_add_ex(shgrp, geom, ob, false); \
} \
} while (0)
#define ADD_SHGROUP_CALL_SAFE(shgrp, ob, ma, geom, oedata) \
#define ADD_SHGROUP_CALL_SAFE(shgrp, ob, geom, oedata) \
do { \
if (shgrp) { \
ADD_SHGROUP_CALL(shgrp, ob, ma, geom, oedata); \
ADD_SHGROUP_CALL(shgrp, ob, geom, oedata); \
} \
} while (0)
@@ -1691,9 +1691,9 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
if (is_sculpt_mode) {
/* Vcol is not supported in the modes that require PBVH drawing. */
bool use_vcol = false;
DRW_shgroup_call_sculpt_with_materials_add(shgrp_array, ma_array, ob, use_vcol);
DRW_shgroup_call_sculpt_with_materials_add(shgrp_depth_array, ma_array, ob, use_vcol);
DRW_shgroup_call_sculpt_with_materials_add(shgrp_depth_clip_array, ma_array, ob, use_vcol);
DRW_shgroup_call_sculpt_with_materials_add(shgrp_array, ob, use_vcol);
DRW_shgroup_call_sculpt_with_materials_add(shgrp_depth_array, ob, use_vcol);
DRW_shgroup_call_sculpt_with_materials_add(shgrp_depth_clip_array, ob, use_vcol);
/* TODO(fclem): Support shadows in sculpt mode. */
}
else if (mat_geom) {
@@ -1718,9 +1718,9 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
oedata->test_data = &sldata->probes->vis_data;
}
ADD_SHGROUP_CALL(shgrp_array[i], ob, ma_array[i], mat_geom[i], oedata);
ADD_SHGROUP_CALL_SAFE(shgrp_depth_array[i], ob, ma_array[i], mat_geom[i], oedata);
ADD_SHGROUP_CALL_SAFE(shgrp_depth_clip_array[i], ob, ma_array[i], mat_geom[i], oedata);
ADD_SHGROUP_CALL(shgrp_array[i], ob, mat_geom[i], oedata);
ADD_SHGROUP_CALL_SAFE(shgrp_depth_array[i], ob, mat_geom[i], oedata);
ADD_SHGROUP_CALL_SAFE(shgrp_depth_clip_array[i], ob, mat_geom[i], oedata);
char *name = auto_layer_names;
for (int j = 0; j < auto_layer_count; ++j) {

View File

@@ -1036,24 +1036,23 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
/* Draw material color */
if (is_sculpt_mode) {
struct DRWShadingGroup **shgrps = BLI_array_alloca(shgrps, materials_len);
struct Material **mats = BLI_array_alloca(mats, materials_len);
for (int i = 0; i < materials_len; ++i) {
mats[i] = give_current_material(ob, i + 1);
if (mats[i] != NULL && mats[i]->a < 1.0f) {
struct Material *mat = give_current_material(ob, i + 1);
if (mat != NULL && mat->a < 1.0f) {
/* Hack */
wpd->shading.xray_alpha = mats[i]->a;
wpd->shading.xray_alpha = mat->a;
material = workbench_forward_get_or_create_material_data(
vedata, ob, mats[i], NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, is_sculpt_mode);
vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, is_sculpt_mode);
has_transp_mat = true;
}
else {
material = get_or_create_material_data(
vedata, ob, mats[i], NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0);
vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0);
}
shgrps[i] = material->shgrp;
}
DRW_shgroup_call_sculpt_with_materials_add(shgrps, mats, ob, false);
DRW_shgroup_call_sculpt_with_materials_add(shgrps, ob, false);
}
else {
struct GPUBatch **geoms;

View File

@@ -623,18 +623,17 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
/* Draw material color */
if (is_sculpt_mode) {
struct DRWShadingGroup **shgrps = BLI_array_alloca(shgrps, materials_len);
struct Material **mats = BLI_array_alloca(mats, materials_len);
for (int i = 0; i < materials_len; ++i) {
mats[i] = give_current_material(ob, i + 1);
struct Material *mat = give_current_material(ob, i + 1);
material = workbench_forward_get_or_create_material_data(
vedata, ob, mats[i], NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, is_sculpt_mode);
vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, is_sculpt_mode);
shgrps[i] = material->shgrp;
}
/* TODO(fclem) make this call optional */
DRW_shgroup_call_sculpt_add(material->shgrp_object_outline, ob, false, false, false);
if (!is_wire) {
DRW_shgroup_call_sculpt_with_materials_add(shgrps, mats, ob, false);
DRW_shgroup_call_sculpt_with_materials_add(shgrps, ob, false);
}
}
else {

View File

@@ -421,16 +421,14 @@ void DRW_shgroup_call_procedural_triangles_add(DRWShadingGroup *shgroup,
void DRW_shgroup_call_object_add_ex(DRWShadingGroup *shgroup,
struct GPUBatch *geom,
struct Object *ob,
struct Material *ma,
bool bypass_culling);
#define DRW_shgroup_call_object_add(shgroup, geom, ob) \
DRW_shgroup_call_object_add_ex(shgroup, geom, ob, NULL, false)
DRW_shgroup_call_object_add_ex(shgroup, geom, ob, false)
#define DRW_shgroup_call_object_add_no_cull(shgroup, geom, ob) \
DRW_shgroup_call_object_add_ex(shgroup, geom, ob, NULL, true)
DRW_shgroup_call_object_add_ex(shgroup, geom, ob, true)
void DRW_shgroup_call_object_add_with_callback(DRWShadingGroup *shgroup,
struct GPUBatch *geom,
struct Object *ob,
struct Material *ma,
DRWCallVisibilityFn *callback,
void *user_data);
@@ -440,7 +438,6 @@ void DRW_shgroup_call_sculpt_add(DRWShadingGroup *shading_group,
bool use_mask,
bool use_vert_color);
void DRW_shgroup_call_sculpt_with_materials_add(DRWShadingGroup **shgroups,
Material **materials,
Object *ob,
bool use_vcol);

View File

@@ -100,9 +100,9 @@ enum {
/* Used by DRWCallState.matflag */
enum {
DRW_CALL_MODELINVERSE = (1 << 0),
DRW_CALL_MODELVIEWPROJECTION = (1 << 3),
DRW_CALL_ORCOTEXFAC = (1 << 7),
DRW_CALL_OBJECTINFO = (1 << 8),
DRW_CALL_MODELVIEWPROJECTION = (1 << 1),
DRW_CALL_ORCOTEXFAC = (1 << 2),
DRW_CALL_OBJECTINFO = (1 << 3),
};
typedef struct DRWCallState {
@@ -110,8 +110,9 @@ typedef struct DRWCallState {
void *user_data;
uchar flag;
uchar cache_id; /* Compared with DST.state_cache_id to see if matrices are still valid. */
uint16_t matflag; /* Which matrices to compute. */
uchar cache_id; /* Compared with DST.state_cache_id to see if matrices are still valid. */
uchar matflag; /* Which matrices to compute. */
short ob_index;
/* Culling: Using Bounding Sphere for now for faster culling.
* Not ideal for planes. */
BoundSphere bsphere;
@@ -120,7 +121,7 @@ typedef struct DRWCallState {
float modelinverse[4][4];
float modelviewprojection[4][4];
float orcotexfac[2][3]; /* Not view dependent */
float objectinfo[2];
float ob_random;
} DRWCallState;
typedef enum {
@@ -141,7 +142,6 @@ typedef struct DRWCall {
union {
struct { /* type == DRW_CALL_SINGLE */
GPUBatch *geometry;
short ma_index;
} single;
struct { /* type == DRW_CALL_RANGE */
GPUBatch *geometry;
@@ -250,7 +250,7 @@ struct DRWShadingGroup {
int orcotexfac;
int callid;
int objectinfo;
uint16_t matflag; /* Matrices needed, same as DRWCall.flag */
uchar matflag; /* Matrices needed, same as DRWCall.flag */
DRWPass *pass_parent; /* backlink to pass we're in */
#ifndef NDEBUG

View File

@@ -386,7 +386,7 @@ static void drw_call_state_update_matflag(DRWCallState *state,
}
if (new_flags & DRW_CALL_OBJECTINFO) {
state->objectinfo[0] = ob ? ob->index : 0;
state->ob_index = ob ? ob->index : 0;
uint random;
if (DST.dupli_source) {
random = DST.dupli_source->random_id;
@@ -394,7 +394,7 @@ static void drw_call_state_update_matflag(DRWCallState *state,
else {
random = BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0);
}
state->objectinfo[1] = random * (1.0f / (float)0xFFFFFFFF);
state->ob_random = random * (1.0f / (float)0xFFFFFFFF);
}
}
@@ -528,8 +528,10 @@ void DRW_shgroup_call_procedural_triangles_add(DRWShadingGroup *shgroup,
}
/* These calls can be culled and are optimized for redraw */
void DRW_shgroup_call_object_add_ex(
DRWShadingGroup *shgroup, GPUBatch *geom, Object *ob, Material *ma, bool bypass_culling)
void DRW_shgroup_call_object_add_ex(DRWShadingGroup *shgroup,
GPUBatch *geom,
Object *ob,
bool bypass_culling)
{
BLI_assert(geom != NULL);
BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM));
@@ -542,7 +544,6 @@ void DRW_shgroup_call_object_add_ex(
call->state->flag |= (bypass_culling) ? DRW_CALL_BYPASS_CULLING : 0;
call->type = DRW_CALL_SINGLE;
call->single.geometry = geom;
call->single.ma_index = ma ? ma->index : 0;
#ifdef USE_GPU_SELECT
call->select_id = DST.select_id;
#endif
@@ -551,7 +552,6 @@ void DRW_shgroup_call_object_add_ex(
void DRW_shgroup_call_object_add_with_callback(DRWShadingGroup *shgroup,
GPUBatch *geom,
Object *ob,
Material *ma,
DRWCallVisibilityFn *callback,
void *user_data)
{
@@ -566,7 +566,6 @@ void DRW_shgroup_call_object_add_with_callback(DRWShadingGroup *shgroup,
call->state->user_data = user_data;
call->type = DRW_CALL_SINGLE;
call->single.geometry = geom;
call->single.ma_index = ma ? ma->index : 0;
#ifdef USE_GPU_SELECT
call->select_id = DST.select_id;
#endif
@@ -618,7 +617,6 @@ void DRW_shgroup_call_object_instances_add(DRWShadingGroup *shgroup,
typedef struct DRWSculptCallbackData {
Object *ob;
DRWShadingGroup **shading_groups;
Material **materials;
bool use_wire;
bool use_mats;
bool use_mask;
@@ -646,7 +644,6 @@ static float sculpt_debug_colors[9][4] = {
static void sculpt_draw_cb(DRWSculptCallbackData *scd, GPU_PBVH_Buffers *buffers)
{
GPUBatch *geom = GPU_pbvh_buffers_batch_get(buffers, scd->fast_mode, scd->use_wire);
Material *ma = NULL;
short index = 0;
/* Meh... use_mask is a bit misleading here. */
@@ -656,7 +653,6 @@ static void sculpt_draw_cb(DRWSculptCallbackData *scd, GPU_PBVH_Buffers *buffers
if (scd->use_mats) {
index = GPU_pbvh_buffers_material_index_get(buffers);
ma = scd->materials[index];
}
DRWShadingGroup *shgrp = scd->shading_groups[index];
@@ -668,7 +664,7 @@ static void sculpt_draw_cb(DRWSculptCallbackData *scd, GPU_PBVH_Buffers *buffers
#endif
/* DRW_shgroup_call_object_add_ex reuses matrices calculations for all the drawcalls of this
* object. */
DRW_shgroup_call_object_add_ex(shgrp, geom, scd->ob, ma, true);
DRW_shgroup_call_object_add_ex(shgrp, geom, scd->ob, true);
}
}
@@ -735,7 +731,6 @@ void DRW_shgroup_call_sculpt_add(
DRWSculptCallbackData scd = {
.ob = ob,
.shading_groups = &shgroup,
.materials = NULL,
.use_wire = use_wire,
.use_mats = false,
.use_mask = use_mask,
@@ -744,14 +739,12 @@ void DRW_shgroup_call_sculpt_add(
}
void DRW_shgroup_call_sculpt_with_materials_add(DRWShadingGroup **shgroups,
Material **materials,
Object *ob,
bool use_vcol)
{
DRWSculptCallbackData scd = {
.ob = ob,
.shading_groups = shgroups,
.materials = materials,
.use_wire = false,
.use_mats = true,
.use_mask = false,

View File

@@ -818,12 +818,12 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
(float *)state->modelviewprojection);
}
if (shgroup->objectinfo != -1) {
float objectinfo[4];
objectinfo[0] = state->objectinfo[0];
objectinfo[1] = call->single.ma_index; /* WATCH this is only valid for single drawcalls. */
objectinfo[2] = state->objectinfo[1];
objectinfo[3] = (state->flag & DRW_CALL_NEGSCALE) ? -1.0f : 1.0f;
GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 4, 1, (float *)objectinfo);
float infos[4];
infos[0] = state->ob_index;
// infos[1]; /* UNUSED. */
infos[2] = state->ob_random;
infos[3] = (state->flag & DRW_CALL_NEGSCALE) ? -1.0f : 1.0f;
GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 4, 1, (float *)infos);
}
if (shgroup->orcotexfac != -1) {
GPU_shader_uniform_vector(