Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_materials.cc
- This file was moved from source/blender/draw/engines/workbench/workbench_materials.c.
| Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | BLI_INLINE Material *workbench_object_material_get(Object *ob, int mat_nr) | ||||
| } | } | ||||
| return ma; | return ma; | ||||
| } | } | ||||
| BLI_INLINE void workbench_material_get_image( | BLI_INLINE void workbench_material_get_image( | ||||
| Object *ob, int mat_nr, Image **r_image, ImageUser **r_iuser, eGPUSamplerState *r_sampler) | Object *ob, int mat_nr, Image **r_image, ImageUser **r_iuser, eGPUSamplerState *r_sampler) | ||||
| { | { | ||||
| const bNode *node; | const bNode *node; | ||||
| *r_sampler = 0; | *r_sampler = eGPUSamplerState(0); | ||||
| ED_object_get_active_image(ob, mat_nr, r_image, r_iuser, &node, NULL); | ED_object_get_active_image(ob, mat_nr, r_image, r_iuser, &node, NULL); | ||||
| if (node && *r_image) { | if (node && *r_image) { | ||||
| switch (node->type) { | switch (node->type) { | ||||
| case SH_NODE_TEX_IMAGE: { | case SH_NODE_TEX_IMAGE: { | ||||
| const NodeTexImage *storage = node->storage; | const NodeTexImage *storage = static_cast<NodeTexImage *>(node->storage); | ||||
| const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST); | const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST); | ||||
| const bool use_repeat = (storage->extension == SHD_IMAGE_EXTENSION_REPEAT); | const bool use_repeat = (storage->extension == SHD_IMAGE_EXTENSION_REPEAT); | ||||
| const bool use_clip = (storage->extension == SHD_IMAGE_EXTENSION_CLIP); | const bool use_clip = (storage->extension == SHD_IMAGE_EXTENSION_CLIP); | ||||
| SET_FLAG_FROM_TEST(*r_sampler, use_filter, GPU_SAMPLER_FILTER); | SET_FLAG_FROM_TEST(*r_sampler, use_filter, GPU_SAMPLER_FILTER); | ||||
| SET_FLAG_FROM_TEST(*r_sampler, use_repeat, GPU_SAMPLER_REPEAT); | SET_FLAG_FROM_TEST(*r_sampler, use_repeat, GPU_SAMPLER_REPEAT); | ||||
| SET_FLAG_FROM_TEST(*r_sampler, use_clip, GPU_SAMPLER_CLAMP_BORDER); | SET_FLAG_FROM_TEST(*r_sampler, use_clip, GPU_SAMPLER_CLAMP_BORDER); | ||||
| break; | break; | ||||
| } | } | ||||
| case SH_NODE_TEX_ENVIRONMENT: { | case SH_NODE_TEX_ENVIRONMENT: { | ||||
| const NodeTexEnvironment *storage = node->storage; | const NodeTexEnvironment *storage = static_cast<NodeTexEnvironment *>(node->storage); | ||||
| const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST); | const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST); | ||||
| SET_FLAG_FROM_TEST(*r_sampler, use_filter, GPU_SAMPLER_FILTER); | SET_FLAG_FROM_TEST(*r_sampler, use_filter, GPU_SAMPLER_FILTER); | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| BLI_assert_msg(0, "Node type not supported by workbench"); | BLI_assert_msg(0, "Node type not supported by workbench"); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Return true if the current material ubo has changed and needs to be rebind. */ | /* Return true if the current material ubo has changed and needs to be rebind. */ | ||||
| BLI_INLINE bool workbench_material_chunk_select(WORKBENCH_PrivateData *wpd, | BLI_INLINE bool workbench_material_chunk_select(WORKBENCH_PrivateData *wpd, | ||||
| uint32_t id, | uint32_t id, | ||||
| uint32_t *r_mat_id) | uint32_t *r_mat_id) | ||||
| { | { | ||||
| bool resource_changed = false; | bool resource_changed = false; | ||||
| /* Divide in chunks of MAX_MATERIAL. */ | /* Divide in chunks of MAX_MATERIAL. */ | ||||
| uint32_t chunk = id >> 12u; | uint32_t chunk = id >> 12u; | ||||
| *r_mat_id = id & 0xFFFu; | *r_mat_id = id & 0xFFFu; | ||||
| /* We need to add a new chunk. */ | /* We need to add a new chunk. */ | ||||
| while (chunk >= wpd->material_chunk_count) { | while (chunk >= wpd->material_chunk_count) { | ||||
| wpd->material_chunk_count++; | wpd->material_chunk_count++; | ||||
| wpd->material_ubo_data_curr = BLI_memblock_alloc(wpd->material_ubo_data); | wpd->material_ubo_data_curr = static_cast<WORKBENCH_UBO_Material *>( | ||||
| wpd->material_ubo_curr = workbench_material_ubo_alloc(wpd); | BLI_memblock_alloc(wpd->material_ubo_data)); | ||||
| wpd->material_ubo_curr = static_cast<GPUUniformBuf *>(workbench_material_ubo_alloc(wpd)); | |||||
| wpd->material_chunk_curr = chunk; | wpd->material_chunk_curr = chunk; | ||||
| resource_changed = true; | resource_changed = true; | ||||
| } | } | ||||
| /* We need to go back to a previous chunk. */ | /* We need to go back to a previous chunk. */ | ||||
| if (wpd->material_chunk_curr != chunk) { | if (wpd->material_chunk_curr != chunk) { | ||||
| wpd->material_ubo_data_curr = BLI_memblock_elem_get(wpd->material_ubo_data, 0, chunk); | wpd->material_ubo_data_curr = static_cast<WORKBENCH_UBO_Material *>( | ||||
| wpd->material_ubo_curr = BLI_memblock_elem_get(wpd->material_ubo, 0, chunk); | BLI_memblock_elem_get(wpd->material_ubo_data, 0, chunk)); | ||||
| wpd->material_ubo_curr = static_cast<GPUUniformBuf *>( | |||||
| BLI_memblock_elem_get(wpd->material_ubo, 0, chunk)); | |||||
| wpd->material_chunk_curr = chunk; | wpd->material_chunk_curr = chunk; | ||||
| resource_changed = true; | resource_changed = true; | ||||
| } | } | ||||
| return resource_changed; | return resource_changed; | ||||
| } | } | ||||
| DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd, | DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd, | ||||
| Object *ob, | Object *ob, | ||||
| ▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines | |||||