[Bf-blender-cvs] [a34611b4531] sculpt-dev: Sculpt-dev: Roughed out brush channel C++ API.

Joseph Eagar noreply at git.blender.org
Sun Jan 23 21:56:58 CET 2022


Commit: a34611b4531d387fbd66047764e2c1f00885dccf
Author: Joseph Eagar
Date:   Sun Jan 23 12:52:46 2022 -0800
Branches: sculpt-dev
https://developer.blender.org/rBa34611b4531d387fbd66047764e2c1f00885dccf

Sculpt-dev: Roughed out brush channel
            C++ API.

Basic idea is to wrap the C DNA structs
in a C++ wrapper class.  Instances of
this class are then passed around by
value.

Rewrote BKE_brush_channelset_get_final_float
and BKE_brush_channelset_get_final_vector to
use these classes.  Seems to work, will test
more.

Also, added a bunch of files that git failed
to add in the last merge.

===================================================================

M	source/blender/blenkernel/BKE_brush_engine.hh
A	source/blender/blenkernel/BKE_idprop.hh
M	source/blender/blenkernel/intern/brush_engine.c
M	source/blender/blenkernel/intern/brush_engine.cc
A	source/blender/blenkernel/intern/idprop_create.cc
A	source/blender/blenkernel/intern/idprop_serialize.cc
A	source/blender/blenkernel/intern/idprop_serialize_test.cc
A	source/blender/blenkernel/intern/lib_remap_test.cc
A	source/blender/blenkernel/intern/mesh_debug.cc
A	source/blender/bmesh/intern/bmesh_mesh_convert.cc
A	source/blender/bmesh/intern/bmesh_mesh_debug.c
A	source/blender/bmesh/intern/bmesh_mesh_debug.h
A	source/blender/draw/engines/workbench/shaders/workbench_effect_cavity_info.hh
A	source/blender/draw/engines/workbench/shaders/workbench_prepass_info.hh
A	source/blender/draw/engines/workbench/workbench_shader_shared.h
A	source/blender/draw/intern/draw_shader_shared.h
A	source/blender/draw/intern/shaders/draw_fullscreen_info.hh
A	source/blender/draw/intern/shaders/draw_object_infos_info.hh
A	source/blender/draw/intern/shaders/draw_view_info.hh
A	source/blender/gpu/GPU_shader_shared.h
A	source/blender/gpu/intern/gpu_shader_builder.cc
A	source/blender/gpu/intern/gpu_shader_builder_stubs.cc
A	source/blender/gpu/intern/gpu_shader_create_info.cc
A	source/blender/gpu/intern/gpu_shader_create_info.hh
A	source/blender/gpu/intern/gpu_shader_create_info_private.hh
A	source/blender/gpu/intern/gpu_shader_dependency.cc
A	source/blender/gpu/intern/gpu_shader_dependency_private.h
A	source/blender/gpu/intern/gpu_shader_info_baked.cc
A	source/blender/gpu/intern/gpu_shader_shared_utils.h
A	source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh
A	source/blender/gpu/shaders/infos/gpu_interface_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_area_borders_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_checker_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_diag_stripes_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_flat_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_image_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_image_desaturate_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_image_multi_rect_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_merge_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_stereo_merge_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_image_shuffle_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_line_dashed_uniform_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_aa_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_outline_aa_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_point_varying_size_varying_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_smooth_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_2D_uniform_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_3D_depth_only_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_3D_flat_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_3D_image_modulate_alpha_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_3D_line_dashed_uniform_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_3D_point_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_3D_smooth_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_3D_uniform_color_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_gpencil_stroke_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_instance_varying_color_varying_size_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_keyframe_shape_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_simple_lighting_info.hh
A	source/blender/gpu/shaders/infos/gpu_shader_text_info.hh
A	source/blender/gpu/shaders/infos/gpu_srgb_to_framebuffer_space_info.hh
A	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
A	source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc
A	source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc
A	source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc
A	source/blender/render/RE_texture_margin.h
A	source/blender/render/intern/texture_margin.cc
A	source/blender/sequencer/SEQ_animation.h
A	source/blender/sequencer/intern/animation.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_brush_engine.hh b/source/blender/blenkernel/BKE_brush_engine.hh
index 3e9dc9de1b0..f85286c6b62 100644
--- a/source/blender/blenkernel/BKE_brush_engine.hh
+++ b/source/blender/blenkernel/BKE_brush_engine.hh
@@ -1,53 +1,52 @@
-#if 1
-
-#  include "DNA_brush_enums.h"
-#  include "DNA_brush_types.h"
-#  include "DNA_color_types.h"
-#  include "DNA_curveprofile_types.h"
-#  include "DNA_material_types.h"
-#  include "DNA_node_types.h"
-#  include "DNA_sculpt_brush_types.h"
-
-#  include "BLI_compiler_attrs.h"
-#  include "BLI_compiler_compat.h"
-#  include "BLI_ghash.h"
-#  include "BLI_listbase.h"
-#  include "BLI_math.h"
-#  include "BLI_rand.h"
-#  include "BLI_rect.h"
-#  include "BLI_smallhash.h"
-#  include "BLI_utildefines.h"
-
-#  include "BKE_brush_engine.h"
-
-#  include "BKE_brush.h"
-#  include "BKE_brush_engine.h"
-#  include "BKE_colorband.h"
-#  include "BKE_colortools.h"
-#  include "BKE_context.h"
-#  include "BKE_curvemapping_cache.h"
-#  include "BKE_curveprofile.h"
-#  include "BKE_lib_override.h"
-#  include "BKE_lib_query.h"
-#  include "BKE_main.h"
-#  include "BKE_node.h"
-#  include "BKE_paint.h"
-
-#  include <algorithm>
-#  include <cmath>
-#  include <cstdio>
-#  include <string>
-#  include <type_traits>
-
-#  include "intern/brush_channel_names.hh"
-
-#  define IS_CACHE_CURVE(curve) BKE_curvemapping_in_cache(curve)
+
+#include "DNA_brush_enums.h"
+#include "DNA_brush_types.h"
+#include "DNA_color_types.h"
+#include "DNA_curveprofile_types.h"
+#include "DNA_material_types.h"
+#include "DNA_node_types.h"
+#include "DNA_sculpt_brush_types.h"
+
+#include "BLI_compiler_attrs.h"
+#include "BLI_compiler_compat.h"
+#include "BLI_ghash.h"
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_rand.h"
+#include "BLI_rect.h"
+#include "BLI_smallhash.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_brush_engine.h"
+
+#include "BKE_brush.h"
+#include "BKE_brush_engine.h"
+#include "BKE_colorband.h"
+#include "BKE_colortools.h"
+#include "BKE_context.h"
+#include "BKE_curvemapping_cache.h"
+#include "BKE_curveprofile.h"
+#include "BKE_lib_override.h"
+#include "BKE_lib_query.h"
+#include "BKE_main.h"
+#include "BKE_node.h"
+#include "BKE_paint.h"
+
+#include <algorithm>
+#include <cmath>
+#include <cstdio>
+#include <string>
+#include <type_traits>
+
+#include "intern/brush_channel_names.hh"
+
+#define IS_CACHE_CURVE(curve) BKE_curvemapping_in_cache(curve)
 // frees curve if it wasn't cached, returns cache curved
-#  define GET_CACHE_CURVE(curve) BKE_curvemapping_cache_get(brush_curve_cache, curve, true)
-#  define RELEASE_CACHE_CURVE(curve) BKE_curvemapping_cache_release(brush_curve_cache, curve)
-#  define RELEASE_OR_FREE_CURVE(curve) \
-    curve ? (BKE_curvemapping_cache_release_or_free(brush_curve_cache, curve), nullptr) : nullptr
-#  define CURVE_ADDREF(curve) BKE_curvemapping_cache_aquire(brush_curve_cache, curve)
+#define GET_CACHE_CURVE(curve) BKE_curvemapping_cache_get(brush_curve_cache, curve, true)
+#define RELEASE_CACHE_CURVE(curve) BKE_curvemapping_cache_release(brush_curve_cache, curve)
+#define RELEASE_OR_FREE_CURVE(curve) \
+  curve ? (BKE_curvemapping_cache_release_or_free(brush_curve_cache, curve), nullptr) : nullptr
+#define CURVE_ADDREF(curve) BKE_curvemapping_cache_aquire(brush_curve_cache, curve)
 
 struct CurveMappingCache *brush_curve_cache = NULL;
 extern BrushChannelType brush_builtin_channels[];
@@ -57,7 +56,8 @@ extern int brush_builtin_channel_len;
 
 /** return eithers a reference to a brush channel type,
    or if T is BrushCurve the (non-reference) BrushCurveIF wrapper type*/
-#  define BRUSH_VALUE_REF(T) typename std::conditional<std::is_same_v<T, BrushCurve>, BrushCurveIF, T &>::type
+#define BRUSH_VALUE_REF(T) \
+  typename std::conditional<std::is_same_v<T, BrushCurve>, BrushCurveIF, T &>::type
 
 template<class T> struct extract_float_array {
   using type = typename std::conditional<std::is_array_v<T>, float, T>::type;
@@ -155,6 +155,11 @@ template<typename T> class BrushChannelIF {
   {
   }
 
+  const int type()
+  {
+    return _channel->type;
+  }
+
   eBrushChannelFlag &flag()
   {
     eBrushChannelFlag *f = reinterpret_cast<eBrushChannelFlag *>(&_channel->flag);
@@ -220,7 +225,8 @@ template<typename T> class BrushChannelIF {
   }
 
   /* vectorIndex is only used for float[3] and float[4] specializations*/
-  typename extract_float_array<T>::type evaluate(BrushMappingData *mapping = nullptr, int vectorIndex = 0)
+  typename extract_float_array<T>::type evaluate(BrushMappingData *mapping = nullptr,
+                                                 int vectorIndex = 0)
   {
     if constexpr (std::is_same_v<T, float>) {
       return (float)_evaluate((double)_channel->fvalue, 0, mapping);
@@ -232,7 +238,7 @@ template<typename T> class BrushChannelIF {
       return fabs(_evaluate((double)(_channel->ivalue & 1), 0, mapping)) > FLT_EPSILON;
     }
     else if constexpr (std::is_same_v<T, float[3]> || std::is_same_v<T, float[4]>) {
-      return (float)_evaluate((double)_channel->vector, vectorIndex, mapping);
+      return (float)_evaluate((double)_channel->vector[vectorIndex], vectorIndex, mapping);
     }
 
     static_assert(!std::is_same_v<T, BrushCurveIF>, "cannot use evaluate with brush curves");
@@ -409,11 +415,10 @@ class BrushChannelSetIF {
   one in parentset, depending on inheritance flags.
   */
   template<typename T>
-  typename extract_float_array<T>::type
-  getFinalValue(BrushChannelSetIF &parentSet,
-                BrushChannelIF<T> ch,
-                BrushMappingData *mapping = nullptr,
-                int vectorIndex = 0)
+  typename extract_float_array<T>::type getFinalValue(BrushChannelSetIF &parentSet,
+                                                      BrushChannelIF<T> ch,
+                                                      BrushMappingData *mapping = nullptr,
+                                                      int vectorIndex = 0)
   {
     BrushChannelIF<T> ch2;
 
@@ -463,8 +468,8 @@ examples:
   }
 */
 
-#  define BRUSH_CHANNEL_MAKE_CPP_LOOKUPS
-#  include "intern/brush_channel_define.h"
+#define BRUSH_CHANNEL_MAKE_CPP_LOOKUPS
+#include "intern/brush_channel_define.h"
 
  private:
   BrushChannelSet *_chset;
@@ -472,4 +477,3 @@ examples:
 
 }  // namespace brush
 }  // namespace blender
-#endif
diff --git a/source/blender/blenkernel/BKE_idprop.hh b/source/blender/blenkernel/BKE_idprop.hh
new file mode 100644
index 00000000000..782fa9c7404
--- /dev/null
+++ b/source/blender/blenkernel/BKE_idprop.hh
@@ -0,0 +1,93 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include "BKE_idprop.h"
+
+#include "BLI_serialize.hh"
+#include "BLI_span.hh"
+
+namespace blender::bke::idprop {
+
+/**
+ * \brief Convert the given `properties` to `Value` objects for serialization.
+ *
+ * `IDP_ID` and `IDP_IDPARRAY` are not supported and will be ignored.
+ *
+ * UI data such as max/min will not be serialized.
+ */
+std::unique_ptr<io::serialize::ArrayValue> convert_to_serialize_values(
+    const IDProperty *properties);
+
+/**
+ * \brief Convert the given `value` to an `IDProperty`.
+ */
+IDProperty *convert_from_serialize_value(const blender::io::serialize::Value &value);
+
+class IDPropertyDeleter {
+ public:
+  void operator()(IDProperty *id_prop)
+  {
+    IDP_FreeProperty(id_prop);
+  }
+};
+
+/** \brief Allocate a new IDProperty of type IDP_INT, set its name and value. */
+std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name, int32_t value);
+
+/** \brief Allocate a new IDProperty of type IDP_FLOAT, set its name and value. */
+std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name, float value);
+
+/** \brief Allocate a new IDProperty of type IDP_DOUBLE, set its name and value. */
+std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name, double value);
+
+/** \brief Allocate a new IDProperty of type IDP_STRING, set its name and value. */
+std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
+                                                      const StringRefNull value);
+
+/**
+ * \brief Allocate a new IDProperty of type IDP_ARRAY and subtype IDP_INT.
+ *
+ * \param values: The values will be copied into the IDProperty.
+ */
+std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
+                                                      Span<int32_t> values);
+
+/**
+ * \brief Allocate a new IDProperty of type IDP_ARRAY and subtype IDP_FLOAT.
+ *
+ * \param values: The values will be copied into the IDProperty.
+ */
+std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name, Span<float> values);
+
+/**
+ * \brief Allocate a new IDProperty of type IDP_ARRAY and subtype IDP_DOUBLE.
+ *
+ * \param values: The values will be copied into the IDProperty.
+ */
+std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name,
+                                                      Span<double> values);
+
+/**
+ * \brief Allocate a new IDProperty of type IDP_GROUP.
+ *
+ * \param prop_name: The name of the newly created property.
+ */
+
+std::unique_ptr<IDProperty, IDPropertyDeleter> create_group(StringRefNull prop_name);
+
+}  // namespace blender::bke::idprop
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index f8089957673..c8559dd94dd 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/ble

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list