Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_forward.c
| Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| WORKBENCH_MaterialData *workbench_forward_get_or_create_material_data(WORKBENCH_Data *vedata, | WORKBENCH_MaterialData *workbench_forward_get_or_create_material_data(WORKBENCH_Data *vedata, | ||||
| Object *ob, | Object *ob, | ||||
| Material *mat, | Material *mat, | ||||
| Image *ima, | Image *ima, | ||||
| ImageUser *iuser, | ImageUser *iuser, | ||||
| int color_type, | int color_type, | ||||
| int interp, | int interp) | ||||
| bool use_sculpt_pbvh) | |||||
| { | { | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| WORKBENCH_FORWARD_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; | WORKBENCH_FORWARD_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; | ||||
| WORKBENCH_StorageList *stl = vedata->stl; | WORKBENCH_StorageList *stl = vedata->stl; | ||||
| WORKBENCH_PassList *psl = vedata->psl; | WORKBENCH_PassList *psl = vedata->psl; | ||||
| WORKBENCH_PrivateData *wpd = stl->g_data; | WORKBENCH_PrivateData *wpd = stl->g_data; | ||||
| WORKBENCH_MaterialData *material; | WORKBENCH_MaterialData *material; | ||||
| WORKBENCH_ObjectData *engine_object_data = (WORKBENCH_ObjectData *)DRW_drawdata_ensure( | WORKBENCH_ObjectData *engine_object_data = (WORKBENCH_ObjectData *)DRW_drawdata_ensure( | ||||
| &ob->id, | &ob->id, | ||||
| &draw_engine_workbench_solid, | &draw_engine_workbench_solid, | ||||
| sizeof(WORKBENCH_ObjectData), | sizeof(WORKBENCH_ObjectData), | ||||
| &workbench_init_object_data, | &workbench_init_object_data, | ||||
| NULL); | NULL); | ||||
| WORKBENCH_MaterialData material_template; | WORKBENCH_MaterialData material_template; | ||||
| DRWShadingGroup *grp; | DRWShadingGroup *grp; | ||||
| /* Solid */ | /* Solid */ | ||||
| workbench_material_update_data(wpd, ob, mat, &material_template); | workbench_material_update_data(wpd, ob, mat, &material_template, color_type); | ||||
| material_template.object_id = OBJECT_ID_PASS_ENABLED(wpd) ? engine_object_data->object_id : 1; | material_template.object_id = OBJECT_ID_PASS_ENABLED(wpd) ? engine_object_data->object_id : 1; | ||||
| material_template.color_type = color_type; | material_template.color_type = color_type; | ||||
| material_template.ima = ima; | material_template.ima = ima; | ||||
| material_template.iuser = iuser; | material_template.iuser = iuser; | ||||
| material_template.interp = interp; | material_template.interp = interp; | ||||
| uint hash = workbench_material_get_hash(&material_template, false); | uint hash = workbench_material_get_hash(&material_template, false); | ||||
| material = BLI_ghash_lookup(wpd->material_transp_hash, POINTER_FROM_UINT(hash)); | material = BLI_ghash_lookup(wpd->material_transp_hash, POINTER_FROM_UINT(hash)); | ||||
| if (material == NULL) { | if (material == NULL) { | ||||
| material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), __func__); | material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), __func__); | ||||
| /* transparent accum */ | /* transparent accum */ | ||||
| grp = DRW_shgroup_create(wpd->shading.color_type == color_type ? | /* select the correct transparent accum shader */ | ||||
| GPUShader *shader = (wpd->shading.color_type == color_type) ? | |||||
| wpd->transparent_accum_sh : | wpd->transparent_accum_sh : | ||||
| wpd->transparent_accum_uniform_sh, | wpd->transparent_accum_uniform_sh; | ||||
| psl->transparent_accum_pass); | if (color_type == V3D_SHADING_TEXTURE_COLOR) { | ||||
| shader = wpd->transparent_accum_textured_sh; | |||||
| } | |||||
| grp = DRW_shgroup_create(shader, psl->transparent_accum_pass); | |||||
| DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo); | DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo); | ||||
| DRW_shgroup_uniform_float_copy(grp, "alpha", material_template.alpha); | DRW_shgroup_uniform_float_copy(grp, "alpha", material_template.alpha); | ||||
| DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)wpd->viewvecs, 3); | DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)wpd->viewvecs, 3); | ||||
| workbench_material_copy(material, &material_template); | workbench_material_copy(material, &material_template); | ||||
| if (STUDIOLIGHT_TYPE_MATCAP_ENABLED(wpd)) { | if (STUDIOLIGHT_TYPE_MATCAP_ENABLED(wpd)) { | ||||
| BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE); | BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE); | ||||
| DRW_shgroup_uniform_texture( | DRW_shgroup_uniform_texture( | ||||
| grp, "matcapImage", wpd->studio_light->equirect_radiance_gputexture); | grp, "matcapImage", wpd->studio_light->equirect_radiance_gputexture); | ||||
| } | } | ||||
| if (SPECULAR_HIGHLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) { | if (SPECULAR_HIGHLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) { | ||||
| DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1); | DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1); | ||||
| } | } | ||||
| if (SHADOW_ENABLED(wpd)) { | if (SHADOW_ENABLED(wpd)) { | ||||
| DRW_shgroup_uniform_float_copy(grp, "shadowMultiplier", wpd->shadow_multiplier); | DRW_shgroup_uniform_float_copy(grp, "shadowMultiplier", wpd->shadow_multiplier); | ||||
| DRW_shgroup_uniform_float_copy(grp, "shadowShift", wpd->shadow_shift); | DRW_shgroup_uniform_float_copy(grp, "shadowShift", wpd->shadow_shift); | ||||
| DRW_shgroup_uniform_float_copy(grp, "shadowFocus", wpd->shadow_focus); | DRW_shgroup_uniform_float_copy(grp, "shadowFocus", wpd->shadow_focus); | ||||
| } | } | ||||
| workbench_material_shgroup_uniform(wpd, grp, material, ob, false, false, interp); | workbench_material_shgroup_uniform(wpd, grp, material, ob, false, false, interp); | ||||
| material->shgrp = grp; | material->shgrp = grp; | ||||
| /* Depth */ | /* Depth */ | ||||
| if (workbench_material_determine_color_type(wpd, material->ima, ob, use_sculpt_pbvh) == | if (color_type == V3D_SHADING_TEXTURE_COLOR) { | ||||
| V3D_SHADING_TEXTURE_COLOR) { | |||||
| material->shgrp_object_outline = DRW_shgroup_create(sh_data->object_outline_texture_sh, | material->shgrp_object_outline = DRW_shgroup_create(sh_data->object_outline_texture_sh, | ||||
| psl->object_outline_pass); | psl->object_outline_pass); | ||||
| GPUTexture *tex = GPU_texture_from_blender(material->ima, material->iuser, GL_TEXTURE_2D); | GPUTexture *tex = GPU_texture_from_blender(material->ima, material->iuser, GL_TEXTURE_2D); | ||||
| DRW_shgroup_uniform_texture(material->shgrp_object_outline, "image", tex); | DRW_shgroup_uniform_texture(material->shgrp_object_outline, "image", tex); | ||||
| } | } | ||||
| else { | else { | ||||
| material->shgrp_object_outline = DRW_shgroup_create(sh_data->object_outline_sh, | material->shgrp_object_outline = DRW_shgroup_create(sh_data->object_outline_sh, | ||||
| psl->object_outline_pass); | psl->object_outline_pass); | ||||
| } | } | ||||
| material->object_id = engine_object_data->object_id; | material->object_id = engine_object_data->object_id; | ||||
| DRW_shgroup_uniform_int(material->shgrp_object_outline, "object_id", &material->object_id, 1); | DRW_shgroup_uniform_int(material->shgrp_object_outline, "object_id", &material->object_id, 1); | ||||
| if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) { | if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) { | ||||
| DRW_shgroup_state_enable(material->shgrp_object_outline, DRW_STATE_CLIP_PLANES); | DRW_shgroup_state_enable(material->shgrp_object_outline, DRW_STATE_CLIP_PLANES); | ||||
| } | } | ||||
| BLI_ghash_insert(wpd->material_transp_hash, POINTER_FROM_UINT(hash), material); | BLI_ghash_insert(wpd->material_transp_hash, POINTER_FROM_UINT(hash), material); | ||||
| } | } | ||||
| return material; | return material; | ||||
| } | } | ||||
| static GPUShader *ensure_forward_accum_shaders(WORKBENCH_PrivateData *wpd, | static GPUShader *ensure_forward_accum_shaders(WORKBENCH_PrivateData *wpd, | ||||
| bool is_uniform_color, | bool is_uniform_color, | ||||
| bool is_hair, | bool is_hair, | ||||
| bool is_texture_painting, | |||||
| eGPUShaderConfig sh_cfg) | eGPUShaderConfig sh_cfg) | ||||
| { | { | ||||
| WORKBENCH_FORWARD_Shaders *sh_data = &e_data.sh_data[sh_cfg]; | WORKBENCH_FORWARD_Shaders *sh_data = &e_data.sh_data[sh_cfg]; | ||||
| int index = workbench_material_get_accum_shader_index(wpd, is_uniform_color, is_hair); | int index = workbench_material_get_accum_shader_index( | ||||
| wpd, is_uniform_color, is_hair, is_texture_painting); | |||||
| if (sh_data->transparent_accum_sh_cache[index] == NULL) { | if (sh_data->transparent_accum_sh_cache[index] == NULL) { | ||||
| const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; | const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; | ||||
| char *defines = workbench_material_build_defines(wpd, is_uniform_color, is_hair); | char *defines = workbench_material_build_defines( | ||||
| wpd, is_uniform_color, is_hair, is_texture_painting); | |||||
| char *transparent_accum_vert = workbench_build_forward_vert(is_hair); | char *transparent_accum_vert = workbench_build_forward_vert(is_hair); | ||||
| char *transparent_accum_frag = workbench_build_forward_transparent_accum_frag(); | char *transparent_accum_frag = workbench_build_forward_transparent_accum_frag(); | ||||
| sh_data->transparent_accum_sh_cache[index] = GPU_shader_create_from_arrays({ | sh_data->transparent_accum_sh_cache[index] = GPU_shader_create_from_arrays({ | ||||
| .vert = (const char *[]){sh_cfg_data->lib, transparent_accum_vert, NULL}, | .vert = (const char *[]){sh_cfg_data->lib, transparent_accum_vert, NULL}, | ||||
| .frag = (const char *[]){transparent_accum_frag, NULL}, | .frag = (const char *[]){transparent_accum_frag, NULL}, | ||||
| .defs = (const char *[]){sh_cfg_data->def, defines, NULL}, | .defs = (const char *[]){sh_cfg_data->def, defines, NULL}, | ||||
| }); | }); | ||||
| MEM_freeN(transparent_accum_vert); | MEM_freeN(transparent_accum_vert); | ||||
| MEM_freeN(transparent_accum_frag); | MEM_freeN(transparent_accum_frag); | ||||
| MEM_freeN(defines); | MEM_freeN(defines); | ||||
| } | } | ||||
| return sh_data->transparent_accum_sh_cache[index]; | return sh_data->transparent_accum_sh_cache[index]; | ||||
| } | } | ||||
| static GPUShader *ensure_forward_composite_shaders(WORKBENCH_PrivateData *wpd) | static GPUShader *ensure_forward_composite_shaders(WORKBENCH_PrivateData *wpd) | ||||
| { | { | ||||
| int index = OBJECT_OUTLINE_ENABLED(wpd) ? 1 : 0; | int index = OBJECT_OUTLINE_ENABLED(wpd) ? 1 : 0; | ||||
| if (e_data.composite_sh_cache[index] == NULL) { | if (e_data.composite_sh_cache[index] == NULL) { | ||||
| char *defines = workbench_material_build_defines(wpd, false, false); | char *defines = workbench_material_build_defines(wpd, false, false, false); | ||||
| char *composite_frag = workbench_build_forward_composite_frag(); | char *composite_frag = workbench_build_forward_composite_frag(); | ||||
| e_data.composite_sh_cache[index] = DRW_shader_create_fullscreen(composite_frag, defines); | e_data.composite_sh_cache[index] = DRW_shader_create_fullscreen(composite_frag, defines); | ||||
| MEM_freeN(composite_frag); | MEM_freeN(composite_frag); | ||||
| MEM_freeN(defines); | MEM_freeN(defines); | ||||
| } | } | ||||
| return e_data.composite_sh_cache[index]; | return e_data.composite_sh_cache[index]; | ||||
| } | } | ||||
| void workbench_forward_choose_shaders(WORKBENCH_PrivateData *wpd, eGPUShaderConfig sh_cfg) | void workbench_forward_choose_shaders(WORKBENCH_PrivateData *wpd, eGPUShaderConfig sh_cfg) | ||||
| { | { | ||||
| wpd->composite_sh = ensure_forward_composite_shaders(wpd); | wpd->composite_sh = ensure_forward_composite_shaders(wpd); | ||||
| wpd->transparent_accum_sh = ensure_forward_accum_shaders(wpd, false, false, sh_cfg); | wpd->transparent_accum_sh = ensure_forward_accum_shaders(wpd, false, false, false, sh_cfg); | ||||
| wpd->transparent_accum_hair_sh = ensure_forward_accum_shaders(wpd, false, true, sh_cfg); | wpd->transparent_accum_hair_sh = ensure_forward_accum_shaders(wpd, false, true, false, sh_cfg); | ||||
| wpd->transparent_accum_uniform_sh = ensure_forward_accum_shaders(wpd, true, false, sh_cfg); | wpd->transparent_accum_uniform_sh = ensure_forward_accum_shaders( | ||||
| wpd->transparent_accum_uniform_hair_sh = ensure_forward_accum_shaders(wpd, true, true, sh_cfg); | wpd, true, false, false, sh_cfg); | ||||
| wpd->transparent_accum_uniform_hair_sh = ensure_forward_accum_shaders( | |||||
| wpd, true, true, false, sh_cfg); | |||||
| wpd->transparent_accum_textured_sh = ensure_forward_accum_shaders( | |||||
| wpd, false, false, true, sh_cfg); | |||||
| } | } | ||||
| void workbench_forward_outline_shaders_ensure(WORKBENCH_PrivateData *wpd, eGPUShaderConfig sh_cfg) | void workbench_forward_outline_shaders_ensure(WORKBENCH_PrivateData *wpd, eGPUShaderConfig sh_cfg) | ||||
| { | { | ||||
| WORKBENCH_FORWARD_Shaders *sh_data = &e_data.sh_data[sh_cfg]; | WORKBENCH_FORWARD_Shaders *sh_data = &e_data.sh_data[sh_cfg]; | ||||
| if (sh_data->object_outline_sh == NULL) { | if (sh_data->object_outline_sh == NULL) { | ||||
| const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; | const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; | ||||
| char *defines = workbench_material_build_defines(wpd, false, false); | char *defines = workbench_material_build_defines(wpd, false, false, false); | ||||
| char *defines_texture = workbench_material_build_defines(wpd, true, false); | char *defines_texture = workbench_material_build_defines(wpd, true, false, false); | ||||
| char *defines_hair = workbench_material_build_defines(wpd, false, true); | char *defines_hair = workbench_material_build_defines(wpd, false, true, false); | ||||
| char *forward_vert = workbench_build_forward_vert(false); | char *forward_vert = workbench_build_forward_vert(false); | ||||
| char *forward_hair_vert = workbench_build_forward_vert(true); | char *forward_hair_vert = workbench_build_forward_vert(true); | ||||
| sh_data->object_outline_sh = GPU_shader_create_from_arrays({ | sh_data->object_outline_sh = GPU_shader_create_from_arrays({ | ||||
| .vert = (const char *[]){sh_cfg_data->lib, forward_vert, NULL}, | .vert = (const char *[]){sh_cfg_data->lib, forward_vert, NULL}, | ||||
| .frag = (const char *[]){datatoc_workbench_forward_depth_frag_glsl, NULL}, | .frag = (const char *[]){datatoc_workbench_forward_depth_frag_glsl, NULL}, | ||||
| .defs = (const char *[]){sh_cfg_data->def, defines, NULL}, | .defs = (const char *[]){sh_cfg_data->def, defines, NULL}, | ||||
| }); | }); | ||||
| ▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | if (draw_as == PART_DRAW_PATH) { | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| Material *mat; | Material *mat; | ||||
| Image *image; | Image *image; | ||||
| ImageUser *iuser; | ImageUser *iuser; | ||||
| int interp; | int interp; | ||||
| workbench_material_get_image_and_mat(ob, part->omat, &image, &iuser, &interp, &mat); | workbench_material_get_image_and_mat(ob, part->omat, &image, &iuser, &interp, &mat); | ||||
| int color_type = workbench_material_determine_color_type(wpd, image, ob, false); | int color_type = workbench_material_determine_color_type(wpd, image, ob, false); | ||||
| WORKBENCH_MaterialData *material = workbench_forward_get_or_create_material_data( | WORKBENCH_MaterialData *material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, mat, image, iuser, color_type, interp, false); | vedata, ob, mat, image, iuser, color_type, interp); | ||||
| struct GPUShader *shader = (wpd->shading.color_type == color_type) ? | struct GPUShader *shader = (wpd->shading.color_type == color_type) ? | ||||
| wpd->transparent_accum_hair_sh : | wpd->transparent_accum_hair_sh : | ||||
| wpd->transparent_accum_uniform_hair_sh; | wpd->transparent_accum_uniform_hair_sh; | ||||
| DRWShadingGroup *shgrp = DRW_shgroup_hair_create( | DRWShadingGroup *shgrp = DRW_shgroup_hair_create( | ||||
| ob, psys, md, psl->transparent_accum_pass, shader); | ob, psys, md, psl->transparent_accum_pass, shader); | ||||
| DRW_shgroup_uniform_block(shgrp, "world_block", wpd->world_ubo); | DRW_shgroup_uniform_block(shgrp, "world_block", wpd->world_ubo); | ||||
| workbench_material_shgroup_uniform(wpd, shgrp, material, ob, false, false, interp); | workbench_material_shgroup_uniform(wpd, shgrp, material, ob, false, false, interp); | ||||
| Show All 13 Lines | if (draw_as == PART_DRAW_PATH) { | ||||
| WORKBENCH_FORWARD_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; | WORKBENCH_FORWARD_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; | ||||
| shgrp = DRW_shgroup_hair_create( | shgrp = DRW_shgroup_hair_create( | ||||
| ob, psys, md, vedata->psl->object_outline_pass, sh_data->object_outline_hair_sh); | ob, psys, md, vedata->psl->object_outline_pass, sh_data->object_outline_hair_sh); | ||||
| DRW_shgroup_uniform_int(shgrp, "object_id", &material->object_id, 1); | DRW_shgroup_uniform_int(shgrp, "object_id", &material->object_id, 1); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static bool workbench_forward_cache_populate_texture_paint_mode(WORKBENCH_Data *vedata, Object *ob) | |||||
fclem: Safe issue here. | |||||
| { | |||||
| WORKBENCH_StorageList *stl = vedata->stl; | |||||
| WORKBENCH_PrivateData *wpd = stl->g_data; | |||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | |||||
| if (ob->type != OB_MESH) { | |||||
| return false; | |||||
| } | |||||
| bool drawn = false; | |||||
| Mesh *mesh = ob->data; | |||||
| Scene *scene = draw_ctx->scene; | |||||
| const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d); | |||||
| WORKBENCH_MaterialData *material; | |||||
| /* Force workbench to render active object textured when in texture paint mode */ | |||||
| const bool texture_paint_mode = workbench_is_object_in_texture_paint_mode(ob); | |||||
| if (mesh && mesh->mloopuv && texture_paint_mode) { | |||||
| const ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; | |||||
| /* Single Image mode */ | |||||
| if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) { | |||||
| Image *image = imapaint->canvas; | |||||
| int interp = (imapaint->interp == IMAGEPAINT_INTERP_LINEAR) ? SHD_INTERP_LINEAR : | |||||
| SHD_INTERP_CLOSEST; | |||||
| int color_type = workbench_material_determine_color_type(wpd, image, ob, use_sculpt_pbvh); | |||||
| struct GPUBatch *geom = DRW_cache_mesh_surface_texpaint_single_get(ob); | |||||
| material = workbench_forward_get_or_create_material_data( | |||||
| vedata, ob, NULL, image, NULL, color_type, interp); | |||||
| DRW_shgroup_call(material->shgrp, geom, ob); | |||||
| DRW_shgroup_call(material->shgrp_object_outline, geom, ob); | |||||
| } | |||||
| else { | |||||
| /* IMAGEPAINT_MODE_MATERIAL */ | |||||
| const int materials_len = MAX2(1, ob->totcol); | |||||
| struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob); | |||||
| for (int i = 0; i < materials_len; i++) { | |||||
| if (geom_array != NULL && geom_array[i] != NULL) { | |||||
| Material *mat; | |||||
| Image *image; | |||||
| ImageUser *iuser; | |||||
| int interp; | |||||
| workbench_material_get_image_and_mat(ob, i + 1, &image, &iuser, &interp, &mat); | |||||
| int color_type = workbench_material_determine_color_type( | |||||
| wpd, image, ob, use_sculpt_pbvh); | |||||
| material = workbench_forward_get_or_create_material_data( | |||||
| vedata, ob, mat, image, iuser, color_type, interp); | |||||
| DRW_shgroup_call(material->shgrp, geom_array[i], ob); | |||||
| DRW_shgroup_call(material->shgrp_object_outline, geom_array[i], ob); | |||||
| } | |||||
| } | |||||
| } | |||||
| drawn = true; | |||||
| } | |||||
| return drawn; | |||||
| } | |||||
| void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob) | void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob) | ||||
| { | { | ||||
| WORKBENCH_StorageList *stl = vedata->stl; | WORKBENCH_StorageList *stl = vedata->stl; | ||||
| WORKBENCH_PrivateData *wpd = stl->g_data; | WORKBENCH_PrivateData *wpd = stl->g_data; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| Scene *scene = draw_ctx->scene; | Scene *scene = draw_ctx->scene; | ||||
| const bool is_wire = (ob->dt == OB_WIRE); | const bool is_wire = (ob->dt == OB_WIRE); | ||||
| Show All 23 Lines | void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob) | ||||
| } | } | ||||
| WORKBENCH_MaterialData *material; | WORKBENCH_MaterialData *material; | ||||
| if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) { | if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) { | ||||
| const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d); | const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d); | ||||
| const int materials_len = MAX2(1, ob->totcol); | const int materials_len = MAX2(1, ob->totcol); | ||||
| const Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL; | const Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL; | ||||
| if (workbench_forward_cache_populate_texture_paint_mode(vedata, ob)) { | |||||
| return; | |||||
| } | |||||
| if (!use_sculpt_pbvh && TEXTURE_DRAWING_ENABLED(wpd) && me && me->mloopuv) { | if (!use_sculpt_pbvh && TEXTURE_DRAWING_ENABLED(wpd) && me && me->mloopuv) { | ||||
| struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob); | struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob); | ||||
| for (int i = 0; i < materials_len; i++) { | for (int i = 0; i < materials_len; i++) { | ||||
| Material *mat; | Material *mat; | ||||
| Image *image; | Image *image; | ||||
| ImageUser *iuser; | ImageUser *iuser; | ||||
| int interp; | int interp; | ||||
| workbench_material_get_image_and_mat(ob, i + 1, &image, &iuser, &interp, &mat); | workbench_material_get_image_and_mat(ob, i + 1, &image, &iuser, &interp, &mat); | ||||
| int color_type = workbench_material_determine_color_type(wpd, image, ob, use_sculpt_pbvh); | int color_type = workbench_material_determine_color_type(wpd, image, ob, use_sculpt_pbvh); | ||||
| material = workbench_forward_get_or_create_material_data( | material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, mat, image, iuser, color_type, interp, use_sculpt_pbvh); | vedata, ob, mat, image, iuser, color_type, interp); | ||||
| DRW_shgroup_call(material->shgrp_object_outline, geom_array[i], ob); | DRW_shgroup_call(material->shgrp_object_outline, geom_array[i], ob); | ||||
| DRW_shgroup_call(material->shgrp, geom_array[i], ob); | DRW_shgroup_call(material->shgrp, geom_array[i], ob); | ||||
| } | } | ||||
| } | } | ||||
| else if (ELEM(wpd->shading.color_type, | else if (ELEM(wpd->shading.color_type, | ||||
| V3D_SHADING_SINGLE_COLOR, | V3D_SHADING_SINGLE_COLOR, | ||||
| V3D_SHADING_OBJECT_COLOR, | V3D_SHADING_OBJECT_COLOR, | ||||
| V3D_SHADING_RANDOM_COLOR, | V3D_SHADING_RANDOM_COLOR, | ||||
| V3D_SHADING_VERTEX_COLOR)) { | V3D_SHADING_VERTEX_COLOR)) { | ||||
| /* No material split needed */ | /* No material split needed */ | ||||
| int color_type = workbench_material_determine_color_type(wpd, NULL, ob, use_sculpt_pbvh); | int color_type = workbench_material_determine_color_type(wpd, NULL, ob, use_sculpt_pbvh); | ||||
| if (use_sculpt_pbvh) { | if (use_sculpt_pbvh) { | ||||
| material = workbench_forward_get_or_create_material_data( | material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, NULL, NULL, NULL, color_type, 0, use_sculpt_pbvh); | vedata, ob, NULL, NULL, NULL, color_type, 0); | ||||
| bool use_vcol = (color_type == V3D_SHADING_VERTEX_COLOR); | bool use_vcol = (color_type == V3D_SHADING_VERTEX_COLOR); | ||||
| /* TODO(fclem) make this call optional */ | /* TODO(fclem) make this call optional */ | ||||
| DRW_shgroup_call_sculpt(material->shgrp_object_outline, ob, false, false, false); | DRW_shgroup_call_sculpt(material->shgrp_object_outline, ob, false, false, false); | ||||
| if (!is_wire) { | if (!is_wire) { | ||||
| DRW_shgroup_call_sculpt(material->shgrp, ob, false, false, use_vcol); | DRW_shgroup_call_sculpt(material->shgrp, ob, false, false, use_vcol); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| struct GPUBatch *geom = (color_type == V3D_SHADING_VERTEX_COLOR) ? | struct GPUBatch *geom = (color_type == V3D_SHADING_VERTEX_COLOR) ? | ||||
| DRW_cache_mesh_surface_vertpaint_get(ob) : | DRW_cache_mesh_surface_vertpaint_get(ob) : | ||||
| DRW_cache_object_surface_get(ob); | DRW_cache_object_surface_get(ob); | ||||
| if (geom) { | if (geom) { | ||||
| material = workbench_forward_get_or_create_material_data( | material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, NULL, NULL, NULL, color_type, 0, use_sculpt_pbvh); | vedata, ob, NULL, NULL, NULL, color_type, 0); | ||||
| /* TODO(fclem) make this call optional */ | /* TODO(fclem) make this call optional */ | ||||
| DRW_shgroup_call(material->shgrp_object_outline, geom, ob); | DRW_shgroup_call(material->shgrp_object_outline, geom, ob); | ||||
| if (!is_wire) { | if (!is_wire) { | ||||
| DRW_shgroup_call(material->shgrp, geom, ob); | DRW_shgroup_call(material->shgrp, geom, ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Draw material color */ | /* Draw material color */ | ||||
| if (use_sculpt_pbvh) { | if (use_sculpt_pbvh) { | ||||
| struct DRWShadingGroup **shgrps = BLI_array_alloca(shgrps, materials_len); | struct DRWShadingGroup **shgrps = BLI_array_alloca(shgrps, materials_len); | ||||
| for (int i = 0; i < materials_len; ++i) { | for (int i = 0; i < materials_len; ++i) { | ||||
| struct Material *mat = give_current_material(ob, i + 1); | struct Material *mat = give_current_material(ob, i + 1); | ||||
| material = workbench_forward_get_or_create_material_data( | material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, use_sculpt_pbvh); | vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0); | ||||
| shgrps[i] = material->shgrp; | shgrps[i] = material->shgrp; | ||||
| } | } | ||||
| /* TODO(fclem) make this call optional */ | /* TODO(fclem) make this call optional */ | ||||
| DRW_shgroup_call_sculpt(material->shgrp_object_outline, ob, false, false, false); | DRW_shgroup_call_sculpt(material->shgrp_object_outline, ob, false, false, false); | ||||
| if (!is_wire) { | if (!is_wire) { | ||||
| DRW_shgroup_call_sculpt_with_materials(shgrps, ob, false); | DRW_shgroup_call_sculpt_with_materials(shgrps, ob, false); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len); | struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len); | ||||
| memset(gpumat_array, 0, sizeof(*gpumat_array) * materials_len); | memset(gpumat_array, 0, sizeof(*gpumat_array) * materials_len); | ||||
| struct GPUBatch **mat_geom = DRW_cache_object_surface_material_get( | struct GPUBatch **mat_geom = DRW_cache_object_surface_material_get( | ||||
| ob, gpumat_array, materials_len, NULL, NULL, NULL); | ob, gpumat_array, materials_len, NULL, NULL, NULL); | ||||
| if (mat_geom) { | if (mat_geom) { | ||||
| for (int i = 0; i < materials_len; ++i) { | for (int i = 0; i < materials_len; ++i) { | ||||
| if (mat_geom[i] == NULL) { | if (mat_geom[i] == NULL) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| Material *mat = give_current_material(ob, i + 1); | Material *mat = give_current_material(ob, i + 1); | ||||
| material = workbench_forward_get_or_create_material_data( | material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, use_sculpt_pbvh); | vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0); | ||||
| /* TODO(fclem) make this call optional */ | /* TODO(fclem) make this call optional */ | ||||
| DRW_shgroup_call(material->shgrp_object_outline, mat_geom[i], ob); | DRW_shgroup_call(material->shgrp_object_outline, mat_geom[i], ob); | ||||
| if (!is_wire) { | if (!is_wire) { | ||||
| DRW_shgroup_call(material->shgrp, mat_geom[i], ob); | DRW_shgroup_call(material->shgrp, mat_geom[i], ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines | |||||
Safe issue here.