Blender V5.3
BKE_paint_bvh_pixels.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_array.hh"
12#include "BLI_function_ref.hh"
13#include "BLI_map.hh"
15#include "BLI_rect.hh"
16#include "BLI_vector.hh"
17
18#include "DNA_image_types.h"
19
20#include "BKE_image.hh"
21#include "BKE_image_wrappers.hh"
22#include "BKE_paint_bvh.hh"
23
24#include "IMB_imbuf_types.hh"
25#include "IMB_partial_update.hh"
26
28
38
45
46 struct {
47 bool dirty : 1;
49
50 /* Dirty region of the tile in image space. */
52
54
57
60
62 {
63 flags.dirty = false;
65 }
66
73
75 {
77 flags.dirty = false;
78 }
79};
80
84struct PixelNode {
85 struct {
86 /* Indicates whether the node data was painted to */
87 bool dirty : 1;
88
89 /* Indicates whether the node data should be rebuilt */
90 bool rebuild : 1;
92
94
105
107 {
108 flags.dirty = false;
109 flags.rebuild = true;
110 }
111
113 {
114 for (UDIMTilePixels &tile : tiles) {
115 if (tile.tile_number == image_tile.get_tile_number()) {
116 return &tile;
117 }
118 }
119 return nullptr;
120 }
121
122 void mark_region(UDIMTilePixels &tile, ImBuf &image_buffer)
123 {
124 if (tile.flags.dirty) {
125 if (image_buffer.color_mode == ImColorMode::BW) {
126 image_buffer.color_mode = ImColorMode::RGBA;
127 IMB_partial_update_mark_full(&image_buffer);
128 }
129 else {
130 IMB_partial_update_mark_region(&image_buffer, tile.dirty_region);
131 }
132 IMB_mark_dirty(&image_buffer);
133 tile.clear_dirty();
134 }
135 }
136
138 {
139 for (UDIMTilePixels &tile : tiles) {
140 if (tile.flags.dirty) {
141 r_dirty_tiles.append_non_duplicates(tile.tile_number);
142 }
143 }
144 }
145
147 {
148 tiles.clear();
149 uv_primitives.tri_indices.reinitialize(0);
150 uv_primitives.pixel_to_position.reinitialize(0);
151 }
152};
153
154/* -------------------------------------------------------------------- */
157
163constexpr int SEAM_TILE_BITS = 6;
164constexpr int SEAM_TILE_SIZE = 1 << SEAM_TILE_BITS;
165
176
183
188
194
196
197 static int seam_tile_index(const int2 source, const int seam_tiles_x)
198 {
199 return (source.x >> SEAM_TILE_BITS) + (source.y >> SEAM_TILE_BITS) * seam_tiles_x;
200 }
201
202 void build_seam_tile_map(const int2 resolution);
203
204 void copy_pixels(ImBuf &tile_buffer, IndexRange group_range) const;
205
206 void print_compression_rate() const;
207};
208
211
212 std::optional<std::reference_wrapper<CopyPixelTile>> find_tile(image::TileNumber tile_number)
213 {
214 for (CopyPixelTile &tile : tiles) {
215 if (tile.tile_number == tile_number) {
216 return tile;
217 }
218 }
219 return std::nullopt;
220 }
221
222 void clear()
223 {
224 tiles.clear();
225 }
226};
227
229
243
245 PixelNode &pixel_node,
248void collect_dirty_tiles(PixelNode &pixel_node, Vector<image::TileNumber> &r_dirty_tiles);
249
252 image::TileNumber tile_number,
253 Span<uint8_t> seam_tiles_modified,
254 FunctionRef<void(int x_start, int x_end, int y)> push_undo_tiles);
255
256} // namespace blender::bke::pbvh::pixels
A BVH for high poly meshes.
void append_non_duplicates(const T &value)
const ccl_global KernelWorkTile * tile
PixelData & data_get(bke::pbvh::Tree &pbvh)
void collect_dirty_tiles(PixelNode &pixel_node, Vector< image::TileNumber > &r_dirty_tiles)
void copy_pixels(bke::pbvh::Tree &pbvh, Map< image::TileNumber, ImBuf * > &buffers, image::TileNumber tile_number, Span< uint8_t > seam_tiles_modified, FunctionRef< void(int x_start, int x_end, int y)> push_undo_tiles)
void mark_image_dirty(bke::pbvh::Node &node, PixelNode &pixel_node, Map< image::TileNumber, ImBuf * > &buffers)
__int64 int64_t
Definition BKE_text.h:90
VecBase< int8_t, 2 > char2
void IMB_mark_dirty(ImBuf *ibuf)
unsigned short ushort
Definition BKE_text.h:56
void BLI_rcti_init_minmax(struct rcti *rect)
Definition rct.cc:488
void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2])
Definition rct.cc:500
VecBase< int32_t, 2 > int2
unsigned char uint8_t
Definition BKE_text.h:79
void IMB_partial_update_mark_region(ImBuf *ibuf, const rcti &region)
void IMB_partial_update_mark_full(ImBuf *ibuf)
ImColorMode color_mode
void build_seam_tile_map(const int2 resolution)
static int seam_tile_index(const int2 source, const int seam_tiles_x)
Vector< DeltaCopyPixelCommand > command_deltas
std::optional< std::reference_wrapper< CopyPixelTile > > find_tile(image::TileNumber tile_number)
DeltaCopyPixelCommand(char2 delta_source_1, char2 delta_source_2, uint8_t mix_factor)
struct blender::bke::pbvh::pixels::PixelData::@306346156271221265040373004232360117117316076073 flags
UDIMTilePixels * find_tile_data(const image::ImageTileWrapper &image_tile)
void collect_dirty_tiles(Vector< image::TileNumber > &r_dirty_tiles)
struct blender::bke::pbvh::pixels::PixelNode::@370321035024016012235212162017206013166215342344 flags
struct blender::bke::pbvh::pixels::PixelNode::@204347010204307204275117222140300103004304270323 uv_primitives
void mark_region(UDIMTilePixels &tile, ImBuf &image_buffer)
struct blender::bke::pbvh::pixels::UDIMTilePixels::@304110110127162000274075361305170307020300266014 flags
void mark_dirty(const Bounds< int2 > &bounds)