WIP: Vulkan: Workbench #107886

Closed
Jeroen Bakker wants to merge 88 commits from Jeroen-Bakker:vulkan-draw-manager-workbench into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
105 changed files with 1830 additions and 689 deletions
Showing only changes of commit de680d302d - Show all commits

View File

@ -155,12 +155,15 @@ ccl_device_inline void shader_setup_from_sample(KernelGlobals kg,
sd->Ng = Ng;
sd->wi = I;
sd->shader = shader;
if (prim != PRIM_NONE)
sd->type = PRIMITIVE_TRIANGLE;
else if (lamp != LAMP_NONE)
if (lamp != LAMP_NONE) {
sd->type = PRIMITIVE_LAMP;
else
}
else if (prim != PRIM_NONE) {
sd->type = PRIMITIVE_TRIANGLE;
}
else {
sd->type = PRIMITIVE_NONE;
}
/* primitive */
sd->object = object;

View File

@ -1221,7 +1221,7 @@ class IMAGE_PT_tools_brush_display(Panel, BrushButtonsPanel, DisplayPanel):
bl_context = ".paint_common_2d"
bl_parent_id = "IMAGE_PT_paint_settings"
bl_category = "Tool"
bl_label = "Brush Tip"
bl_label = "Cursor"
bl_options = {'DEFAULT_CLOSED'}
bl_ui_units_x = 15

View File

@ -335,6 +335,7 @@ compositor_node_categories = [
NodeItem("CompositorNodeSunBeams"),
NodeItem("CompositorNodeDenoise"),
NodeItem("CompositorNodeAntiAliasing"),
NodeItem("CompositorNodeKuwahara"),
]),
CompositorNodeCategory("CMP_OP_VECTOR", "Vector", items=[
NodeItem("CompositorNodeNormal"),

View File

@ -124,6 +124,7 @@ class AssetLibrary {
*/
AssetRepresentation &add_external_asset(StringRef relative_asset_path,
StringRef name,
int id_type,
std::unique_ptr<AssetMetaData> metadata);
/** See #AssetLibrary::add_external_asset(). */
AssetRepresentation &add_local_id_asset(StringRef relative_asset_path, ID &id);

View File

@ -22,6 +22,7 @@ typedef struct AssetRepresentation AssetRepresentation;
const char *AS_asset_representation_name_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
int AS_asset_representation_id_type_get(const AssetRepresentation *asset) ATTR_WARN_UNUSED_RESULT;
AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
struct ID *AS_asset_representation_local_id_get(const AssetRepresentation *asset)

View File

@ -42,6 +42,7 @@ class AssetRepresentation {
struct ExternalAsset {
std::string name;
int id_type = 0;
std::unique_ptr<AssetMetaData> metadata_ = nullptr;
};
union {
@ -55,6 +56,7 @@ class AssetRepresentation {
/** Constructs an asset representation for an external ID. The asset will not be editable. */
AssetRepresentation(AssetIdentifier &&identifier,
StringRef name,
int id_type,
std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library);
/**
@ -85,6 +87,7 @@ class AssetRepresentation {
std::unique_ptr<AssetWeakReference> make_weak_reference() const;
StringRefNull get_name() const;
int get_id_type() const;
AssetMetaData &get_metadata() const;
/**
* Get the import method to use for this asset. A different one may be used if
@ -114,6 +117,9 @@ class AssetRepresentation {
/* C-Handle */
struct AssetRepresentation;
const blender::StringRefNull AS_asset_representation_library_relative_identifier_get(
const AssetRepresentation *asset_handle);
std::string AS_asset_representation_full_path_get(const ::AssetRepresentation *asset);
/**
* Get the absolute path to the .blend file containing the given asset. String will be empty if

View File

@ -230,11 +230,12 @@ void AssetLibrary::refresh()
AssetRepresentation &AssetLibrary::add_external_asset(StringRef relative_asset_path,
StringRef name,
const int id_type,
std::unique_ptr<AssetMetaData> metadata)
{
AssetIdentifier identifier = asset_identifier_from_library(relative_asset_path);
return asset_storage_->add_external_asset(
std::move(identifier), name, std::move(metadata), *this);
std::move(identifier), name, id_type, std::move(metadata), *this);
}
AssetRepresentation &AssetLibrary::add_local_id_asset(StringRef relative_asset_path, ID &id)

View File

@ -21,6 +21,7 @@ namespace blender::asset_system {
AssetRepresentation::AssetRepresentation(AssetIdentifier &&identifier,
StringRef name,
const int id_type,
std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library)
: identifier_(identifier),
@ -29,6 +30,7 @@ AssetRepresentation::AssetRepresentation(AssetIdentifier &&identifier,
external_asset_()
{
external_asset_.name = name;
external_asset_.id_type = id_type;
external_asset_.metadata_ = std::move(metadata);
}
@ -87,6 +89,15 @@ StringRefNull AssetRepresentation::get_name() const
return external_asset_.name;
}
int AssetRepresentation::get_id_type() const
{
if (is_local_id_) {
return GS(local_asset_id_->name);
}
return external_asset_.id_type;
}
AssetMetaData &AssetRepresentation::get_metadata() const
{
return is_local_id_ ? *local_asset_id_->asset_data : *external_asset_.metadata_;
@ -135,6 +146,15 @@ const AssetLibrary &AssetRepresentation::owner_asset_library() const
using namespace blender;
const StringRefNull AS_asset_representation_library_relative_identifier_get(
const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
const asset_system::AssetIdentifier &identifier = asset->get_identifier();
return identifier.library_relative_identifier();
}
std::string AS_asset_representation_full_path_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
@ -183,6 +203,13 @@ const char *AS_asset_representation_name_get(const AssetRepresentation *asset_ha
return asset->get_name().c_str();
}
int AS_asset_representation_id_type_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->get_id_type();
}
AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =

View File

@ -27,11 +27,12 @@ AssetRepresentation &AssetStorage::add_local_id_asset(AssetIdentifier &&identifi
AssetRepresentation &AssetStorage::add_external_asset(AssetIdentifier &&identifier,
StringRef name,
const int id_type,
std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library)
{
return *external_assets_.lookup_key_or_add(std::make_unique<AssetRepresentation>(
std::move(identifier), name, std::move(metadata), owner_asset_library));
std::move(identifier), name, id_type, std::move(metadata), owner_asset_library));
}
bool AssetStorage::remove_asset(AssetRepresentation &asset)

View File

@ -37,6 +37,7 @@ class AssetStorage {
/** See #AssetLibrary::add_external_asset(). */
AssetRepresentation &add_external_asset(AssetIdentifier &&identifier,
StringRef name,
int id_type,
std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library);
/** See #AssetLibrary::add_external_asset(). */

View File

@ -32,7 +32,8 @@ class AssetRepresentationTest : public AssetLibraryTestBase {
AssetRepresentation &add_dummy_asset(AssetLibrary &library, StringRef relative_path)
{
std::unique_ptr<AssetMetaData> dummy_metadata = std::make_unique<AssetMetaData>();
return library.add_external_asset(relative_path, "Some asset name", std::move(dummy_metadata));
return library.add_external_asset(
relative_path, "Some asset name", 0, std::move(dummy_metadata));
}
};

View File

@ -1061,6 +1061,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, i
#define CMP_NODE_INPAINT 272
#define CMP_NODE_DESPECKLE 273
#define CMP_NODE_ANTIALIASING 274
#define CMP_NODE_KUWAHARA 275
#define CMP_NODE_GLARE 301
#define CMP_NODE_TONEMAP 302

View File

@ -16,9 +16,9 @@
#include "MEM_guardedalloc.h"
#include "BLI_array.hh"
#include "BLI_array_utils.hh"
#include "BLI_index_range.hh"
#include "BLI_math_vector.h"
#include "BLI_math_vector_types.hh"
#include "BLI_span.hh"
#include "BLI_task.hh"
@ -27,6 +27,7 @@
#include "BKE_attribute.h"
#include "BKE_attribute.hh"
#include "BKE_attribute_math.hh"
#include "BKE_bvhutils.h"
#include "BKE_customdata.h"
#include "BKE_editmesh.h"
@ -35,6 +36,7 @@
#include "BKE_mesh_mapping.h"
#include "BKE_mesh_remesh_voxel.h" /* own include */
#include "BKE_mesh_runtime.h"
#include "BKE_mesh_sample.hh"
#include "bmesh_tools.h"
@ -360,116 +362,104 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source)
void BKE_remesh_reproject_vertex_paint(Mesh *target, const Mesh *source)
{
BVHTreeFromMesh bvhtree = {nullptr};
BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2);
using namespace blender;
using namespace blender::bke;
const AttributeAccessor src_attributes = source->attributes();
MutableAttributeAccessor dst_attributes = target->attributes_for_write();
int i = 0;
const CustomDataLayer *layer;
Vector<AttributeIDRef> point_ids;
Vector<AttributeIDRef> corner_ids;
source->attributes().for_all([&](const AttributeIDRef &id, const AttributeMetaData &meta_data) {
if (CD_TYPE_AS_MASK(meta_data.data_type) & CD_MASK_COLOR_ALL) {
if (meta_data.domain == ATTR_DOMAIN_POINT) {
point_ids.append(id);
}
else if (meta_data.domain == ATTR_DOMAIN_CORNER) {
corner_ids.append(id);
}
}
return true;
});
if (point_ids.is_empty() && corner_ids.is_empty()) {
return;
}
Array<int> source_vert_to_loop_offsets;
Array<int> source_vert_to_loop_indices;
blender::GroupedSpan<int> source_lmap;
GroupedSpan<int> source_lmap;
Array<int> target_vert_to_loop_offsets;
Array<int> target_vert_to_loop_indices;
blender::GroupedSpan<int> target_lmap;
GroupedSpan<int> target_lmap;
BVHTreeFromMesh bvhtree = {nullptr};
threading::parallel_invoke(
[&]() { BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2); },
[&]() {
source_lmap = mesh::build_vert_to_loop_map(source->corner_verts(),
source->totvert,
source_vert_to_loop_offsets,
source_vert_to_loop_indices);
},
[&]() {
target_lmap = mesh::build_vert_to_loop_map(target->corner_verts(),
target->totvert,
target_vert_to_loop_offsets,
target_vert_to_loop_indices);
});
while ((layer = BKE_id_attribute_from_index(
const_cast<ID *>(&source->id), i++, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL)))
{
eAttrDomain domain = BKE_id_attribute_domain(&source->id, layer);
const eCustomDataType type = eCustomDataType(layer->type);
CustomData *target_cdata = domain == ATTR_DOMAIN_POINT ? &target->vdata : &target->ldata;
const CustomData *source_cdata = domain == ATTR_DOMAIN_POINT ? &source->vdata : &source->ldata;
/* Check attribute exists in target. */
int layer_i = CustomData_get_named_layer_index(target_cdata, type, layer->name);
if (layer_i == -1) {
int elem_num = domain == ATTR_DOMAIN_POINT ? target->totvert : target->totloop;
CustomData_add_layer_named(target_cdata, type, CD_SET_DEFAULT, elem_num, layer->name);
layer_i = CustomData_get_named_layer_index(target_cdata, type, layer->name);
const Span<float3> target_positions = target->vert_positions();
Array<int> nearest_src_verts(target_positions.size());
threading::parallel_for(target_positions.index_range(), 1024, [&](const IndexRange range) {
for (const int i : range) {
BVHTreeNearest nearest;
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
BLI_bvhtree_find_nearest(
bvhtree.tree, target_positions[i], &nearest, bvhtree.nearest_callback, &bvhtree);
nearest_src_verts[i] = nearest.index;
}
});
size_t data_size = CustomData_sizeof(type);
void *target_data = target_cdata->layers[layer_i].data;
void *source_data = layer->data;
const Span<float3> target_positions = target->vert_positions();
for (const AttributeIDRef &id : point_ids) {
const GVArraySpan src = *src_attributes.lookup(id, ATTR_DOMAIN_POINT);
GSpanAttributeWriter dst = dst_attributes.lookup_or_add_for_write_only_span(
id, ATTR_DOMAIN_POINT, cpp_type_to_custom_data_type(src.type()));
attribute_math::gather(src, nearest_src_verts, dst.span);
dst.finish();
}
if (domain == ATTR_DOMAIN_POINT) {
blender::threading::parallel_for(
IndexRange(target->totvert), 4096, [&](const IndexRange range) {
for (const int i : range) {
BVHTreeNearest nearest;
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
BLI_bvhtree_find_nearest(
bvhtree.tree, target_positions[i], &nearest, bvhtree.nearest_callback, &bvhtree);
if (nearest.index != -1) {
memcpy(POINTER_OFFSET(target_data, size_t(i) * data_size),
POINTER_OFFSET(source_data, size_t(nearest.index) * data_size),
data_size);
if (!corner_ids.is_empty()) {
for (const AttributeIDRef &id : corner_ids) {
const GVArraySpan src = *src_attributes.lookup(id, ATTR_DOMAIN_CORNER);
GSpanAttributeWriter dst = dst_attributes.lookup_or_add_for_write_only_span(
id, ATTR_DOMAIN_CORNER, cpp_type_to_custom_data_type(src.type()));
threading::parallel_for(target_positions.index_range(), 1024, [&](const IndexRange range) {
src.type().to_static_type_tag<ColorGeometry4b, ColorGeometry4f>([&](auto type_tag) {
using T = typename decltype(type_tag)::type;
if constexpr (std::is_void_v<T>) {
BLI_assert_unreachable();
}
else {
const Span<T> src_typed = src.typed<T>();
MutableSpan<T> dst_typed = dst.span.typed<T>();
for (const int dst_vert : range) {
/* Find the average value at the corners of the closest vertex on the
* source mesh. */
const int src_vert = nearest_src_verts[dst_vert];
T value;
typename blender::bke::attribute_math::DefaultMixer<T> mixer({&value, 1});
for (const int corner : source_lmap[src_vert]) {
mixer.mix_in(0, src_typed[corner]);
}
dst_typed.fill_indices(target_lmap[dst_vert], value);
}
});
}
else {
/* Lazily init vertex -> loop maps. */
if (source_lmap.is_empty()) {
source_lmap = blender::bke::mesh::build_vert_to_loop_map(source->corner_verts(),
source->totvert,
source_vert_to_loop_offsets,
source_vert_to_loop_indices);
target_lmap = blender::bke::mesh::build_vert_to_loop_map(target->corner_verts(),
target->totvert,
target_vert_to_loop_offsets,
target_vert_to_loop_indices);
}
}
});
});
blender::threading::parallel_for(
IndexRange(target->totvert), 2048, [&](const IndexRange range) {
for (const int i : range) {
BVHTreeNearest nearest;
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
BLI_bvhtree_find_nearest(
bvhtree.tree, target_positions[i], &nearest, bvhtree.nearest_callback, &bvhtree);
if (nearest.index == -1) {
continue;
}
const Span<int> source_loops = source_lmap[nearest.index];
const Span<int> target_loops = target_lmap[i];
if (target_loops.size() == 0 || source_loops.size() == 0) {
continue;
}
/*
* Average color data for loops around the source vertex into
* the first target loop around the target vertex
*/
CustomData_interp(source_cdata,
target_cdata,
source_loops.data(),
nullptr,
nullptr,
source_loops.size(),
target_loops[0]);
void *elem = POINTER_OFFSET(target_data, size_t(target_loops[0]) * data_size);
/* Copy to rest of target loops. */
for (int j = 1; j < target_loops.size(); j++) {
memcpy(POINTER_OFFSET(target_data, size_t(target_loops[j]) * data_size),
elem,
data_size);
}
}
});
dst.finish();
}
}

View File

@ -179,94 +179,98 @@ static void libmv_frame_to_normalized_relative(const float frame_coord[2],
/** \name Conversion of markers between Blender's DNA and Libmv.
* \{ */
static void dna_marker_to_libmv_marker(/*const*/ MovieTrackingTrack *track,
const MovieTrackingMarker *marker,
int clip,
int track_index,
int frame_width,
int frame_height,
bool backwards,
libmv_Marker *libmv_marker)
static libmv_Marker dna_marker_to_libmv_marker(/*const*/ MovieTrackingTrack &track,
const MovieTrackingMarker &marker,
const int clip,
const int track_index,
const int frame_width,
const int frame_height,
const bool backwards)
{
const int frame_dimensions[2] = {frame_width, frame_height};
libmv_marker->clip = clip;
libmv_marker->frame = marker->framenr;
libmv_marker->track = track_index;
libmv_Marker libmv_marker{};
normalized_to_libmv_frame(marker->pos, frame_dimensions, libmv_marker->center);
const int frame_dimensions[2] = {frame_width, frame_height};
libmv_marker.clip = clip;
libmv_marker.frame = marker.framenr;
libmv_marker.track = track_index;
normalized_to_libmv_frame(marker.pos, frame_dimensions, libmv_marker.center);
for (int i = 0; i < 4; i++) {
normalized_relative_to_libmv_frame(
marker->pattern_corners[i], marker->pos, frame_dimensions, libmv_marker->patch[i]);
marker.pattern_corners[i], marker.pos, frame_dimensions, libmv_marker.patch[i]);
}
normalized_relative_to_libmv_frame(
marker->search_min, marker->pos, frame_dimensions, libmv_marker->search_region_min);
marker.search_min, marker.pos, frame_dimensions, libmv_marker.search_region_min);
normalized_relative_to_libmv_frame(
marker->search_max, marker->pos, frame_dimensions, libmv_marker->search_region_max);
marker.search_max, marker.pos, frame_dimensions, libmv_marker.search_region_max);
/* NOTE: All the markers does have 1.0 weight.
* Might support in the future, but will require more elaborated process which will involve
* F-Curve evaluation. */
libmv_marker->weight = 1.0f;
libmv_marker.weight = 1.0f;
if (marker->flag & MARKER_TRACKED) {
libmv_marker->source = LIBMV_MARKER_SOURCE_TRACKED;
if (marker.flag & MARKER_TRACKED) {
libmv_marker.source = LIBMV_MARKER_SOURCE_TRACKED;
}
else {
libmv_marker->source = LIBMV_MARKER_SOURCE_MANUAL;
libmv_marker.source = LIBMV_MARKER_SOURCE_MANUAL;
}
libmv_marker->status = LIBMV_MARKER_STATUS_UNKNOWN;
libmv_marker->model_type = LIBMV_MARKER_MODEL_TYPE_POINT;
libmv_marker->model_id = 0;
libmv_marker.status = LIBMV_MARKER_STATUS_UNKNOWN;
libmv_marker.model_type = LIBMV_MARKER_MODEL_TYPE_POINT;
libmv_marker.model_id = 0;
/* NOTE: We currently don't support reference marker from different clip. */
libmv_marker->reference_clip = clip;
libmv_marker.reference_clip = clip;
if (track->pattern_match == TRACK_MATCH_KEYFRAME) {
if (track.pattern_match == TRACK_MATCH_KEYFRAME) {
const MovieTrackingMarker *keyframe_marker = tracking_get_keyframed_marker(
track, marker->framenr, backwards);
libmv_marker->reference_frame = keyframe_marker->framenr;
&track, marker.framenr, backwards);
libmv_marker.reference_frame = keyframe_marker->framenr;
}
else {
libmv_marker->reference_frame = backwards ? marker->framenr - 1 : marker->framenr;
libmv_marker.reference_frame = backwards ? marker.framenr - 1 : marker.framenr;
}
libmv_marker->disabled_channels =
((track->flag & TRACK_DISABLE_RED) ? LIBMV_MARKER_CHANNEL_R : 0) |
((track->flag & TRACK_DISABLE_GREEN) ? LIBMV_MARKER_CHANNEL_G : 0) |
((track->flag & TRACK_DISABLE_BLUE) ? LIBMV_MARKER_CHANNEL_B : 0);
libmv_marker.disabled_channels =
((track.flag & TRACK_DISABLE_RED) ? LIBMV_MARKER_CHANNEL_R : 0) |
((track.flag & TRACK_DISABLE_GREEN) ? LIBMV_MARKER_CHANNEL_G : 0) |
((track.flag & TRACK_DISABLE_BLUE) ? LIBMV_MARKER_CHANNEL_B : 0);
return libmv_marker;
}
static void libmv_marker_to_dna_marker(libmv_Marker *libmv_marker,
int frame_width,
int frame_height,
MovieTrackingMarker *marker)
static MovieTrackingMarker libmv_marker_to_dna_marker(const libmv_Marker &libmv_marker,
const int frame_width,
const int frame_height)
{
const int frame_dimensions[2] = {frame_width, frame_height};
marker->framenr = libmv_marker->frame;
MovieTrackingMarker marker{};
libmv_frame_to_normalized(libmv_marker->center, frame_dimensions, marker->pos);
const int frame_dimensions[2] = {frame_width, frame_height};
marker.framenr = libmv_marker.frame;
libmv_frame_to_normalized(libmv_marker.center, frame_dimensions, marker.pos);
for (int i = 0; i < 4; i++) {
libmv_frame_to_normalized_relative(libmv_marker->patch[i],
libmv_marker->center,
frame_dimensions,
marker->pattern_corners[i]);
libmv_frame_to_normalized_relative(
libmv_marker.patch[i], libmv_marker.center, frame_dimensions, marker.pattern_corners[i]);
}
libmv_frame_to_normalized_relative(
libmv_marker->search_region_min, libmv_marker->center, frame_dimensions, marker->search_min);
libmv_marker.search_region_min, libmv_marker.center, frame_dimensions, marker.search_min);
libmv_frame_to_normalized_relative(
libmv_marker->search_region_max, libmv_marker->center, frame_dimensions, marker->search_max);
libmv_marker.search_region_max, libmv_marker.center, frame_dimensions, marker.search_max);
marker->flag = 0;
if (libmv_marker->source == LIBMV_MARKER_SOURCE_TRACKED) {
marker->flag |= MARKER_TRACKED;
marker.flag = 0;
if (libmv_marker.source == LIBMV_MARKER_SOURCE_TRACKED) {
marker.flag |= MARKER_TRACKED;
}
else {
marker->flag &= ~MARKER_TRACKED;
marker.flag &= ~MARKER_TRACKED;
}
return marker;
}
/** \} */
@ -279,29 +283,28 @@ static void libmv_marker_to_dna_marker(libmv_Marker *libmv_marker,
* \{ */
/* Returns false if marker crossed margin area from frame bounds. */
static bool tracking_check_marker_margin(const libmv_Marker *libmv_marker,
int margin,
int frame_width,
int frame_height)
static bool tracking_check_marker_margin(const libmv_Marker &libmv_marker,
const int margin,
const int frame_width,
const int frame_height)
{
float patch_min[2], patch_max[2];
float margin_left, margin_top, margin_right, margin_bottom;
INIT_MINMAX2(patch_min, patch_max);
minmax_v2v2_v2(patch_min, patch_max, libmv_marker->patch[0]);
minmax_v2v2_v2(patch_min, patch_max, libmv_marker->patch[1]);
minmax_v2v2_v2(patch_min, patch_max, libmv_marker->patch[2]);
minmax_v2v2_v2(patch_min, patch_max, libmv_marker->patch[3]);
minmax_v2v2_v2(patch_min, patch_max, libmv_marker.patch[0]);
minmax_v2v2_v2(patch_min, patch_max, libmv_marker.patch[1]);
minmax_v2v2_v2(patch_min, patch_max, libmv_marker.patch[2]);
minmax_v2v2_v2(patch_min, patch_max, libmv_marker.patch[3]);
margin_left = max_ff(libmv_marker->center[0] - patch_min[0], margin);
margin_top = max_ff(patch_max[1] - libmv_marker->center[1], margin);
margin_right = max_ff(patch_max[0] - libmv_marker->center[0], margin);
margin_bottom = max_ff(libmv_marker->center[1] - patch_min[1], margin);
margin_left = max_ff(libmv_marker.center[0] - patch_min[0], margin);
margin_top = max_ff(patch_max[1] - libmv_marker.center[1], margin);
margin_right = max_ff(patch_max[0] - libmv_marker.center[0], margin);
margin_bottom = max_ff(libmv_marker.center[1] - patch_min[1], margin);
if (libmv_marker->center[0] < margin_left ||
libmv_marker->center[0] > frame_width - margin_right ||
libmv_marker->center[1] < margin_bottom ||
libmv_marker->center[1] > frame_height - margin_top)
if (libmv_marker.center[0] < margin_left ||
libmv_marker.center[0] > frame_width - margin_right ||
libmv_marker.center[1] < margin_bottom || libmv_marker.center[1] > frame_height - margin_top)
{
return false;
}
@ -315,9 +318,9 @@ static bool tracking_check_marker_margin(const libmv_Marker *libmv_marker,
/** \name Auto-Track Context Initialization
* \{ */
static bool autotrack_is_marker_usable(const MovieTrackingMarker *marker)
static bool autotrack_is_marker_usable(const MovieTrackingMarker &marker)
{
if (marker->flag & MARKER_DISABLED) {
if (marker.flag & MARKER_DISABLED) {
return false;
}
return true;
@ -334,7 +337,7 @@ static bool autotrack_is_track_trackable(const AutoTrackContext *context,
clip, context->start_scene_frame);
const MovieTrackingMarker *marker = BKE_tracking_marker_get(track, clip_frame_number);
return autotrack_is_marker_usable(marker);
return autotrack_is_marker_usable(*marker);
}
return false;
}
@ -430,7 +433,7 @@ static size_t autotrack_count_all_usable_markers(AutoTrackContext *context)
for (int track_index = 0; track_index < context->num_all_tracks; ++track_index) {
const MovieTrackingTrack *track = context->all_autotrack_tracks[track_index].track;
for (int marker_index = 0; marker_index < track->markersnr; ++marker_index) {
const MovieTrackingMarker *marker = &track->markers[marker_index];
const MovieTrackingMarker &marker = track->markers[marker_index];
if (!autotrack_is_marker_usable(marker)) {
continue;
}
@ -475,21 +478,21 @@ static void autotrack_context_init_autotrack(AutoTrackContext *context)
int num_filled_libmv_markers = 0;
for (int track_index = 0; track_index < context->num_all_tracks; ++track_index) {
const AutoTrackTrack *autotrack_track = &context->all_autotrack_tracks[track_index];
/*const*/ MovieTrackingTrack *track = autotrack_track->track;
for (int marker_index = 0; marker_index < track->markersnr; ++marker_index) {
/*const*/ MovieTrackingMarker *marker = &track->markers[marker_index];
/*const*/ MovieTrackingTrack &track = *autotrack_track->track;
for (int marker_index = 0; marker_index < track.markersnr; ++marker_index) {
/*const*/ MovieTrackingMarker &marker = track.markers[marker_index];
if (!autotrack_is_marker_usable(marker)) {
continue;
}
const AutoTrackClip *autotrack_clip = &context->autotrack_clips[autotrack_track->clip_index];
dna_marker_to_libmv_marker(track,
marker,
autotrack_track->clip_index,
track_index,
autotrack_clip->width,
autotrack_clip->height,
context->is_backwards,
&libmv_markers[num_filled_libmv_markers++]);
libmv_markers[num_filled_libmv_markers++] = dna_marker_to_libmv_marker(
track,
marker,
autotrack_track->clip_index,
track_index,
autotrack_clip->width,
autotrack_clip->height,
context->is_backwards);
}
}
@ -525,18 +528,17 @@ static void autotrack_context_init_markers(AutoTrackContext *context)
const int clip_frame_number = BKE_movieclip_remap_scene_to_clip_frame(
clip, context->start_scene_frame);
/*const*/ MovieTrackingTrack *track = context->all_autotrack_tracks[track_index].track;
const MovieTrackingMarker *marker = BKE_tracking_marker_get(track, clip_frame_number);
/*const*/ MovieTrackingTrack &track = *context->all_autotrack_tracks[track_index].track;
const MovieTrackingMarker &marker = *BKE_tracking_marker_get(&track, clip_frame_number);
AutoTrackMarker *autotrack_marker = &context->autotrack_markers[autotrack_marker_index++];
dna_marker_to_libmv_marker(track,
marker,
autotrack_track->clip_index,
track_index,
autotrack_clip->width,
autotrack_clip->height,
context->is_backwards,
&autotrack_marker->libmv_marker);
autotrack_marker->libmv_marker = dna_marker_to_libmv_marker(track,
marker,
autotrack_track->clip_index,
track_index,
autotrack_clip->width,
autotrack_clip->height,
context->is_backwards);
}
}
@ -633,35 +635,35 @@ static void autotrack_context_step_cb(void *__restrict userdata,
AutoTrackContext *context = static_cast<AutoTrackContext *>(userdata);
AutoTrackTLS *autotrack_tls = (AutoTrackTLS *)tls->userdata_chunk;
const AutoTrackMarker *autotrack_marker = &context->autotrack_markers[marker_index];
const libmv_Marker *libmv_current_marker = &autotrack_marker->libmv_marker;
const AutoTrackMarker &autotrack_marker = context->autotrack_markers[marker_index];
const libmv_Marker &libmv_current_marker = autotrack_marker.libmv_marker;
const int frame_delta = context->is_backwards ? -1 : 1;
const int clip_index = libmv_current_marker->clip;
const int track_index = libmv_current_marker->track;
const int clip_index = libmv_current_marker.clip;
const int track_index = libmv_current_marker.track;
const AutoTrackClip *autotrack_clip = &context->autotrack_clips[clip_index];
const AutoTrackTrack *autotrack_track = &context->all_autotrack_tracks[track_index];
const MovieTrackingTrack *track = autotrack_track->track;
const AutoTrackClip &autotrack_clip = context->autotrack_clips[clip_index];
const AutoTrackTrack &autotrack_track = context->all_autotrack_tracks[track_index];
const MovieTrackingTrack &track = *autotrack_track.track;
/* Check whether marker is going outside of allowed frame margin. */
if (!tracking_check_marker_margin(
libmv_current_marker, track->margin, autotrack_clip->width, autotrack_clip->height))
libmv_current_marker, track.margin, autotrack_clip.width, autotrack_clip.height))
{
return;
}
const int new_marker_frame = libmv_current_marker->frame + frame_delta;
const int new_marker_frame = libmv_current_marker.frame + frame_delta;
AutoTrackTrackingResult *autotrack_result = MEM_cnew<AutoTrackTrackingResult>(
"autotrack result");
autotrack_result->libmv_marker = *libmv_current_marker;
autotrack_result->libmv_marker = libmv_current_marker;
autotrack_result->libmv_marker.frame = new_marker_frame;
/* Update reference frame. */
libmv_Marker libmv_reference_marker;
if (track->pattern_match == TRACK_MATCH_KEYFRAME) {
autotrack_result->libmv_marker.reference_frame = libmv_current_marker->reference_frame;
if (track.pattern_match == TRACK_MATCH_KEYFRAME) {
autotrack_result->libmv_marker.reference_frame = libmv_current_marker.reference_frame;
libmv_autoTrackGetMarker(context->autotrack,
clip_index,
autotrack_result->libmv_marker.reference_frame,
@ -669,14 +671,14 @@ static void autotrack_context_step_cb(void *__restrict userdata,
&libmv_reference_marker);
}
else {
BLI_assert(track->pattern_match == TRACK_MATCH_PREVIOUS_FRAME);
autotrack_result->libmv_marker.reference_frame = libmv_current_marker->frame;
libmv_reference_marker = *libmv_current_marker;
BLI_assert(track.pattern_match == TRACK_MATCH_PREVIOUS_FRAME);
autotrack_result->libmv_marker.reference_frame = libmv_current_marker.frame;
libmv_reference_marker = libmv_current_marker;
}
/* Perform actual tracking. */
autotrack_result->success = libmv_autoTrackMarker(context->autotrack,
&autotrack_track->track_region_options,
&autotrack_track.track_region_options,
&autotrack_result->libmv_marker,
&autotrack_result->libmv_result);
@ -684,7 +686,7 @@ static void autotrack_context_step_cb(void *__restrict userdata,
* This is how Blender side is currently expecting failed track to be handled. Without this the
* marker is left in an arbitrary position which did not provide good correlation. */
if (!autotrack_result->success) {
autotrack_result->libmv_marker = *libmv_current_marker;
autotrack_result->libmv_marker = libmv_current_marker;
autotrack_result->libmv_marker.frame = new_marker_frame;
}
@ -768,22 +770,21 @@ void BKE_autotrack_context_sync(AutoTrackContext *context)
BLI_spin_unlock(&context->spin_lock);
LISTBASE_FOREACH_MUTABLE (AutoTrackTrackingResult *, autotrack_result, &results_to_sync) {
const libmv_Marker *libmv_marker = &autotrack_result->libmv_marker;
const int clip_index = libmv_marker->clip;
const int track_index = libmv_marker->track;
const AutoTrackClip *autotrack_clip = &context->autotrack_clips[clip_index];
const MovieClip *clip = autotrack_clip->clip;
const AutoTrackTrack *autotrack_track = &context->all_autotrack_tracks[track_index];
MovieTrackingTrack *track = autotrack_track->track;
const libmv_Marker &libmv_marker = autotrack_result->libmv_marker;
const int clip_index = libmv_marker.clip;
const int track_index = libmv_marker.track;
const AutoTrackClip &autotrack_clip = context->autotrack_clips[clip_index];
const MovieClip *clip = autotrack_clip.clip;
const AutoTrackTrack &autotrack_track = context->all_autotrack_tracks[track_index];
MovieTrackingTrack *track = autotrack_track.track;
const int start_clip_frame = BKE_movieclip_remap_scene_to_clip_frame(
clip, context->start_scene_frame);
const int first_result_frame = start_clip_frame + frame_delta;
/* Insert marker which corresponds to the tracking result. */
MovieTrackingMarker marker;
libmv_marker_to_dna_marker(
&autotrack_result->libmv_marker, autotrack_clip->width, autotrack_clip->height, &marker);
MovieTrackingMarker marker = libmv_marker_to_dna_marker(
autotrack_result->libmv_marker, autotrack_clip.width, autotrack_clip.height);
if (!autotrack_result->success) {
marker.flag |= MARKER_DISABLED;
}

View File

@ -186,7 +186,7 @@ bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
*/
bool BLI_dir_create_recursive(const char *dir) ATTR_NONNULL();
/**
* Returns the number of free bytes on the volume containing the specified pathname.
* Returns the number of free bytes on the volume containing the specified path.
*
* \note Not actually used anywhere.
*/

View File

@ -74,12 +74,6 @@ template<typename T> struct AngleRadianBase {
/** Methods. */
/* 'mod_inline(-3, 4)= 1', 'fmod(-3, 4)= -3' */
static float mod_inline(float a, float b)
{
return a - (b * floorf(a / b));
}
/**
* Return the angle wrapped inside [-pi..pi] interval. Basically `(angle + pi) % 2pi - pi`.
*/

View File

@ -680,7 +680,7 @@ template<typename T> QuaternionBase<T> QuaternionBase<T>::expmap(const VecBase<T
T angle;
const VecBase<T, 3> axis = normalize_and_get_length(expmap, angle);
if (LIKELY(angle != T(0))) {
return to_quaternion(AxisAngleT(axis, angle_wrap_rad(angle)));
return to_quaternion(AxisAngleT(axis, AngleRadianBase<T>(angle).wrapped()));
}
return QuaternionBase<T>::identity();
}

View File

@ -162,6 +162,11 @@ template<typename T> struct QuaternionBase {
return (a.w == b.w) && (a.x == b.x) && (a.y == b.y) && (a.z == b.z);
}
uint64_t hash() const
{
return VecBase<T, 4>(*this).hash();
}
friend std::ostream &operator<<(std::ostream &stream, const QuaternionBase &rot)
{
return stream << "Quaternion" << static_cast<VecBase<T, 4>>(rot);

View File

@ -34,7 +34,7 @@ extern "C" {
#define BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE 5
/**
* Duplicates the first \a len bytes of cstring \a str
* Duplicates the first \a len bytes of the C-string \a str
* into a newly mallocN'd string and returns it. \a str
* is assumed to be at least len bytes long.
*
@ -45,7 +45,7 @@ extern "C" {
char *BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
/**
* Duplicates the cstring \a str into a newly mallocN'd
* Duplicates the C-string \a str into a newly mallocN'd
* string and returns it.
*
* \param str: The string to be duplicated

View File

@ -72,7 +72,7 @@ set(SRC
intern/bmesh_edgeloop.c
intern/bmesh_edgeloop.h
intern/bmesh_inline.h
intern/bmesh_interp.c
intern/bmesh_interp.cc
intern/bmesh_interp.h
intern/bmesh_iterators.cc
intern/bmesh_iterators.h

View File

@ -35,7 +35,7 @@ typedef struct BMEdgeLoopStore {
#define EDGELOOP_EPS 1e-10f
/* -------------------------------------------------------------------- */
/* BM_mesh_edgeloops_find & Util Functions. */
/* BM_mesh_edgeloops_find & Utility Functions. */
static int bm_vert_other_tag(BMVert *v, BMVert *v_prev, BMEdge **r_e)
{

View File

@ -63,7 +63,7 @@ static void bm_data_interp_from_elem(CustomData *data_layer,
src[1] = ele_src_2->head.data;
w[0] = 1.0f - fac;
w[1] = fac;
CustomData_bmesh_interp(data_layer, src, w, NULL, 2, ele_dst->head.data);
CustomData_bmesh_interp(data_layer, src, w, nullptr, 2, ele_dst->head.data);
}
}
}
@ -88,21 +88,21 @@ void BM_data_interp_from_edges(
* Sets all the customdata (e.g. vert, loop) associated with a vert
* to the average of the face regions surrounding it.
*/
static void UNUSED_FUNCTION(BM_Data_Vert_Average)(BMesh *UNUSED(bm), BMFace *UNUSED(f))
static void UNUSED_FUNCTION(BM_Data_Vert_Average)(BMesh * /*bm*/, BMFace * /*f*/)
{
// BMIter iter;
}
void BM_data_interp_face_vert_edge(BMesh *bm,
const BMVert *v_src_1,
const BMVert *UNUSED(v_src_2),
const BMVert * /*v_src_2*/,
BMVert *v,
BMEdge *e,
const float fac)
{
float w[2];
BMLoop *l_v1 = NULL, *l_v = NULL, *l_v2 = NULL;
BMLoop *l_iter = NULL;
BMLoop *l_v1 = nullptr, *l_v = nullptr, *l_v2 = nullptr;
BMLoop *l_iter = nullptr;
if (!e->l) {
return;
@ -132,7 +132,7 @@ void BM_data_interp_face_vert_edge(BMesh *bm,
src[0] = l_v1->head.data;
src[1] = l_v2->head.data;
CustomData_bmesh_interp(&bm->ldata, src, w, NULL, 2, l_v->head.data);
CustomData_bmesh_interp(&bm->ldata, src, w, nullptr, 2, l_v->head.data);
} while ((l_iter = l_iter->radial_next) != e->l);
}
@ -148,7 +148,7 @@ void BM_face_interp_from_face_ex(BMesh *bm,
BMLoop *l_iter;
BMLoop *l_first;
float *w = BLI_array_alloca(w, f_src->len);
float *w = static_cast<float *>(BLI_array_alloca(w, f_src->len));
float co[2];
if (f_src != f_dst) {
@ -160,9 +160,9 @@ void BM_face_interp_from_face_ex(BMesh *bm,
do {
mul_v2_m3v3(co, axis_mat, l_iter->v->co);
interp_weights_poly_v2(w, cos_2d, f_src->len, co);
CustomData_bmesh_interp(&bm->ldata, blocks_l, w, NULL, f_src->len, l_iter->head.data);
CustomData_bmesh_interp(&bm->ldata, blocks_l, w, nullptr, f_src->len, l_iter->head.data);
if (do_vertex) {
CustomData_bmesh_interp(&bm->vdata, blocks_v, w, NULL, f_src->len, l_iter->v->head.data);
CustomData_bmesh_interp(&bm->vdata, blocks_v, w, nullptr, f_src->len, l_iter->v->head.data);
}
} while ((l_iter = l_iter->next) != l_first);
}
@ -172,9 +172,11 @@ void BM_face_interp_from_face(BMesh *bm, BMFace *f_dst, const BMFace *f_src, con
BMLoop *l_iter;
BMLoop *l_first;
const void **blocks_l = BLI_array_alloca(blocks_l, f_src->len);
const void **blocks_v = do_vertex ? BLI_array_alloca(blocks_v, f_src->len) : NULL;
float(*cos_2d)[2] = BLI_array_alloca(cos_2d, f_src->len);
const void **blocks_l = static_cast<const void **>(BLI_array_alloca(blocks_l, f_src->len));
const void **blocks_v = do_vertex ?
static_cast<const void **>(BLI_array_alloca(blocks_v, f_src->len)) :
nullptr;
float(*cos_2d)[2] = static_cast<float(*)[2]>(BLI_array_alloca(cos_2d, f_src->len));
float axis_mat[3][3]; /* use normal to transform into 2d xy coords */
int i;
@ -287,7 +289,7 @@ static bool quad_co(const float v1[3],
static void mdisp_axis_from_quad(const float v1[3],
const float v2[3],
float UNUSED(v3[3]),
float[3] /*v3[3]*/,
const float v4[3],
float r_axis_x[3],
float r_axis_y[3])
@ -421,9 +423,9 @@ typedef struct BMLoopInterpMultiresData {
static void loop_interp_multires_cb(void *__restrict userdata,
const int ix,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
BMLoopInterpMultiresData *data = userdata;
BMLoopInterpMultiresData *data = static_cast<BMLoopInterpMultiresData *>(userdata);
BMLoop *l_first = data->l_src_first;
BMLoop *l_dst = data->l_dst;
@ -458,7 +460,7 @@ static void loop_interp_multires_cb(void *__restrict userdata,
float src_axis_x[3], src_axis_y[3];
float uv[2];
md_src = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_mdisp_offset);
md_src = static_cast<MDisps *>(BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_mdisp_offset));
if (mdisp_in_mdispquad(l_dst, l_iter, f_src_center, co, res, src_axis_x, src_axis_y, uv)) {
old_mdisps_bilinear(md_dst->disps[iy * res + ix], md_src->disps, res, uv[0], uv[1]);
@ -470,7 +472,7 @@ static void loop_interp_multires_cb(void *__restrict userdata,
}
}
void BM_loop_interp_multires_ex(BMesh *UNUSED(bm),
void BM_loop_interp_multires_ex(BMesh * /*bm*/,
BMLoop *l_dst,
const BMFace *f_src,
const float f_dst_center[3],
@ -486,17 +488,19 @@ void BM_loop_interp_multires_ex(BMesh *UNUSED(bm),
return;
}
md_dst = BM_ELEM_CD_GET_VOID_P(l_dst, cd_loop_mdisp_offset);
md_dst = static_cast<MDisps *>(BM_ELEM_CD_GET_VOID_P(l_dst, cd_loop_mdisp_offset));
compute_mdisp_quad(l_dst, f_dst_center, v1, v2, v3, v4, e1, e2);
/* if no disps data allocate a new grid, the size of the first grid in f_src. */
if (!md_dst->totdisp) {
const MDisps *md_src = BM_ELEM_CD_GET_VOID_P(BM_FACE_FIRST_LOOP(f_src), cd_loop_mdisp_offset);
const MDisps *md_src = static_cast<const MDisps *>(
BM_ELEM_CD_GET_VOID_P(BM_FACE_FIRST_LOOP(f_src), cd_loop_mdisp_offset));
md_dst->totdisp = md_src->totdisp;
md_dst->level = md_src->level;
if (md_dst->totdisp) {
md_dst->disps = MEM_callocN(sizeof(float[3]) * md_dst->totdisp, __func__);
md_dst->disps = static_cast<float(*)[3]>(
MEM_callocN(sizeof(float[3]) * md_dst->totdisp, __func__));
}
else {
return;
@ -506,21 +510,21 @@ void BM_loop_interp_multires_ex(BMesh *UNUSED(bm),
mdisp_axis_from_quad(v1, v2, v3, v4, axis_x, axis_y);
const int res = (int)sqrt(md_dst->totdisp);
BMLoopInterpMultiresData data = {
.l_dst = l_dst,
.l_src_first = BM_FACE_FIRST_LOOP(f_src),
.cd_loop_mdisp_offset = cd_loop_mdisp_offset,
.md_dst = md_dst,
.f_src_center = f_src_center,
.axis_x = axis_x,
.axis_y = axis_y,
.v1 = v1,
.v4 = v4,
.e1 = e1,
.e2 = e2,
.res = res,
.d = 1.0f / (float)(res - 1),
};
BMLoopInterpMultiresData data = {};
data.l_dst = l_dst;
data.l_src_first = BM_FACE_FIRST_LOOP(f_src);
data.cd_loop_mdisp_offset = cd_loop_mdisp_offset;
data.md_dst = md_dst;
data.f_src_center = f_src_center;
data.axis_x = axis_x;
data.axis_y = axis_y;
data.v1 = v1;
data.v4 = v4;
data.e1 = e1;
data.e2 = e2;
data.res = res;
data.d = 1.0f / (float)(res - 1);
TaskParallelSettings settings;
BLI_parallel_range_settings_defaults(&settings);
settings.use_threading = (res > 5);
@ -583,9 +587,9 @@ void BM_face_multires_bounds_smooth(BMesh *bm, BMFace *f)
}
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
MDisps *mdp = BM_ELEM_CD_GET_VOID_P(l->prev, cd_loop_mdisp_offset);
MDisps *mdl = BM_ELEM_CD_GET_VOID_P(l, cd_loop_mdisp_offset);
MDisps *mdn = BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_mdisp_offset);
MDisps *mdp = static_cast<MDisps *>(BM_ELEM_CD_GET_VOID_P(l->prev, cd_loop_mdisp_offset));
MDisps *mdl = static_cast<MDisps *>(BM_ELEM_CD_GET_VOID_P(l, cd_loop_mdisp_offset));
MDisps *mdn = static_cast<MDisps *>(BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_mdisp_offset));
float co1[3];
int sides;
int y;
@ -615,7 +619,7 @@ void BM_face_multires_bounds_smooth(BMesh *bm, BMFace *f)
}
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
MDisps *mdl1 = BM_ELEM_CD_GET_VOID_P(l, cd_loop_mdisp_offset);
MDisps *mdl1 = static_cast<MDisps *>(BM_ELEM_CD_GET_VOID_P(l, cd_loop_mdisp_offset));
MDisps *mdl2;
float co1[3], co2[3], co[3];
int sides;
@ -641,10 +645,11 @@ void BM_face_multires_bounds_smooth(BMesh *bm, BMFace *f)
}
if (l->radial_next->v == l->v) {
mdl2 = BM_ELEM_CD_GET_VOID_P(l->radial_next, cd_loop_mdisp_offset);
mdl2 = static_cast<MDisps *>(BM_ELEM_CD_GET_VOID_P(l->radial_next, cd_loop_mdisp_offset));
}
else {
mdl2 = BM_ELEM_CD_GET_VOID_P(l->radial_next->next, cd_loop_mdisp_offset);
mdl2 = static_cast<MDisps *>(
BM_ELEM_CD_GET_VOID_P(l->radial_next->next, cd_loop_mdisp_offset));
}
sides = (int)sqrt(mdl1->totdisp);
@ -685,10 +690,12 @@ void BM_loop_interp_from_face(
{
BMLoop *l_iter;
BMLoop *l_first;
const void **vblocks = do_vertex ? BLI_array_alloca(vblocks, f_src->len) : NULL;
const void **blocks = BLI_array_alloca(blocks, f_src->len);
float(*cos_2d)[2] = BLI_array_alloca(cos_2d, f_src->len);
float *w = BLI_array_alloca(w, f_src->len);
const void **vblocks = do_vertex ?
static_cast<const void **>(BLI_array_alloca(vblocks, f_src->len)) :
nullptr;
const void **blocks = static_cast<const void **>(BLI_array_alloca(blocks, f_src->len));
float(*cos_2d)[2] = static_cast<float(*)[2]>(BLI_array_alloca(cos_2d, f_src->len));
float *w = static_cast<float *>(BLI_array_alloca(w, f_src->len));
float axis_mat[3][3]; /* use normal to transform into 2d xy coords */
float co[2];
@ -723,9 +730,9 @@ void BM_loop_interp_from_face(
/* interpolate */
interp_weights_poly_v2(w, cos_2d, f_src->len, co);
CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, f_src->len, l_dst->head.data);
CustomData_bmesh_interp(&bm->ldata, blocks, w, nullptr, f_src->len, l_dst->head.data);
if (do_vertex) {
CustomData_bmesh_interp(&bm->vdata, vblocks, w, NULL, f_src->len, l_dst->v->head.data);
CustomData_bmesh_interp(&bm->vdata, vblocks, w, nullptr, f_src->len, l_dst->v->head.data);
}
if (do_multires) {
@ -737,9 +744,9 @@ void BM_vert_interp_from_face(BMesh *bm, BMVert *v_dst, const BMFace *f_src)
{
BMLoop *l_iter;
BMLoop *l_first;
const void **blocks = BLI_array_alloca(blocks, f_src->len);
float(*cos_2d)[2] = BLI_array_alloca(cos_2d, f_src->len);
float *w = BLI_array_alloca(w, f_src->len);
const void **blocks = static_cast<const void **>(BLI_array_alloca(blocks, f_src->len));
float(*cos_2d)[2] = static_cast<float(*)[2]>(BLI_array_alloca(cos_2d, f_src->len));
float *w = static_cast<float *>(BLI_array_alloca(w, f_src->len));
float axis_mat[3][3]; /* use normal to transform into 2d xy coords */
float co[2];
@ -758,7 +765,7 @@ void BM_vert_interp_from_face(BMesh *bm, BMVert *v_dst, const BMFace *f_src)
/* interpolate */
interp_weights_poly_v2(w, cos_2d, f_src->len, co);
CustomData_bmesh_interp(&bm->vdata, blocks, w, NULL, f_src->len, v_dst->head.data);
CustomData_bmesh_interp(&bm->vdata, blocks, w, nullptr, f_src->len, v_dst->head.data);
}
static void update_data_blocks(BMesh *bm, CustomData *olddata, CustomData *data)
@ -773,7 +780,7 @@ static void update_data_blocks(BMesh *bm, CustomData *olddata, CustomData *data)
CustomData_bmesh_init_pool(data, bm->totvert, BM_VERT);
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
block = NULL;
block = nullptr;
CustomData_bmesh_set_default(data, &block);
CustomData_bmesh_copy_data(olddata, data, eve->head.data, &block);
CustomData_bmesh_free_block(olddata, &eve->head.data);
@ -786,7 +793,7 @@ static void update_data_blocks(BMesh *bm, CustomData *olddata, CustomData *data)
CustomData_bmesh_init_pool(data, bm->totedge, BM_EDGE);
BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
block = NULL;
block = nullptr;
CustomData_bmesh_set_default(data, &block);
CustomData_bmesh_copy_data(olddata, data, eed->head.data, &block);
CustomData_bmesh_free_block(olddata, &eed->head.data);
@ -801,7 +808,7 @@ static void update_data_blocks(BMesh *bm, CustomData *olddata, CustomData *data)
CustomData_bmesh_init_pool(data, bm->totloop, BM_LOOP);
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
block = NULL;
block = nullptr;
CustomData_bmesh_set_default(data, &block);
CustomData_bmesh_copy_data(olddata, data, l->head.data, &block);
CustomData_bmesh_free_block(olddata, &l->head.data);
@ -815,7 +822,7 @@ static void update_data_blocks(BMesh *bm, CustomData *olddata, CustomData *data)
CustomData_bmesh_init_pool(data, bm->totface, BM_FACE);
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
block = NULL;
block = nullptr;
CustomData_bmesh_set_default(data, &block);
CustomData_bmesh_copy_data(olddata, data, efa->head.data, &block);
CustomData_bmesh_free_block(olddata, &efa->head.data);
@ -838,11 +845,13 @@ static void update_data_blocks(BMesh *bm, CustomData *olddata, CustomData *data)
void BM_data_layer_add(BMesh *bm, CustomData *data, int type)
{
CustomData olddata = *data;
olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL;
olddata.layers = (olddata.layers) ?
static_cast<CustomDataLayer *>(MEM_dupallocN(olddata.layers)) :
nullptr;
/* The pool is now owned by `olddata` and must not be shared. */
data->pool = NULL;
data->pool = nullptr;
CustomData_add_layer(data, type, CD_SET_DEFAULT, 0);
CustomData_add_layer(data, eCustomDataType(type), CD_SET_DEFAULT, 0);
update_data_blocks(bm, &olddata, data);
if (olddata.layers) {
@ -853,11 +862,13 @@ void BM_data_layer_add(BMesh *bm, CustomData *data, int type)
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const char *name)
{
CustomData olddata = *data;
olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL;
olddata.layers = (olddata.layers) ?
static_cast<CustomDataLayer *>(MEM_dupallocN(olddata.layers)) :
nullptr;
/* The pool is now owned by `olddata` and must not be shared. */
data->pool = NULL;
data->pool = nullptr;
CustomData_add_layer_named(data, type, CD_SET_DEFAULT, 0, name);
CustomData_add_layer_named(data, eCustomDataType(type), CD_SET_DEFAULT, 0, name);
update_data_blocks(bm, &olddata, data);
if (olddata.layers) {
@ -867,7 +878,7 @@ void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const char *
void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const char *name)
{
if (CustomData_get_named_layer_index(data, type, name) == -1) {
if (CustomData_get_named_layer_index(data, eCustomDataType(type), name) == -1) {
BM_data_layer_add_named(bm, data, type, name);
}
}
@ -923,11 +934,13 @@ void BM_uv_map_ensure_pin_attr(BMesh *bm, const char *uv_map_name)
void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
{
CustomData olddata = *data;
olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL;
olddata.layers = (olddata.layers) ?
static_cast<CustomDataLayer *>(MEM_dupallocN(olddata.layers)) :
nullptr;
/* The pool is now owned by `olddata` and must not be shared. */
data->pool = NULL;
data->pool = nullptr;
const bool had_layer = CustomData_free_layer_active(data, type, 0);
const bool had_layer = CustomData_free_layer_active(data, eCustomDataType(type), 0);
/* Assert because its expensive to realloc - better not do if layer isn't present. */
BLI_assert(had_layer != false);
UNUSED_VARS_NDEBUG(had_layer);
@ -941,9 +954,11 @@ void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
bool BM_data_layer_free_named(BMesh *bm, CustomData *data, const char *name)
{
CustomData olddata = *data;
olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL;
olddata.layers = (olddata.layers) ?
static_cast<CustomDataLayer *>(MEM_dupallocN(olddata.layers)) :
nullptr;
/* The pool is now owned by `olddata` and must not be shared. */
data->pool = NULL;
data->pool = nullptr;
const bool had_layer = CustomData_free_layer_named(data, name, 0);
@ -965,12 +980,17 @@ bool BM_data_layer_free_named(BMesh *bm, CustomData *data, const char *name)
void BM_data_layer_free_n(BMesh *bm, CustomData *data, int type, int n)
{
CustomData olddata = *data;
olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL;
olddata.layers = (olddata.layers) ?
static_cast<CustomDataLayer *>(MEM_dupallocN(olddata.layers)) :
nullptr;
/* The pool is now owned by `olddata` and must not be shared. */
data->pool = NULL;
data->pool = nullptr;
const bool had_layer = CustomData_free_layer(
data, type, 0, CustomData_get_layer_index_n(data, type, n));
data,
eCustomDataType(type),
0,
CustomData_get_layer_index_n(data, eCustomDataType(type), n));
/* Assert because its expensive to realloc - better not do if layer isn't present. */
BLI_assert(had_layer != false);
UNUSED_VARS_NDEBUG(had_layer);
@ -989,24 +1009,24 @@ void BM_data_layer_copy(BMesh *bm, CustomData *data, int type, int src_n, int ds
BMVert *eve;
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
void *ptr = CustomData_bmesh_get_n(data, eve->head.data, type, src_n);
CustomData_bmesh_set_n(data, eve->head.data, type, dst_n, ptr);
void *ptr = CustomData_bmesh_get_n(data, eve->head.data, eCustomDataType(type), src_n);
CustomData_bmesh_set_n(data, eve->head.data, eCustomDataType(type), dst_n, ptr);
}
}
else if (&bm->edata == data) {
BMEdge *eed;
BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
void *ptr = CustomData_bmesh_get_n(data, eed->head.data, type, src_n);
CustomData_bmesh_set_n(data, eed->head.data, type, dst_n, ptr);
void *ptr = CustomData_bmesh_get_n(data, eed->head.data, eCustomDataType(type), src_n);
CustomData_bmesh_set_n(data, eed->head.data, eCustomDataType(type), dst_n, ptr);
}
}
else if (&bm->pdata == data) {
BMFace *efa;
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
void *ptr = CustomData_bmesh_get_n(data, efa->head.data, type, src_n);
CustomData_bmesh_set_n(data, efa->head.data, type, dst_n, ptr);
void *ptr = CustomData_bmesh_get_n(data, efa->head.data, eCustomDataType(type), src_n);
CustomData_bmesh_set_n(data, efa->head.data, eCustomDataType(type), dst_n, ptr);
}
}
else if (&bm->ldata == data) {
@ -1016,8 +1036,8 @@ void BM_data_layer_copy(BMesh *bm, CustomData *data, int type, int src_n, int ds
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
void *ptr = CustomData_bmesh_get_n(data, l->head.data, type, src_n);
CustomData_bmesh_set_n(data, l->head.data, type, dst_n, ptr);
void *ptr = CustomData_bmesh_get_n(data, l->head.data, eCustomDataType(type), src_n);
CustomData_bmesh_set_n(data, l->head.data, eCustomDataType(type), dst_n, ptr);
}
}
}
@ -1029,13 +1049,15 @@ void BM_data_layer_copy(BMesh *bm, CustomData *data, int type, int src_n, int ds
float BM_elem_float_data_get(CustomData *cd, void *element, int type)
{
const float *f = CustomData_bmesh_get(cd, ((BMHeader *)element)->data, type);
const float *f = static_cast<const float *>(
CustomData_bmesh_get(cd, ((BMHeader *)element)->data, eCustomDataType(type)));
return f ? *f : 0.0f;
}
void BM_elem_float_data_set(CustomData *cd, void *element, int type, const float val)
{
float *f = CustomData_bmesh_get(cd, ((BMHeader *)element)->data, type);
float *f = static_cast<float *>(
CustomData_bmesh_get(cd, ((BMHeader *)element)->data, eCustomDataType(type)));
if (f) {
*f = val;
}
@ -1117,8 +1139,9 @@ static void bm_loop_walk_data(struct LoopWalkCtx *lwc, BMLoop *l_walk)
{
int i;
BLI_assert(CustomData_data_equals(
lwc->type, lwc->data_ref, BM_ELEM_CD_GET_VOID_P(l_walk, lwc->cd_layer_offset)));
BLI_assert(CustomData_data_equals(eCustomDataType(lwc->type),
lwc->data_ref,
BM_ELEM_CD_GET_VOID_P(l_walk, lwc->cd_layer_offset)));
BLI_assert(BM_elem_flag_test(l_walk, BM_ELEM_INTERNAL_TAG));
bm_loop_walk_add(lwc, l_walk);
@ -1132,8 +1155,9 @@ static void bm_loop_walk_data(struct LoopWalkCtx *lwc, BMLoop *l_walk)
}
BLI_assert(l_other->v == l_walk->v);
if (BM_elem_flag_test(l_other, BM_ELEM_INTERNAL_TAG)) {
if (CustomData_data_equals(
lwc->type, lwc->data_ref, BM_ELEM_CD_GET_VOID_P(l_other, lwc->cd_layer_offset)))
if (CustomData_data_equals(eCustomDataType(lwc->type),
lwc->data_ref,
BM_ELEM_CD_GET_VOID_P(l_other, lwc->cd_layer_offset)))
{
bm_loop_walk_data(lwc, l_other);
}
@ -1146,7 +1170,7 @@ LinkNode *BM_vert_loop_groups_data_layer_create(
BMesh *bm, BMVert *v, const int layer_n, const float *loop_weights, MemArena *arena)
{
struct LoopWalkCtx lwc;
LinkNode *groups = NULL;
LinkNode *groups = nullptr;
BMLoop *l;
BMIter liter;
int loop_num;
@ -1166,13 +1190,14 @@ LinkNode *BM_vert_loop_groups_data_layer_create(
bm->elem_index_dirty |= BM_LOOP;
lwc.data_len = 0;
lwc.data_array = BLI_memarena_alloc(lwc.arena, sizeof(void *) * loop_num);
lwc.data_index_array = BLI_memarena_alloc(lwc.arena, sizeof(int) * loop_num);
lwc.weight_array = BLI_memarena_alloc(lwc.arena, sizeof(float) * loop_num);
lwc.data_array = static_cast<void **>(BLI_memarena_alloc(lwc.arena, sizeof(void *) * loop_num));
lwc.data_index_array = static_cast<int *>(BLI_memarena_alloc(lwc.arena, sizeof(int) * loop_num));
lwc.weight_array = static_cast<float *>(BLI_memarena_alloc(lwc.arena, sizeof(float) * loop_num));
BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
if (BM_elem_flag_test(l, BM_ELEM_INTERNAL_TAG)) {
struct LoopGroupCD *lf = BLI_memarena_alloc(lwc.arena, sizeof(*lf));
struct LoopGroupCD *lf = static_cast<LoopGroupCD *>(
BLI_memarena_alloc(lwc.arena, sizeof(*lf)));
int len_prev = lwc.data_len;
lwc.data_ref = BM_ELEM_CD_GET_VOID_P(l, lwc.cd_layer_offset);
@ -1208,7 +1233,7 @@ static void bm_vert_loop_groups_data_layer_merge__single(BMesh *bm,
int layer_n,
void *data_tmp)
{
struct LoopGroupCD *lf = lf_p;
struct LoopGroupCD *lf = static_cast<LoopGroupCD *>(lf_p);
const int type = bm->ldata.layers[layer_n].type;
int i;
const float *data_weights;
@ -1216,23 +1241,23 @@ static void bm_vert_loop_groups_data_layer_merge__single(BMesh *bm,
data_weights = lf->data_weights;
CustomData_bmesh_interp_n(
&bm->ldata, (const void **)lf->data, data_weights, NULL, lf->data_len, data_tmp, layer_n);
&bm->ldata, (const void **)lf->data, data_weights, nullptr, lf->data_len, data_tmp, layer_n);
for (i = 0; i < lf->data_len; i++) {
CustomData_copy_elements(type, data_tmp, lf->data[i], 1);
CustomData_copy_elements(eCustomDataType(type), data_tmp, lf->data[i], 1);
}
}
static void bm_vert_loop_groups_data_layer_merge_weights__single(
BMesh *bm, void *lf_p, const int layer_n, void *data_tmp, const float *loop_weights)
{
struct LoopGroupCD *lf = lf_p;
struct LoopGroupCD *lf = static_cast<LoopGroupCD *>(lf_p);
const int type = bm->ldata.layers[layer_n].type;
int i;
const float *data_weights;
/* re-weight */
float *temp_weights = BLI_array_alloca(temp_weights, lf->data_len);
float *temp_weights = static_cast<float *>(BLI_array_alloca(temp_weights, lf->data_len));
float weight_accum = 0.0f;
for (i = 0; i < lf->data_len; i++) {
@ -1250,17 +1275,17 @@ static void bm_vert_loop_groups_data_layer_merge_weights__single(
}
CustomData_bmesh_interp_n(
&bm->ldata, (const void **)lf->data, data_weights, NULL, lf->data_len, data_tmp, layer_n);
&bm->ldata, (const void **)lf->data, data_weights, nullptr, lf->data_len, data_tmp, layer_n);
for (i = 0; i < lf->data_len; i++) {
CustomData_copy_elements(type, data_tmp, lf->data[i], 1);
CustomData_copy_elements(eCustomDataType(type), data_tmp, lf->data[i], 1);
}
}
void BM_vert_loop_groups_data_layer_merge(BMesh *bm, LinkNode *groups, const int layer_n)
{
const int type = bm->ldata.layers[layer_n].type;
const int size = CustomData_sizeof(type);
const int size = CustomData_sizeof(eCustomDataType(type));
void *data_tmp = alloca(size);
do {
@ -1274,7 +1299,7 @@ void BM_vert_loop_groups_data_layer_merge_weights(BMesh *bm,
const float *loop_weights)
{
const int type = bm->ldata.layers[layer_n].type;
const int size = CustomData_sizeof(type);
const int size = CustomData_sizeof(eCustomDataType(type));
void *data_tmp = alloca(size);
do {

View File

@ -109,7 +109,7 @@ typedef struct PathLinkState {
} PathLinkState;
/* -------------------------------------------------------------------- */
/** \name Min Dist Dir Util
/** \name Min Dist Dir Utilities
*
* Simply getting the closest intersecting vert/edge is _not_ good enough. see #43792
* we need to get the closest in both directions since the absolute closest may be a dead-end.

View File

@ -766,7 +766,7 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op)
vert_coords = BLI_ghash_ptr_new(__func__);
}
/* util macros */
/* Utility macros. */
#define VERT_ORIG_STORE(_v) \
{ \
float *_co = BLI_memarena_alloc(vert_coords_orig, sizeof(float[3])); \

View File

@ -322,6 +322,8 @@ if(WITH_COMPOSITOR_CPU)
nodes/COM_FilterNode.h
nodes/COM_InpaintNode.cc
nodes/COM_InpaintNode.h
nodes/COM_KuwaharaNode.h
nodes/COM_KuwaharaNode.cc
nodes/COM_PosterizeNode.cc
nodes/COM_PosterizeNode.h
@ -349,6 +351,10 @@ if(WITH_COMPOSITOR_CPU)
operations/COM_GaussianXBlurOperation.h
operations/COM_GaussianYBlurOperation.cc
operations/COM_GaussianYBlurOperation.h
operations/COM_KuwaharaClassicOperation.h
operations/COM_KuwaharaClassicOperation.cc
operations/COM_KuwaharaAnisotropicOperation.h
operations/COM_KuwaharaAnisotropicOperation.cc
operations/COM_MovieClipAttributeOperation.cc
operations/COM_MovieClipAttributeOperation.h
operations/COM_MovieDistortionOperation.cc

View File

@ -62,6 +62,7 @@
#include "COM_InvertNode.h"
#include "COM_KeyingNode.h"
#include "COM_KeyingScreenNode.h"
#include "COM_KuwaharaNode.h"
#include "COM_LensDistortionNode.h"
#include "COM_LuminanceMatteNode.h"
#include "COM_MapRangeNode.h"
@ -436,6 +437,9 @@ Node *COM_convert_bnode(bNode *b_node)
case CMP_NODE_COMBINE_XYZ:
node = new CombineXYZNode(b_node);
break;
case CMP_NODE_KUWAHARA:
node = new KuwaharaNode(b_node);
break;
}
return node;
}

View File

@ -0,0 +1,103 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "COM_KuwaharaNode.h"
#include "COM_FastGaussianBlurOperation.h"
#include "COM_KuwaharaAnisotropicOperation.h"
#include "COM_KuwaharaClassicOperation.h"
#include "COM_MathBaseOperation.h"
#include "COM_SetValueOperation.h"
namespace blender::compositor {
void KuwaharaNode::convert_to_operations(NodeConverter &converter,
const CompositorContext & /*context*/) const
{
const bNode *node = this->get_bnode();
const NodeKuwaharaData *data = (const NodeKuwaharaData *)node->storage;
switch (data->variation) {
case CMP_NODE_KUWAHARA_CLASSIC: {
KuwaharaClassicOperation *operation = new KuwaharaClassicOperation();
operation->set_kernel_size(data->size);
converter.add_operation(operation);
converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
converter.map_output_socket(get_output_socket(0), operation->get_output_socket());
break;
}
case CMP_NODE_KUWAHARA_ANISOTROPIC: {
/* Edge detection */
auto const_fact = new SetValueOperation();
const_fact->set_value(1.0f);
converter.add_operation(const_fact);
auto sobel_x = new ConvolutionFilterOperation();
sobel_x->set3x3Filter(1, 0, -1, 2, 0, -2, 1, 0, -1);
converter.add_operation(sobel_x);
converter.map_input_socket(get_input_socket(0), sobel_x->get_input_socket(0));
converter.add_link(const_fact->get_output_socket(0), sobel_x->get_input_socket(1));
auto sobel_y = new ConvolutionFilterOperation();
sobel_y->set3x3Filter(1, 2, 1, 0, 0, 0, -1, -2, -1);
converter.add_operation(sobel_y);
converter.map_input_socket(get_input_socket(0), sobel_y->get_input_socket(0));
converter.add_link(const_fact->get_output_socket(0), sobel_y->get_input_socket(1));
/* Compute intensity of edges */
auto sobel_xx = new MathMultiplyOperation();
auto sobel_yy = new MathMultiplyOperation();
auto sobel_xy = new MathMultiplyOperation();
converter.add_operation(sobel_xx);
converter.add_operation(sobel_yy);
converter.add_operation(sobel_xy);
converter.add_link(sobel_x->get_output_socket(0), sobel_xx->get_input_socket(0));
converter.add_link(sobel_x->get_output_socket(0), sobel_xx->get_input_socket(1));
converter.add_link(sobel_y->get_output_socket(0), sobel_yy->get_input_socket(0));
converter.add_link(sobel_y->get_output_socket(0), sobel_yy->get_input_socket(1));
converter.add_link(sobel_x->get_output_socket(0), sobel_xy->get_input_socket(0));
converter.add_link(sobel_y->get_output_socket(0), sobel_xy->get_input_socket(1));
/* Blurring for more robustness. */
const int sigma = data->smoothing;
auto blur_sobel_xx = new FastGaussianBlurOperation();
auto blur_sobel_yy = new FastGaussianBlurOperation();
auto blur_sobel_xy = new FastGaussianBlurOperation();
blur_sobel_yy->set_size(sigma, sigma);
blur_sobel_xx->set_size(sigma, sigma);
blur_sobel_xy->set_size(sigma, sigma);
converter.add_operation(blur_sobel_xx);
converter.add_operation(blur_sobel_yy);
converter.add_operation(blur_sobel_xy);
converter.add_link(sobel_xx->get_output_socket(0), blur_sobel_xx->get_input_socket(0));
converter.add_link(sobel_yy->get_output_socket(0), blur_sobel_yy->get_input_socket(0));
converter.add_link(sobel_xy->get_output_socket(0), blur_sobel_xy->get_input_socket(0));
/* Apply anisotropic Kuwahara filter. */
KuwaharaAnisotropicOperation *aniso = new KuwaharaAnisotropicOperation();
aniso->set_kernel_size(data->size + 4);
converter.map_input_socket(get_input_socket(0), aniso->get_input_socket(0));
converter.add_operation(aniso);
converter.add_link(blur_sobel_xx->get_output_socket(0), aniso->get_input_socket(1));
converter.add_link(blur_sobel_yy->get_output_socket(0), aniso->get_input_socket(2));
converter.add_link(blur_sobel_xy->get_output_socket(0), aniso->get_input_socket(3));
converter.map_output_socket(get_output_socket(0), aniso->get_output_socket(0));
break;
}
}
}
} // namespace blender::compositor

View File

@ -0,0 +1,23 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "COM_Node.h"
namespace blender::compositor {
/**
* \brief KuwaharaNode
* \ingroup Node
*/
class KuwaharaNode : public Node {
public:
KuwaharaNode(bNode *editor_node) : Node(editor_node) {}
void convert_to_operations(NodeConverter &converter,
const CompositorContext &context) const override;
};
} // namespace blender::compositor

View File

@ -11,6 +11,7 @@ namespace blender::compositor {
FastGaussianBlurOperation::FastGaussianBlurOperation() : BlurBaseOperation(DataType::Color)
{
iirgaus_ = nullptr;
data_.filtertype = R_FILTER_FAST_GAUSS;
}
void FastGaussianBlurOperation::execute_pixel(float output[4], int x, int y, void *data)
@ -68,6 +69,15 @@ void FastGaussianBlurOperation::deinit_execution()
BlurBaseOperation::deinit_mutex();
}
void FastGaussianBlurOperation::set_size(int size_x, int size_y)
{
/* TODO: there should be a better way to use the operation without knowing specifics of the blur
* node (i.e. data_). We could use factory pattern to solve this problem. */
data_.sizex = size_x;
data_.sizey = size_y;
sizeavailable_ = true;
}
void *FastGaussianBlurOperation::initialize_tile_data(rcti *rect)
{
lock_mutex();

View File

@ -28,6 +28,8 @@ class FastGaussianBlurOperation : public BlurBaseOperation {
void deinit_execution() override;
void init_execution() override;
void set_size(int size_x, int size_y);
void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
void update_memory_buffer_started(MemoryBuffer *output,
const rcti &area,

View File

@ -0,0 +1,295 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "COM_KuwaharaAnisotropicOperation.h"
#include "BLI_math_base.hh"
#include "BLI_vector.hh"
#include "IMB_colormanagement.h"
namespace blender::compositor {
KuwaharaAnisotropicOperation::KuwaharaAnisotropicOperation()
{
this->add_input_socket(DataType::Color);
this->add_input_socket(DataType::Color);
this->add_input_socket(DataType::Color);
this->add_input_socket(DataType::Color);
this->add_output_socket(DataType::Color);
this->n_div_ = 8;
this->set_kernel_size(5);
this->flags_.is_fullframe_operation = true;
}
void KuwaharaAnisotropicOperation::init_execution()
{
image_reader_ = this->get_input_socket_reader(0);
s_xx_reader_ = this->get_input_socket_reader(1);
s_yy_reader_ = this->get_input_socket_reader(2);
s_xy_reader_ = this->get_input_socket_reader(3);
}
void KuwaharaAnisotropicOperation::deinit_execution()
{
image_reader_ = nullptr;
}
void KuwaharaAnisotropicOperation::execute_pixel_sampled(float output[4],
float x,
float y,
PixelSampler sampler)
{
const int width = this->get_width();
const int height = this->get_height();
BLI_assert(width == s_xx_reader_->get_width());
BLI_assert(height == s_xx_reader_->get_height());
BLI_assert(width == s_yy_reader_->get_width());
BLI_assert(height == s_yy_reader_->get_height());
BLI_assert(width == s_xy_reader_->get_width());
BLI_assert(height == s_xy_reader_->get_height());
/* Values recommended by authors in original paper. */
const float angle = 2.0 * M_PI / n_div_;
const float q = 3.0;
const float EPS = 1.0e-10;
/* For now use green channel to compute orientation. */
/* TODO: convert to HSV and compute orientation and strength on luminance channel */
float tmp[4];
s_xx_reader_->read(tmp, x, y, nullptr);
const float a = tmp[1];
s_xy_reader_->read(tmp, x, y, nullptr);
const float b = tmp[1];
s_yy_reader_->read(tmp, x, y, nullptr);
const float c = tmp[1];
/* Compute egenvalues of structure tensor. */
const double tr = a + c;
const double discr = sqrt((a - b) * (a - b) + 4 * b * c);
const double lambda1 = (tr + discr) / 2;
const double lambda2 = (tr - discr) / 2;
/* Compute orientation and its strength based on structure tensor. */
const double orientation = 0.5 * atan2(2 * b, a - c);
const double strength = (lambda1 == 0 && lambda2 == 0) ?
0 :
(lambda1 - lambda2) / (lambda1 + lambda2);
Vector<double> mean(n_div_);
Vector<double> sum(n_div_);
Vector<double> var(n_div_);
Vector<double> weight(n_div_);
for (int ch = 0; ch < 3; ch++) {
mean.fill(0.0);
sum.fill(0.0);
var.fill(0.0);
weight.fill(0.0);
double sx = 1.0f / (strength + 1.0f);
double sy = (1.0f + strength) / 1.0f;
double theta = -orientation;
for (int dy = -kernel_size_; dy <= kernel_size_; dy++) {
for (int dx = -kernel_size_; dx <= kernel_size_; dx++) {
if (dx == 0 && dy == 0)
continue;
/* Rotate and scale the kernel. This is the "anisotropic" part. */
int dx2 = int(sx * (cos(theta) * dx - sin(theta) * dy));
int dy2 = int(sy * (sin(theta) * dx + cos(theta) * dy));
/* Clamp image to avoid artifacts at borders. */
const int xx = math::clamp(int(x) + dx2, 0, width - 1);
const int yy = math::clamp(int(y) + dy2, 0, height - 1);
const double ddx2 = double(dx2);
const double ddy2 = double(dy2);
const double theta = atan2(ddy2, ddx2) + M_PI;
const int t = int(floor(theta / angle)) % n_div_;
double d2 = dx2 * dx2 + dy2 * dy2;
double g = exp(-d2 / (2.0 * kernel_size_));
float color[4];
image_reader_->read(color, xx, yy, nullptr);
const double v = color[ch];
/* TODO(@zazizizou): only compute lum once per region */
const float lum = IMB_colormanagement_get_luminance(color);
/* TODO(@zazizizou): only compute mean for the selected region */
mean[t] += g * v;
sum[t] += g * lum;
var[t] += g * lum * lum;
weight[t] += g;
}
}
/* Calculate weighted average */
double de = 0.0;
double nu = 0.0;
for (int i = 0; i < n_div_; i++) {
double weight_inv = 1.0 / weight[i];
mean[i] = weight[i] != 0 ? mean[i] * weight_inv : 0.0;
sum[i] = weight[i] != 0 ? sum[i] * weight_inv : 0.0;
var[i] = weight[i] != 0 ? var[i] * weight_inv : 0.0;
var[i] = var[i] - sum[i] * sum[i];
var[i] = var[i] > FLT_EPSILON ? sqrt(var[i]) : FLT_EPSILON;
double w = powf(var[i], -q);
de += mean[i] * w;
nu += w;
}
double val = nu > EPS ? de / nu : 0.0;
output[ch] = val;
}
/* No changes for alpha channel. */
image_reader_->read_sampled(tmp, x, y, sampler);
output[3] = tmp[3];
}
void KuwaharaAnisotropicOperation::set_kernel_size(int kernel_size)
{
/* Filter will be split into n_div.
* Add n_div / 2 to avoid artifacts such as random black pixels in image. */
kernel_size_ = kernel_size + n_div_ / 2;
}
int KuwaharaAnisotropicOperation::get_kernel_size()
{
return kernel_size_;
}
int KuwaharaAnisotropicOperation::get_n_div()
{
return n_div_;
}
void KuwaharaAnisotropicOperation::update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> inputs)
{
/* Implementation based on Kyprianidis, Jan & Kang, Henry & Döllner, Jürgen. (2009).
* "Image and Video Abstraction by Anisotropic Kuwahara Filtering".
* Comput. Graph. Forum. 28. 1955-1963. 10.1111/j.1467-8659.2009.01574.x.
* Used reference implementation from lime image processing library (MIT license). */
MemoryBuffer *image = inputs[0];
MemoryBuffer *s_xx = inputs[1];
MemoryBuffer *s_yy = inputs[2];
MemoryBuffer *s_xy = inputs[3];
const int width = image->get_width();
const int height = image->get_height();
BLI_assert(width == s_xx->get_width());
BLI_assert(height == s_xx->get_height());
BLI_assert(width == s_yy->get_width());
BLI_assert(height == s_yy->get_height());
BLI_assert(width == s_xy->get_width());
BLI_assert(height == s_xy->get_height());
/* Values recommended by authors in original paper. */
const float angle = 2.0 * M_PI / n_div_;
const float q = 3.0;
const float EPS = 1.0e-10;
for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
const int x = it.x;
const int y = it.y;
/* For now use green channel to compute orientation. */
/* TODO: convert to HSV and compute orientation and strength on luminance channel. */
const float a = s_xx->get_value(x, y, 1);
const float b = s_xy->get_value(x, y, 1);
const float c = s_yy->get_value(x, y, 1);
/* Compute egenvalues of structure tensor */
const double tr = a + c;
const double discr = sqrt((a - b) * (a - b) + 4 * b * c);
const double lambda1 = (tr + discr) / 2;
const double lambda2 = (tr - discr) / 2;
/* Compute orientation and its strength based on structure tensor. */
const double orientation = 0.5 * atan2(2 * b, a - c);
const double strength = (lambda1 == 0 && lambda2 == 0) ?
0 :
(lambda1 - lambda2) / (lambda1 + lambda2);
Vector<double> mean(n_div_);
Vector<double> sum(n_div_);
Vector<double> var(n_div_);
Vector<double> weight(n_div_);
for (int ch = 0; ch < 3; ch++) {
mean.fill(0.0);
sum.fill(0.0);
var.fill(0.0);
weight.fill(0.0);
double sx = 1.0f / (strength + 1.0f);
double sy = (1.0f + strength) / 1.0f;
double theta = -orientation;
for (int dy = -kernel_size_; dy <= kernel_size_; dy++) {
for (int dx = -kernel_size_; dx <= kernel_size_; dx++) {
if (dx == 0 && dy == 0)
continue;
/* Rotate and scale the kernel. This is the "anisotropic" part. */
int dx2 = int(sx * (cos(theta) * dx - sin(theta) * dy));
int dy2 = int(sy * (sin(theta) * dx + cos(theta) * dy));
/* Clamp image to avoid artifacts at borders. */
const int xx = math::clamp(x + dx2, 0, width - 1);
const int yy = math::clamp(y + dy2, 0, height - 1);
const double ddx2 = double(dx2);
const double ddy2 = double(dy2);
const double theta = atan2(ddy2, ddx2) + M_PI;
const int t = int(floor(theta / angle)) % n_div_;
double d2 = dx2 * dx2 + dy2 * dy2;
double g = exp(-d2 / (2.0 * kernel_size_));
const double v = image->get_value(xx, yy, ch);
float color[4];
image->read_elem(xx, yy, color);
/* TODO(@zazizizou): only compute lum once per region. */
const float lum = IMB_colormanagement_get_luminance(color);
/* TODO(@zazizizou): only compute mean for the selected region. */
mean[t] += g * v;
sum[t] += g * lum;
var[t] += g * lum * lum;
weight[t] += g;
}
}
/* Calculate weighted average. */
double de = 0.0;
double nu = 0.0;
for (int i = 0; i < n_div_; i++) {
double weight_inv = 1.0 / weight[i];
mean[i] = weight[i] != 0 ? mean[i] * weight_inv : 0.0;
sum[i] = weight[i] != 0 ? sum[i] * weight_inv : 0.0;
var[i] = weight[i] != 0 ? var[i] * weight_inv : 0.0;
var[i] = var[i] - sum[i] * sum[i];
var[i] = var[i] > FLT_EPSILON ? sqrt(var[i]) : FLT_EPSILON;
double w = powf(var[i], -q);
de += mean[i] * w;
nu += w;
}
double val = nu > EPS ? de / nu : 0.0;
it.out[ch] = val;
}
/* No changes for alpha channel. */
it.out[3] = image->get_value(x, y, 3);
}
}
} // namespace blender::compositor

View File

@ -0,0 +1,36 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
class KuwaharaAnisotropicOperation : public MultiThreadedOperation {
SocketReader *image_reader_;
SocketReader *s_xx_reader_;
SocketReader *s_yy_reader_;
SocketReader *s_xy_reader_;
int kernel_size_;
int n_div_;
public:
KuwaharaAnisotropicOperation();
void init_execution() override;
void deinit_execution() override;
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override;
void set_kernel_size(int kernel_size);
int get_kernel_size();
int get_n_div();
void update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor

View File

@ -0,0 +1,199 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "COM_KuwaharaClassicOperation.h"
#include "IMB_colormanagement.h"
namespace blender::compositor {
KuwaharaClassicOperation::KuwaharaClassicOperation()
{
this->add_input_socket(DataType::Color);
this->add_output_socket(DataType::Color);
this->set_kernel_size(4);
this->flags_.is_fullframe_operation = true;
}
void KuwaharaClassicOperation::init_execution()
{
image_reader_ = this->get_input_socket_reader(0);
}
void KuwaharaClassicOperation::deinit_execution()
{
image_reader_ = nullptr;
}
void KuwaharaClassicOperation::execute_pixel_sampled(float output[4],
float x,
float y,
PixelSampler sampler)
{
for (int ch = 0; ch < 3; ch++) {
float sum[4] = {0.0f, 0.0f, 0.0f, 0.0f};
float mean[4] = {0.0f, 0.0f, 0.0f, 0.0f};
float var[4] = {0.0f, 0.0f, 0.0f, 0.0f};
int cnt[4] = {0, 0, 0, 0};
/* Split surroundings of pixel into 4 overlapping regions. */
for (int dy = -kernel_size_; dy <= kernel_size_; dy++) {
for (int dx = -kernel_size_; dx <= kernel_size_; dx++) {
int xx = x + dx;
int yy = y + dy;
if (xx >= 0 && yy >= 0 && xx < this->get_width() && yy < this->get_height()) {
float color[4];
image_reader_->read_sampled(color, xx, yy, sampler);
const float v = color[ch];
const float lum = IMB_colormanagement_get_luminance(color);
if (dx <= 0 && dy <= 0) {
mean[0] += v;
sum[0] += lum;
var[0] += lum * lum;
cnt[0]++;
}
if (dx >= 0 && dy <= 0) {
mean[1] += v;
sum[1] += lum;
var[1] += lum * lum;
cnt[1]++;
}
if (dx <= 0 && dy >= 0) {
mean[2] += v;
sum[2] += lum;
var[2] += lum * lum;
cnt[2]++;
}
if (dx >= 0 && dy >= 0) {
mean[3] += v;
sum[3] += lum;
var[3] += lum * lum;
cnt[3]++;
}
}
}
}
/* Compute region variances. */
for (int i = 0; i < 4; i++) {
mean[i] = cnt[i] != 0 ? mean[i] / cnt[i] : 0.0f;
sum[i] = cnt[i] != 0 ? sum[i] / cnt[i] : 0.0f;
var[i] = cnt[i] != 0 ? var[i] / cnt[i] : 0.0f;
const float temp = sum[i] * sum[i];
var[i] = var[i] > temp ? sqrt(var[i] - temp) : 0.0f;
}
/* Choose the region with lowest variance. */
float min_var = FLT_MAX;
int min_index = 0;
for (int i = 0; i < 4; i++) {
if (var[i] < min_var) {
min_var = var[i];
min_index = i;
}
}
output[ch] = mean[min_index];
}
}
void KuwaharaClassicOperation::set_kernel_size(int kernel_size)
{
kernel_size_ = kernel_size;
}
int KuwaharaClassicOperation::get_kernel_size()
{
return kernel_size_;
}
void KuwaharaClassicOperation::update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> inputs)
{
MemoryBuffer *image = inputs[0];
for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
const int x = it.x;
const int y = it.y;
it.out[3] = image->get_value(x, y, 3);
for (int ch = 0; ch < 3; ch++) {
float sum[4] = {0.0f, 0.0f, 0.0f, 0.0f};
float mean[4] = {0.0f, 0.0f, 0.0f, 0.0f};
float var[4] = {0.0f, 0.0f, 0.0f, 0.0f};
int cnt[4] = {0, 0, 0, 0};
/* Split surroundings of pixel into 4 overlapping regions. */
for (int dy = -kernel_size_; dy <= kernel_size_; dy++) {
for (int dx = -kernel_size_; dx <= kernel_size_; dx++) {
int xx = x + dx;
int yy = y + dy;
if (xx >= 0 && yy >= 0 && xx < image->get_width() && yy < image->get_height()) {
const float v = image->get_value(xx, yy, ch);
float color[4];
image->read_elem(xx, yy, color);
const float lum = IMB_colormanagement_get_luminance(color);
if (dx <= 0 && dy <= 0) {
mean[0] += v;
sum[0] += lum;
var[0] += lum * lum;
cnt[0]++;
}
if (dx >= 0 && dy <= 0) {
mean[1] += v;
sum[1] += lum;
var[1] += lum * lum;
cnt[1]++;
}
if (dx <= 0 && dy >= 0) {
mean[2] += v;
sum[2] += lum;
var[2] += lum * lum;
cnt[2]++;
}
if (dx >= 0 && dy >= 0) {
mean[3] += v;
sum[3] += lum;
var[3] += lum * lum;
cnt[3]++;
}
}
}
}
/* Compute region variances. */
for (int i = 0; i < 4; i++) {
mean[i] = cnt[i] != 0 ? mean[i] / cnt[i] : 0.0f;
sum[i] = cnt[i] != 0 ? sum[i] / cnt[i] : 0.0f;
var[i] = cnt[i] != 0 ? var[i] / cnt[i] : 0.0f;
const float temp = sum[i] * sum[i];
var[i] = var[i] > temp ? sqrt(var[i] - temp) : 0.0f;
}
/* Choose the region with lowest variance. */
float min_var = FLT_MAX;
int min_index = 0;
for (int i = 0; i < 4; i++) {
if (var[i] < min_var) {
min_var = var[i];
min_index = i;
}
}
output->get_value(x, y, ch) = mean[min_index];
}
}
}
} // namespace blender::compositor

View File

@ -0,0 +1,31 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "COM_MultiThreadedOperation.h"
namespace blender::compositor {
class KuwaharaClassicOperation : public MultiThreadedOperation {
SocketReader *image_reader_;
int kernel_size_;
public:
KuwaharaClassicOperation();
void init_execution() override;
void deinit_execution() override;
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override;
void set_kernel_size(int kernel_size);
int get_kernel_size();
void update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor

View File

@ -11,6 +11,11 @@ shared float zdists_cache[gl_WorkGroupSize.x];
void main()
{
/* Early exit if no lights are present to prevent out of bounds buffer read. */
if (light_cull_buf.visible_count == 0) {
return;
}
uint src_index = gl_GlobalInvocationID.x;
bool valid_thread = true;

View File

@ -40,7 +40,7 @@ void main()
tile.is_used = true;
}
/* Reset count for next level. */
usage_grid[tile_co.y][tile_co.x] = 0u;
usage_grid[tile_co.y / 2][tile_co.x / 2] = 0u;
}
barrier();

View File

@ -57,7 +57,8 @@ void main()
ivec2 tile_co = ivec2(gl_GlobalInvocationID.xy);
ivec2 tile_shifted = tile_co + tilemap.grid_shift;
ivec2 tile_wrapped = ivec2(tile_shifted % SHADOW_TILEMAP_RES);
/* Ensure value is shifted into positive range to avoid modulo on negative. */
ivec2 tile_wrapped = ivec2((ivec2(SHADOW_TILEMAP_RES) + tile_shifted) % SHADOW_TILEMAP_RES);
/* If this tile was shifted in and contains old information, update it.
* Note that cubemap always shift all tiles on update. */
@ -72,7 +73,7 @@ void main()
uint lod_size = uint(SHADOW_TILEMAP_RES);
for (int lod = 0; lod <= lod_max; lod++, lod_size >>= 1u) {
bool thread_active = all(lessThan(tile_co, ivec2(lod_size)));
ShadowTileDataPacked tile;
ShadowTileDataPacked tile = 0;
int tile_load = shadow_tile_offset(tile_wrapped, tilemap.tiles_index, lod);
if (thread_active) {
tile = init_tile_data(tiles_buf[tile_load], do_update);

View File

@ -175,9 +175,9 @@ struct ObjectInfos {
float4 infos;
#else
/** Uploaded as center + size. Converted to mul+bias to local coord. */
float3 orco_add;
packed_float3 orco_add;
uint object_attrs_offset;
float3 orco_mul;
packed_float3 orco_mul;
uint object_attrs_len;
float4 ob_color;

View File

@ -29,27 +29,27 @@ void main()
vec3 diagonal = p01 + p02 + p03;
vec3 center = p0 + diagonal * 0.5;
float min_axis = min_v3(abs(diagonal));
bounds_buf[resource_id].bounding_sphere.xyz = transform_point(model_mat, center);
bounds.bounding_sphere.xyz = transform_point(model_mat, center);
/* We have to apply scaling to the diagonal. */
bounds_buf[resource_id].bounding_sphere.w = length(transform_direction(model_mat, diagonal)) *
0.5;
bounds_buf[resource_id]._inner_sphere_radius = min_axis;
bounds_buf[resource_id].bounding_corners[0].xyz = transform_point(model_mat, p0);
bounds_buf[resource_id].bounding_corners[1].xyz = transform_direction(model_mat, p01);
bounds_buf[resource_id].bounding_corners[2].xyz = transform_direction(model_mat, p02);
bounds_buf[resource_id].bounding_corners[3].xyz = transform_direction(model_mat, p03);
bounds.bounding_sphere.w = length(transform_direction(model_mat, diagonal)) * 0.5;
bounds._inner_sphere_radius = min_axis;
bounds.bounding_corners[0].xyz = transform_point(model_mat, p0);
bounds.bounding_corners[1].xyz = transform_direction(model_mat, p01);
bounds.bounding_corners[2].xyz = transform_direction(model_mat, p02);
bounds.bounding_corners[3].xyz = transform_direction(model_mat, p03);
/* Always have correct handedness in the corners vectors. */
if (flag_test(infos.flag, OBJECT_NEGATIVE_SCALE)) {
bounds_buf[resource_id].bounding_corners[0].xyz +=
bounds_buf[resource_id].bounding_corners[1].xyz;
bounds_buf[resource_id].bounding_corners[1].xyz =
-bounds_buf[resource_id].bounding_corners[1].xyz;
bounds.bounding_corners[0].xyz += bounds.bounding_corners[1].xyz;
bounds.bounding_corners[1].xyz = -bounds.bounding_corners[1].xyz;
}
/* TODO: Bypass test for very large objects (see #67319). */
if (bounds_buf[resource_id].bounding_sphere.w > 1e12) {
bounds_buf[resource_id].bounding_sphere.w = -1.0;
if (bounds.bounding_sphere.w > 1e12) {
bounds.bounding_sphere.w = -1.0;
}
/* Update bounds. */
bounds_buf[resource_id] = bounds;
}
vec3 loc = infos.orco_add; /* Box center. */

View File

@ -566,13 +566,14 @@ bool ANIM_animdata_can_have_greasepencil(const eAnimCont_Types type)
((filter_mode & ANIMFILTER_SEL) && test_func) || \
((filter_mode & ANIMFILTER_UNSEL) && test_func == 0))
/* quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes
* - _SELEDIT means that only selected curves will have visible+editable keyframes
/**
* Quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes
* - `*_SELEDIT` means that only selected curves will have visible+editable key-frames.
*
* checks here work as follows:
* 1) seledit off - don't need to consider the implications of this option
* 2) foredit off - we're not considering editing, so channel is ok still
* 3) test_func (i.e. selection test) - only if selected, this test will pass
* 1) SELEDIT off - don't need to consider the implications of this option.
* 2) FOREDIT off - we're not considering editing, so channel is ok still.
* 3) test_func (i.e. selection test) - only if selected, this test will pass.
*/
#define ANIMCHANNEL_SELEDITOK(test_func) \
(!(filter_mode & ANIMFILTER_SELEDIT) || !(filter_mode & ANIMFILTER_FOREDIT) || (test_func))
@ -1194,7 +1195,7 @@ static bool skip_fcurve_with_name(
*/
static bool fcurve_has_errors(const FCurve *fcu)
{
/* F-Curve disabled - path eval error */
/* F-Curve disabled (path evaluation error). */
if (fcu->flag & FCURVE_DISABLED) {
return true;
}

View File

@ -31,9 +31,9 @@ ID_Type ED_asset_handle_get_id_type(const struct AssetHandle *asset);
int ED_asset_handle_get_preview_icon_id(const struct AssetHandle *asset);
void ED_asset_handle_get_full_library_path(
const struct AssetHandle *asset,
/* `1090` for #FILE_MAX_LIBEXTRA,
/* `1024` for #FILE_MAX,
* rely on warnings to let us know if this gets out of sync. */
char r_full_lib_path[1090]);
char r_full_lib_path[1024]);
bool ED_asset_handle_get_use_relative_path(const struct AssetHandle *asset);
#ifdef __cplusplus
@ -44,9 +44,13 @@ bool ED_asset_handle_get_use_relative_path(const struct AssetHandle *asset);
# include <optional>
# include "BLI_string_ref.hh"
/** The asset library may have an import method (e.g. append vs. link) defined to use. If so, this
* returns it. Otherwise a reasonable method should be used, usually "Append (Reuse Data)". */
std::optional<eAssetImportMethod> ED_asset_handle_get_import_method(
const struct AssetHandle *asset);
blender::StringRefNull ED_asset_handle_get_library_relative_identifier(const AssetHandle &asset);
#endif

View File

@ -60,8 +60,7 @@ struct ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle);
/**
* \return True if the region needs a UI redraw.
*/
bool ED_assetlist_listen(const struct AssetLibraryReference *library_reference,
const struct wmNotifier *notifier);
bool ED_assetlist_listen(const struct wmNotifier *notifier);
/**
* \return The number of assets stored in the asset list for \a library_reference, or -1 if there
* is no list fetched for it.

View File

@ -36,14 +36,14 @@ AssetMetaData *ED_asset_handle_get_metadata(const AssetHandle *asset_handle)
return AS_asset_representation_metadata_get(asset_handle->file_data->asset);
}
ID *ED_asset_handle_get_local_id(const AssetHandle *asset)
ID *ED_asset_handle_get_local_id(const AssetHandle *asset_handle)
{
return asset->file_data->id;
return AS_asset_representation_local_id_get(asset_handle->file_data->asset);
}
ID_Type ED_asset_handle_get_id_type(const AssetHandle *asset)
ID_Type ED_asset_handle_get_id_type(const AssetHandle *asset_handle)
{
return static_cast<ID_Type>(asset->file_data->blentype);
return static_cast<ID_Type>(AS_asset_representation_id_type_get(asset_handle->file_data->asset));
}
int ED_asset_handle_get_preview_icon_id(const AssetHandle *asset)
@ -57,8 +57,13 @@ std::optional<eAssetImportMethod> ED_asset_handle_get_import_method(
return AS_asset_representation_import_method_get(asset_handle->file_data->asset);
}
blender::StringRefNull ED_asset_handle_get_library_relative_identifier(const AssetHandle &asset)
{
return AS_asset_representation_library_relative_identifier_get(asset.file_data->asset);
}
void ED_asset_handle_get_full_library_path(const AssetHandle *asset_handle,
char r_full_lib_path[FILE_MAX_LIBEXTRA])
char r_full_lib_path[FILE_MAX])
{
*r_full_lib_path = '\0';
@ -68,7 +73,7 @@ void ED_asset_handle_get_full_library_path(const AssetHandle *asset_handle,
return;
}
BLI_strncpy(r_full_lib_path, library_path.c_str(), FILE_MAX_LIBEXTRA);
BLI_strncpy(r_full_lib_path, library_path.c_str(), FILE_MAX);
}
bool ED_asset_handle_get_use_relative_path(const AssetHandle *asset)

View File

@ -109,6 +109,8 @@ class AssetList : NonCopyable {
AssetList(AssetList &&other) = default;
~AssetList() = default;
static bool listen(const wmNotifier &notifier);
void setup();
void fetch(const bContext &C);
void ensurePreviewsJob(const bContext *C);
@ -120,7 +122,6 @@ class AssetList : NonCopyable {
bool isLoaded() const;
asset_system::AssetLibrary *asset_library() const;
void iterate(AssetListIterFn fn) const;
bool listen(const wmNotifier &notifier) const;
int size() const;
void tagMainDataDirty() const;
void remapID(ID *id_old, ID *id_new) const;
@ -259,7 +260,7 @@ AssetHandle AssetList::asset_get_by_index(int index) const
/**
* \return True if the asset-list needs a UI redraw.
*/
bool AssetList::listen(const wmNotifier &notifier) const
bool AssetList::listen(const wmNotifier &notifier)
{
switch (notifier.category) {
case NC_ID: {
@ -499,14 +500,9 @@ ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle)
return filelist_geticon_image_ex(asset_handle->file_data);
}
bool ED_assetlist_listen(const AssetLibraryReference *library_reference,
const wmNotifier *notifier)
bool ED_assetlist_listen(const wmNotifier *notifier)
{
AssetList *list = AssetListStorage::lookup_list(*library_reference);
if (list) {
return list->listen(*notifier);
}
return false;
return AssetList::listen(*notifier);
}
int ED_assetlist_size(const AssetLibraryReference *library_reference)

View File

@ -263,6 +263,13 @@ enum {
#define UI_NAVIGATION_REGION_WIDTH UI_COMPACT_PANEL_WIDTH
#define UI_NARROW_NAVIGATION_REGION_WIDTH 100
/* The width of one icon column of the Toolbar. */
#define UI_TOOLBAR_COLUMN (1.25f * ICON_DEFAULT_HEIGHT_TOOLBAR)
/* The space between the Toolbar and the area's edge. */
#define UI_TOOLBAR_MARGIN (0.5f * ICON_DEFAULT_HEIGHT_TOOLBAR)
/* Total width of Toolbar showing one icon column. */
#define UI_TOOLBAR_WIDTH UI_TOOLBAR_MARGIN + UI_TOOLBAR_COLUMN
#define UI_PANEL_CATEGORY_MARGIN_WIDTH (U.widget_unit * 1.0f)
/* Both these margins should be ignored if the panel doesn't show a background (check

View File

@ -11729,7 +11729,12 @@ bool UI_textbutton_activate_rna(const bContext *C,
}
if (but_text) {
ARegion *region_ctx = CTX_wm_region(C);
/* Temporary context override for activating the button. */
CTX_wm_region_set(const_cast<bContext *>(C), region);
UI_but_active_only(C, region, block_text, but_text);
CTX_wm_region_set(const_cast<bContext *>(C), region_ctx);
return true;
}
return false;

View File

@ -146,9 +146,8 @@ static void asset_view_filter_items(uiList *ui_list,
});
}
static void asset_view_listener(uiList *ui_list, wmRegionListenerParams *params)
static void asset_view_listener(uiList * /*ui_list*/, wmRegionListenerParams *params)
{
AssetViewListData *list_data = (AssetViewListData *)ui_list->dyn_data->customdata;
const wmNotifier *notifier = params->notifier;
switch (notifier->category) {
@ -160,7 +159,7 @@ static void asset_view_listener(uiList *ui_list, wmRegionListenerParams *params)
}
}
if (ED_assetlist_listen(&list_data->asset_library_ref, params->notifier)) {
if (ED_assetlist_listen(params->notifier)) {
ED_region_tag_redraw(params->region);
}
}

View File

@ -22,6 +22,7 @@
#include "ED_screen.h"
#include "UI_interface.h"
#include "UI_interface_icons.h"
/* -------------------------------------------------------------------- */
@ -47,9 +48,8 @@ int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, in
/* Using Y axis avoids slight feedback loop when adjusting X. */
const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
(BLI_rcti_size_y(&region->v2d.mask) + 1);
const float icon_size = ICON_DEFAULT_HEIGHT_TOOLBAR / aspect;
const float column = 1.25f * icon_size;
const float margin = 0.5f * icon_size;
const float column = UI_TOOLBAR_COLUMN / aspect;
const float margin = UI_TOOLBAR_MARGIN / aspect;
const float snap_units[] = {
column + margin,
(2.0f * column) + margin,

View File

@ -127,7 +127,7 @@ static SpaceLink *action_create(const ScrArea *area, const Scene *scene)
return (SpaceLink *)saction;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void action_free(SpaceLink * /*sl*/)
{
// SpaceAction *saction = (SpaceAction *) sl;

View File

@ -303,7 +303,7 @@ static SpaceLink *xxx_create(const ScrArea *UNUSED(area), const Scene *UNUSED(sc
return NULL;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void xxx_free(SpaceLink *UNUSED(sl)) {}
/* spacetype; init callback for usage, should be re-doable. */

View File

@ -51,10 +51,7 @@ static int buttons_start_filter_exec(bContext *C, wmOperator *UNUSED(op))
ScrArea *area = CTX_wm_area(C);
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
ARegion *region_ctx = CTX_wm_region(C);
CTX_wm_region_set(C, region);
UI_textbutton_activate_rna(C, region, space, "search_filter");
CTX_wm_region_set(C, region_ctx);
return OPERATOR_FINISHED;
}

View File

@ -87,7 +87,7 @@ static SpaceLink *buttons_create(const ScrArea *UNUSED(area), const Scene *UNUSE
return (SpaceLink *)sbuts;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void buttons_free(SpaceLink *sl)
{
SpaceProperties *sbuts = (SpaceProperties *)sl;

View File

@ -200,7 +200,7 @@ static SpaceLink *clip_create(const ScrArea * /*area*/, const Scene * /*scene*/)
return (SpaceLink *)sc;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void clip_free(SpaceLink *sl)
{
SpaceClip *sc = (SpaceClip *)sl;

View File

@ -22,11 +22,11 @@ set(INC_SYS
)
set(SRC
console_draw.c
console_ops.c
space_console.c
console_draw.cc
console_ops.cc
space_console.cc
console_intern.h
console_intern.hh
)
set(LIB

View File

@ -6,7 +6,7 @@
* \ingroup spconsole
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
@ -22,18 +22,18 @@
#include "UI_resources.h"
#include "UI_view2d.h"
#include "console_intern.h"
#include "console_intern.hh"
#include "../space_info/textview.h"
#include "../space_info/textview.hh"
static enum eTextViewContext_LineFlag console_line_data(TextViewContext *tvc,
uchar fg[4],
uchar UNUSED(bg[4]),
int *UNUSED(icon),
uchar UNUSED(icon_fg[4]),
uchar UNUSED(icon_bg[4]))
uchar /*bg*/[4],
int * /*icon*/,
uchar /*icon_fg*/[4],
uchar /*icon_bg*/[4])
{
const ConsoleLine *cl_iter = tvc->iter;
const ConsoleLine *cl_iter = static_cast<const ConsoleLine *>(tvc->iter);
int fg_id = TH_TEXT;
switch (cl_iter->type) {
@ -58,13 +58,13 @@ static enum eTextViewContext_LineFlag console_line_data(TextViewContext *tvc,
void console_scrollback_prompt_begin(SpaceConsole *sc, ConsoleLine *cl_dummy)
{
/* fake the edit line being in the scroll buffer */
ConsoleLine *cl = sc->history.last;
ConsoleLine *cl = static_cast<ConsoleLine *>(sc->history.last);
int prompt_len = strlen(sc->prompt);
cl_dummy->type = CONSOLE_LINE_INPUT;
cl_dummy->len = prompt_len + cl->len;
cl_dummy->len_alloc = cl_dummy->len + 1;
cl_dummy->line = MEM_mallocN(cl_dummy->len_alloc, "cl_dummy");
cl_dummy->line = static_cast<char *>(MEM_mallocN(cl_dummy->len_alloc, "cl_dummy"));
memcpy(cl_dummy->line, sc->prompt, prompt_len);
memcpy(cl_dummy->line + prompt_len, cl->line, cl->len + 1);
BLI_addtail(&sc->scrollback, cl_dummy);
@ -85,7 +85,7 @@ static int console_textview_begin(TextViewContext *tvc)
/* iterator */
tvc->iter = sc->scrollback.last;
return (tvc->iter != NULL);
return (tvc->iter != nullptr);
}
static void console_textview_end(TextViewContext *tvc)
@ -96,12 +96,12 @@ static void console_textview_end(TextViewContext *tvc)
static int console_textview_step(TextViewContext *tvc)
{
return ((tvc->iter = (void *)((Link *)tvc->iter)->prev) != NULL);
return ((tvc->iter = (void *)((Link *)tvc->iter)->prev) != nullptr);
}
static void console_textview_line_get(TextViewContext *tvc, const char **r_line, int *r_len)
{
const ConsoleLine *cl = tvc->iter;
const ConsoleLine *cl = static_cast<const ConsoleLine *>(tvc->iter);
*r_line = cl->line;
*r_len = cl->len;
// printf("'%s' %d\n", *line, cl->len);
@ -137,12 +137,12 @@ static void console_textview_draw_cursor(TextViewContext *tvc, int cwidth, int c
const ConsoleLine *cl = (ConsoleLine *)sc->history.last;
int offl = 0, offc = 0;
console_cursor_wrap_offset(sc->prompt, columns, &offl, &offc, NULL);
console_cursor_wrap_offset(sc->prompt, columns, &offl, &offc, nullptr);
console_cursor_wrap_offset(cl->line, columns, &offl, &offc, cl->line + cl->cursor);
pen[0] = cwidth * offc;
pen[1] = -tvc->lheight * offl;
console_cursor_wrap_offset(cl->line + cl->cursor, columns, &offl, &offc, NULL);
console_cursor_wrap_offset(cl->line + cl->cursor, columns, &offl, &offc, nullptr);
pen[1] += tvc->lheight * offl;
pen[0] += tvc->draw_rect.xmin;
@ -160,7 +160,7 @@ static void console_textview_draw_cursor(TextViewContext *tvc, int cwidth, int c
immUnbindProgram();
}
static void console_textview_const_colors(TextViewContext *UNUSED(tvc), uchar bg_sel[4])
static void console_textview_const_colors(TextViewContext * /*tvc*/, uchar bg_sel[4])
{
UI_GetThemeColor4ubv(TH_CONSOLE_SELECT, bg_sel);
}
@ -189,7 +189,7 @@ static int console_textview_main__internal(SpaceConsole *sc,
void **r_mval_pick_item,
int *r_mval_pick_offset)
{
ConsoleLine cl_dummy = {NULL};
ConsoleLine cl_dummy = {nullptr};
int ret = 0;
const View2D *v2d = &region->v2d;
@ -206,7 +206,7 @@ static int console_textview_main__internal(SpaceConsole *sc,
tvc.const_colors = console_textview_const_colors;
tvc.arg1 = sc;
tvc.arg2 = NULL;
tvc.arg2 = nullptr;
/* view */
tvc.sel_start = sc->sel_start;
@ -227,19 +227,19 @@ static int console_textview_main__internal(SpaceConsole *sc,
void console_textview_main(SpaceConsole *sc, const ARegion *region)
{
const int mval[2] = {INT_MAX, INT_MAX};
console_textview_main__internal(sc, region, true, mval, NULL, NULL);
console_textview_main__internal(sc, region, true, mval, nullptr, nullptr);
}
int console_textview_height(SpaceConsole *sc, const ARegion *region)
{
const int mval[2] = {INT_MAX, INT_MAX};
return console_textview_main__internal(sc, region, false, mval, NULL, NULL);
return console_textview_main__internal(sc, region, false, mval, nullptr, nullptr);
}
int console_char_pick(SpaceConsole *sc, const ARegion *region, const int mval[2])
{
int r_mval_pick_offset = 0;
void *mval_pick_item = NULL;
void *mval_pick_item = nullptr;
console_textview_main__internal(sc, region, false, mval, &mval_pick_item, &r_mval_pick_offset);
return r_mval_pick_offset;

View File

@ -6,9 +6,9 @@
* \ingroup spconsole
*/
#include <ctype.h> /* #ispunct */
#include <stdlib.h>
#include <string.h>
#include <cctype> /* #ispunct */
#include <cstdlib>
#include <cstring>
#include <sys/stat.h>
#include "MEM_guardedalloc.h"
@ -35,7 +35,7 @@
#include "RNA_access.h"
#include "RNA_define.h"
#include "console_intern.h"
#include "console_intern.hh"
/* -------------------------------------------------------------------- */
/** \name Utilities
@ -44,23 +44,23 @@
static char *console_select_to_buffer(SpaceConsole *sc)
{
if (sc->sel_start == sc->sel_end) {
return NULL;
return nullptr;
}
ConsoleLine cl_dummy = {NULL};
ConsoleLine cl_dummy = {nullptr};
console_scrollback_prompt_begin(sc, &cl_dummy);
int offset = 0;
for (ConsoleLine *cl = sc->scrollback.first; cl; cl = cl->next) {
for (ConsoleLine *cl = static_cast<ConsoleLine *>(sc->scrollback.first); cl; cl = cl->next) {
offset += cl->len + 1;
}
char *buf_str = NULL;
char *buf_str = nullptr;
if (offset != 0) {
offset -= 1;
int sel[2] = {offset - sc->sel_end, offset - sc->sel_start};
DynStr *buf_dyn = BLI_dynstr_new();
for (ConsoleLine *cl = sc->scrollback.first; cl; cl = cl->next) {
for (ConsoleLine *cl = static_cast<ConsoleLine *>(sc->scrollback.first); cl; cl = cl->next) {
if (sel[0] <= cl->len && sel[1] >= 0) {
int sta = max_ii(sel[0], 0);
int end = min_ii(sel[1], cl->len);
@ -94,7 +94,7 @@ static void console_select_update_primary_clipboard(SpaceConsole *sc)
return;
}
char *buf = console_select_to_buffer(sc);
if (buf == NULL) {
if (buf == nullptr) {
return;
}
WM_clipboard_text_set(buf, true);
@ -108,7 +108,7 @@ static void console_scroll_bottom(ARegion *region)
{
View2D *v2d = &region->v2d;
v2d->cur.ymin = 0.0;
v2d->cur.ymax = (float)v2d->winy;
v2d->cur.ymax = float(v2d->winy);
}
void console_textview_update_rect(SpaceConsole *sc, ARegion *region)
@ -142,7 +142,7 @@ static void console_scrollback_limit(SpaceConsole *sc)
int tot;
for (tot = BLI_listbase_count(&sc->scrollback); tot > U.scrollback; tot--) {
console_scrollback_free(sc, sc->scrollback.first);
console_scrollback_free(sc, static_cast<ConsoleLine *>(sc->scrollback.first));
}
}
@ -150,7 +150,7 @@ static ConsoleLine *console_history_find(SpaceConsole *sc, const char *str, Cons
{
ConsoleLine *cl;
for (cl = sc->history.last; cl; cl = cl->prev) {
for (cl = static_cast<ConsoleLine *>(sc->history.last); cl; cl = cl->prev) {
if (cl == cl_ignore) {
continue;
}
@ -160,7 +160,7 @@ static ConsoleLine *console_history_find(SpaceConsole *sc, const char *str, Cons
}
}
return NULL;
return nullptr;
}
/* return 0 if no change made, clamps the range */
@ -208,7 +208,8 @@ static void console_history_debug(const bContext *C)
static ConsoleLine *console_lb_add__internal(ListBase *lb, ConsoleLine *from)
{
ConsoleLine *ci = MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add");
ConsoleLine *ci = static_cast<ConsoleLine *>(
MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add"));
if (from) {
BLI_assert(strlen(from->line) == from->len);
@ -218,7 +219,7 @@ static ConsoleLine *console_lb_add__internal(ListBase *lb, ConsoleLine *from)
ci->type = from->type;
}
else {
ci->line = MEM_callocN(64, "console-in-line");
ci->line = static_cast<char *>(MEM_callocN(64, "console-in-line"));
ci->len_alloc = 64;
ci->len = 0;
}
@ -243,7 +244,8 @@ static ConsoleLine *console_scrollback_add(const bContext *C, ConsoleLine *from)
static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, bool own)
{
ConsoleLine *ci = MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add");
ConsoleLine *ci = static_cast<ConsoleLine *>(
MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add"));
if (own) {
ci->line = str;
}
@ -270,9 +272,9 @@ ConsoleLine *console_scrollback_add_str(SpaceConsole *sc, char *str, bool own)
ConsoleLine *console_history_verify(const bContext *C)
{
SpaceConsole *sc = CTX_wm_space_console(C);
ConsoleLine *ci = sc->history.last;
if (ci == NULL) {
ci = console_history_add(sc, NULL);
ConsoleLine *ci = static_cast<ConsoleLine *>(sc->history.last);
if (ci == nullptr) {
ci = console_history_add(sc, nullptr);
}
return ci;
@ -288,7 +290,7 @@ static void console_line_verify_length(ConsoleLine *ci, int len)
#else
int new_len = (len + 1) * 2;
#endif
ci->line = MEM_recallocN_id(ci->line, new_len, "console line");
ci->line = static_cast<char *>(MEM_recallocN_id(ci->line, new_len, "console line"));
ci->len_alloc = new_len;
}
}
@ -323,7 +325,7 @@ static bool console_line_column_from_index(
ConsoleLine *cl;
int offset = 0;
for (cl = sc->scrollback.last; cl; cl = cl->prev) {
for (cl = static_cast<ConsoleLine *>(sc->scrollback.last); cl; cl = cl->prev) {
offset += cl->len + 1;
if (offset >= pos) {
break;
@ -338,7 +340,7 @@ static bool console_line_column_from_index(
return true;
}
*r_cl = NULL;
*r_cl = nullptr;
*r_cl_offset = -1;
*r_col = -1;
return false;
@ -354,7 +356,7 @@ static const EnumPropertyItem console_move_type_items[] = {
{NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
{PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
{NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
static int console_move_exec(bContext *C, wmOperator *op)
@ -434,13 +436,13 @@ static int console_insert_exec(bContext *C, wmOperator *op)
SpaceConsole *sc = CTX_wm_space_console(C);
ARegion *region = CTX_wm_region(C);
ConsoleLine *ci = console_history_verify(C);
char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
char *str = RNA_string_get_alloc(op->ptr, "text", nullptr, 0, nullptr);
int len;
if (str[0] == '\t' && str[1] == '\0') {
len = TAB_LENGTH;
MEM_freeN(str);
str = MEM_mallocN(len + 1, "insert_exec");
str = static_cast<char *>(MEM_mallocN(len + 1, "insert_exec"));
memset(str, ' ', len);
str[len] = '\0';
}
@ -518,7 +520,7 @@ void CONSOLE_OT_insert(wmOperatorType *ot)
/* properties */
prop = RNA_def_string(
ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
ot->srna, "text", nullptr, 0, "Text", "Text to insert at the cursor position");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
@ -526,7 +528,7 @@ void CONSOLE_OT_insert(wmOperatorType *ot)
/** \name Indent or Autocomplete Operator
* \{ */
static int console_indent_or_autocomplete_exec(bContext *C, wmOperator *UNUSED(op))
static int console_indent_or_autocomplete_exec(bContext *C, wmOperator * /*op*/)
{
ConsoleLine *ci = console_history_verify(C);
bool text_before_cursor = false;
@ -542,10 +544,10 @@ static int console_indent_or_autocomplete_exec(bContext *C, wmOperator *UNUSED(o
}
if (text_before_cursor) {
WM_operator_name_call(C, "CONSOLE_OT_autocomplete", WM_OP_INVOKE_DEFAULT, NULL, NULL);
WM_operator_name_call(C, "CONSOLE_OT_autocomplete", WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
}
else {
WM_operator_name_call(C, "CONSOLE_OT_indent", WM_OP_EXEC_DEFAULT, NULL, NULL);
WM_operator_name_call(C, "CONSOLE_OT_indent", WM_OP_EXEC_DEFAULT, nullptr, nullptr);
}
return OPERATOR_FINISHED;
}
@ -571,7 +573,7 @@ void CONSOLE_OT_indent_or_autocomplete(wmOperatorType *ot)
/** \name Indent Operator
* \{ */
static int console_indent_exec(bContext *C, wmOperator *UNUSED(op))
static int console_indent_exec(bContext *C, wmOperator * /*op*/)
{
SpaceConsole *sc = CTX_wm_space_console(C);
ARegion *region = CTX_wm_region(C);
@ -618,7 +620,7 @@ void CONSOLE_OT_indent(wmOperatorType *ot)
/** \} */
static int console_unindent_exec(bContext *C, wmOperator *UNUSED(op))
static int console_unindent_exec(bContext *C, wmOperator * /*op*/)
{
SpaceConsole *sc = CTX_wm_space_console(C);
ARegion *region = CTX_wm_region(C);
@ -675,7 +677,7 @@ static const EnumPropertyItem console_delete_type_items[] = {
{DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
{DEL_NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
{DEL_PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
static int console_delete_exec(bContext *C, wmOperator *op)
@ -773,7 +775,7 @@ void CONSOLE_OT_delete(wmOperatorType *ot)
"Which part of the text to delete");
}
static int console_clear_line_exec(bContext *C, wmOperator *UNUSED(op))
static int console_clear_line_exec(bContext *C, wmOperator * /*op*/)
{
SpaceConsole *sc = CTX_wm_space_console(C);
ARegion *region = CTX_wm_region(C);
@ -784,7 +786,7 @@ static int console_clear_line_exec(bContext *C, wmOperator *UNUSED(op))
}
console_history_add(sc, ci);
console_history_add(sc, NULL);
console_history_add(sc, nullptr);
console_select_offset(sc, -ci->len);
console_textview_update_rect(sc, region);
@ -821,13 +823,13 @@ static int console_clear_exec(bContext *C, wmOperator *op)
if (scrollback) { /* Last item in history. */
while (sc->scrollback.first) {
console_scrollback_free(sc, sc->scrollback.first);
console_scrollback_free(sc, static_cast<ConsoleLine *>(sc->scrollback.first));
}
}
if (history) {
while (sc->history.first) {
console_history_free(sc, sc->history.first);
console_history_free(sc, static_cast<ConsoleLine *>(sc->history.first));
}
console_history_verify(C);
}
@ -850,8 +852,8 @@ void CONSOLE_OT_clear(wmOperatorType *ot)
ot->poll = ED_operator_console_active;
/* properties */
RNA_def_boolean(ot->srna, "scrollback", 1, "Scrollback", "Clear the scrollback history");
RNA_def_boolean(ot->srna, "history", 0, "History", "Clear the command history");
RNA_def_boolean(ot->srna, "scrollback", true, "Scrollback", "Clear the scrollback history");
RNA_def_boolean(ot->srna, "history", false, "History", "Clear the command history");
}
/* the python exec operator uses this */
@ -876,12 +878,12 @@ static int console_history_cycle_exec(bContext *C, wmOperator *op)
}
if (reverse) { /* last item in history */
ci = sc->history.last;
ci = static_cast<ConsoleLine *>(sc->history.last);
BLI_remlink(&sc->history, ci);
BLI_addhead(&sc->history, ci);
}
else {
ci = sc->history.first;
ci = static_cast<ConsoleLine *>(sc->history.first);
BLI_remlink(&sc->history, ci);
BLI_addtail(&sc->history, ci);
}
@ -895,7 +897,7 @@ static int console_history_cycle_exec(bContext *C, wmOperator *op)
console_history_add(sc, (ConsoleLine *)sc->history.last);
}
ci = sc->history.last;
ci = static_cast<ConsoleLine *>(sc->history.last);
console_select_offset(sc, ci->len - prev_len);
/* could be wrapped so update scroll rect */
@ -919,7 +921,7 @@ void CONSOLE_OT_history_cycle(wmOperatorType *ot)
ot->poll = ED_operator_console_active;
/* properties */
RNA_def_boolean(ot->srna, "reverse", 0, "Reverse", "Reverse cycle history");
RNA_def_boolean(ot->srna, "reverse", false, "Reverse", "Reverse cycle history");
}
/* the python exec operator uses this */
@ -930,7 +932,7 @@ static int console_history_append_exec(bContext *C, wmOperator *op)
ScrArea *area = CTX_wm_area(C);
ConsoleLine *ci = console_history_verify(C);
/* own this text in the new line, don't free */
char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
char *str = RNA_string_get_alloc(op->ptr, "text", nullptr, 0, nullptr);
int cursor = RNA_int_get(op->ptr, "current_character");
const bool rem_dupes = RNA_boolean_get(op->ptr, "remove_duplicates");
int prev_len = ci->len;
@ -948,7 +950,7 @@ static int console_history_append_exec(bContext *C, wmOperator *op)
}
}
ci = console_history_add_str(sc, str, 1); /* own the string */
ci = console_history_add_str(sc, str, true); /* own the string */
console_select_offset(sc, ci->len - prev_len);
console_line_cursor_set(ci, cursor);
@ -975,12 +977,12 @@ void CONSOLE_OT_history_append(wmOperatorType *ot)
ot->poll = ED_operator_console_active;
/* properties */
RNA_def_string(ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
RNA_def_string(ot->srna, "text", nullptr, 0, "Text", "Text to insert at the cursor position");
RNA_def_int(
ot->srna, "current_character", 0, 0, INT_MAX, "Cursor", "The index of the cursor", 0, 10000);
RNA_def_boolean(ot->srna,
"remove_duplicates",
0,
false,
"Remove Duplicates",
"Remove duplicate items in the history");
}
@ -993,12 +995,12 @@ static int console_scrollback_append_exec(bContext *C, wmOperator *op)
ConsoleLine *ci;
/* own this text in the new line, don't free */
char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
char *str = RNA_string_get_alloc(op->ptr, "text", nullptr, 0, nullptr);
int type = RNA_enum_get(op->ptr, "type");
console_history_verify(C);
ci = console_scrollback_add_str(sc, str, 1); /* own the string */
ci = console_scrollback_add_str(sc, str, true); /* own the string */
ci->type = type;
console_scrollback_limit(sc);
@ -1022,7 +1024,7 @@ void CONSOLE_OT_scrollback_append(wmOperatorType *ot)
{CONSOLE_LINE_INPUT, "INPUT", 0, "Input", ""},
{CONSOLE_LINE_INFO, "INFO", 0, "Information", ""},
{CONSOLE_LINE_ERROR, "ERROR", 0, "Error", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
/* identifiers */
@ -1035,7 +1037,7 @@ void CONSOLE_OT_scrollback_append(wmOperatorType *ot)
ot->poll = ED_operator_console_active;
/* properties */
RNA_def_string(ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
RNA_def_string(ot->srna, "text", nullptr, 0, "Text", "Text to insert at the cursor position");
RNA_def_enum(ot->srna,
"type",
console_line_type_items,
@ -1044,15 +1046,15 @@ void CONSOLE_OT_scrollback_append(wmOperatorType *ot)
"Console output type");
}
static int console_copy_exec(bContext *C, wmOperator *UNUSED(op))
static int console_copy_exec(bContext *C, wmOperator * /*op*/)
{
SpaceConsole *sc = CTX_wm_space_console(C);
char *buf = console_select_to_buffer(sc);
if (buf == NULL) {
if (buf == nullptr) {
return OPERATOR_CANCELLED;
}
WM_clipboard_text_set(buf, 0);
WM_clipboard_text_set(buf, false);
MEM_freeN(buf);
return OPERATOR_FINISHED;
}
@ -1080,7 +1082,7 @@ static int console_paste_exec(bContext *C, wmOperator *op)
int buf_str_len;
char *buf_str = WM_clipboard_text_get(selection, true, &buf_str_len);
if (buf_str == NULL) {
if (buf_str == nullptr) {
return OPERATOR_CANCELLED;
}
if (*buf_str == '\0') {
@ -1093,7 +1095,7 @@ static int console_paste_exec(bContext *C, wmOperator *op)
buf_step = (char *)BLI_strchr_or_end(buf, '\n');
const int buf_len = buf_step - buf;
if (buf != buf_str) {
WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL, NULL);
WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, nullptr, nullptr);
ci = console_history_verify(C);
}
console_line_insert(ci, buf, buf_len);
@ -1125,20 +1127,20 @@ void CONSOLE_OT_paste(wmOperatorType *ot)
PropertyRNA *prop;
prop = RNA_def_boolean(ot->srna,
"selection",
0,
false,
"Selection",
"Paste text selected elsewhere rather than copied (X11/Wayland only)");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
typedef struct SetConsoleCursor {
struct SetConsoleCursor {
int sel_old[2];
int sel_init;
} SetConsoleCursor;
};
/* TODO: cursor placement without selection. */
static void console_cursor_set_to_pos(
SpaceConsole *sc, ARegion *region, SetConsoleCursor *scu, const int mval[2], int UNUSED(sel))
SpaceConsole *sc, ARegion *region, SetConsoleCursor *scu, const int mval[2], int /*sel*/)
{
int pos;
pos = console_char_pick(sc, region, mval);
@ -1166,7 +1168,7 @@ static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEven
{
SpaceConsole *sc = CTX_wm_space_console(C);
ARegion *region = CTX_wm_region(C);
SetConsoleCursor *scu = op->customdata;
SetConsoleCursor *scu = static_cast<SetConsoleCursor *>(op->customdata);
int mval[2];
int sel_prev[2];
@ -1187,7 +1189,7 @@ static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEven
static void console_cursor_set_exit(bContext *C, wmOperator *op)
{
SpaceConsole *sc = CTX_wm_space_console(C);
SetConsoleCursor *scu = op->customdata;
SetConsoleCursor *scu = static_cast<SetConsoleCursor *>(op->customdata);
console_select_update_primary_clipboard(sc);
@ -1201,7 +1203,7 @@ static int console_modal_select_invoke(bContext *C, wmOperator *op, const wmEven
SetConsoleCursor *scu;
op->customdata = MEM_callocN(sizeof(SetConsoleCursor), "SetConsoleCursor");
scu = op->customdata;
scu = static_cast<SetConsoleCursor *>(op->customdata);
scu->sel_old[0] = sc->sel_start;
scu->sel_old[1] = sc->sel_end;
@ -1253,12 +1255,12 @@ void CONSOLE_OT_select_set(wmOperatorType *ot)
ot->poll = ED_operator_console_active;
}
static int console_selectword_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
static int console_selectword_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event)
{
SpaceConsole *sc = CTX_wm_space_console(C);
ARegion *region = CTX_wm_region(C);
ConsoleLine cl_dummy = {NULL};
ConsoleLine cl_dummy = {nullptr};
ConsoleLine *cl;
int ret = OPERATOR_CANCELLED;
int pos, offset, n;

View File

@ -6,8 +6,8 @@
* \ingroup spconsole
*/
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -32,29 +32,29 @@
#include "BLO_read_write.h"
#include "console_intern.h" /* own include */
#include "console_intern.hh" /* own include */
/* ******************** default callbacks for console space ***************** */
static SpaceLink *console_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
static SpaceLink *console_create(const ScrArea * /*area*/, const Scene * /*scene*/)
{
ARegion *region;
SpaceConsole *sconsole;
sconsole = MEM_callocN(sizeof(SpaceConsole), "initconsole");
sconsole = static_cast<SpaceConsole *>(MEM_callocN(sizeof(SpaceConsole), "initconsole"));
sconsole->spacetype = SPACE_CONSOLE;
sconsole->lheight = 14;
/* header */
region = MEM_callocN(sizeof(ARegion), "header for console");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "header for console"));
BLI_addtail(&sconsole->regionbase, region);
region->regiontype = RGN_TYPE_HEADER;
region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
/* main region */
region = MEM_callocN(sizeof(ARegion), "main region for text");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "main region for text"));
BLI_addtail(&sconsole->regionbase, region);
region->regiontype = RGN_TYPE_WINDOW;
@ -73,26 +73,26 @@ static SpaceLink *console_create(const ScrArea *UNUSED(area), const Scene *UNUSE
return (SpaceLink *)sconsole;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void console_free(SpaceLink *sl)
{
SpaceConsole *sc = (SpaceConsole *)sl;
while (sc->scrollback.first) {
console_scrollback_free(sc, sc->scrollback.first);
console_scrollback_free(sc, static_cast<ConsoleLine *>(sc->scrollback.first));
}
while (sc->history.first) {
console_history_free(sc, sc->history.first);
console_history_free(sc, static_cast<ConsoleLine *>(sc->history.first));
}
}
/* spacetype; init callback */
static void console_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area)) {}
static void console_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
static SpaceLink *console_duplicate(SpaceLink *sl)
{
SpaceConsole *sconsolen = MEM_dupallocN(sl);
SpaceConsole *sconsolen = static_cast<SpaceConsole *>(MEM_dupallocN(sl));
/* clear or remove stuff from old */
@ -138,7 +138,7 @@ static void console_main_region_init(wmWindowManager *wm, ARegion *region)
}
/* same as 'text_cursor' */
static void console_cursor(wmWindow *win, ScrArea *UNUSED(area), ARegion *region)
static void console_cursor(wmWindow *win, ScrArea * /*area*/, ARegion *region)
{
int wmcursor = WM_CURSOR_TEXT_EDIT;
const wmEvent *event = win->eventstate;
@ -151,12 +151,12 @@ static void console_cursor(wmWindow *win, ScrArea *UNUSED(area), ARegion *region
/* ************* dropboxes ************* */
static bool id_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
static bool id_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
{
return WM_drag_get_local_ID(drag, 0) != NULL;
return WM_drag_get_local_ID(drag, 0) != nullptr;
}
static void id_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
static void id_drop_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
{
ID *id = WM_drag_get_local_ID(drag, 0);
@ -166,12 +166,12 @@ static void id_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
MEM_freeN(text);
}
static bool path_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
static bool path_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
{
return (drag->type == WM_DRAG_PATH);
}
static void path_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
static void path_drop_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
{
char pathname[FILE_MAX + 2];
SNPRINTF(pathname, "\"%s\"", WM_drag_get_path(drag));
@ -179,12 +179,12 @@ static void path_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
}
/* this region dropbox definition */
static void console_dropboxes(void)
static void console_dropboxes()
{
ListBase *lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
WM_dropbox_add(lb, "CONSOLE_OT_insert", id_drop_poll, id_drop_copy, NULL, NULL);
WM_dropbox_add(lb, "CONSOLE_OT_insert", path_drop_poll, path_drop_copy, NULL, NULL);
WM_dropbox_add(lb, "CONSOLE_OT_insert", id_drop_poll, id_drop_copy, nullptr, nullptr);
WM_dropbox_add(lb, "CONSOLE_OT_insert", path_drop_poll, path_drop_copy, nullptr, nullptr);
}
/* ************* end drop *********** */
@ -196,7 +196,8 @@ static void console_main_region_draw(const bContext *C, ARegion *region)
View2D *v2d = &region->v2d;
if (BLI_listbase_is_empty(&sc->scrollback)) {
WM_operator_name_call((bContext *)C, "CONSOLE_OT_banner", WM_OP_EXEC_DEFAULT, NULL, NULL);
WM_operator_name_call(
(bContext *)C, "CONSOLE_OT_banner", WM_OP_EXEC_DEFAULT, nullptr, nullptr);
}
/* clear and setup matrix */
@ -214,10 +215,10 @@ static void console_main_region_draw(const bContext *C, ARegion *region)
UI_view2d_view_restore(C);
/* scrollers */
UI_view2d_scrollers_draw(v2d, NULL);
UI_view2d_scrollers_draw(v2d, nullptr);
}
static void console_operatortypes(void)
static void console_operatortypes()
{
/* console_ops.c */
WM_operatortype_append(CONSOLE_OT_move);
@ -249,7 +250,7 @@ static void console_keymap(wmKeyConfig *keyconf)
/****************** header region ******************/
/* add handlers, stuff you only do once or on area/region changes */
static void console_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
static void console_header_region_init(wmWindowManager * /*wm*/, ARegion *region)
{
ED_region_header_init(region);
}
@ -272,7 +273,7 @@ static void console_main_region_listener(const wmRegionListenerParams *params)
if (wmn->action == NA_EDITED) {
if ((wmn->reference && area) && (wmn->reference == area->spacedata.first)) {
/* we've modified the geometry (font size), re-calculate rect */
console_textview_update_rect(wmn->reference, region);
console_textview_update_rect(static_cast<SpaceConsole *>(wmn->reference), region);
ED_region_tag_redraw(region);
}
}
@ -316,14 +317,14 @@ static void console_space_blend_write(BlendWriter *writer, SpaceLink *sl)
LISTBASE_FOREACH (ConsoleLine *, cl, &con->history) {
/* 'len_alloc' is invalid on write, set from 'len' on read */
BLO_write_struct(writer, ConsoleLine, cl);
BLO_write_raw(writer, (size_t)cl->len + 1, cl->line);
BLO_write_raw(writer, size_t(cl->len) + 1, cl->line);
}
BLO_write_struct(writer, SpaceConsole, sl);
}
void ED_spacetype_console(void)
{
SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype console");
SpaceType *st = static_cast<SpaceType *>(MEM_callocN(sizeof(SpaceType), "spacetype console"));
ARegionType *art;
st->spaceid = SPACE_CONSOLE;
@ -340,7 +341,7 @@ void ED_spacetype_console(void)
st->blend_write = console_space_blend_write;
/* regions: main window */
art = MEM_callocN(sizeof(ARegionType), "spacetype console region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype console region"));
art->regionid = RGN_TYPE_WINDOW;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D;
@ -353,7 +354,7 @@ void ED_spacetype_console(void)
BLI_addhead(&st->regiontypes, art);
/* regions: header */
art = MEM_callocN(sizeof(ARegionType), "spacetype console region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype console region"));
art->regionid = RGN_TYPE_HEADER;
art->prefsizey = HEADERY;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;

View File

@ -3210,19 +3210,14 @@ static int file_start_filter_exec(bContext *C, wmOperator *UNUSED(op))
const SpaceFile *sfile = CTX_wm_space_file(C);
const FileSelectParams *params = ED_fileselect_get_active_params(sfile);
ARegion *region_ctx = CTX_wm_region(C);
if (area) {
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
CTX_wm_region_set(C, region);
if (UI_textbutton_activate_rna(C, region, params, "filter_search")) {
break;
}
}
}
CTX_wm_region_set(C, region_ctx);
return OPERATOR_FINISHED;
}
@ -3251,19 +3246,14 @@ static int file_edit_directory_path_exec(bContext *C, wmOperator *UNUSED(op))
const SpaceFile *sfile = CTX_wm_space_file(C);
const FileSelectParams *params = ED_fileselect_get_active_params(sfile);
ARegion *region_ctx = CTX_wm_region(C);
if (area) {
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
CTX_wm_region_set(C, region);
if (UI_textbutton_activate_rna(C, region, params, "directory")) {
break;
}
}
}
CTX_wm_region_set(C, region_ctx);
return OPERATOR_FINISHED;
}

View File

@ -3187,7 +3187,7 @@ static void filelist_readjob_list_lib_add_datablock(FileListReadJob *job_params,
datablock_info->free_asset_data = false;
entry->asset = &job_params->load_asset_library->add_external_asset(
entry->relpath, datablock_info->name, std::move(metadata));
entry->relpath, datablock_info->name, idcode, std::move(metadata));
}
}
}

View File

@ -107,7 +107,7 @@ static SpaceLink *file_create(const ScrArea *UNUSED(area), const Scene *UNUSED(s
return (SpaceLink *)sfile;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void file_free(SpaceLink *sl)
{
SpaceFile *sfile = (SpaceFile *)sl;

View File

@ -2183,7 +2183,7 @@ void GRAPH_OT_frame_jump(wmOperatorType *ot)
static bool find_closest_frame(const FCurve *fcu,
const float frame,
const bool next,
float *closest_frame)
float *r_closest_frame)
{
bool replace;
int bezt_index = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, frame, fcu->totvert, &replace);
@ -2205,7 +2205,7 @@ static bool find_closest_frame(const FCurve *fcu,
bezt = &fcu->bezt[bezt_index - 1];
}
*closest_frame = bezt->vec[1][0];
*r_closest_frame = bezt->vec[1][0];
return true;
}

View File

@ -121,7 +121,7 @@ static SpaceLink *graph_create(const ScrArea *UNUSED(area), const Scene *scene)
return (SpaceLink *)sipo;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void graph_free(SpaceLink *sl)
{
SpaceGraph *si = (SpaceGraph *)sl;

View File

@ -161,7 +161,7 @@ static SpaceLink *image_create(const ScrArea *UNUSED(area), const Scene *UNUSED(
return (SpaceLink *)simage;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void image_free(SpaceLink *sl)
{
SpaceImage *simage = (SpaceImage *)sl;
@ -1135,7 +1135,7 @@ void ED_spacetype_image(void)
/* regions: tool(bar) */
art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
art->regionid = RGN_TYPE_TOOLS;
art->prefsizex = 58; /* XXX */
art->prefsizex = (int)UI_TOOLBAR_WIDTH;
art->prefsizey = 50; /* XXX */
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
art->listener = image_tools_region_listener;

View File

@ -28,15 +28,15 @@ set(INC_SYS
)
set(SRC
info_draw.c
info_ops.c
info_report.c
info_draw.cc
info_ops.cc
info_report.cc
info_stats.cc
space_info.c
textview.c
space_info.cc
textview.cc
info_intern.h
textview.h
info_intern.hh
textview.hh
)
set(LIB

View File

@ -6,8 +6,8 @@
* \ingroup spinfo
*/
#include <limits.h>
#include <string.h>
#include <climits>
#include <cstring>
#include "BLI_utildefines.h"
@ -20,8 +20,8 @@
#include "UI_resources.h"
#include "UI_view2d.h"
#include "info_intern.h"
#include "textview.h"
#include "info_intern.hh"
#include "textview.hh"
static enum eTextViewContext_LineFlag report_line_data(TextViewContext *tvc,
uchar fg[4],
@ -30,7 +30,7 @@ static enum eTextViewContext_LineFlag report_line_data(TextViewContext *tvc,
uchar r_icon_fg[4],
uchar r_icon_bg[4])
{
const Report *report = tvc->iter;
const Report *report = static_cast<const Report *>(tvc->iter);
/* Same text color no matter what type of report. */
UI_GetThemeColor4ubv((report->flag & SELECT) ? TH_INFO_SELECTED_TEXT : TH_TEXT, fg);
@ -65,7 +65,7 @@ static enum eTextViewContext_LineFlag report_line_data(TextViewContext *tvc,
/* reports! */
static void report_textview_init__internal(TextViewContext *tvc)
{
const Report *report = tvc->iter;
const Report *report = static_cast<const Report *>(tvc->iter);
const char *str = report->message;
for (int i = tvc->iter_char_end - 1; i >= 0; i -= 1) {
if (str[i] == '\n') {
@ -78,17 +78,17 @@ static void report_textview_init__internal(TextViewContext *tvc)
static int report_textview_skip__internal(TextViewContext *tvc)
{
const SpaceInfo *sinfo = tvc->arg1;
const SpaceInfo *sinfo = static_cast<const SpaceInfo *>(tvc->arg1);
const int report_mask = info_report_mask(sinfo);
while (tvc->iter && (((const Report *)tvc->iter)->type & report_mask) == 0) {
tvc->iter = (void *)((Link *)tvc->iter)->prev;
}
return (tvc->iter != NULL);
return (tvc->iter != nullptr);
}
static int report_textview_begin(TextViewContext *tvc)
{
const ReportList *reports = tvc->arg2;
const ReportList *reports = static_cast<const ReportList *>(tvc->arg2);
tvc->sel_start = 0;
tvc->sel_end = 0;
@ -101,7 +101,7 @@ static int report_textview_begin(TextViewContext *tvc)
tvc->iter_tmp = 0;
if (tvc->iter && report_textview_skip__internal(tvc)) {
/* init the newline iterator */
const Report *report = tvc->iter;
const Report *report = static_cast<const Report *>(tvc->iter);
tvc->iter_char_end = report->len;
report_textview_init__internal(tvc);
@ -111,7 +111,7 @@ static int report_textview_begin(TextViewContext *tvc)
return false;
}
static void report_textview_end(TextViewContext *UNUSED(tvc))
static void report_textview_end(TextViewContext * /*tvc*/)
{
/* pass */
}
@ -124,7 +124,7 @@ static int report_textview_step(TextViewContext *tvc)
if (tvc->iter && report_textview_skip__internal(tvc)) {
tvc->iter_tmp++;
const Report *report = tvc->iter;
const Report *report = static_cast<const Report *>(tvc->iter);
tvc->iter_char_end = report->len; /* reset start */
report_textview_init__internal(tvc);
@ -142,7 +142,7 @@ static int report_textview_step(TextViewContext *tvc)
static void report_textview_line_get(TextViewContext *tvc, const char **r_line, int *r_len)
{
const Report *report = tvc->iter;
const Report *report = static_cast<const Report *>(tvc->iter);
*r_line = report->message + tvc->iter_char_begin;
*r_len = tvc->iter_char_end - tvc->iter_char_begin;
}
@ -183,7 +183,7 @@ static int info_textview_main__internal(const SpaceInfo *sinfo,
tvc.step = report_textview_step;
tvc.line_get = report_textview_line_get;
tvc.line_data = report_line_data;
tvc.const_colors = NULL;
tvc.const_colors = nullptr;
tvc.arg1 = sinfo;
tvc.arg2 = reports;
@ -208,21 +208,21 @@ void *info_text_pick(const SpaceInfo *sinfo,
const ReportList *reports,
int mouse_y)
{
void *mval_pick_item = NULL;
void *mval_pick_item = nullptr;
const int mval[2] = {0, mouse_y};
info_textview_main__internal(sinfo, region, reports, false, mval, &mval_pick_item, NULL);
info_textview_main__internal(sinfo, region, reports, false, mval, &mval_pick_item, nullptr);
return (void *)mval_pick_item;
}
int info_textview_height(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
{
const int mval[2] = {INT_MAX, INT_MAX};
return info_textview_main__internal(sinfo, region, reports, false, mval, NULL, NULL);
return info_textview_main__internal(sinfo, region, reports, false, mval, nullptr, nullptr);
}
void info_textview_main(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
{
const int mval[2] = {INT_MAX, INT_MAX};
info_textview_main__internal(sinfo, region, reports, true, mval, NULL, NULL);
info_textview_main__internal(sinfo, region, reports, true, mval, nullptr, nullptr);
}

View File

@ -6,8 +6,8 @@
* \ingroup spinfo
*/
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h"
@ -39,7 +39,7 @@
#include "RNA_access.h"
#include "RNA_define.h"
#include "info_intern.h"
#include "info_intern.hh"
/* -------------------------------------------------------------------- */
/** \name Pack Blend File Libraries Operator
@ -87,7 +87,7 @@ static int unpack_libraries_exec(bContext *C, wmOperator *op)
/** \name Unpack Blend File Libraries Operator
* \{ */
static int unpack_libraries_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int unpack_libraries_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
return WM_operator_confirm_message(
C, op, "Unpack Linked Libraries - creates directories, all new paths should work");
@ -158,13 +158,15 @@ static int pack_all_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
Main *bmain = CTX_data_main(C);
Image *ima;
/* First check for dirty images. */
for (ima = bmain->images.first; ima; ima = ima->id.next) {
for (ima = static_cast<Image *>(bmain->images.first); ima;
ima = static_cast<Image *>(ima->id.next))
{
if (BKE_image_is_dirty(ima)) {
break;
}
@ -219,13 +221,13 @@ static const EnumPropertyItem unpack_all_method_items[] = {
{PF_KEEP, "KEEP", 0, "Disable auto-pack, keep all packed files", ""},
{PF_REMOVE, "REMOVE", 0, "Remove Pack", ""},
/* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
static int unpack_all_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
int method = RNA_enum_get(op->ptr, "method");
ePF_FileStatus method = ePF_FileStatus(RNA_enum_get(op->ptr, "method"));
if (method != PF_KEEP) {
WM_cursor_wait(true);
@ -237,7 +239,7 @@ static int unpack_all_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int unpack_all_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int unpack_all_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
Main *bmain = CTX_data_main(C);
uiPopupMenu *pup;
@ -314,7 +316,7 @@ static const EnumPropertyItem unpack_item_method_items[] = {
"Write file to original location (overwrite existing file)",
""},
/* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
static int unpack_item_exec(bContext *C, wmOperator *op)
@ -323,12 +325,12 @@ static int unpack_item_exec(bContext *C, wmOperator *op)
ID *id;
char idname[MAX_ID_NAME - 2];
int type = RNA_int_get(op->ptr, "id_type");
int method = RNA_enum_get(op->ptr, "method");
ePF_FileStatus method = ePF_FileStatus(RNA_enum_get(op->ptr, "method"));
RNA_string_get(op->ptr, "id_name", idname);
id = BKE_libblock_find_name(bmain, type, idname);
if (id == NULL) {
if (id == nullptr) {
BKE_report(op->reports, RPT_WARNING, "No packed file");
return OPERATOR_CANCELLED;
}
@ -344,7 +346,7 @@ static int unpack_item_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int unpack_item_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int unpack_item_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
uiPopupMenu *pup;
uiLayout *layout;
@ -353,7 +355,12 @@ static int unpack_item_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED
layout = UI_popup_menu_layout(pup);
uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
uiItemsFullEnumO(layout, op->type->idname, "method", op->ptr->data, WM_OP_EXEC_REGION_WIN, 0);
uiItemsFullEnumO(layout,
op->type->idname,
"method",
static_cast<IDProperty *>(op->ptr->data),
WM_OP_EXEC_REGION_WIN,
0);
UI_popup_menu_end(C, pup);
@ -378,7 +385,7 @@ void FILE_OT_unpack_item(wmOperatorType *ot)
RNA_def_enum(
ot->srna, "method", unpack_item_method_items, PF_USE_LOCAL, "Method", "How to unpack");
RNA_def_string(
ot->srna, "id_name", NULL, BKE_ST_MAXNAME, "ID Name", "Name of ID block to unpack");
ot->srna, "id_name", nullptr, BKE_ST_MAXNAME, "ID Name", "Name of ID block to unpack");
RNA_def_int(ot->srna,
"id_type",
ID_IM,
@ -409,7 +416,7 @@ static int make_paths_relative_exec(bContext *C, wmOperator *op)
BKE_bpath_relative_convert(bmain, blendfile_path, op->reports);
/* redraw everything so any changed paths register */
WM_main_add_notifier(NC_WINDOW, NULL);
WM_main_add_notifier(NC_WINDOW, nullptr);
return OPERATOR_FINISHED;
}
@ -447,7 +454,7 @@ static int make_paths_absolute_exec(bContext *C, wmOperator *op)
BKE_bpath_absolute_convert(bmain, blendfile_path, op->reports);
/* redraw everything so any changed paths register */
WM_main_add_notifier(NC_WINDOW, NULL);
WM_main_add_notifier(NC_WINDOW, nullptr);
return OPERATOR_FINISHED;
}
@ -505,7 +512,7 @@ void FILE_OT_report_missing_files(wmOperatorType *ot)
static int find_missing_files_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
const char *searchpath = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
const char *searchpath = RNA_string_get_alloc(op->ptr, "directory", nullptr, 0, nullptr);
const bool find_all = RNA_boolean_get(op->ptr, "find_all");
BKE_bpath_missing_files_find(bmain, searchpath, op->reports, find_all);
@ -514,7 +521,7 @@ static int find_missing_files_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int find_missing_files_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int find_missing_files_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
/* XXX file open button text "Find Missing Files" */
WM_event_add_fileselect(C, op);
@ -568,7 +575,7 @@ void FILE_OT_find_missing_files(wmOperatorType *ot)
#define FLASH_TIMEOUT 1.0f
#define COLLAPSE_TIMEOUT 0.25f
#define BRIGHTEN_AMOUNT 0.1f
static int update_reports_display_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
static int update_reports_display_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event)
{
wmWindowManager *wm = CTX_wm_manager(C);
ReportList *reports = CTX_wm_reports(C);
@ -580,8 +587,8 @@ static int update_reports_display_invoke(bContext *C, wmOperator *UNUSED(op), co
int send_note = 0;
/* escape if not our timer */
if ((reports->reporttimer == NULL) || (reports->reporttimer != event->customdata) ||
((report = BKE_reports_last_displayable(reports)) == NULL))
if ((reports->reporttimer == nullptr) || (reports->reporttimer != event->customdata) ||
((report = BKE_reports_last_displayable(reports)) == nullptr))
{
/* May have been deleted. */
return OPERATOR_PASS_THROUGH;
@ -592,11 +599,11 @@ static int update_reports_display_invoke(bContext *C, wmOperator *UNUSED(op), co
timeout = (report->type & RPT_ERROR_ALL) ? ERROR_TIMEOUT : INFO_TIMEOUT;
/* clear the report display after timeout */
if ((float)reports->reporttimer->duration > timeout) {
WM_event_remove_timer(wm, NULL, reports->reporttimer);
reports->reporttimer = NULL;
if (float(reports->reporttimer->duration) > timeout) {
WM_event_remove_timer(wm, nullptr, reports->reporttimer);
reports->reporttimer = nullptr;
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, NULL);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, nullptr);
return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH);
}
@ -617,8 +624,8 @@ static int update_reports_display_invoke(bContext *C, wmOperator *UNUSED(op), co
rti->widthfac = 1.0f;
}
progress = powf((float)reports->reporttimer->duration / timeout, 2.0f);
flash_progress = powf((float)reports->reporttimer->duration / flash_timeout, 2.0);
progress = powf(float(reports->reporttimer->duration) / timeout, 2.0f);
flash_progress = powf(float(reports->reporttimer->duration) / flash_timeout, 2.0);
/* save us from too many draws */
if (flash_progress <= 1.0f) {
@ -636,7 +643,7 @@ static int update_reports_display_invoke(bContext *C, wmOperator *UNUSED(op), co
}
if (send_note) {
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, NULL);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, nullptr);
}
return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH);

View File

@ -6,9 +6,9 @@
* \ingroup spinfo
*/
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <climits>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -27,13 +27,15 @@
#include "RNA_access.h"
#include "RNA_define.h"
#include "info_intern.h"
#include "info_intern.hh"
static void reports_select_all(ReportList *reports, int report_mask, int action)
{
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
for (Report *report = reports->list.last; report; report = report->prev) {
for (const Report *report = static_cast<const Report *>(reports->list.last); report;
report = report->prev)
{
if ((report->type & report_mask) && (report->flag & SELECT)) {
action = SEL_DESELECT;
break;
@ -41,7 +43,7 @@ static void reports_select_all(ReportList *reports, int report_mask, int action)
}
}
for (Report *report = reports->list.last; report; report = report->prev) {
for (Report *report = static_cast<Report *>(reports->list.last); report; report = report->prev) {
if (report->type & report_mask) {
switch (action) {
case SEL_SELECT:
@ -60,7 +62,7 @@ static void reports_select_all(ReportList *reports, int report_mask, int action)
}
}
int info_report_mask(const SpaceInfo *UNUSED(sinfo))
int info_report_mask(const SpaceInfo * /*sinfo*/)
{
#if 0
int report_mask = 0;
@ -88,7 +90,7 @@ int info_report_mask(const SpaceInfo *UNUSED(sinfo))
RPT_ERROR_ALL;
}
static int report_replay_exec(bContext *C, wmOperator *UNUSED(op))
static int report_replay_exec(bContext *C, wmOperator * /*op*/)
{
/* TODO: get this working again! */
#if 0
@ -138,7 +140,7 @@ static int select_report_pick_exec(bContext *C, wmOperator *op)
int report_index = RNA_int_get(op->ptr, "report_index");
bool extend = RNA_boolean_get(op->ptr, "extend");
Report *report = BLI_findlink(&CTX_wm_reports(C)->list, report_index);
Report *report = static_cast<Report *>(BLI_findlink(&CTX_wm_reports(C)->list, report_index));
SpaceInfo *sinfo = CTX_wm_space_info(C);
ReportList *reports = CTX_wm_reports(C);
@ -164,7 +166,7 @@ static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent
ReportList *reports = CTX_wm_reports(C);
Report *report;
report = info_text_pick(sinfo, region, reports, event->mval[1]);
report = static_cast<Report *>(info_text_pick(sinfo, region, reports, event->mval[1]));
RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
@ -235,7 +237,7 @@ static int box_select_exec(bContext *C, wmOperator *op)
WM_operator_properties_border_to_rcti(op, &rect);
const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
const eSelectOp sel_op = eSelectOp(RNA_enum_get(op->ptr, "mode"));
const int select = (sel_op != SEL_OP_SUB);
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
LISTBASE_FOREACH (Report *, report, &reports->list) {
@ -246,11 +248,11 @@ static int box_select_exec(bContext *C, wmOperator *op)
}
}
report_min = info_text_pick(sinfo, region, reports, rect.ymax);
report_max = info_text_pick(sinfo, region, reports, rect.ymin);
report_min = static_cast<Report *>(info_text_pick(sinfo, region, reports, rect.ymax));
report_max = static_cast<Report *>(info_text_pick(sinfo, region, reports, rect.ymin));
/* get the first report if none found */
if (report_min == NULL) {
if (report_min == nullptr) {
// printf("find_min\n");
LISTBASE_FOREACH (Report *, report, &reports->list) {
if (report->type & report_mask) {
@ -260,9 +262,10 @@ static int box_select_exec(bContext *C, wmOperator *op)
}
}
if (report_max == NULL) {
if (report_max == nullptr) {
// printf("find_max\n");
for (Report *report = reports->list.last; report; report = report->prev) {
for (Report *report = static_cast<Report *>(reports->list.last); report; report = report->prev)
{
if (report->type & report_mask) {
report_max = report;
break;
@ -270,7 +273,7 @@ static int box_select_exec(bContext *C, wmOperator *op)
}
}
if (report_min == NULL || report_max == NULL) {
if (report_min == nullptr || report_max == nullptr) {
return OPERATOR_CANCELLED;
}
@ -311,7 +314,7 @@ void INFO_OT_select_box(wmOperatorType *ot)
WM_operator_properties_select_operation_simple(ot);
}
static int report_delete_exec(bContext *C, wmOperator *UNUSED(op))
static int report_delete_exec(bContext *C, wmOperator * /*op*/)
{
SpaceInfo *sinfo = CTX_wm_space_info(C);
ReportList *reports = CTX_wm_reports(C);
@ -319,8 +322,7 @@ static int report_delete_exec(bContext *C, wmOperator *UNUSED(op))
Report *report, *report_next;
for (report = reports->list.first; report;) {
for (report = static_cast<Report *>(reports->list.first); report;) {
report_next = report->next;
if ((report->type & report_mask) && (report->flag & SELECT)) {
@ -354,7 +356,7 @@ void INFO_OT_report_delete(wmOperatorType *ot)
/* properties */
}
static int report_copy_exec(bContext *C, wmOperator *UNUSED(op))
static int report_copy_exec(bContext *C, wmOperator * /*op*/)
{
SpaceInfo *sinfo = CTX_wm_space_info(C);
ReportList *reports = CTX_wm_reports(C);
@ -365,7 +367,7 @@ static int report_copy_exec(bContext *C, wmOperator *UNUSED(op))
DynStr *buf_dyn = BLI_dynstr_new();
char *buf_str;
for (report = reports->list.first; report; report = report->next) {
for (report = static_cast<Report *>(reports->list.first); report; report = report->next) {
if ((report->type & report_mask) && (report->flag & SELECT)) {
BLI_dynstr_append(buf_dyn, report->message);
BLI_dynstr_append(buf_dyn, "\n");
@ -375,7 +377,7 @@ static int report_copy_exec(bContext *C, wmOperator *UNUSED(op))
buf_str = BLI_dynstr_get_cstring(buf_dyn);
BLI_dynstr_free(buf_dyn);
WM_clipboard_text_set(buf_str, 0);
WM_clipboard_text_set(buf_str, false);
MEM_freeN(buf_str);
return OPERATOR_FINISHED;

View File

@ -6,8 +6,8 @@
* \ingroup spinfo
*/
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -31,29 +31,29 @@
#include "BLO_read_write.h"
#include "info_intern.h" /* own include */
#include "info_intern.hh" /* own include */
/* ******************** default callbacks for info space ***************** */
static SpaceLink *info_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
static SpaceLink *info_create(const ScrArea * /*area*/, const Scene * /*scene*/)
{
ARegion *region;
SpaceInfo *sinfo;
sinfo = MEM_callocN(sizeof(SpaceInfo), "initinfo");
sinfo = static_cast<SpaceInfo *>(MEM_callocN(sizeof(SpaceInfo), "initinfo"));
sinfo->spacetype = SPACE_INFO;
sinfo->rpt_mask = INFO_RPT_OP;
/* header */
region = MEM_callocN(sizeof(ARegion), "header for info");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "header for info"));
BLI_addtail(&sinfo->regionbase, region);
region->regiontype = RGN_TYPE_HEADER;
region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
/* main region */
region = MEM_callocN(sizeof(ARegion), "main region for info");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "main region for info"));
BLI_addtail(&sinfo->regionbase, region);
region->regiontype = RGN_TYPE_WINDOW;
@ -72,18 +72,18 @@ static SpaceLink *info_create(const ScrArea *UNUSED(area), const Scene *UNUSED(s
return (SpaceLink *)sinfo;
}
/* not spacelink itself */
static void info_free(SpaceLink *UNUSED(sl))
/* Doesn't free the space-link itself. */
static void info_free(SpaceLink * /*sl*/)
{
// SpaceInfo *sinfo = (SpaceInfo *) sl;
}
/* spacetype; init callback */
static void info_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area)) {}
static void info_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
static SpaceLink *info_duplicate(SpaceLink *sl)
{
SpaceInfo *sinfon = MEM_dupallocN(sl);
SpaceInfo *sinfon = static_cast<SpaceInfo *>(MEM_dupallocN(sl));
/* clear or remove stuff from old */
@ -139,10 +139,10 @@ static void info_main_region_draw(const bContext *C, ARegion *region)
UI_view2d_view_restore(C);
/* scrollers */
UI_view2d_scrollers_draw(v2d, NULL);
UI_view2d_scrollers_draw(v2d, nullptr);
}
static void info_operatortypes(void)
static void info_operatortypes()
{
WM_operatortype_append(FILE_OT_autopack_toggle);
WM_operatortype_append(FILE_OT_pack_all);
@ -174,7 +174,7 @@ static void info_keymap(wmKeyConfig *keyconf)
}
/* add handlers, stuff you only do once or on area/region changes */
static void info_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
static void info_header_region_init(wmWindowManager * /*wm*/, ARegion *region)
{
ED_region_header_init(region);
}
@ -237,10 +237,10 @@ static void info_header_listener(const wmRegionListenerParams *params)
static void info_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
{
struct wmMsgBus *mbus = params->message_bus;
wmMsgBus *mbus = params->message_bus;
ARegion *region = params->region;
wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {NULL};
wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {nullptr};
msg_sub_value_region_tag_redraw.owner = region;
msg_sub_value_region_tag_redraw.user_data = region;
msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
@ -256,7 +256,7 @@ static void info_space_blend_write(BlendWriter *writer, SpaceLink *sl)
void ED_spacetype_info(void)
{
SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype info");
SpaceType *st = static_cast<SpaceType *>(MEM_callocN(sizeof(SpaceType), "spacetype info"));
ARegionType *art;
st->spaceid = SPACE_INFO;
@ -271,7 +271,7 @@ void ED_spacetype_info(void)
st->blend_write = info_space_blend_write;
/* regions: main window */
art = MEM_callocN(sizeof(ARegionType), "spacetype info region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype info region"));
art->regionid = RGN_TYPE_WINDOW;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES;
@ -282,7 +282,7 @@ void ED_spacetype_info(void)
BLI_addhead(&st->regiontypes, art);
/* regions: header */
art = MEM_callocN(sizeof(ARegionType), "spacetype info region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype info region"));
art->regionid = RGN_TYPE_HEADER;
art->prefsizey = HEADERY;

View File

@ -22,7 +22,7 @@
#include "UI_interface.h"
#include "UI_interface_icons.h"
#include "textview.h"
#include "textview.hh"
static void textview_font_begin(const int font_id, const int lheight)
{
@ -30,7 +30,7 @@ static void textview_font_begin(const int font_id, const int lheight)
BLF_size(font_id, 0.8f * lheight);
}
typedef struct TextViewDrawState {
struct TextViewDrawState {
int font_id;
int cwidth;
int lheight;
@ -50,7 +50,7 @@ typedef struct TextViewDrawState {
int *mval_pick_offset;
const int *mval; // [2]
bool do_draw;
} TextViewDrawState;
};
BLI_INLINE void textview_step_sel(TextViewDrawState *tds, const int step)
{
@ -99,10 +99,10 @@ static int textview_wrap_offsets(
*r_lines = 1;
*r_offsets = MEM_callocN(
*r_offsets = static_cast<int *>(MEM_callocN(
sizeof(**r_offsets) *
(str_len * BLI_UTF8_WIDTH_MAX / MAX2(1, width - (BLI_UTF8_WIDTH_MAX - 1)) + 1),
__func__);
__func__));
(*r_offsets)[0] = 0;
for (i = 0, end = width, j = 0; j < str_len && str[j]; j += BLI_str_utf8_size_safe(str + j)) {
@ -152,13 +152,13 @@ static bool textview_draw_string(TextViewDrawState *tds,
/* Wrap. */
if (tot_lines > 1) {
int iofs = (int)((float)(y_next - tds->mval[1]) / tds->lheight);
int iofs = int(float(y_next - tds->mval[1]) / tds->lheight);
ofs += offsets[MIN2(iofs, tot_lines - 1)];
}
/* Last part. */
ofs += BLI_str_utf8_offset_from_column(str + ofs,
(int)floor((float)tds->mval[0] / tds->cwidth));
int(floor(float(tds->mval[0]) / tds->cwidth)));
CLAMP(ofs, 0, str_len);
*tds->mval_pick_offset += str_len - ofs;
@ -213,16 +213,14 @@ static bool textview_draw_string(TextViewDrawState *tds,
rgba_uchar_to_float(col, icon_bg);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
UI_draw_roundbox_4fv(
&(const rctf){
.xmin = hpadding,
.xmax = bg_size + hpadding,
.ymin = line_top - bg_size - vpadding,
.ymax = line_top - vpadding,
},
true,
4 * UI_SCALE_FAC,
col);
rctf roundbox_rect;
roundbox_rect.xmin = hpadding;
roundbox_rect.xmax = bg_size + hpadding;
roundbox_rect.ymin = line_top - bg_size - vpadding;
roundbox_rect.ymax = line_top - vpadding;
UI_draw_roundbox_4fv(&roundbox_rect, true, 4 * UI_SCALE_FAC, col);
}
if (icon) {
@ -325,13 +323,13 @@ int textview_draw(TextViewContext *tvc,
CLAMPIS(mval_init[1], tvc->draw_rect.ymin, tvc->draw_rect.ymax) + tvc->scroll_ymin,
};
if (r_mval_pick_offset != NULL) {
if (r_mval_pick_offset != nullptr) {
*r_mval_pick_offset = 0;
}
/* Constants for the text-view context. */
tds.font_id = font_id;
tds.cwidth = (int)BLF_fixed_width(font_id);
tds.cwidth = int(BLF_fixed_width(font_id));
BLI_assert(tds.cwidth > 0);
tds.lheight = tvc->lheight;
tds.row_vpadding = tvc->row_vpadding;
@ -382,11 +380,11 @@ int textview_draw(TextViewContext *tvc,
&tds,
ext_line,
ext_len,
(data_flag & TVC_LINE_FG) ? fg : NULL,
(data_flag & TVC_LINE_BG) ? bg : NULL,
(data_flag & TVC_LINE_FG) ? fg : nullptr,
(data_flag & TVC_LINE_BG) ? bg : nullptr,
(data_flag & TVC_LINE_ICON) ? icon : 0,
(data_flag & TVC_LINE_ICON_FG) ? icon_fg : NULL,
(data_flag & TVC_LINE_ICON_BG) ? icon_bg : NULL,
(data_flag & TVC_LINE_ICON_FG) ? icon_fg : nullptr,
(data_flag & TVC_LINE_ICON_BG) ? icon_bg : nullptr,
bg_sel);
if (do_draw) {

View File

@ -15,6 +15,7 @@ enum eTextViewContext_LineFlag {
TVC_LINE_ICON_FG = (1 << 3),
TVC_LINE_ICON_BG = (1 << 4)
};
ENUM_OPERATORS(eTextViewContext_LineFlag, TVC_LINE_ICON_BG)
typedef struct TextViewContext {
/** Font size scaled by the interface size. */

View File

@ -114,7 +114,7 @@ static SpaceLink *nla_create(const ScrArea *area, const Scene *scene)
return (SpaceLink *)snla;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void nla_free(SpaceLink *sl)
{
SpaceNla *snla = (SpaceNla *)sl;

View File

@ -1185,7 +1185,7 @@ void ED_spacetype_node()
/* regions: toolbar */
art = MEM_cnew<ARegionType>("spacetype view3d tools region");
art->regionid = RGN_TYPE_TOOLS;
art->prefsizex = 58; /* XXX */
art->prefsizex = int(UI_TOOLBAR_WIDTH);
art->prefsizey = 50; /* XXX */
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
art->listener = node_region_listener;

View File

@ -354,7 +354,7 @@ static SpaceLink *outliner_create(const ScrArea * /*area*/, const Scene * /*scen
return (SpaceLink *)space_outliner;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void outliner_free(SpaceLink *sl)
{
SpaceOutliner *space_outliner = (SpaceOutliner *)sl;

View File

@ -62,7 +62,7 @@ static SpaceLink *script_create(const ScrArea *UNUSED(area), const Scene *UNUSED
return (SpaceLink *)sscript;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void script_free(SpaceLink *sl)
{
SpaceScript *sscript = (SpaceScript *)sl;

View File

@ -1064,7 +1064,7 @@ void ED_spacetype_sequencer(void)
/* Toolbar. */
art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer tools region");
art->regionid = RGN_TYPE_TOOLS;
art->prefsizex = 58; /* XXX */
art->prefsizex = (int)UI_TOOLBAR_WIDTH;
art->prefsizey = 50; /* XXX */
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
art->message_subscribe = ED_region_generic_tools_region_message_subscribe;

View File

@ -48,7 +48,7 @@ static SpaceLink *statusbar_create(const ScrArea *UNUSED(area), const Scene *UNU
return (SpaceLink *)sstatusbar;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void statusbar_free(SpaceLink *UNUSED(sl)) {}
/* spacetype; init callback */

View File

@ -84,7 +84,7 @@ static SpaceLink *text_create(const ScrArea * /*area*/, const Scene * /*scene*/)
return (SpaceLink *)stext;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void text_free(SpaceLink *sl)
{
SpaceText *stext = (SpaceText *)sl;

View File

@ -1625,7 +1625,7 @@ void draw_text_main(SpaceText *st, ARegion *region)
txt_clean_text(text);
}
/* update rects for scroll */
/* Update rectangles for scroll. */
calc_text_rcts(st, region, &scroll, &back); /* scroll will hold the entire bar size */
/* update syntax formatting if needed */

View File

@ -51,7 +51,7 @@
static void txt_screen_clamp(SpaceText *st, ARegion *region);
/* -------------------------------------------------------------------- */
/** \name Util
/** \name Utilities
* \{ */
/**

View File

@ -65,7 +65,7 @@ static SpaceLink *topbar_create(const ScrArea *UNUSED(area), const Scene *UNUSED
return (SpaceLink *)stopbar;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void topbar_free(SpaceLink *UNUSED(sl)) {}
/* spacetype; init callback */

View File

@ -77,7 +77,7 @@ static SpaceLink *userpref_create(const ScrArea *area, const Scene *UNUSED(scene
return (SpaceLink *)spref;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void userpref_free(SpaceLink *UNUSED(sl))
{
// SpaceUserPref *spref = (SpaceUserPref *)sl;

View File

@ -308,7 +308,7 @@ static SpaceLink *view3d_create(const ScrArea * /*area*/, const Scene *scene)
return (SpaceLink *)v3d;
}
/* not spacelink itself */
/* Doesn't free the space-link itself. */
static void view3d_free(SpaceLink *sl)
{
View3D *vd = (View3D *)sl;
@ -2172,7 +2172,7 @@ void ED_spacetype_view3d()
/* regions: tool(bar) */
art = MEM_cnew<ARegionType>("spacetype view3d tools region");
art->regionid = RGN_TYPE_TOOLS;
art->prefsizex = 58; /* XXX */
art->prefsizex = int(UI_TOOLBAR_WIDTH);
art->prefsizey = 50; /* XXX */
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
art->listener = view3d_buttons_region_listener;

View File

@ -3276,7 +3276,7 @@ static eSnapMode transform_snap_context_project_view3d_mixed_impl(SnapObjectCont
sctx->ret.dist_sq = FLT_MAX;
sctx->ret.is_edit = false;
BLI_assert((snap_to_flag & SCE_SNAP_MODE_GEOM) != 0);
BLI_assert(snap_to_flag & (SCE_SNAP_MODE_GEOM | SCE_SNAP_MODE_FACE_NEAREST));
eSnapMode retval = SCE_SNAP_MODE_NONE;

View File

@ -1783,7 +1783,7 @@ static float pack_islands_scale_margin(const Span<PackIsland *> islands,
rctf locked_bounds = {0.0f}; /* AABB of islands which can't translate. */
int64_t locked_island_count = 0; /* Index of first non-locked island. */
for (int64_t i = 0; i < islands.size(); i++) {
PackIsland *pack_island = islands[i];
PackIsland *pack_island = islands[aabbs[i]->index];
if (pack_island->can_translate_(params)) {
break;
}
@ -1796,6 +1796,12 @@ static float pack_islands_scale_margin(const Span<PackIsland *> islands,
}
float2 top_right = pack_island->pivot_ + pack_island->half_diagonal_;
BLI_rctf_do_minmax_v(&locked_bounds, top_right);
uv_phi &phi = r_phis[aabbs[i]->index]; /* Lock in place. */
phi.translation = pack_island->pivot_;
sub_v2_v2(phi.translation, params.udim_base_offset);
phi.rotation = 0.0f;
locked_island_count = i + 1;
}

View File

@ -383,6 +383,21 @@ struct MTLContextTextureUtils {
}
};
class MTLContextComputeUtils {
private:
id<MTLComputePipelineState> buffer_clear_pso_ = nil;
public:
id<MTLComputePipelineState> get_buffer_clear_pso();
void cleanup()
{
if (buffer_clear_pso_) {
[buffer_clear_pso_ release];
buffer_clear_pso_ = nil;
}
}
};
/* Combined sampler state configuration for Argument Buffer caching. */
struct MTLSamplerArray {
uint num_samplers;
@ -703,6 +718,7 @@ class MTLContext : public Context {
/* Compute and specialization caches. */
MTLContextTextureUtils texture_utils_;
MTLContextComputeUtils compute_utils_;
/* Texture Samplers. */
/* Cache of generated #MTLSamplerState objects based on permutations of the members of
@ -865,6 +881,12 @@ class MTLContext : public Context {
return texture_utils_;
}
/* Compute utilities. */
MTLContextComputeUtils &get_compute_utils()
{
return compute_utils_;
}
bool get_active()
{
return is_active_;

View File

@ -287,6 +287,7 @@ MTLContext::~MTLContext()
/* Release update/blit shaders. */
this->get_texture_utils().cleanup();
this->get_compute_utils().cleanup();
/* Detach resource references. */
GPU_texture_unbind_all();
@ -1483,10 +1484,10 @@ bool MTLContext::ensure_buffer_bindings(
uint32_t buffer_bind_index = pipeline_state_instance.base_storage_buffer_index +
buffer_index;
/* Bind Vertex UBO. */
/* Bind Compute SSBO. */
if (bool(ssbo.stage_mask & ShaderStage::COMPUTE)) {
BLI_assert(buffer_bind_index >= 0 && buffer_bind_index < MTL_MAX_BUFFER_BINDINGS);
cs.bind_compute_buffer(ssbo_buffer, 0, buffer_bind_index);
cs.bind_compute_buffer(ssbo_buffer, 0, buffer_bind_index, true);
}
}
else {
@ -2455,6 +2456,77 @@ id<MTLSamplerState> MTLContext::get_default_sampler_state()
/** \} */
/* -------------------------------------------------------------------- */
/** \name Compute Utils Implementation
* \{ */
id<MTLComputePipelineState> MTLContextComputeUtils::get_buffer_clear_pso()
{
if (buffer_clear_pso_ != nil) {
return buffer_clear_pso_;
}
/* Fetch active context. */
MTLContext *ctx = static_cast<MTLContext *>(unwrap(GPU_context_active_get()));
BLI_assert(ctx);
@autoreleasepool {
/* Source as NSString. */
const char *src =
"\
struct BufferClearParams {\
uint clear_value;\
};\
kernel void compute_buffer_clear(constant BufferClearParams &params [[buffer(0)]],\
device uint32_t* output_data [[buffer(1)]],\
uint position [[thread_position_in_grid]])\
{\
output_data[position] = params.clear_value;\
}";
NSString *compute_buffer_clear_src = [NSString stringWithUTF8String:src];
/* Prepare shader library for buffer clearing. */
MTLCompileOptions *options = [[[MTLCompileOptions alloc] init] autorelease];
options.languageVersion = MTLLanguageVersion2_2;
NSError *error = nullptr;
id<MTLLibrary> temp_lib = [[ctx->device newLibraryWithSource:compute_buffer_clear_src
options:options
error:&error] autorelease];
if (error) {
/* Only exit out if genuine error and not warning. */
if ([[error localizedDescription] rangeOfString:@"Compilation succeeded"].location ==
NSNotFound) {
NSLog(@"Compile Error - Metal Shader Library error %@ ", error);
BLI_assert(false);
return nil;
}
}
/* Fetch compute function. */
BLI_assert(temp_lib != nil);
id<MTLFunction> temp_compute_function = [[temp_lib newFunctionWithName:@"compute_buffer_clear"]
autorelease];
BLI_assert(temp_compute_function);
/* Compile compute PSO */
buffer_clear_pso_ = [ctx->device newComputePipelineStateWithFunction:temp_compute_function
error:&error];
if (error || buffer_clear_pso_ == nil) {
NSLog(@"Failed to prepare compute_buffer_clear MTLComputePipelineState %@", error);
BLI_assert(false);
return nil;
}
[buffer_clear_pso_ retain];
}
BLI_assert(buffer_clear_pso_ != nil);
return buffer_clear_pso_;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Swap-chain management and Metal presentation.
* \{ */

View File

@ -45,12 +45,12 @@ void MTLIndexBuf::bind_as_ssbo(uint32_t binding)
this->flag_can_optimize(false);
this->free_optimized_buffer();
/* Ensure we have a valid IBO. */
BLI_assert(this->ibo_);
/* Ensure resource is initialized. */
this->upload_data();
/* Ensure we have a valid IBO. */
BLI_assert(this->ibo_);
/* Create MTLStorageBuffer to wrap this resource and use conventional binding. */
if (ssbo_wrapper_ == nullptr) {
ssbo_wrapper_ = new MTLStorageBuf(this, alloc_size_);
@ -61,8 +61,24 @@ void MTLIndexBuf::bind_as_ssbo(uint32_t binding)
void MTLIndexBuf::read(uint32_t *data) const
{
if (ibo_ != nullptr) {
/* Fetch active context. */
MTLContext *ctx = MTLContext::get();
BLI_assert(ctx);
/* Ensure data is flushed for host caches. */
id<MTLBuffer> source_buffer = ibo_->get_metal_buffer();
if (source_buffer.storageMode == MTLStorageModeManaged) {
id<MTLBlitCommandEncoder> enc = ctx->main_command_buffer.ensure_begin_blit_encoder();
[enc synchronizeResource:source_buffer];
}
/* Ensure GPU has finished operating on commands which may modify data. */
GPU_finish();
/* Read data. */
void *host_ptr = ibo_->get_host_ptr();
memcpy(data, host_ptr, size_get());
return;
}
BLI_assert(false && "Index buffer not ready to be read.");
}
@ -101,19 +117,27 @@ void MTLIndexBuf::upload_data()
}
/* Prepare Buffer and Upload Data. */
if (ibo_ == nullptr && data_ != nullptr) {
if (ibo_ == nullptr) {
alloc_size_ = this->size_get();
if (alloc_size_ == 0) {
MTL_LOG_WARNING("Warning! Trying to allocate index buffer with size=0 bytes");
}
else {
ibo_ = MTLContext::get_global_memory_manager()->allocate_with_data(alloc_size_, true, data_);
if (data_) {
ibo_ = MTLContext::get_global_memory_manager()->allocate_with_data(
alloc_size_, true, data_);
}
else {
ibo_ = MTLContext::get_global_memory_manager()->allocate(alloc_size_, true);
}
BLI_assert(ibo_);
ibo_->set_label(@"Index Buffer");
}
/* No need to keep copy of data_ in system memory. */
MEM_SAFE_FREE(data_);
if (data_) {
MEM_SAFE_FREE(data_);
}
}
}

View File

@ -218,10 +218,31 @@ void MTLStorageBuf::clear(uint32_t clear_value)
}
if (ctx) {
id<MTLBlitCommandEncoder> blit_encoder = ctx->main_command_buffer.ensure_begin_blit_encoder();
[blit_encoder fillBuffer:metal_buffer_->get_metal_buffer()
range:NSMakeRange(0, size_in_bytes_)
value:clear_value];
/* If all 4 bytes within clear value are equal, use the builtin fast-path for clearing. */
uint clear_byte = clear_value & 0xFF;
bool clear_value_bytes_equal = (clear_byte == (clear_value >> 8) & 0xFF) &&
(clear_byte == (clear_value >> 16) & 0xFF) &&
(clear_byte == (clear_value >> 24) & 0xFF);
if (clear_value_bytes_equal) {
id<MTLBlitCommandEncoder> blit_encoder =
ctx->main_command_buffer.ensure_begin_blit_encoder();
[blit_encoder fillBuffer:metal_buffer_->get_metal_buffer()
range:NSMakeRange(0, size_in_bytes_)
value:clear_byte];
}
else {
/* We need a special compute routine to update 32 bit values efficiently. */
id<MTLComputePipelineState> pso = ctx->get_compute_utils().get_buffer_clear_pso();
id<MTLComputeCommandEncoder> compute_encoder =
ctx->main_command_buffer.ensure_begin_compute_encoder();
MTLComputeState &cs = ctx->main_command_buffer.get_compute_state();
cs.bind_pso(pso);
cs.bind_compute_bytes(&clear_value, sizeof(uint32_t), 0);
cs.bind_compute_buffer(metal_buffer_->get_metal_buffer(), 0, 1, true);
[compute_encoder dispatchThreads:MTLSizeMake(size_in_bytes_ / sizeof(uint32_t), 1, 1)
threadsPerThreadgroup:MTLSizeMake(128, 1, 1)];
}
}
}
@ -250,11 +271,11 @@ void MTLStorageBuf::read(void *data)
/* Ensure GPU updates are flushed back to CPU. */
id<MTLBlitCommandEncoder> blit_encoder = ctx->main_command_buffer.ensure_begin_blit_encoder();
[blit_encoder synchronizeResource:metal_buffer_->get_metal_buffer()];
/* Ensure sync has occurred. */
GPU_finish();
}
/* Ensure sync has occurred. */
GPU_finish();
/* Read data. NOTE: Unless explicitly synchronized with GPU work, results may not be ready. */
memcpy(data, metal_buffer_->get_host_ptr(), size_in_bytes_);
}

View File

@ -340,10 +340,60 @@ void MTLVertBuf::bind_as_texture(uint binding)
void MTLVertBuf::read(void *data) const
{
/* Fetch active context. */
MTLContext *ctx = MTLContext::get();
BLI_assert(ctx);
BLI_assert(vbo_ != nullptr);
BLI_assert(usage_ != GPU_USAGE_DEVICE_ONLY);
void *host_ptr = vbo_->get_host_ptr();
memcpy(data, host_ptr, alloc_size_);
if (usage_ != GPU_USAGE_DEVICE_ONLY) {
/* Ensure data is flushed for host caches. */
id<MTLBuffer> source_buffer = vbo_->get_metal_buffer();
if (source_buffer.storageMode == MTLStorageModeManaged) {
id<MTLBlitCommandEncoder> enc = ctx->main_command_buffer.ensure_begin_blit_encoder();
[enc synchronizeResource:source_buffer];
}
/* Ensure GPU has finished operating on commands which may modify data. */
GPU_finish();
/* Simple direct read. */
void *host_ptr = vbo_->get_host_ptr();
memcpy(data, host_ptr, alloc_size_);
}
else {
/* Copy private data into temporary staging buffer. */
gpu::MTLBuffer *dst_tmp_vbo_ = MTLContext::get_global_memory_manager()->allocate(alloc_size_,
true);
id<MTLBuffer> source_buffer = vbo_->get_metal_buffer();
id<MTLBuffer> dest_buffer = dst_tmp_vbo_->get_metal_buffer();
BLI_assert(source_buffer != nil);
BLI_assert(dest_buffer != nil);
/* Ensure a blit command encoder is active for buffer copy operation. */
id<MTLBlitCommandEncoder> enc = ctx->main_command_buffer.ensure_begin_blit_encoder();
[enc copyFromBuffer:source_buffer
sourceOffset:0
toBuffer:dest_buffer
destinationOffset:0
size:min_ulul([dest_buffer length], [dest_buffer length])];
/* Flush newly copied data back to host-side buffer, if one exists.
* Ensures data and cache coherency for managed MTLBuffers. */
if (dest_buffer.storageMode == MTLStorageModeManaged) {
[enc synchronizeResource:dest_buffer];
}
/* wait for GPU. */
GPU_finish();
/* Simple direct read. */
void *host_ptr = dst_tmp_vbo_->get_host_ptr();
memcpy(data, host_ptr, alloc_size_);
dst_tmp_vbo_->free();
}
}
void MTLVertBuf::wrap_handle(uint64_t handle)

View File

@ -66,7 +66,7 @@ using uvec4 = uint4;
/* Compute decorators. */
#define TG threadgroup
#define barrier() threadgroup_barrier(mem_flags::mem_threadgroup)
#define barrier() threadgroup_barrier(mem_flags::mem_threadgroup | mem_flags::mem_device | mem_flags::mem_texture)
#ifdef MTL_USE_WORKGROUP_SIZE
/* Compute workgroup size. */

View File

@ -85,8 +85,8 @@ void VKTexture::generate_mipmap()
* individually. */
command_buffer.submit();
}
/* Ensure that all mipmap levels are in `VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL`. All miplevels are
* except the last one. */
/* Ensure that all mipmap levels are in `VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL`.
* All MIP-levels are except the last one. */
layout_ensure(context,
IndexRange(mipmaps_ - 1, 1),
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,

View File

@ -881,6 +881,12 @@ typedef struct NodeBilateralBlurData {
char _pad[2];
} NodeBilateralBlurData;
typedef struct NodeKuwaharaData {
short size;
short variation;
int smoothing;
} NodeKuwaharaData;
typedef struct NodeAntiAliasingData {
float threshold;
float contrast_limit;
@ -2136,6 +2142,12 @@ typedef enum CMPNodeGlareType {
CMP_NODE_GLARE_GHOST = 3,
} CMPNodeGlareType;
/* Kuwahara Node. Stored in variation */
typedef enum CMPNodeKuwahara {
CMP_NODE_KUWAHARA_CLASSIC = 0,
CMP_NODE_KUWAHARA_ANISOTROPIC = 1,
} CMPNodeKuwahara;
/* Stabilize 2D node. Stored in custom1. */
typedef enum CMPNodeStabilizeInterpolation {
CMP_NODE_STABILIZE_INTERPOLATION_NEAREST = 0,

View File

@ -2328,7 +2328,7 @@ ENUM_OPERATORS(eSnapMode, SCE_SNAP_MODE_FACE_RAYCAST)
#define SCE_SNAP_MODE_GEOM \
(SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE | \
SCE_SNAP_MODE_EDGE_PERPENDICULAR | SCE_SNAP_MODE_EDGE_MIDPOINT | SCE_SNAP_MODE_FACE_NEAREST)
SCE_SNAP_MODE_EDGE_PERPENDICULAR | SCE_SNAP_MODE_EDGE_MIDPOINT)
/** #SequencerToolSettings.snap_mode */
#define SEQ_SNAP_TO_STRIPS (1 << 0)

View File

@ -729,8 +729,8 @@ static void rna_ID_asset_data_set(PointerRNA *ptr, PointerRNA value, struct Repo
{
ID *destination = ptr->data;
/* Avoid marking as asset by assigning. This should be done wiht .asset_mark(). This is just for
* clarity of the API, and to accomodate future changes. */
/* Avoid marking as asset by assigning. This should be done with `.asset_mark()`.
* This is just for clarity of the API, and to accommodate future changes. */
if (destination->asset_data == NULL) {
BKE_report(reports,
RPT_ERROR,
@ -741,7 +741,7 @@ static void rna_ID_asset_data_set(PointerRNA *ptr, PointerRNA value, struct Repo
const AssetMetaData *asset_data = value.data;
if (asset_data == NULL) {
/* Avoid clearing the asset data on assets. Un-marking as asset should be done with
* .asset_clear(). This is just for clarity of the API, and to accomodate future changes. */
* `.asset_clear()`. This is just for clarity of the API, and to accommodate future changes. */
BKE_report(reports, RPT_ERROR, "Asset data cannot be None");
return;
}

View File

@ -9374,6 +9374,43 @@ static void def_cmp_denoise(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_cmp_kuwahara(StructRNA *srna)
{
PropertyRNA *prop;
RNA_def_struct_sdna_from(srna, "NodeKuwaharaData", "storage");
static const EnumPropertyItem variation_items[] = {
{0, "CLASSIC", 0, "Classic", "Fast but less accurate variation"},
{1, "ANISOTROPIC", 0, "Anisotropic", "Accurate but slower variation"},
{0, NULL, 0, NULL, NULL},
};
prop = RNA_def_property(srna, "size", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "size");
RNA_def_property_range(prop, 1.0, 100.0);
RNA_def_property_ui_range(prop, 1, 100, 1, -1);
RNA_def_property_ui_text(
prop, "Size", "Size of filter. Larger values give stronger stylized effect");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
prop = RNA_def_property(srna, "variation", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "variation");
RNA_def_property_enum_items(prop, variation_items);
RNA_def_property_ui_text(prop, "", "Variation of Kuwahara filter to use");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
prop = RNA_def_property(srna, "smoothing", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "smoothing");
RNA_def_property_range(prop, 0.0, 50.0);
RNA_def_property_ui_range(prop, 0, 50, 1, -1);
RNA_def_property_ui_text(prop,
"Smoothing",
"Smoothing degree before applying filter. Higher values remove details "
"and give smoother edges");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_cmp_antialiasing(StructRNA *srna)
{
PropertyRNA *prop;

View File

@ -2066,7 +2066,7 @@ static const EnumPropertyItem *rna_SpaceProperties_context_itemf(bContext *UNUSE
}
}
RNA_enum_item_end(&item, &totitem);
RNA_enum_item_end(&item, &totitem_added);
*r_free = true;
return item;

View File

@ -224,6 +224,7 @@ DefNode(CompositorNode, CMP_NODE_COMBINE_XYZ, 0, "COMBIN
DefNode(CompositorNode, CMP_NODE_SEPARATE_XYZ, 0, "SEPARATE_XYZ", SeparateXYZ, "Separate XYZ", "" )
DefNode(CompositorNode, CMP_NODE_SEPARATE_COLOR, def_cmp_combsep_color, "SEPARATE_COLOR", SeparateColor, "Separate Color", "" )
DefNode(CompositorNode, CMP_NODE_COMBINE_COLOR, def_cmp_combsep_color, "COMBINE_COLOR", CombineColor, "Combine Color", "" )
DefNode(CompositorNode, CMP_NODE_KUWAHARA, def_cmp_kuwahara, "KUWAHARA", Kuwahara, "Kuwahara", "" )
DefNode(TextureNode, TEX_NODE_OUTPUT, def_tex_output, "OUTPUT", Output, "Output", "" )
DefNode(TextureNode, TEX_NODE_CHECKER, 0, "CHECKER", Checker, "Checker", "" )

View File

@ -77,6 +77,7 @@ set(SRC
nodes/node_composite_invert.cc
nodes/node_composite_keying.cc
nodes/node_composite_keyingscreen.cc
nodes/node_composite_kuwahara.cc
nodes/node_composite_lensdist.cc
nodes/node_composite_levels.cc
nodes/node_composite_luma_matte.cc

Some files were not shown because too many files have changed in this diff Show More