Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_volume.cc
| Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | static DRWShadingGroup *drw_volume_object_grids_init(Object *ob, | ||||
| grp = DRW_shgroup_create_sub(grp); | grp = DRW_shgroup_create_sub(grp); | ||||
| volume_infos.density_scale = BKE_volume_density_scale(volume, ob->obmat); | volume_infos.density_scale = BKE_volume_density_scale(volume, ob->obmat); | ||||
| volume_infos.color_mul = float4(1.0f); | volume_infos.color_mul = float4(1.0f); | ||||
| volume_infos.temperature_mul = 1.0f; | volume_infos.temperature_mul = 1.0f; | ||||
| volume_infos.temperature_bias = 0.0f; | volume_infos.temperature_bias = 0.0f; | ||||
| /* Bind volume grid textures. */ | /* Bind volume grid textures. */ | ||||
| int grid_id = 0; | int grid_id = 0, grids_len = 0; | ||||
| LISTBASE_FOREACH (GPUMaterialAttribute *, attr, attrs) { | LISTBASE_FOREACH (GPUMaterialAttribute *, attr, attrs) { | ||||
| const VolumeGrid *volume_grid = BKE_volume_grid_find_for_read(volume, attr->name); | const VolumeGrid *volume_grid = BKE_volume_grid_find_for_read(volume, attr->name); | ||||
| const DRWVolumeGrid *drw_grid = (volume_grid) ? | const DRWVolumeGrid *drw_grid = (volume_grid) ? | ||||
| DRW_volume_batch_cache_get_grid(volume, volume_grid) : | DRW_volume_batch_cache_get_grid(volume, volume_grid) : | ||||
| nullptr; | nullptr; | ||||
| /* Count number of valid attributes. */ | |||||
| grids_len += int(volume_grid != nullptr); | |||||
| /* Handle 3 cases here: | /* Handle 3 cases here: | ||||
| * - Grid exists and texture was loaded -> use texture. | * - Grid exists and texture was loaded -> use texture. | ||||
| * - Grid exists but has zero size or failed to load -> use zero. | * - Grid exists but has zero size or failed to load -> use zero. | ||||
| * - Grid does not exist -> use default value. */ | * - Grid does not exist -> use default value. */ | ||||
| const GPUTexture *grid_tex = (drw_grid) ? drw_grid->texture : | const GPUTexture *grid_tex = (drw_grid) ? drw_grid->texture : | ||||
| (volume_grid) ? g_data.dummy_zero : | (volume_grid) ? g_data.dummy_zero : | ||||
| grid_default_texture(attr->default_value); | grid_default_texture(attr->default_value); | ||||
| DRW_shgroup_uniform_texture(grp, attr->input_name, grid_tex); | DRW_shgroup_uniform_texture(grp, attr->input_name, grid_tex); | ||||
| copy_m4_m4(volume_infos.grids_xform[grid_id++].ptr(), drw_grid->object_to_texture); | copy_m4_m4(volume_infos.grids_xform[grid_id++].ptr(), | ||||
| (drw_grid) ? drw_grid->object_to_texture : g_data.dummy_grid_mat); | |||||
brecht: I think this should be `(drw_grid) ?`. Otherwise this could still crash if the grid exists but… | |||||
| } | |||||
| /* Render nothing if there is no attribute for the shader to render. | |||||
| * This also avoids an assert caused by the bounding box being zero in size. */ | |||||
| if (grids_len == 0) { | |||||
| return nullptr; | |||||
| } | } | ||||
| volume_infos.push_update(); | volume_infos.push_update(); | ||||
| DRW_shgroup_uniform_block(grp, "drw_volume", volume_infos); | DRW_shgroup_uniform_block(grp, "drw_volume", volume_infos); | ||||
| return grp; | return grp; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines | |||||
I think this should be (drw_grid) ?. Otherwise this could still crash if the grid exists but failed to be allocated on the GPU.