57 bool use_color_management,
68 for (const int64_t y : sub_y_range) {
69 for (const int64_t x : IndexRange(size.x)) {
72 const float2 pixel_coordinates = ((float2(x, y) + 0.5f) / float2(size)) * 2.0f - 1.0f;
74 const float3 coordinates = (float3(pixel_coordinates, 0.0f) + offset) * scale;
76 TexResult texture_result;
77 const int result_type = multitex_ext_safe(
78 texture, coordinates, &texture_result, image_pool, use_color_management, false);
80 float4 color = float4(texture_result.trgba);
81 color.w = texture_result.talpha ? color.w : texture_result.tin;
82 if (!(result_type & TEX_RGB)) {
83 copy_v3_fl(color, color.w);
86 color_pixels[y * size.x + x] = color;
87 value_pixels[y * size.x + x] = color.w;
95 "Cached Color Texture",
101 *color_pixels.data());
104 "Cached Value Texture",
110 value_pixels.data());
133void CachedTextureContainer::reset()
136 for (
auto &cached_textures_for_id : map_.values()) {
137 cached_textures_for_id.remove_if([](
auto item) {
return !item.value->needed; });
139 map_.remove_if([](
auto item) {
return item.value.is_empty(); });
143 for (
auto &cached_textures_for_id : map_.values()) {
144 for (
auto &value : cached_textures_for_id.values()) {
145 value->needed =
false;
152 bool use_color_management,
159 const std::string library_key = texture->id.lib ? texture->id.lib->id.name :
"";
160 const std::string id_key = std::string(texture->id.name) + library_key;
161 auto &cached_textures_for_id = map_.lookup_or_add_default(id_key);
164 if (context.query_id_recalc_flag(
reinterpret_cast<ID *
>(texture)) &
ID_RECALC_ALL) {
165 cached_textures_for_id.clear();
168 auto &cached_texture = *cached_textures_for_id.lookup_or_add_cb(key, [&]() {
169 return std::make_unique<CachedTexture>(
170 context, texture, use_color_management, size, offset, scale);
173 cached_texture.needed =
true;
174 return cached_texture;
void BKE_texture_fetch_images_for_pool(struct Tex *texture, struct ImagePool *pool)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
@ GPU_TEXTURE_USAGE_SHADER_READ
CachedTextureKey(int2 size, float3 offset, float3 scale)
CachedTexture(Context &context, Tex *texture, bool use_color_management, int2 size, float3 offset, float3 scale)