- if (is_sculpt_mode) {
- DRW_shgroup_call_sculpt_add(material->shgrp, ob, ob->obmat);
- }
- else {
- DRW_shgroup_call_object_add(material->shgrp, geom, ob);
+
+ if ((vedata->stl->g_data->drawtype_options & V3D_DRAWOPTION_SOLID_COLOR_MASK) != 0 || is_sculpt_mode) {
+ /* No material split needed */
+ struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
+ if (geom) {
+ material = get_or_create_material_data(vedata, props, ob, NULL);
+ if (is_sculpt_mode) {
+ DRW_shgroup_call_sculpt_add(material->shgrp, ob, ob->obmat);
+ }
+ else {
+ DRW_shgroup_call_object_add(material->shgrp, geom, ob);
+ }
+ }
+ }
+ else { /* MATERIAL colors */
+ const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol));
+ struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
+ for (int i = 0; i < materials_len; i ++) {
+ gpumat_array[i] = NULL;
+ }
+
+ struct Gwn_Batch **mat_geom = DRW_cache_object_surface_material_get(ob, gpumat_array, materials_len);
+ if (mat_geom) {
+ for (int i = 0; i < materials_len; ++i) {
+ Material *mat = give_current_material(ob, i + 1);
+ material = get_or_create_material_data(vedata, props, ob, mat);
+ DRW_shgroup_call_object_add(material->shgrp, mat_geom[i], ob);
+ }
+ }