Blender V5.3
workbench_materials.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "BLI_ghash.hh"
12#include "BLI_hash_c.hh"
13#include "BLI_math_color_c.hh"
14
16
17/* get_image */
18#include "BKE_image_gpu.hh"
20#include "DNA_material_types.h"
21#include "DNA_node_types.h"
22#include "ED_uvedit.hh"
23/* get_image */
24
25namespace blender::workbench {
26
43
44MaterialTexture::MaterialTexture(Manager &manager, Object *ob, int material_index)
45{
46 const blender::bNode *node = nullptr;
47
48 blender::Image *image = nullptr;
49 ImageUser *user = nullptr;
50 ED_object_get_active_image(ob, material_index + 1, &image, &user, &node, nullptr);
51 if (!node || !image) {
52 return;
53 }
54
55 switch (node->type_legacy) {
56 case SH_NODE_TEX_IMAGE: {
57 const NodeTexImage *storage = static_cast<NodeTexImage *>(node->storage);
58 const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST);
59 sampler_state.set_filtering_flag_from_test(GPU_SAMPLER_FILTERING_LINEAR, use_filter);
60 switch (storage->extension) {
62 default:
65 break;
69 break;
73 break;
77 break;
78 }
79 break;
80 }
82 const NodeTexEnvironment *storage = static_cast<NodeTexEnvironment *>(node->storage);
83 const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST);
84 sampler_state.set_filtering_flag_from_test(GPU_SAMPLER_FILTERING_LINEAR, use_filter);
85 break;
86 }
87 default:
88 BLI_assert_msg(0, "Node type not supported by workbench");
89 }
90
92 manager.hold_texture(gpu.texture);
93 manager.hold_texture(gpu.tile_mapping);
94 premultiplied = image->alpha_mode == IMA_ALPHA_PREMUL;
96 name = image->id.name;
97}
98
101 ImageUser *user /* = nullptr */)
102{
104 manager.hold_texture(gpu.texture);
105 manager.hold_texture(gpu.tile_mapping);
106 premultiplied = image->alpha_mode == IMA_ALPHA_PREMUL;
108 name = image->id.name;
109}
110
111} // namespace blender::workbench
#define SH_NODE_TEX_IMAGE
#define SH_NODE_TEX_ENVIRONMENT
#define ELEM(...)
#define BLI_assert_msg(a, msg)
void hold_texture(gpu::Texture *texture)
#define storage(slot, qualifiers)
@ IMA_ALPHA_CHANNEL_PACKED
unsigned int uint
Definition BKE_text.h:55
@ SHD_IMAGE_EXTENSION_EXTEND
@ SHD_IMAGE_EXTENSION_CLIP
@ SHD_IMAGE_EXTENSION_MIRROR
@ SHD_IMAGE_EXTENSION_REPEAT
ImageGPUTextures BKE_image_acquire_gpu_material_texture(Image *image, ImageUser *iuser, const bool use_tile_mapping, const bool try_only)
Definition image_gpu.cc:762
@ GPU_SAMPLER_EXTEND_MODE_MIRRORED_REPEAT
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
@ GPU_SAMPLER_EXTEND_MODE_REPEAT
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
@ GPU_SAMPLER_FILTERING_LINEAR
BLI_INLINE float BLI_hash_int_01(unsigned int k)
Definition BLI_hash_c.hh:94
unsigned int BLI_ghashutil_strhash_p_murmur(const void *ptr)
BLI_INLINE void IMB_colormanagement_rec709_to_scene_linear(float scene_linear[3], const float rec709[3])
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition math_color.cc:61
VecBase< float, 3 > float3
bool ED_object_get_active_image(Object *ob, int mat_nr, Image **r_ima, ImageUser **r_iuser, const bNode **r_node, const bNodeTree **r_ntree)
Definition uvedit_ops.cc:98
#define hash
Definition noise_c.cc:156
char name[258]
Definition DNA_ID.h:433
struct Library * lib
Definition DNA_ID.h:421
char filepath[1024]
Definition DNA_ID.h:562
static uint32_t pack_data(float metallic, float roughness, float alpha)