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.
131 changed files with 1888 additions and 939 deletions
Showing only changes of commit cbee6639ce - Show all commits

View File

@ -5,8 +5,24 @@
#ifdef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H
# undef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H
-# define _DEBUG
+// BLENDER: TBB excepts this to have a value.
+// BLENDER: TBB expects this to have a value.
+# define _DEBUG 1
# ifdef _CRT_NOFORCE_MANIFEST_DEFINED_FROM_WRAP_PYTHON_H
# undef _CRT_NOFORCE_MANIFEST_DEFINED_FROM_WRAP_PYTHON_H
# undef _CRT_NOFORCE_MANIFEST
--- a/boost/config/stdlib/libcpp.hpp 2022-08-03 22:47:07.000000000 -0400
+++ b/boost/config/stdlib/libcpp.hpp 2022-09-16 22:16:17.044119011 -0400
@@ -168,4 +168,13 @@
# define BOOST_NO_CXX14_HDR_SHARED_MUTEX
#endif
+#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 15000
+//
+// Unary function is now deprecated in C++11 and later:
+//
+#if __cplusplus >= 201103L
+#define BOOST_NO_CXX98_FUNCTION_BASE
+#endif
+#endif
+
// --- end ---

View File

@ -1,5 +1,10 @@
# SPDX-License-Identifier: GPL-2.0-or-later
if(CMAKE_COMPILER_IS_GNUCC)
# NOTE: Resolved up-stream, quiet noisy compiler warnings for now.
add_cxx_flag("-Wno-uninitialized")
endif()
set(INC
include
)

View File

@ -104,7 +104,7 @@ ccl_device int bsdf_ashikhmin_velvet_sample(ccl_private const ShaderClosure *sc,
float cosHI = fabsf(dot(wi, H));
float cosNH = dot(N, H);
if (!(fabsf(cosNI) > 1e-5f && fabsf(cosNH) < 1.0f - 1e-5f && cosHI > 1e-5f)) {
if (!(cosNI > 1e-5f && fabsf(cosNH) < 1.0f - 1e-5f && cosHI > 1e-5f)) {
*pdf = 0.0f;
*eval = zero_spectrum();
return LABEL_NONE;

View File

@ -224,7 +224,7 @@ ccl_device void osl_closure_dielectric_bsdf_setup(KernelGlobals kg,
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
}
}
/* GGX (either single- or multiscattering) */
/* GGX (either single- or multi-scattering). */
else {
if (has_reflection && has_transmission) {
sd->flag |= bsdf_microfacet_ggx_glass_setup(bsdf);
@ -278,7 +278,7 @@ ccl_device void osl_closure_conductor_bsdf_setup(KernelGlobals kg,
if (closure->distribution == make_string("beckmann", 14712237670914973463ull)) {
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
}
/* GGX (either single- or multiscattering) */
/* GGX (either single- or multi-scattering) */
else {
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
preserve_energy = (closure->distribution == make_string("multi_ggx", 16842698693386468366ull));
@ -338,7 +338,7 @@ ccl_device void osl_closure_generalized_schlick_bsdf_setup(
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
}
}
/* GGX (either single- or multiscattering) */
/* GGX (either single- or multi-scattering) */
else {
if (has_reflection && has_transmission) {
sd->flag |= bsdf_microfacet_ggx_glass_setup(bsdf);
@ -414,7 +414,7 @@ ccl_device void osl_closure_microfacet_setup(KernelGlobals kg,
else if (closure->distribution == make_string("ashikhmin_shirley", 11318482998918370922ull)) {
sd->flag |= bsdf_ashikhmin_shirley_setup(bsdf);
}
/* GGX (either single- or multiscattering) */
/* GGX (either single- or multi-scattering) */
else {
if (closure->refract == 1) {
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
@ -523,7 +523,7 @@ ccl_device void osl_closure_microfacet_aniso_fresnel_setup(
bsdf->ior = closure->ior;
bsdf->T = closure->T;
/* Only GGX (either single- or multiscattering) supported here */
/* Only GGX (either single- or multi-scattering) supported here */
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
const bool preserve_energy = (closure->distribution ==

View File

@ -47,7 +47,9 @@ shader node_texture_coordinate(
if (!getattribute("geom:generated", Generated)) {
Generated = transform("object", P);
}
getattribute("geom:uv", UV);
if (!getattribute("geom:uv", UV)) {
UV = point(1.0 - u - v, u, 0.0);
}
}
if (use_transform) {

View File

@ -26,7 +26,7 @@ closure color principled_diffuse(normal N, float roughness) BUILTIN;
closure color principled_sheen(normal N) BUILTIN;
closure color principled_clearcoat(normal N, float clearcoat, float clearcoat_roughness) BUILTIN;
/* Needed to pass along the color for multiscattering saturation adjustment,
/* Needed to pass along the color for multi-scattering saturation adjustment,
* otherwise could be replaced by microfacet() */
closure color microfacet_multi_ggx_glass(normal N, float ag, float eta, color C) BUILTIN;
closure color microfacet_multi_ggx_aniso(normal N, vector T, float ax, float ay, color C) BUILTIN;

View File

@ -71,6 +71,11 @@ ccl_device_noinline void svm_node_attr(KernelGlobals kg,
}
#endif
if (sd->type == PRIMITIVE_LAMP && node.y == ATTR_STD_UV) {
stack_store_float3(stack, out_offset, make_float3(1.0f - sd->u - sd->v, sd->u, 0.0f));
return;
}
if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
/* No generated attribute, fall back to object coordinates. */
float3 f = sd->P;

View File

@ -170,14 +170,15 @@ typedef enum {
GHOST_kModifierKeyNum
} GHOST_TModifierKey;
/**
* \note these values are stored in #wmWindow::windowstate,
* don't change, only add new values.
*/
typedef enum {
GHOST_kWindowStateNormal = 0,
GHOST_kWindowStateMaximized,
GHOST_kWindowStateMinimized,
GHOST_kWindowStateFullScreen,
GHOST_kWindowStateEmbedded,
// GHOST_kWindowStateModified,
// GHOST_kWindowStateUnModified,
GHOST_kWindowStateMaximized = 1,
GHOST_kWindowStateMinimized = 2,
GHOST_kWindowStateFullScreen = 3,
} GHOST_TWindowState;
typedef enum {

View File

@ -332,9 +332,6 @@ static bool gwl_window_state_set_for_libdecor(libdecor_frame *frame,
libdecor_frame_set_fullscreen(frame, nullptr);
break;
}
case GHOST_kWindowStateEmbedded: {
return false;
}
}
return true;
}
@ -377,9 +374,6 @@ static bool gwl_window_state_set_for_xdg(xdg_toplevel *toplevel,
xdg_toplevel_set_fullscreen(toplevel, nullptr);
break;
}
case GHOST_kWindowStateEmbedded: {
return false;
}
}
return true;
}

View File

@ -80,7 +80,7 @@ def keyconfig_update(keyconfig_data, keyconfig_version):
km_items.append(('ROTATE_NORMALS', {"type": 'N', "value": 'PRESS'}, None))
break
if keyconfig_version <= (3, 6, 3):
if keyconfig_version <= (4, 0, 3):
if not has_copy:
keyconfig_data = copy.deepcopy(keyconfig_data)
has_copy = True

View File

@ -8,7 +8,6 @@ from bpy.app.translations import pgettext_tip as tip_
def guess_player_path(preset):
import os
import sys
if preset == 'INTERNAL':
@ -17,6 +16,7 @@ def guess_player_path(preset):
elif preset == 'DJV':
player_path = "djv"
if sys.platform == "darwin":
import os
test_path = "/Applications/DJV2.app/Contents/Resources/bin/djv"
if os.path.exists(test_path):
player_path = test_path
@ -141,7 +141,15 @@ class PlayRenderedAnim(Operator):
opts = [file, "%d-%d" % (scene.frame_start, scene.frame_end)]
cmd.extend(opts)
elif preset == 'RV':
opts = ["-fps", str(rd.fps), "-play", "[ %s ]" % file]
opts = ["-fps", str(rd.fps), "-play"]
if scene.use_preview_range:
opts += [
"%s" % file.replace("#", "", file.count('#') - 1),
"%d-%d" % (frame_start, frame_end),
]
else:
opts.append(file)
cmd.extend(opts)
elif preset == 'MPLAYER':
opts = []

View File

@ -937,7 +937,6 @@ def brush_settings_advanced(layout, context, brush, popover=False):
col = layout.column(heading="Auto-Masking", align=True)
col = layout.column(align=True)
col.prop(brush, "use_automasking_topology", text="Topology")
col.prop(brush, "use_automasking_face_sets", text="Face Sets")

View File

@ -764,20 +764,26 @@ class NODE_PT_quality(bpy.types.Panel):
tree = snode.node_tree
prefs = bpy.context.preferences
use_realtime = False
col = layout.column()
if prefs.experimental.use_full_frame_compositor:
if prefs.experimental.use_experimental_compositors:
col.prop(tree, "execution_mode")
use_realtime = tree.execution_mode == 'REALTIME'
col = layout.column()
col.active = not use_realtime
col.prop(tree, "render_quality", text="Render")
col.prop(tree, "edit_quality", text="Edit")
col.prop(tree, "chunk_size")
col = layout.column()
col.active = not use_realtime
col.prop(tree, "use_opencl")
col.prop(tree, "use_groupnode_buffer")
col.prop(tree, "use_two_pass")
col.prop(tree, "use_viewer_border")
col.separator()
col = layout.column()
col.prop(snode, "use_auto_render")

View File

@ -25,7 +25,7 @@ if "_icon_cache" in locals():
del release
# (filename -> icon_value) map
# (icon_name -> icon_value) map
_icon_cache = {}
@ -236,14 +236,14 @@ class ToolSelectPanelHelper:
icon_value = _icon_cache.get(icon_name)
if icon_value is None:
dirname = bpy.utils.system_resource('DATAFILES', path="icons")
filename = os.path.join(dirname, icon_name + ".dat")
filepath = os.path.join(dirname, icon_name + ".dat")
try:
icon_value = bpy.app.icons.new_triangles_from_file(filename)
icon_value = bpy.app.icons.new_triangles_from_file(filepath)
except Exception as ex:
if not os.path.exists(filename):
print("Missing icons:", filename, ex)
if not os.path.exists(filepath):
print("Missing icons:", filepath, ex)
else:
print("Corrupt icon:", filename, ex)
print("Corrupt icon:", filepath, ex)
# Use none as a fallback (avoids layout issues).
if icon_name != "none":
icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle("none")

View File

@ -2417,7 +2417,7 @@ class USERPREF_PT_experimental_prototypes(ExperimentalPanel, Panel):
({"property": "use_new_curves_tools"}, ("blender/blender/issues/68981", "#68981")),
({"property": "use_new_point_cloud_type"}, ("blender/blender/issues/75717", "#75717")),
({"property": "use_sculpt_texture_paint"}, ("blender/blender/issues/96225", "#96225")),
({"property": "use_full_frame_compositor"}, ("blender/blender/issues/88150", "#88150")),
({"property": "use_experimental_compositors"}, ("blender/blender/issues/88150", "#88150")),
({"property": "enable_eevee_next"}, ("blender/blender/issues/93220", "#93220")),
({"property": "enable_workbench_next"}, ("blender/blender/issues/101619", "#101619")),
({"property": "use_grease_pencil_version3"}, ("blender/blender/projects/40", "Grease Pencil 3.0")),

View File

@ -2028,7 +2028,7 @@ class VIEW3D_MT_select_edit_gpencil(Menu):
layout.operator("grease_pencil.select_all", text="None").action = 'DESELECT'
layout.operator("grease_pencil.select_all", text="Invert").action = 'INVERT'
layout.separator()
layout.separator()
class VIEW3D_MT_select_paint_mask(Menu):

View File

@ -65,7 +65,7 @@ void BKE_blendfile_read_setup_readfile(struct bContext *C,
const char *startup_app_template);
/**
* Simpler version of #BKE_blendfile_read_setup_readfile used when reading undoe steps from
* Simpler version of #BKE_blendfile_read_setup_readfile used when reading undo steps from
* memfile. */
void BKE_blendfile_read_setup_undo(struct bContext *C,
struct BlendFileData *bfd,

View File

@ -75,15 +75,13 @@ bool BKE_texture_dependsOnTime(const struct Tex *texture);
*/
bool BKE_texture_is_image_user(const struct Tex *tex);
void BKE_texture_get_value_ex(const struct Scene *scene,
struct Tex *texture,
void BKE_texture_get_value_ex(struct Tex *texture,
const float *tex_co,
struct TexResult *texres,
struct ImagePool *pool,
bool use_color_management);
void BKE_texture_get_value(const struct Scene *scene,
struct Tex *texture,
void BKE_texture_get_value(struct Tex *texture,
const float *tex_co,
struct TexResult *texres,
bool use_color_management);

View File

@ -21,6 +21,7 @@ struct MovieClipUser;
struct MovieDistortion;
struct MovieReconstructContext;
struct MovieTracking;
struct MovieTrackingCamera;
struct MovieTrackingMarker;
struct MovieTrackingObject;
struct MovieTrackingPlaneMarker;
@ -464,6 +465,16 @@ void BKE_tracking_camera_principal_point_pixel_get(struct MovieClip *clip,
void BKE_tracking_camera_principal_point_pixel_set(struct MovieClip *clip,
const float principal_point_pixel[2]);
/* Compares distortion related parameters of camera. Ideally, this implementation will be
* abstracted away in the future, but for now, one needs to be careful about it and handle any
* extra parameters of distortions models. */
bool BKE_tracking_camera_distortion_equal(const struct MovieTrackingCamera *a,
const struct MovieTrackingCamera *b);
/* Hashes distortion related parameters of camera. Ideally, this implementation will be
* abstracted away in the future, but for now, one needs to be careful about it and handle any
* extra parameters of distortions models. */
uint64_t BKE_tracking_camera_distortion_hash(const struct MovieTrackingCamera *camera);
/* --------------------------------------------------------------------
* (Un)distortion.
*/

View File

@ -1852,7 +1852,7 @@ void BKE_pose_blend_write(BlendWriter *writer, bPose *pose, bArmature *arm)
animviz_motionpath_blend_write(writer, chan->mpath);
/* Prevent crashes with autosave,
/* Prevent crashes with auto-save,
* when a bone duplicated in edit-mode has not yet been assigned to its pose-channel.
* Also needed with memundo, in some cases we can store a step before pose has been
* properly rebuilt from previous undo step. */

View File

@ -114,10 +114,10 @@ AnimData *BKE_animdata_ensure_id(ID *id)
return NULL;
}
/* Action / Tmpact Setter shared code -------------------------
/* Action / `tmpact` Setter shared code -------------------------
*
* Both the action and tmpact setter functions have essentially
* identical semantics, because tmpact is just a place to temporarily
* Both the action and `tmpact` setter functions have essentially
* identical semantics, because `tmpact` is just a place to temporarily
* store the main action during tweaking. This function contains the
* shared code between those two setter functions, setting the action
* of the passed `act_slot` to `act`.

View File

@ -65,7 +65,7 @@ static void pchan_deform_accumulate(const DualQuat *deform_dq,
BLI_assert(!co_accum);
if (deform_dq->scale_weight) {
/* FIX https://projects.blender.org/blender/blender/issues/32022 */
/* FIX #32022. */
DualQuat mdq = *deform_dq;
float dst[3];
mul_v3_m4v3(dst, mdq.scale, co_in);

View File

@ -208,14 +208,13 @@ static void setup_app_userdef(BlendFileData *bfd)
BKE_blender_userdef_data_set_and_free(bfd->user);
bfd->user = nullptr;
/* Security issue: any blend file could include a USER block.
/* Security issue: any blend file could include a #BLO_CODE_USER block.
*
* Currently we load prefs from BLENDER_STARTUP_FILE and later on load BLENDER_USERPREF_FILE,
* to load the preferences defined in the users home dir.
* Preferences are loaded from #BLENDER_STARTUP_FILE and later on load #BLENDER_USERPREF_FILE,
* to load the preferences defined in the users home directory.
*
* This means we will never accidentally (or maliciously)
* enable scripts auto-execution by loading a '.blend' file.
*/
* enable scripts auto-execution by loading a `.blend` file. */
U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
}
}
@ -251,7 +250,7 @@ typedef struct ReuseOldBMainData {
* NOTE: The case where the `old_bmain` would be a library in the newly read one is not handled
* here, as it does not create explicit issues. The local data from `old_bmain` is either
* discarded, or added to the `new_bmain` as local data as well. Worst case, there will be a
* doublon of a linked data as a local one, without any known relationships between them. In
* double of a linked data as a local one, without any known relationships between them. In
* practice, this latter case is not expected to commonly happen.
*/
static IDRemapper *reuse_bmain_data_remapper_ensure(ReuseOldBMainData *reuse_data)
@ -747,7 +746,7 @@ static void setup_app_data(bContext *C,
wmWindow *win = nullptr;
bScreen *curscreen = nullptr;
/* Ensure that there is a valid scene and viewlayer. */
/* Ensure that there is a valid scene and view-layer. */
if (curscene == nullptr) {
curscene = static_cast<Scene *>(bfd->main->scenes.first);
}
@ -904,7 +903,7 @@ static void setup_app_data(bContext *C,
bmain->filepath[0] = '\0';
}
else if (recover) {
/* In case of autosave or quit.blend, use original filepath instead. */
/* In case of auto-save or quit.blend, use original filepath instead. */
bmain->recovered = true;
STRNCPY(bmain->filepath, bfd->filepath);
}

View File

@ -1931,7 +1931,7 @@ static void sample_mesh(FluidFlowSettings *ffs,
tex_co[1] = tex_co[1] * 2.0f - 1.0f;
tex_co[2] = ffs->texture_offset;
}
BKE_texture_get_value(nullptr, ffs->noise_texture, tex_co, &texres, false);
BKE_texture_get_value(ffs->noise_texture, tex_co, &texres, false);
emission_strength *= texres.tin;
}
}

View File

@ -14,7 +14,7 @@
*
* Usage:
*
* ```
* \code{.cc}
* Image *image = ...;
* ImBuf *image_buffer = ...;
*
@ -44,8 +44,7 @@
*
* // Free partial_update_user.
* BKE_image_partial_update_free(partial_update_user);
*
* ```
* \endcode
*/
#include <optional>

View File

@ -331,7 +331,6 @@ static void library_foreach_node_socket(LibraryForeachIDData *data, bNodeSocket
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -479,7 +478,6 @@ static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *so
case SOCK_CUSTOM:
/* Custom node sockets where default_value is defined uses custom properties for storage. */
break;
case SOCK_MESH_DEPRECATED:
case SOCK_SHADER:
case SOCK_GEOMETRY:
BLI_assert_unreachable();
@ -923,7 +921,6 @@ static void lib_link_node_socket(BlendLibReader *reader, ID *self_id, bNodeSocke
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -1016,7 +1013,6 @@ static void expand_node_socket(BlendExpander *expander, bNodeSocket *sock)
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -1705,7 +1701,6 @@ static void socket_id_user_increment(bNodeSocket *sock)
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -1751,7 +1746,6 @@ static bool socket_id_user_decrement(bNodeSocket *sock)
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -1804,7 +1798,6 @@ void nodeModifySocketType(bNodeTree *ntree,
case SOCK_SHADER:
case SOCK_BOOLEAN:
case SOCK_CUSTOM:
case SOCK_MESH_DEPRECATED:
case SOCK_OBJECT:
case SOCK_IMAGE:
case SOCK_GEOMETRY:
@ -1944,7 +1937,6 @@ const char *nodeStaticSocketType(const int type, const int subtype)
case SOCK_MATERIAL:
return "NodeSocketMaterial";
case SOCK_CUSTOM:
case SOCK_MESH_DEPRECATED:
break;
}
return nullptr;
@ -2024,7 +2016,6 @@ const char *nodeStaticSocketInterfaceType(const int type, const int subtype)
case SOCK_MATERIAL:
return "NodeSocketInterfaceMaterial";
case SOCK_CUSTOM:
case SOCK_MESH_DEPRECATED:
break;
}
return nullptr;
@ -2060,7 +2051,6 @@ const char *nodeStaticSocketLabel(const int type, const int /*subtype*/)
case SOCK_MATERIAL:
return "Material";
case SOCK_CUSTOM:
case SOCK_MESH_DEPRECATED:
break;
}
return nullptr;
@ -2582,7 +2572,6 @@ static void *socket_value_storage(bNodeSocket &socket)
case SOCK_STRING:
/* We don't want do this now! */
return nullptr;
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:

View File

@ -705,22 +705,15 @@ bool BKE_texture_dependsOnTime(const Tex *texture)
/* ------------------------------------------------------------------------- */
void BKE_texture_get_value_ex(const Scene *scene,
Tex *texture,
void BKE_texture_get_value_ex(Tex *texture,
const float *tex_co,
TexResult *texres,
ImagePool *pool,
bool use_color_management)
{
int result_type;
bool do_color_manage = false;
if (scene && use_color_management) {
do_color_manage = BKE_scene_check_color_management_enabled(scene);
}
/* no node textures for now */
result_type = multitex_ext_safe(texture, tex_co, texres, pool, do_color_manage, false);
const int result_type = multitex_ext_safe(
texture, tex_co, texres, pool, use_color_management, false);
/* if the texture gave an RGB value, we assume it didn't give a valid
* intensity, since this is in the context of modifiers don't use perceptual color conversion.
@ -734,13 +727,12 @@ void BKE_texture_get_value_ex(const Scene *scene,
}
}
void BKE_texture_get_value(const Scene *scene,
Tex *texture,
void BKE_texture_get_value(Tex *texture,
const float *tex_co,
TexResult *texres,
bool use_color_management)
{
BKE_texture_get_value_ex(scene, texture, tex_co, texres, nullptr, use_color_management);
BKE_texture_get_value_ex(texture, tex_co, texres, nullptr, use_color_management);
}
static void texture_nodes_fetch_images_for_pool(Tex *texture, bNodeTree *ntree, ImagePool *pool)

View File

@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <cstdint>
#include <limits.h>
#include <math.h>
#include <memory.h>
@ -23,9 +24,12 @@
#include "BLI_bitmap_draw_2d.h"
#include "BLI_ghash.h"
#include "BLI_hash.hh"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector_types.hh"
#include "BLI_string.h"
#include "BLI_string_utils.h"
#include "BLI_threads.h"
@ -2197,6 +2201,66 @@ void BKE_tracking_camera_principal_point_pixel_set(MovieClip *clip,
principal_point_pixel, frame_width, frame_height, camera->principal_point);
}
bool BKE_tracking_camera_distortion_equal(const MovieTrackingCamera *a,
const MovieTrackingCamera *b)
{
if (a->pixel_aspect != b->pixel_aspect || a->focal != b->focal ||
!equals_v2v2(a->principal_point, b->principal_point))
{
return false;
}
if (a->distortion_model != b->distortion_model) {
return false;
}
switch (a->distortion_model) {
case TRACKING_DISTORTION_MODEL_POLYNOMIAL:
return a->k1 == b->k1 && a->k2 == b->k2 && a->k3 == b->k3;
case TRACKING_DISTORTION_MODEL_DIVISION:
return a->division_k1 == b->division_k1 && a->division_k2 == b->division_k2;
case TRACKING_DISTORTION_MODEL_NUKE:
return a->nuke_k1 == b->nuke_k1 && a->nuke_k2 == b->nuke_k2;
case TRACKING_DISTORTION_MODEL_BROWN:
return a->brown_k1 == b->brown_k1 && a->brown_k2 == b->brown_k2 &&
a->brown_k3 == b->brown_k3 && a->brown_k4 == b->brown_k4 &&
a->brown_p1 == b->brown_p1 && a->brown_p2 == b->brown_p2;
}
BLI_assert_unreachable();
return false;
}
uint64_t BKE_tracking_camera_distortion_hash(const MovieTrackingCamera *camera)
{
using namespace blender;
switch (camera->distortion_model) {
case TRACKING_DISTORTION_MODEL_POLYNOMIAL:
return get_default_hash_4(camera->distortion_model,
float2(camera->pixel_aspect, camera->focal),
float2(camera->principal_point),
float3(camera->k1, camera->k2, camera->k3));
case TRACKING_DISTORTION_MODEL_DIVISION:
return get_default_hash_4(camera->distortion_model,
float2(camera->pixel_aspect, camera->focal),
float2(camera->principal_point),
float2(camera->division_k1, camera->division_k2));
case TRACKING_DISTORTION_MODEL_NUKE:
return get_default_hash_4(camera->distortion_model,
float2(camera->pixel_aspect, camera->focal),
float2(camera->principal_point),
float2(camera->nuke_k1, camera->nuke_k2));
case TRACKING_DISTORTION_MODEL_BROWN:
return get_default_hash_4(
float2(camera->pixel_aspect, camera->focal),
float2(camera->principal_point),
float4(camera->brown_k1, camera->brown_k2, camera->brown_k3, camera->brown_k4),
float2(camera->brown_p1, camera->brown_p2));
}
BLI_assert_unreachable();
return 0;
}
/* --------------------------------------------------------------------
* (Un)distortion.
*/

View File

@ -205,8 +205,8 @@ eFileAttributes BLI_file_attributes(const char *path);
* Usage of this function is strongly discouraged as it is not thread safe. It will likely cause
* issues if there is an operation on another thread that does not expect the current working
* directory to change. This has been added to support USDZ export, which has a problematic
* "feature" described in this issue https://projects.blender.org/blender/blender/issues/99807. It
* will be removed if it is possible to resolve that issue upstream in the USD library.
* "feature" described in this issue #99807. It will be removed if it is possible to resolve
* that issue upstream in the USD library.
*
* \return true on success, false otherwise.
*/

View File

@ -91,6 +91,11 @@ template<typename T> inline T floor(const T &a)
return std::floor(a);
}
template<typename T> inline T round(const T &a)
{
return std::round(a);
}
/**
* Repeats the saw-tooth pattern even on negative numbers.
* ex: `mod_periodic(-3, 4) = 1`, `mod(-3, 4)= -3`
@ -127,6 +132,20 @@ template<typename T> inline T sqrt(const T &a)
return std::sqrt(a);
}
/* Inverse value.
* If the input is zero the output is NaN. */
template<typename T> inline T rcp(const T &a)
{
return T(1) / a;
}
/* Inverse value.
* If the input is zero the output is zero. */
template<typename T> inline T safe_rcp(const T &a)
{
return a ? T(1) / a : T(0);
}
template<typename T> inline T cos(const T &a)
{
return std::cos(a);

View File

@ -111,7 +111,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result = a;
for (int i = 0; i < Size; i++) {
result[i] = std::clamp(result[i], min[i], max[i]);
result[i] = math::clamp(result[i], min[i], max[i]);
}
return result;
}
@ -121,7 +121,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result = a;
for (int i = 0; i < Size; i++) {
result[i] = std::clamp(result[i], min, max);
result[i] = math::clamp(result[i], min, max);
}
return result;
}
@ -132,7 +132,7 @@ template<typename T, int Size>
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
BLI_assert(b[i] != 0);
result[i] = std::fmod(a[i], b[i]);
result[i] = math::mod(a[i], b[i]);
}
return result;
}
@ -143,7 +143,7 @@ template<typename T, int Size>
BLI_assert(b != 0);
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::fmod(a[i], b);
result[i] = math::mod(a[i], b);
}
return result;
}
@ -157,7 +157,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = (b[i] != 0) ? std::fmod(a[i], b[i]) : 0;
result[i] = (b[i] != 0) ? math::mod(a[i], b[i]) : 0;
}
return result;
}
@ -173,7 +173,7 @@ template<typename T, int Size>
}
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::fmod(a[i], b);
result[i] = math::mod(a[i], b);
}
return result;
}
@ -187,7 +187,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::pow(x[i], y);
result[i] = math::pow(x[i], y);
}
return result;
}
@ -201,7 +201,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::pow(x[i], y[i]);
result[i] = math::pow(x[i], y[i]);
}
return result;
}
@ -276,7 +276,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::floor(a[i]);
result[i] = math::floor(a[i]);
}
return result;
}
@ -286,7 +286,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::round(a[i]);
result[i] = math::round(a[i]);
}
return result;
}
@ -296,7 +296,62 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::ceil(a[i]);
result[i] = math::ceil(a[i]);
}
return result;
}
/**
* Per-element square root.
* Negative elements are evaluated to NaN.
*/
template<typename T, int Size>
[[nodiscard]] inline VecBase<T, Size> sqrt(const VecBase<T, Size> &a)
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = math::sqrt(a[i]);
}
return result;
}
/**
* Per-element square root.
* Negative elements are evaluated to zero.
*/
template<typename T, int Size>
[[nodiscard]] inline VecBase<T, Size> safe_sqrt(const VecBase<T, Size> &a)
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = a[i] >= T(0) ? math ::sqrt(a[i]) : T(0);
}
return result;
}
/**
* Per-element inverse.
* Zero elements are evaluated to NaN.
*/
template<typename T, int Size> [[nodiscard]] inline VecBase<T, Size> rcp(const VecBase<T, Size> &a)
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = math::rcp(a[i]);
}
return result;
}
/**
* Per-element inverse.
* Zero elements are evaluated to zero.
*/
template<typename T, int Size>
[[nodiscard]] inline VecBase<T, Size> safe_rcp(const VecBase<T, Size> &a)
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = math::safe_rcp(a[i]);
}
return result;
}
@ -306,7 +361,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = a[i] - std::floor(a[i]);
result[i] = math::fract(a[i]);
}
return result;
}
@ -332,9 +387,9 @@ template<typename T, int Size>
*/
template<typename T, int Size> [[nodiscard]] inline T length_manhattan(const VecBase<T, Size> &a)
{
T result = std::abs(a[0]);
T result = math::abs(a[0]);
for (int i = 1; i < Size; i++) {
result += std::abs(a[i]);
result += math::abs(a[i]);
}
return result;
}
@ -346,7 +401,7 @@ template<typename T, int Size> [[nodiscard]] inline T length_squared(const VecBa
template<typename T, int Size> [[nodiscard]] inline T length(const VecBase<T, Size> &a)
{
return std::sqrt(length_squared(a));
return math::sqrt(length_squared(a));
}
/** Return true if each individual column is unit scaled. Mainly for assert usage. */
@ -356,8 +411,8 @@ template<typename T, int Size> [[nodiscard]] inline bool is_unit_scale(const Vec
* normalized and in the case we don't want NAN to be raising asserts since there
* is nothing to be done in that case. */
const T test_unit = math::length_squared(v);
return (!(std::abs(test_unit - T(1)) >= AssertUnitEpsilon<T>::value) ||
!(std::abs(test_unit) >= AssertUnitEpsilon<T>::value));
return (!(math::abs(test_unit - T(1)) >= AssertUnitEpsilon<T>::value) ||
!(math::abs(test_unit) >= AssertUnitEpsilon<T>::value));
}
template<typename T, int Size>
@ -593,7 +648,7 @@ template<typename T, int Size>
const T epsilon = T(0))
{
for (int i = 0; i < Size; i++) {
if (std::abs(a[i] - b[i]) > epsilon) {
if (math::abs(a[i] - b[i]) > epsilon) {
return false;
}
}

View File

@ -253,7 +253,7 @@ static float BLI_convexhull_aabb_fit_hull_2d(const float (*points_hull)[2], int
i_prev = i;
}
return (area_best != FLT_MAX) ? atan2f(dvec_best[0], dvec_best[1]) : 0.0f;
return (area_best != FLT_MAX) ? (float)atan2(dvec_best[0], dvec_best[1]) : 0.0f;
}
float BLI_convexhull_aabb_fit_points_2d(const float (*points)[2], int n)

View File

@ -136,4 +136,40 @@ TEST(math_vector, Sign)
EXPECT_FLOAT_EQ(result.z, 0);
}
TEST(math_vector, sqrt)
{
const float3 a(1.0f, 4.0f, 9.0f);
const float3 result = math::sqrt(a);
EXPECT_NEAR(result.x, 1.0f, 1e-6f);
EXPECT_NEAR(result.y, 2.0f, 1e-6f);
EXPECT_NEAR(result.z, 3.0f, 1e-6f);
}
TEST(math_vector, safe_sqrt)
{
const float3 a(1.0f, -4.0f, 9.0f);
const float3 result = math::safe_sqrt(a);
EXPECT_NEAR(result.x, 1.0f, 1e-6f);
EXPECT_NEAR(result.y, 0.0f, 1e-6f);
EXPECT_NEAR(result.z, 3.0f, 1e-6f);
}
TEST(math_vector, rcp)
{
const float3 a(1.0f, 2.0f, 4.0f);
const float3 result = math::rcp(a);
EXPECT_NEAR(result.x, 1.0f, 1e-6f);
EXPECT_NEAR(result.y, 0.5f, 1e-6f);
EXPECT_NEAR(result.z, 0.25f, 1e-6f);
}
TEST(math_vector, safe_rcp)
{
const float3 a(1.0f, 0.0f, 4.0f);
const float3 result = math::safe_rcp(a);
EXPECT_NEAR(result.x, 1.0f, 1e-6f);
EXPECT_NEAR(result.y, 0.0f, 1e-6f);
EXPECT_NEAR(result.z, 0.25f, 1e-6f);
}
} // namespace blender::tests

View File

@ -47,8 +47,8 @@ typedef struct WorkspaceConfigFileData {
typedef enum eBlenFileType {
BLENFILETYPE_BLEND = 1,
/* BLENFILETYPE_PUB = 2, */ /* UNUSED */
/* BLENFILETYPE_RUNTIME = 3, */ /* UNUSED */
// BLENFILETYPE_PUB = 2, /* UNUSED */
// BLENFILETYPE_RUNTIME = 3, /* UNUSED */
} eBlenFileType;
typedef struct BlendFileData {
@ -59,17 +59,24 @@ typedef struct BlendFileData {
int globalf;
char filepath[1024]; /* 1024 = FILE_MAX */
struct bScreen *curscreen; /* TODO: think this isn't needed anymore? */
/** TODO: think this isn't needed anymore? */
struct bScreen *curscreen;
struct Scene *curscene;
struct ViewLayer *cur_view_layer; /* layer to activate in workspaces when reading without UI */
/** Layer to activate in workspaces when reading without UI. */
struct ViewLayer *cur_view_layer;
eBlenFileType type;
} BlendFileData;
/** Data used by WM readfile code and BKE's setup_app_data to handle the complex preservation logic
* of WindowManager and other UI data-blocks across blendfile reading prcess. */
/**
* Data used by WM readfile code and BKE's setup_app_data to handle the complex preservation logic
* of WindowManager and other UI data-blocks across blend-file reading process.
*/
typedef struct BlendFileReadWMSetupData {
struct wmWindowManager *old_wm; /** The existing WM when filereading process is started. */
/** The existing WM when filereading process is started. */
struct wmWindowManager *old_wm;
bool is_read_homefile;
} BlendFileReadWMSetupData;
struct BlendFileReadParams {
@ -81,10 +88,10 @@ struct BlendFileReadParams {
};
typedef struct BlendFileReadReport {
/* General reports handling. */
/** General reports handling. */
struct ReportList *reports;
/* Timing information. */
/** Timing information. */
struct {
double whole;
double libraries;
@ -93,38 +100,44 @@ typedef struct BlendFileReadReport {
double lib_overrides_recursive_resync;
} duration;
/* Count information. */
/** Count information. */
struct {
/* Some numbers of IDs that ended up in a specific state, or required some specific process
* during this file read. */
/**
* Some numbers of IDs that ended up in a specific state, or required some specific process
* during this file read.
*/
int missing_libraries;
int missing_linked_id;
/* Some sub-categories of the above `missing_linked_id` counter. */
/** Some sub-categories of the above `missing_linked_id` counter. */
int missing_obdata;
int missing_obproxies;
/* Number of root override IDs that were resynced. */
/** Number of root override IDs that were resynced. */
int resynced_lib_overrides;
/* Number of proxies converted to library overrides. */
/** Number of proxies converted to library overrides. */
int proxies_to_lib_overrides_success;
/* Number of proxies that failed to convert to library overrides. */
/** Number of proxies that failed to convert to library overrides. */
int proxies_to_lib_overrides_failures;
/* Number of sequencer strips that were not read because were in non-supported channels. */
/** Number of sequencer strips that were not read because were in non-supported channels. */
int sequence_strips_skipped;
} count;
/* Number of libraries which had overrides that needed to be resynced, and a single linked list
* of those. */
/**
* Number of libraries which had overrides that needed to be resynced,
* and a single linked list of those.
*/
int resynced_lib_overrides_libraries_count;
bool do_resynced_lib_overrides_libraries_list;
struct LinkNode *resynced_lib_overrides_libraries;
} BlendFileReadReport;
/* skip reading some data-block types (may want to skip screen data too). */
/** Skip reading some data-block types (may want to skip screen data too). */
typedef enum eBLOReadSkip {
BLO_READ_SKIP_NONE = 0,
/** Skip #BLO_CODE_USER blocks. */
BLO_READ_SKIP_USERDEF = (1 << 0),
/** Only read #BLO_CODE_USER (and associated data). */
BLO_READ_SKIP_DATA = (1 << 1),
/** Do not attempt to re-use IDs from old bmain for unchanged ones in case of undo. */
BLO_READ_SKIP_UNDO_OLD_MAIN = (1 << 2),
@ -133,7 +146,7 @@ ENUM_OPERATORS(eBLOReadSkip, BLO_READ_SKIP_UNDO_OLD_MAIN)
#define BLO_READ_SKIP_ALL (BLO_READ_SKIP_USERDEF | BLO_READ_SKIP_DATA)
/**
* Open a blender file from a pathname. The function returns NULL
* Open a blender file from a `filepath`. The function returns NULL
* and sets a report in the list if it cannot open the file.
*
* \param filepath: The path of the file to open.
@ -189,10 +202,12 @@ typedef struct BLODataBlockInfo {
char name[64]; /* MAX_NAME */
struct AssetMetaData *asset_data;
bool free_asset_data;
/* Optimization: Tag data-blocks for which we know there is no preview.
/**
* Optimization: Tag data-blocks for which we know there is no preview.
* Knowing this can be used to skip the (potentially expensive) preview loading process. If this
* is set to true it means we looked for a preview and couldn't find one. False may mean that
* either no preview was found, or that it wasn't looked for in the first place. */
* either no preview was found, or that it wasn't looked for in the first place.
*/
bool no_preview_found;
} BLODataBlockInfo;
@ -336,9 +351,11 @@ typedef enum eBLOLibLinkFlags {
BLO_LIBLINK_FORCE_INDIRECT = 1 << 17,
/** Set fake user on appended IDs. */
BLO_LIBLINK_APPEND_SET_FAKEUSER = 1 << 19,
/** Append (make local) also indirect dependencies of appended IDs coming from other libraries.
/**
* Append (make local) also indirect dependencies of appended IDs coming from other libraries.
* NOTE: All IDs (including indirectly linked ones) coming from the same initial library are
* always made local. */
* always made local.
*/
BLO_LIBLINK_APPEND_RECURSIVE = 1 << 20,
/** Try to re-use previously appended matching ID on new append. */
BLO_LIBLINK_APPEND_LOCAL_ID_REUSE = 1 << 21,
@ -437,7 +454,7 @@ typedef struct TempLibraryContext {
struct LibraryLink_Params liblink_params;
struct Library *lib;
/* The ID datablock that was loaded. Is NULL if loading failed. */
/** The ID datablock that was loaded. Is NULL if loading failed. */
struct ID *temp_id;
} TempLibraryContext;
@ -485,7 +502,7 @@ void BLO_expand_main(void *fdhandle, struct Main *mainvar);
void BLO_update_defaults_startup_blend(struct Main *bmain, const char *app_template);
void BLO_update_defaults_workspace(struct WorkSpace *workspace, const char *app_template);
/* Disable unwanted experimental feature settings on startup. */
/** Disable unwanted experimental feature settings on startup. */
void BLO_sanitize_experimental_features_userpref_blend(struct UserDef *userdef);
/**
@ -498,8 +515,9 @@ void BLO_sanitize_experimental_features_userpref_blend(struct UserDef *userdef);
*/
struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath);
/* datafiles (generated theme) */
/** Default theme, see: `release/datafiles/userdef/userdef_default_theme.c`. */
extern const struct bTheme U_theme_default;
/** Default preferences, defined by: `release/datafiles/userdef/userdef_default.c`. */
extern const struct UserDef U_default;
#ifdef __cplusplus

View File

@ -126,7 +126,7 @@
* - read associated 'direct data'
* - link direct data (internal and to LibBlock)
* - read #FileGlobal
* - read #USER data, only when indicated (file is `~/.config/blender/X.XX/config/userpref.blend`)
* - read #USER data, only when indicated (file is `~/.config/blender/X.X/config/userpref.blend`)
* - free file
* - per Library (per #Main)
* - read file

View File

@ -206,7 +206,7 @@ bool BLO_memfile_write_file(MemFile *memfile, const char *filepath)
MemFileChunk *chunk;
int file, oflags;
/* NOTE: This is currently used for autosave and 'quit.blend',
/* NOTE: This is currently used for auto-save and `quit.blend`,
* where _not_ following symlinks is OK,
* however if this is ever executed explicitly by the user,
* we may want to allow writing to symlinks.

View File

@ -2184,46 +2184,6 @@ static void versioning_replace_legacy_mix_rgb_node(bNodeTree *ntree)
}
}
static void versioning_replace_legacy_glossy_node(bNodeTree *ntree)
{
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == SH_NODE_BSDF_GLOSSY_LEGACY) {
strcpy(node->idname, "ShaderNodeBsdfAnisotropic");
node->type = SH_NODE_BSDF_GLOSSY;
}
}
}
static void versioning_remove_microfacet_sharp_distribution(bNodeTree *ntree)
{
/* Find all glossy, glass and refraction BSDF nodes that have their distribution
* set to SHARP and set them to GGX, disconnect any link to the Roughness input
* and set its value to zero. */
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (!ELEM(node->type, SH_NODE_BSDF_GLOSSY, SH_NODE_BSDF_GLASS, SH_NODE_BSDF_REFRACTION)) {
continue;
}
if (node->custom1 != SHD_GLOSSY_SHARP_DEPRECATED) {
continue;
}
node->custom1 = SHD_GLOSSY_GGX;
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (!STREQ(socket->identifier, "Roughness")) {
continue;
}
if (socket->link != nullptr) {
nodeRemLink(ntree, socket->link);
}
bNodeSocketValueFloat *socket_value = (bNodeSocketValueFloat *)socket->default_value;
socket_value->value = 0.0f;
break;
}
}
}
static void version_fix_image_format_copy(Main *bmain, ImageFormatData *format)
{
/* Fix bug where curves in image format were not properly copied to file output
@ -4461,26 +4421,8 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
/* Convert anisotropic BSDF node to glossy BSDF. */
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
versioning_replace_legacy_glossy_node(ntree);
versioning_remove_microfacet_sharp_distribution(ntree);
}
FOREACH_NODETREE_END;
BKE_animdata_main_cb(bmain, version_liboverride_nla_frame_start_end, nullptr);
if (!MAIN_VERSION_ATLEAST(bmain, 306, 11)) {
BKE_animdata_main_cb(bmain, version_liboverride_nla_frame_start_end, NULL);
/* Store simulation bake directory in geometry nodes modifier. */
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
@ -4519,4 +4461,18 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
}
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - #do_versions_after_linking_300 in this file.
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
}
}

View File

@ -29,9 +29,23 @@
// static CLG_LogRef LOG = {"blo.readfile.doversion"};
void do_versions_after_linking_400(FileData * /*fd*/, Main *bmain)
void do_versions_after_linking_400(FileData * /*fd*/, Main * /*bmain*/)
{
UNUSED_VARS(bmain);
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - #blo_do_versions_400 in this file.
* - "versioning_cycles.cc", #blo_do_versions_cycles
* - "versioning_cycles.cc", #do_versions_after_linking_cycles
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
}
}
static void version_mesh_legacy_to_struct_of_array_format(Mesh &mesh)
@ -101,6 +115,46 @@ static void version_geometry_nodes_add_realize_instance_nodes(bNodeTree *ntree)
}
}
static void versioning_replace_legacy_glossy_node(bNodeTree *ntree)
{
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == SH_NODE_BSDF_GLOSSY_LEGACY) {
strcpy(node->idname, "ShaderNodeBsdfAnisotropic");
node->type = SH_NODE_BSDF_GLOSSY;
}
}
}
static void versioning_remove_microfacet_sharp_distribution(bNodeTree *ntree)
{
/* Find all glossy, glass and refraction BSDF nodes that have their distribution
* set to SHARP and set them to GGX, disconnect any link to the Roughness input
* and set its value to zero. */
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (!ELEM(node->type, SH_NODE_BSDF_GLOSSY, SH_NODE_BSDF_GLASS, SH_NODE_BSDF_REFRACTION)) {
continue;
}
if (node->custom1 != SHD_GLOSSY_SHARP_DEPRECATED) {
continue;
}
node->custom1 = SHD_GLOSSY_GGX;
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (!STREQ(socket->identifier, "Roughness")) {
continue;
}
if (socket->link != nullptr) {
nodeRemLink(ntree, socket->link);
}
bNodeSocketValueFloat *socket_value = (bNodeSocketValueFloat *)socket->default_value;
socket_value->value = 0.0f;
break;
}
}
}
void blo_do_versions_400(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
{
if (!MAIN_VERSION_ATLEAST(bmain, 400, 1)) {
@ -124,7 +178,9 @@ void blo_do_versions_400(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
}
}
if (!MAIN_VERSION_ATLEAST(bmain, 400, 4)) {
/* 400 4 did not require any do_version here. */
if (!MAIN_VERSION_ATLEAST(bmain, 400, 5)) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
#define SCE_SNAP_PROJECT (1 << 3)
if (scene->toolsettings->snap_flag & SCE_SNAP_PROJECT) {
@ -138,12 +194,22 @@ void blo_do_versions_400(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - #do_versions_after_linking_400 in this file.
* - "versioning_cycles.cc", #blo_do_versions_cycles
* - "versioning_cycles.cc", #do_versions_after_linking_cycles
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Convert anisotropic BSDF node to glossy BSDF. */
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
versioning_replace_legacy_glossy_node(ntree);
versioning_remove_microfacet_sharp_distribution(ntree);
}
FOREACH_NODETREE_END;
/* Keep this block, even when empty. */
}
}

View File

@ -50,10 +50,12 @@
* - write library block
* - per LibBlock
* - write the ID of LibBlock
* - write #TEST (#RenderInfo struct. 128x128 blend file preview is optional).
* - write #GLOB (#FileGlobal struct) (some global vars).
* - write #DNA1 (#SDNA struct)
* - write #USER (#UserDef struct) if filename is `~/.config/blender/X.XX/config/startup.blend`.
* - write #BLO_CODE_GLOB (#RenderInfo struct. 128x128 blend file preview is optional).
* - write #BLO_CODE_GLOB (#FileGlobal struct) (some global vars).
* - write #BLO_CODE_DNA1 (#SDNA struct)
* - write #BLO_CODE_USER (#UserDef struct) for file paths:
- #BLENDER_STARTUP_FILE (on UNIX `~/.config/blender/X.X/config/startup.blend`).
- #BLENDER_USERPREF_FILE (on UNIX `~/.config/blender/X.X/config/userpref.blend`).
*/
#include <cerrno>
@ -971,10 +973,10 @@ static void write_libraries(WriteData *wd, Main *main)
}
}
/* To be able to restore 'quit.blend' and temp saves,
/* To be able to restore `quit.blend` and temp saves,
* the packed blend has to be in undo buffers... */
/* XXX needs rethink, just like save UI in undo files now -
* would be nice to append things only for the 'quit.blend' and temp saves. */
* would be nice to append things only for the `quit.blend` and temp saves. */
if (found_one) {
/* Not overridable. */

View File

@ -66,8 +66,7 @@ const char *BLT_pgettext(const char *msgctxt, const char *msgid)
bool BLT_translate(void)
{
#ifdef WITH_INTERNATIONAL
return true;
/* return BLI_thread_is_main(); */
return BLI_thread_is_main();
#else
return false;
#endif

View File

@ -11,6 +11,8 @@
extern "C" {
#endif
struct Render;
/* Keep ascii art. */
/* clang-format off */
@ -294,6 +296,9 @@ extern "C" {
* It can be executed during editing (blenkernel/node.cc) or rendering
* (renderer/pipeline.c)
*
* \param render: [struct Render]
* Render instance for GPU context.
*
* \param render_data: [struct RenderData]
* Render data for this composite, this won't always belong to a scene.
*
@ -305,10 +310,10 @@ extern "C" {
* (true) or editing (false).
* based on this setting the system will work differently:
* - during rendering only Composite & the File output node will be calculated
* \see NodeOperation.is_output_program(int rendering) of the specific operations
* \see NodeOperation.is_output_program(bool rendering) of the specific operations
*
* - during editing all output nodes will be calculated
* \see NodeOperation.is_output_program(int rendering) of the specific operations
* \see NodeOperation.is_output_program(bool rendering) of the specific operations
*
* - another quality setting can be used bNodeTree.
* The quality is determined by the bNodeTree fields.
@ -326,10 +331,11 @@ extern "C" {
*/
/* clang-format off */
void COM_execute(RenderData *render_data,
void COM_execute(Render *render,
RenderData *render_data,
Scene *scene,
bNodeTree *node_tree,
int rendering,
bool rendering,
const char *view_name);
/**

View File

@ -14,6 +14,8 @@
#include "COM_WorkScheduler.h"
#include "COM_compositor.h"
#include "RE_compositor.hh"
static struct {
bool is_initialized = false;
ThreadMutex mutex;
@ -47,10 +49,11 @@ static void compositor_reset_node_tree_status(bNodeTree *node_tree)
node_tree->runtime->stats_draw(node_tree->runtime->sdh, IFACE_("Compositing"));
}
void COM_execute(RenderData *render_data,
void COM_execute(Render *render,
RenderData *render_data,
Scene *scene,
bNodeTree *node_tree,
int rendering,
bool rendering,
const char *view_name)
{
/* Initialize mutex, TODO: this mutex init is actually not thread safe and
@ -73,26 +76,41 @@ void COM_execute(RenderData *render_data,
compositor_init_node_previews(render_data, node_tree);
compositor_reset_node_tree_status(node_tree);
/* Initialize workscheduler. */
const bool use_opencl = (node_tree->flag & NTREE_COM_OPENCL) != 0;
blender::compositor::WorkScheduler::initialize(use_opencl, BKE_render_num_threads(render_data));
if (U.experimental.use_full_frame_compositor &&
node_tree->execution_mode == NTREE_EXECUTION_MODE_REALTIME)
{
/* Realtime GPU compositor. */
/* Execute. */
const bool twopass = (node_tree->flag & NTREE_TWO_PASS) && !rendering;
if (twopass) {
blender::compositor::ExecutionSystem fast_pass(
render_data, scene, node_tree, rendering, true, view_name);
fast_pass.execute();
if (node_tree->runtime->test_break(node_tree->runtime->tbh)) {
BLI_mutex_unlock(&g_compositor.mutex);
return;
}
/* TODO: add persistence and depsgraph updates for better performance. */
blender::render::RealtimeCompositor compositor(
*render, *scene, *render_data, *node_tree, rendering, view_name);
compositor.execute();
}
else {
/* Tiled and Full Frame compositors. */
blender::compositor::ExecutionSystem system(
render_data, scene, node_tree, rendering, false, view_name);
system.execute();
/* Initialize workscheduler. */
const bool use_opencl = (node_tree->flag & NTREE_COM_OPENCL) != 0;
blender::compositor::WorkScheduler::initialize(use_opencl,
BKE_render_num_threads(render_data));
/* Execute. */
const bool twopass = (node_tree->flag & NTREE_TWO_PASS) && !rendering;
if (twopass) {
blender::compositor::ExecutionSystem fast_pass(
render_data, scene, node_tree, rendering, true, view_name);
fast_pass.execute();
if (node_tree->runtime->test_break(node_tree->runtime->tbh)) {
BLI_mutex_unlock(&g_compositor.mutex);
return;
}
}
blender::compositor::ExecutionSystem system(
render_data, scene, node_tree, rendering, false, view_name);
system.execute();
}
BLI_mutex_unlock(&g_compositor.mutex);
}

View File

@ -9,6 +9,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
../../draw
../../gpu
../../imbuf
../../makesdna
@ -17,6 +18,9 @@ set(INC
../../render
../../gpu/intern
../../../../intern/guardedalloc
# dna_type_offsets.h
${CMAKE_CURRENT_BINARY_DIR}/../../makesdna/intern
)
set(INC_SYS
@ -74,6 +78,7 @@ set(SRC
cached_resources/intern/cached_mask.cc
cached_resources/intern/cached_texture.cc
cached_resources/intern/distortion_grid.cc
cached_resources/intern/morphological_distance_feather_weights.cc
cached_resources/intern/ocio_color_space_conversion_shader.cc
cached_resources/intern/smaa_precomputed_textures.cc
@ -83,6 +88,7 @@ set(SRC
cached_resources/COM_cached_mask.hh
cached_resources/COM_cached_resource.hh
cached_resources/COM_cached_texture.hh
cached_resources/COM_distortion_grid.hh
cached_resources/COM_morphological_distance_feather_weights.hh
cached_resources/COM_ocio_color_space_conversion_shader.hh
cached_resources/COM_smaa_precomputed_textures.hh
@ -133,6 +139,7 @@ set(GLSL_SRC
shaders/compositor_morphological_distance_feather.glsl
shaders/compositor_morphological_distance_threshold.glsl
shaders/compositor_morphological_step.glsl
shaders/compositor_movie_distortion.glsl
shaders/compositor_normalize.glsl
shaders/compositor_parallel_reduction.glsl
shaders/compositor_plane_deform.glsl
@ -234,6 +241,7 @@ set(SRC_SHADER_CREATE_INFOS
shaders/infos/compositor_morphological_distance_info.hh
shaders/infos/compositor_morphological_distance_threshold_info.hh
shaders/infos/compositor_morphological_step_info.hh
shaders/infos/compositor_movie_distortion_info.hh
shaders/infos/compositor_normalize_info.hh
shaders/infos/compositor_parallel_reduction_info.hh
shaders/infos/compositor_plane_deform_info.hh

View File

@ -42,8 +42,17 @@ class Context {
public:
Context(TexturePool &texture_pool);
/* Get the active compositing scene. */
virtual const Scene *get_scene() const = 0;
/* Get the node tree used for compositing. */
virtual const bNodeTree &get_node_tree() const = 0;
/* True if compositor should do write file outputs, false if only running for viewing. */
virtual bool use_file_output() const = 0;
/* True if color management should be used for texture evaluation. */
virtual bool use_texture_color_management() const = 0;
/* Get the render settings for compositing. */
virtual const RenderData &get_render_data() const = 0;
/* Get the width and height of the render passes and of the output texture returned by the
* get_input_texture and get_output_texture methods respectively. */
@ -63,7 +72,7 @@ class Context {
/* Get the texture where the given render pass is stored. This should be called by the Render
* Layer node to populate its outputs. */
virtual GPUTexture *get_input_texture(int view_layer, eScenePassType pass_type) = 0;
virtual GPUTexture *get_input_texture(int view_layer, const char *pass_name) = 0;
/* Get the name of the view currently being rendered. */
virtual StringRef get_view_name() = 0;

View File

@ -6,6 +6,7 @@
#include "COM_cached_mask.hh"
#include "COM_cached_texture.hh"
#include "COM_distortion_grid.hh"
#include "COM_morphological_distance_feather_weights.hh"
#include "COM_ocio_color_space_conversion_shader.hh"
#include "COM_smaa_precomputed_textures.hh"
@ -45,6 +46,7 @@ class StaticCacheManager {
CachedMaskContainer cached_masks;
SMAAPrecomputedTexturesContainer smaa_precomputed_textures;
OCIOColorSpaceConversionShaderContainer ocio_color_space_conversion_shaders;
DistortionGridContainer distortion_grids;
/* Reset the cache manager by deleting the cached resources that are no longer needed because
* they weren't used in the last evaluation and prepare the remaining cached resources to track

View File

@ -13,7 +13,6 @@
#include "GPU_texture.h"
#include "DNA_scene_types.h"
#include "DNA_texture_types.h"
#include "COM_cached_resource.hh"
@ -49,7 +48,7 @@ class CachedTexture : public CachedResource {
GPUTexture *value_texture_ = nullptr;
public:
CachedTexture(Tex *texture, const Scene *scene, int2 size, float2 offset, float2 scale);
CachedTexture(Tex *texture, bool use_color_management, int2 size, float2 offset, float2 scale);
~CachedTexture();
@ -74,8 +73,12 @@ class CachedTextureContainer : CachedResourceContainer {
* CachedTexture cached resource with the given parameters in the container, if one exists,
* return it, otherwise, return a newly created one and add it to the container. In both cases,
* tag the cached resource as needed to keep it cached for the next evaluation. */
CachedTexture &get(
Context &context, Tex *texture, const Scene *scene, int2 size, float2 offset, float2 scale);
CachedTexture &get(Context &context,
Tex *texture,
bool use_color_management,
int2 size,
float2 offset,
float2 scale);
};
} // namespace blender::realtime_compositor

View File

@ -0,0 +1,86 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include <cstdint>
#include <memory>
#include "BLI_map.hh"
#include "BLI_math_vector_types.hh"
#include "GPU_shader.h"
#include "GPU_texture.h"
#include "DNA_movieclip_types.h"
#include "COM_cached_resource.hh"
namespace blender::realtime_compositor {
enum class DistortionType : uint8_t {
Distort,
Undistort,
};
/* ------------------------------------------------------------------------------------------------
* Distortion Grid Key.
*/
class DistortionGridKey {
public:
MovieTrackingCamera camera;
int2 size;
DistortionType type;
int2 calibration_size;
DistortionGridKey(MovieTrackingCamera camera,
int2 size,
DistortionType type,
int2 calibration_size);
uint64_t hash() const;
};
bool operator==(const DistortionGridKey &a, const DistortionGridKey &b);
/* -------------------------------------------------------------------------------------------------
* Distortion Grid.
*
* A cached resource that computes and caches a GPU texture containing the normalized coordinates
* after applying the camera distortion of a given movie clip tracking camera. See the constructor
* for more information. */
class DistortionGrid : public CachedResource {
private:
GPUTexture *texture_ = nullptr;
public:
/* The calibration size is the size of the image where the tracking camera was calibrated, this
* is the size of the movie clip in most cases. */
DistortionGrid(MovieClip *movie_clip, int2 size, DistortionType type, int2 calibration_size);
~DistortionGrid();
void bind_as_texture(GPUShader *shader, const char *texture_name) const;
void unbind_as_texture() const;
};
/* ------------------------------------------------------------------------------------------------
* Distortion Grid Container.
*/
class DistortionGridContainer : CachedResourceContainer {
private:
Map<DistortionGridKey, std::unique_ptr<DistortionGrid>> map_;
public:
void reset() override;
/* Check if there is an available DistortionGrid cached resource with the given parameters in the
* container, if one exists, return it, otherwise, return a newly created one and add it to the
* container. In both cases, tag the cached resource as needed to keep it cached for the next
* evaluation. */
DistortionGrid &get(MovieClip *movie_clip, int2 size, DistortionType type, int frame_number);
};
} // namespace blender::realtime_compositor

View File

@ -51,7 +51,7 @@ bool operator==(const CachedTextureKey &a, const CachedTextureKey &b)
*/
CachedTexture::CachedTexture(
Tex *texture, const Scene *scene, int2 size, float2 offset, float2 scale)
Tex *texture, bool use_color_management, int2 size, float2 offset, float2 scale)
{
ImagePool *image_pool = BKE_image_pool_new();
BKE_texture_fetch_images_for_pool(texture, image_pool);
@ -67,7 +67,8 @@ CachedTexture::CachedTexture(
/* Note that it is expected that the offset is scaled by the scale. */
coordinates = (coordinates + offset) * scale;
TexResult texture_result;
BKE_texture_get_value_ex(scene, texture, coordinates, &texture_result, image_pool, true);
BKE_texture_get_value_ex(
texture, coordinates, &texture_result, image_pool, use_color_management);
color_pixels[y * size.x + x] = float4(texture_result.trgba);
value_pixels[y * size.x + x] = texture_result.talpha ? texture_result.trgba[3] :
texture_result.tin;
@ -131,8 +132,12 @@ void CachedTextureContainer::reset()
}
}
CachedTexture &CachedTextureContainer::get(
Context &context, Tex *texture, const Scene *scene, int2 size, float2 offset, float2 scale)
CachedTexture &CachedTextureContainer::get(Context &context,
Tex *texture,
bool use_color_management,
int2 size,
float2 offset,
float2 scale)
{
const CachedTextureKey key(size, offset, scale);
@ -143,8 +148,9 @@ CachedTexture &CachedTextureContainer::get(
cached_textures_for_id.clear();
}
auto &cached_texture = *cached_textures_for_id.lookup_or_add_cb(
key, [&]() { return std::make_unique<CachedTexture>(texture, scene, size, offset, scale); });
auto &cached_texture = *cached_textures_for_id.lookup_or_add_cb(key, [&]() {
return std::make_unique<CachedTexture>(texture, use_color_management, size, offset, scale);
});
cached_texture.needed = true;
return cached_texture;

View File

@ -0,0 +1,160 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include <cstdint>
#include <memory>
#include "BLI_array.hh"
#include "BLI_hash.hh"
#include "BLI_index_range.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_task.hh"
#include "DNA_defaults.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
#include "GPU_texture.h"
#include "BKE_movieclip.h"
#include "BKE_tracking.h"
#include "COM_distortion_grid.hh"
namespace blender::realtime_compositor {
/* --------------------------------------------------------------------
* Distortion Grid Key.
*/
DistortionGridKey::DistortionGridKey(MovieTrackingCamera camera,
int2 size,
DistortionType type,
int2 calibration_size)
: camera(camera), size(size), type(type), calibration_size(calibration_size)
{
}
uint64_t DistortionGridKey::hash() const
{
return get_default_hash_4(
BKE_tracking_camera_distortion_hash(&camera), size, type, calibration_size);
}
bool operator==(const DistortionGridKey &a, const DistortionGridKey &b)
{
return BKE_tracking_camera_distortion_equal(&a.camera, &b.camera) && a.size == b.size &&
a.type == b.type && a.calibration_size == b.calibration_size;
}
/* --------------------------------------------------------------------
* Distortion Grid.
*/
DistortionGrid::DistortionGrid(MovieClip *movie_clip,
int2 size,
DistortionType type,
int2 calibration_size)
{
MovieDistortion *distortion = BKE_tracking_distortion_new(
&movie_clip->tracking, calibration_size.x, calibration_size.y);
Array<float2> distortion_grid(size.x * size.y);
threading::parallel_for(IndexRange(size.y), 1, [&](const IndexRange sub_y_range) {
for (const int64_t y : sub_y_range) {
for (const int64_t x : IndexRange(size.x)) {
/* The tracking distortion functions expect the coordinates to be in the space of the image
* where the tracking camera was calibrated. So we first remap the coordinates into that
* space, apply the distortion, then remap back to the original coordinates space. This is
* done by dividing the by the size then multiplying by the calibration size, making sure
* to add 0.5 to evaluate at the center of pixels. */
float2 coordinates = ((float2(x, y) + 0.5f) / float2(size)) * float2(calibration_size);
if (type == DistortionType::Undistort) {
BKE_tracking_distortion_undistort_v2(distortion, coordinates, coordinates);
}
else {
BKE_tracking_distortion_distort_v2(distortion, coordinates, coordinates);
}
/* Note that we should remap the coordinates back into the original size by dividing by the
* calibration size and multiplying by the size, however, we skip the latter to store the
* coordinates in normalized form, since this is what the shader expects. */
distortion_grid[y * size.x + x] = coordinates / float2(calibration_size);
}
}
});
BKE_tracking_distortion_free(distortion);
texture_ = GPU_texture_create_2d("Distortion Grid",
size.x,
size.y,
1,
GPU_RG16F,
GPU_TEXTURE_USAGE_SHADER_READ,
*distortion_grid.data());
}
DistortionGrid::~DistortionGrid()
{
GPU_texture_free(texture_);
}
void DistortionGrid::bind_as_texture(GPUShader *shader, const char *texture_name) const
{
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name);
GPU_texture_bind(texture_, texture_image_unit);
}
void DistortionGrid::unbind_as_texture() const
{
GPU_texture_unbind(texture_);
}
/* --------------------------------------------------------------------
* Distortion Grid Container.
*/
void DistortionGridContainer::reset()
{
/* First, delete all resources that are no longer needed. */
map_.remove_if([](auto item) { return !item.value->needed; });
/* Second, reset the needed status of the remaining resources to false to ready them to track
* their needed status for the next evaluation. */
for (auto &value : map_.values()) {
value->needed = false;
}
}
static int2 get_movie_clip_size(MovieClip *movie_clip, int frame_number)
{
MovieClipUser user = *DNA_struct_default_get(MovieClipUser);
BKE_movieclip_user_set_frame(&user, frame_number);
int2 size;
BKE_movieclip_get_size(movie_clip, &user, &size.x, &size.y);
return size;
}
DistortionGrid &DistortionGridContainer::get(MovieClip *movie_clip,
int2 size,
DistortionType type,
int frame_number)
{
const int2 calibration_size = get_movie_clip_size(movie_clip, frame_number);
const DistortionGridKey key(movie_clip->tracking.camera, size, type, calibration_size);
auto &distortion_grid = *map_.lookup_or_add_cb(key, [&]() {
return std::make_unique<DistortionGrid>(movie_clip, size, type, calibration_size);
});
distortion_grid.needed = true;
return distortion_grid;
}
} // namespace blender::realtime_compositor

View File

@ -23,18 +23,19 @@ int2 Context::get_compositing_region_size() const
float Context::get_render_percentage() const
{
return get_scene()->r.size / 100.0f;
return get_render_data().size / 100.0f;
}
int Context::get_frame_number() const
{
return get_scene()->r.cfra;
return get_render_data().cfra;
}
float Context::get_time() const
{
const float frame_number = float(get_frame_number());
const float frame_rate = float(get_scene()->r.frs_sec) / float(get_scene()->r.frs_sec_base);
const float frame_rate = float(get_render_data().frs_sec) /
float(get_render_data().frs_sec_base);
return frame_number / frame_rate;
}

View File

@ -66,7 +66,7 @@ bool Evaluator::validate_node_tree()
void Evaluator::compile_and_evaluate()
{
derived_node_tree_ = std::make_unique<DerivedNodeTree>(*context_.get_scene()->nodetree);
derived_node_tree_ = std::make_unique<DerivedNodeTree>(context_.get_node_tree());
if (!validate_node_tree()) {
return;

View File

@ -0,0 +1,7 @@
#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utilities.glsl)
void main()
{
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
imageStore(output_img, texel, texture(input_tx, texture_load(distortion_grid_tx, texel).xy));
}

View File

@ -0,0 +1,13 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(compositor_movie_distortion)
.local_group_size(16, 16)
.sampler(0, ImageType::FLOAT_2D, "input_tx")
.sampler(1, ImageType::FLOAT_2D, "distortion_grid_tx")
.image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_img")
.compute_source("compositor_movie_distortion.glsl")
.do_static_compilation(true);

View File

@ -58,9 +58,24 @@ class Context : public realtime_compositor::Context {
{
}
const Scene *get_scene() const override
const bNodeTree &get_node_tree() const override
{
return DRW_context_state_get()->scene;
return *DRW_context_state_get()->scene->nodetree;
}
bool use_file_output() const override
{
return false;
}
bool use_texture_color_management() const override
{
return BKE_scene_check_color_management_enabled(DRW_context_state_get()->scene);
}
const RenderData &get_render_data() const override
{
return DRW_context_state_get()->scene->r;
}
int2 get_render_size() const override
@ -130,15 +145,20 @@ class Context : public realtime_compositor::Context {
return DRW_viewport_texture_list_get()->color;
}
GPUTexture *get_input_texture(int /*view_layer*/, eScenePassType /*pass_type*/) override
GPUTexture *get_input_texture(int view_layer, const char *pass_name) override
{
return get_output_texture();
if (view_layer == 0 && STREQ(pass_name, RE_PASSNAME_COMBINED)) {
return get_output_texture();
}
else {
return nullptr;
}
}
StringRef get_view_name() override
{
const SceneRenderView *view = static_cast<SceneRenderView *>(
BLI_findlink(&get_scene()->r.views, DRW_context_state_get()->v3d->multiview_eye));
BLI_findlink(&get_render_data().views, DRW_context_state_get()->v3d->multiview_eye));
return view->name;
}

View File

@ -373,7 +373,9 @@ static void try_convert_single_object(Object &curves_ob,
HairKey &key = hair_keys[key_i];
copy_v3_v3(key.co, key_pos_ha);
key.time = 100.0f * key_i / float(hair_keys.size() - 1);
const float key_fac = key_i / float(hair_keys.size() - 1);
key.time = 100.0f * key_fac;
key.weight = 1.0f - key_fac;
}
}

View File

@ -290,7 +290,8 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
uiItemR(sub, imfptr, "export_mesh_type_selection", 0, "", ICON_NONE);
if (RNA_boolean_get(imfptr, "include_animations")) {
uiItemR(col, imfptr, "export_animation_transformation_type_selection", 0, nullptr, ICON_NONE);
uiItemR(
col, imfptr, "export_animation_transformation_type_selection", 0, nullptr, ICON_NONE);
}
else {
uiItemR(col, imfptr, "export_object_transformation_type_selection", 0, nullptr, ICON_NONE);
@ -317,7 +318,8 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
uiLayoutSetActive(row, include_animations && animation_type == BC_ANIMATION_EXPORT_SAMPLES);
if (RNA_boolean_get(imfptr, "include_animations")) {
uiItemR(box, imfptr, "export_animation_transformation_type_selection", 0, nullptr, ICON_NONE);
uiItemR(
box, imfptr, "export_animation_transformation_type_selection", 0, nullptr, ICON_NONE);
}
else {
uiItemR(box, imfptr, "export_object_transformation_type_selection", 0, nullptr, ICON_NONE);

View File

@ -86,7 +86,7 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
const int resolution = RNA_int_get(op->ptr, "resolution");
const float scale = RNA_float_get(op->ptr, "scale");
GpencilIOParams params {};
GpencilIOParams params{};
params.C = C;
params.region = region;
params.v3d = v3d;

View File

@ -1086,7 +1086,7 @@ static void shader_preview_texture(ShaderPreview *sp, Tex *tex, Scene *sce, Rend
/* Fill in image buffer. */
float *rect_float = rv->combined_buffer.data;
float tex_coord[3] = {0.0f, 0.0f, 0.0f};
bool color_manage = true;
bool color_manage = BKE_scene_check_color_management_enabled(sce);
for (int y = 0; y < height; y++) {
/* Tex coords between -1.0f and 1.0f. */
@ -1097,7 +1097,7 @@ static void shader_preview_texture(ShaderPreview *sp, Tex *tex, Scene *sce, Rend
/* Evaluate texture at tex_coord. */
TexResult texres = {0};
BKE_texture_get_value_ex(sce, tex, tex_coord, &texres, img_pool, color_manage);
BKE_texture_get_value_ex(tex, tex_coord, &texres, img_pool, color_manage);
copy_v4_fl4(rect_float,
texres.trgba[0],
texres.trgba[1],

View File

@ -391,8 +391,7 @@ static int palette_color_add_exec(bContext *C, wmOperator * /*op*/)
PAINT_MODE_TEXTURE_3D,
PAINT_MODE_TEXTURE_2D,
PAINT_MODE_VERTEX,
PAINT_MODE_SCULPT))
{
PAINT_MODE_SCULPT)) {
copy_v3_v3(color->rgb, BKE_brush_color_get(scene, brush));
color->value = 0.0;
}

View File

@ -1196,7 +1196,7 @@ static const float std_node_socket_colors[][4] = {
{0.78, 0.78, 0.16, 1.0}, /* SOCK_RGBA */
{0.39, 0.78, 0.39, 1.0}, /* SOCK_SHADER */
{0.80, 0.65, 0.84, 1.0}, /* SOCK_BOOLEAN */
{0.0, 0.0, 0.0, 1.0}, /* SOCK_MESH_DEPRECATED */
{0.0, 0.0, 0.0, 0.0}, /* UNUSED */
{0.35, 0.55, 0.36, 1.0}, /* SOCK_INT */
{0.44, 0.70, 1.00, 1.0}, /* SOCK_STRING */
{0.93, 0.62, 0.36, 1.0}, /* SOCK_OBJECT */

View File

@ -3327,6 +3327,12 @@ static bool realtime_compositor_is_in_use(const bContext &context)
return false;
}
if (U.experimental.use_full_frame_compositor &&
scene->nodetree->execution_mode == NTREE_EXECUTION_MODE_REALTIME)
{
return true;
}
const Main *main = CTX_data_main(&context);
LISTBASE_FOREACH (const bScreen *, screen, &main->screens) {
LISTBASE_FOREACH (const ScrArea *, area, &screen->areabase) {

View File

@ -95,6 +95,8 @@ struct CompoJob {
/* Evaluated state/ */
Depsgraph *compositor_depsgraph;
bNodeTree *localtree;
/* Render instance. */
Render *re;
/* Jon system integration. */
const bool *stop;
bool *do_update;
@ -239,6 +241,9 @@ static void compo_initjob(void *cjv)
if (cj->recalc_flags) {
compo_tag_output_nodes(cj->localtree, cj->recalc_flags);
}
cj->re = RE_NewSceneRender(scene);
RE_gl_context_create(cj->re);
}
/* Called before redraw notifiers, it moves finished previews over. */
@ -286,17 +291,19 @@ static void compo_startjob(void *cjv,
BKE_callback_exec_id(cj->bmain, &scene->id, BKE_CB_EVT_COMPOSITE_PRE);
if ((cj->scene->r.scemode & R_MULTIVIEW) == 0) {
ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, false, true, "");
ntreeCompositExecTree(cj->re, cj->scene, ntree, &cj->scene->r, false, true, "");
}
else {
LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) {
if (BKE_scene_multiview_is_render_view_active(&scene->r, srv) == false) {
continue;
}
ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, false, true, srv->name);
ntreeCompositExecTree(cj->re, cj->scene, ntree, &cj->scene->r, false, true, srv->name);
}
}
RE_gl_context_destroy(cj->re);
ntree->runtime->test_break = nullptr;
ntree->runtime->stats_draw = nullptr;
ntree->runtime->progress = nullptr;

View File

@ -2222,8 +2222,6 @@ void node_insert_on_link_flags(Main &bmain, SpaceNode &snode)
static int get_main_socket_priority(const bNodeSocket *socket)
{
switch ((eNodeSocketDatatype)socket->type) {
case SOCK_MESH_DEPRECATED:
return -1;
case SOCK_CUSTOM:
return 0;
case SOCK_BOOLEAN:

View File

@ -23,21 +23,21 @@ set(INC_SYS
)
set(SRC
space_text.c
text_autocomplete.c
text_draw.c
text_format.c
text_format_lua.c
text_format_osl.c
text_format_pov.c
text_format_pov_ini.c
text_format_py.c
text_header.c
text_ops.c
space_text.cc
text_autocomplete.cc
text_draw.cc
text_format.cc
text_format_lua.cc
text_format_osl.cc
text_format_pov.cc
text_format_pov_ini.cc
text_format_py.cc
text_header.cc
text_ops.cc
text_undo.cc
text_format.h
text_intern.h
text_format.hh
text_intern.hh
)
set(LIB

View File

@ -35,17 +35,17 @@
#include "RNA_access.h"
#include "RNA_path.h"
#include "text_format.h"
#include "text_intern.h" /* own include */
#include "text_format.hh"
#include "text_intern.hh" /* own include */
/* ******************** default callbacks for text space ***************** */
static SpaceLink *text_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
static SpaceLink *text_create(const ScrArea * /*area*/, const Scene * /*scene*/)
{
ARegion *region;
SpaceText *stext;
stext = MEM_callocN(sizeof(SpaceText), "inittext");
stext = static_cast<SpaceText *>(MEM_callocN(sizeof(SpaceText), "inittext"));
stext->spacetype = SPACE_TEXT;
stext->lheight = 12;
@ -55,20 +55,20 @@ static SpaceLink *text_create(const ScrArea *UNUSED(area), const Scene *UNUSED(s
stext->showlinenrs = true;
/* header */
region = MEM_callocN(sizeof(ARegion), "header for text");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "header for text"));
BLI_addtail(&stext->regionbase, region);
region->regiontype = RGN_TYPE_HEADER;
region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
/* footer */
region = MEM_callocN(sizeof(ARegion), "footer for text");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "footer for text"));
BLI_addtail(&stext->regionbase, region);
region->regiontype = RGN_TYPE_FOOTER;
region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_TOP : RGN_ALIGN_BOTTOM;
/* properties region */
region = MEM_callocN(sizeof(ARegion), "properties region for text");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "properties region for text"));
BLI_addtail(&stext->regionbase, region);
region->regiontype = RGN_TYPE_UI;
@ -76,7 +76,7 @@ static SpaceLink *text_create(const ScrArea *UNUSED(area), const Scene *UNUSED(s
region->flag = RGN_FLAG_HIDDEN;
/* 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(&stext->regionbase, region);
region->regiontype = RGN_TYPE_WINDOW;
@ -89,20 +89,20 @@ static void text_free(SpaceLink *sl)
{
SpaceText *stext = (SpaceText *)sl;
stext->text = NULL;
stext->text = nullptr;
text_free_caches(stext);
}
/* spacetype; init callback */
static void text_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area)) {}
static void text_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
static SpaceLink *text_duplicate(SpaceLink *sl)
{
SpaceText *stextn = MEM_dupallocN(sl);
SpaceText *stextn = static_cast<SpaceText *>(MEM_dupallocN(sl));
/* clear or remove stuff from old */
stextn->runtime.drawcache = NULL; /* space need its own cache */
stextn->runtime.drawcache = nullptr; /* space need its own cache */
return (SpaceLink *)stextn;
}
@ -111,13 +111,13 @@ static void text_listener(const wmSpaceTypeListenerParams *params)
{
ScrArea *area = params->area;
const wmNotifier *wmn = params->notifier;
SpaceText *st = area->spacedata.first;
SpaceText *st = static_cast<SpaceText *>(area->spacedata.first);
/* context changes */
switch (wmn->category) {
case NC_TEXT:
/* check if active text was changed, no need to redraw if text isn't active
* (reference == NULL) means text was unlinked, should update anyway for this
* (reference == nullptr) means text was unlinked, should update anyway for this
* case -- no way to know was text active before unlinking or not */
if (wmn->reference && wmn->reference != st->text) {
break;
@ -220,7 +220,7 @@ static void text_keymap(wmKeyConfig *keyconf)
WM_keymap_ensure(keyconf, "Text", SPACE_TEXT, 0);
}
const char *text_context_dir[] = {"edit_text", NULL};
const char *text_context_dir[] = {"edit_text", nullptr};
static int /*eContextResult*/ text_context(const bContext *C,
const char *member,
@ -233,7 +233,7 @@ static int /*eContextResult*/ text_context(const bContext *C,
return CTX_RESULT_OK;
}
if (CTX_data_equals(member, "edit_text")) {
if (st->text != NULL) {
if (st->text != nullptr) {
CTX_data_id_pointer_set(result, &st->text->id);
}
return CTX_RESULT_OK;
@ -286,7 +286,7 @@ static void text_main_region_draw(const bContext *C, ARegion *region)
static void text_cursor(wmWindow *win, ScrArea *area, ARegion *region)
{
SpaceText *st = area->spacedata.first;
SpaceText *st = static_cast<SpaceText *>(area->spacedata.first);
int wmcursor = WM_CURSOR_TEXT_EDIT;
if (st->text && BLI_rcti_isect_pt(&st->runtime.scroll_region_handle,
@ -301,10 +301,10 @@ static void text_cursor(wmWindow *win, ScrArea *area, ARegion *region)
/* ************* dropboxes ************* */
static bool text_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
static bool text_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
{
if (drag->type == WM_DRAG_PATH) {
const eFileSel_File_Types file_type = WM_drag_get_path_file_type(drag);
const eFileSel_File_Types file_type = eFileSel_File_Types(WM_drag_get_path_file_type(drag));
if (ELEM(file_type, 0, FILE_TYPE_PYSCRIPT, FILE_TYPE_TEXT)) {
return true;
}
@ -312,18 +312,18 @@ static bool text_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNU
return false;
}
static void text_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
static void text_drop_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
{
/* copy drag path to properties */
RNA_string_set(drop->ptr, "filepath", WM_drag_get_path(drag));
}
static bool text_drop_paste_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
static bool text_drop_paste_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
{
return (drag->type == WM_DRAG_ID);
}
static void text_drop_paste(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
static void text_drop_paste(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
{
char *text;
ID *id = WM_drag_get_local_ID(drag, 0);
@ -339,8 +339,8 @@ static void text_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy, NULL, NULL);
WM_dropbox_add(lb, "TEXT_OT_insert", text_drop_paste_poll, text_drop_paste, NULL, NULL);
WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy, nullptr, nullptr);
WM_dropbox_add(lb, "TEXT_OT_insert", text_drop_paste_poll, text_drop_paste, nullptr, nullptr);
}
/* ************* end drop *********** */
@ -348,7 +348,7 @@ static void text_dropboxes(void)
/****************** header region ******************/
/* add handlers, stuff you only do once or on area/region changes */
static void text_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
static void text_header_region_init(wmWindowManager * /*wm*/, ARegion *region)
{
ED_region_header_init(region);
}
@ -390,15 +390,13 @@ static void text_properties_region_draw(const bContext *C, ARegion *region)
}
}
static void text_id_remap(ScrArea *UNUSED(area),
SpaceLink *slink,
const struct IDRemapper *mappings)
static void text_id_remap(ScrArea * /*area*/, SpaceLink *slink, const IDRemapper *mappings)
{
SpaceText *stext = (SpaceText *)slink;
BKE_id_remapper_apply(mappings, (ID **)&stext->text, ID_REMAP_APPLY_ENSURE_REAL);
}
static void text_space_blend_read_data(BlendDataReader *UNUSED(reader), SpaceLink *sl)
static void text_space_blend_read_data(BlendDataReader * /*reader*/, SpaceLink *sl)
{
SpaceText *st = (SpaceText *)sl;
memset(&st->runtime, 0x0, sizeof(st->runtime));
@ -419,7 +417,7 @@ static void text_space_blend_write(BlendWriter *writer, SpaceLink *sl)
void ED_spacetype_text(void)
{
SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype text");
SpaceType *st = static_cast<SpaceType *>(MEM_callocN(sizeof(SpaceType), "spacetype text"));
ARegionType *art;
st->spaceid = SPACE_TEXT;
@ -440,7 +438,7 @@ void ED_spacetype_text(void)
st->blend_write = text_space_blend_write;
/* regions: main window */
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype text region"));
art->regionid = RGN_TYPE_WINDOW;
art->init = text_main_region_init;
art->draw = text_main_region_draw;
@ -450,7 +448,7 @@ void ED_spacetype_text(void)
BLI_addhead(&st->regiontypes, art);
/* regions: properties */
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype text region"));
art->regionid = RGN_TYPE_UI;
art->prefsizex = UI_COMPACT_PANEL_WIDTH;
art->keymapflag = ED_KEYMAP_UI;
@ -460,7 +458,7 @@ void ED_spacetype_text(void)
BLI_addhead(&st->regiontypes, art);
/* regions: header */
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype text region"));
art->regionid = RGN_TYPE_HEADER;
art->prefsizey = HEADERY;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
@ -470,7 +468,7 @@ void ED_spacetype_text(void)
BLI_addhead(&st->regiontypes, art);
/* regions: footer */
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype text region"));
art->regionid = RGN_TYPE_FOOTER;
art->prefsizey = HEADERY;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FOOTER;

View File

@ -30,8 +30,8 @@
#include "UI_interface.h"
#include "text_format.h"
#include "text_intern.h" /* own include */
#include "text_format.hh"
#include "text_intern.hh" /* own include */
/* -------------------------------------------------------------------- */
/** \name Public API
@ -155,7 +155,7 @@ static GHash *text_autocomplete_build(Text *text)
gh = BLI_ghash_str_new(__func__);
for (linep = text->lines.first; linep; linep = linep->next) {
for (linep = static_cast<TextLine *>(text->lines.first); linep; linep = linep->next) {
size_t i_start = 0;
size_t i_end = 0;
size_t i_pos = 0;
@ -217,7 +217,7 @@ static GHash *text_autocomplete_build(Text *text)
tft = ED_text_format_get(text);
GHASH_ITER (gh_iter, gh) {
const char *s = BLI_ghashIterator_getValue(&gh_iter);
const char *s = static_cast<char *>(BLI_ghashIterator_getValue(&gh_iter));
texttool_suggest_add(s, tft->format_identifier(s));
}
}
@ -288,7 +288,7 @@ static void confirm_suggestion(Text *text)
/** \name Auto Complete Operator
* \{ */
static int text_autocomplete_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_autocomplete_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -588,10 +588,10 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
static void text_autocomplete_free(bContext *C, wmOperator *op)
{
GHash *gh = op->customdata;
GHash *gh = static_cast<GHash *>(op->customdata);
if (gh) {
BLI_ghash_free(gh, NULL, MEM_freeN);
op->customdata = NULL;
BLI_ghash_free(gh, nullptr, MEM_freeN);
op->customdata = nullptr;
}
/* other stuff */

View File

@ -31,8 +31,8 @@
#include "UI_resources.h"
#include "UI_view2d.h"
#include "text_format.h"
#include "text_intern.h"
#include "text_format.hh"
#include "text_intern.hh"
#include "WM_api.h"
#include "WM_types.h"
@ -41,12 +41,12 @@
/** \name Text Font Drawing
* \{ */
typedef struct TextDrawContext {
struct TextDrawContext {
int font_id;
int cwidth_px;
int lheight_px;
bool syntax_highlight;
} TextDrawContext;
};
static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
{
@ -58,10 +58,10 @@ static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
static void text_font_begin(const TextDrawContext *tdc)
{
BLF_size(tdc->font_id, (float)tdc->lheight_px);
BLF_size(tdc->font_id, float(tdc->lheight_px));
}
static void text_font_end(const TextDrawContext *UNUSED(tdc)) {}
static void text_font_end(const TextDrawContext * /*tdc*/) {}
static int text_font_draw(const TextDrawContext *tdc, int x, int y, const char *str)
{
@ -207,7 +207,7 @@ void wrap_offset(
text = st->text;
/* Move pointer to first visible line (top) */
linep = text->lines.first;
linep = static_cast<TextLine *>(text->lines.first);
i = st->top;
while (i > 0 && linep) {
int lines = text_get_visible_lines(st, region, linep->line);
@ -416,7 +416,7 @@ static int text_draw_wrapped(const SpaceText *st,
int mi, ma, mstart, mend; /* mem */
char fmt_prev = 0xff;
/* don't draw lines below this */
const int clip_min_y = -(int)(st->runtime.lheight_px - 1);
const int clip_min_y = -int(st->runtime.lheight_px - 1);
flatten_string(st, &fs, str);
str = fs.buf;
@ -509,7 +509,7 @@ static void text_draw(const SpaceText *st,
const bool use_syntax = (tdc->syntax_highlight && format);
FlattenString fs;
int columns, size, n, w = 0, padding, amount = 0;
const char *in = NULL;
const char *in = nullptr;
for (n = flatten_string(st, &fs, str), str = fs.buf; n > 0; n--) {
columns = BLI_str_utf8_char_width_safe(str);
@ -567,7 +567,7 @@ static void text_draw(const SpaceText *st,
/** \name Cache Utilities
* \{ */
typedef struct DrawCache {
struct DrawCache {
int *line_height;
int total_lines, nlines;
@ -580,11 +580,12 @@ typedef struct DrawCache {
/* for partial lines recalculation */
short update_flag;
int valid_head, valid_tail; /* amount of unchanged lines */
} DrawCache;
};
static void text_drawcache_init(SpaceText *st)
{
DrawCache *drawcache = MEM_callocN(sizeof(DrawCache), "text draw cache");
DrawCache *drawcache = static_cast<DrawCache *>(
MEM_callocN(sizeof(DrawCache), "text draw cache"));
drawcache->winx = -1;
drawcache->nlines = BLI_listbase_count(&st->text->lines);
@ -599,13 +600,13 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
int full_update = 0, nlines = 0;
Text *txt = st->text;
if (st->runtime.drawcache == NULL) {
if (st->runtime.drawcache == nullptr) {
text_drawcache_init(st);
}
text_update_character_width(st);
drawcache = st->runtime.drawcache;
drawcache = static_cast<DrawCache *>(st->runtime.drawcache);
nlines = drawcache->nlines;
/* check if full cache update is needed */
@ -634,7 +635,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
}
if (drawcache->update_flag) {
TextLine *line = st->text->lines.first;
TextLine *line = static_cast<TextLine *>(st->text->lines.first);
int lineno = 0, size, lines_count;
int *fp = drawcache->line_height, *new_tail, *old_tail;
@ -642,10 +643,10 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
size = sizeof(int) * nlines;
if (fp) {
fp = MEM_reallocN(fp, size);
fp = static_cast<int *>(MEM_reallocN(fp, size));
}
else {
fp = MEM_callocN(size, "text drawcache line_height");
fp = static_cast<int *>(MEM_callocN(size, "text drawcache line_height"));
}
drawcache->valid_tail = drawcache->valid_head = 0;
@ -716,12 +717,12 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
void text_drawcache_tag_update(SpaceText *st, const bool full)
{
/* This happens if text editor ops are called from Python. */
if (st == NULL) {
if (st == nullptr) {
return;
}
if (st->runtime.drawcache != NULL) {
DrawCache *drawcache = st->runtime.drawcache;
if (st->runtime.drawcache != nullptr) {
DrawCache *drawcache = static_cast<DrawCache *>(st->runtime.drawcache);
Text *txt = st->text;
if (drawcache->update_flag) {
@ -764,7 +765,7 @@ void text_drawcache_tag_update(SpaceText *st, const bool full)
void text_free_caches(SpaceText *st)
{
DrawCache *drawcache = st->runtime.drawcache;
DrawCache *drawcache = static_cast<DrawCache *>(st->runtime.drawcache);
if (drawcache) {
if (drawcache->line_height) {
@ -784,7 +785,7 @@ void text_free_caches(SpaceText *st)
/* cache should be updated in caller */
static int text_get_visible_lines_no(const SpaceText *st, int lineno)
{
const DrawCache *drawcache = st->runtime.drawcache;
const DrawCache *drawcache = static_cast<const DrawCache *>(st->runtime.drawcache);
return drawcache->line_height[lineno];
}
@ -853,7 +854,7 @@ int text_get_total_lines(SpaceText *st, ARegion *region)
DrawCache *drawcache;
text_update_drawcache(st, region);
drawcache = st->runtime.drawcache;
drawcache = static_cast<DrawCache *>(st->runtime.drawcache);
return drawcache->total_lines;
}
@ -910,13 +911,15 @@ static void calc_text_rcts(SpaceText *st, ARegion *region, rcti *scroll, rcti *b
CLAMP(st->runtime.scroll_region_handle.ymin, pix_bottom_margin, region->winy - pix_top_margin);
CLAMP(st->runtime.scroll_region_handle.ymax, pix_bottom_margin, region->winy - pix_top_margin);
st->runtime.scroll_px_per_line = (pix_available > 0) ? (float)ltexth / pix_available : 0;
st->runtime.scroll_px_per_line = (pix_available > 0) ? float(ltexth) / pix_available : 0;
if (st->runtime.scroll_px_per_line < 0.1f) {
st->runtime.scroll_px_per_line = 0.1f;
}
curl_off = text_get_span_wrap(st, region, st->text->lines.first, st->text->curl);
sell_off = text_get_span_wrap(st, region, st->text->lines.first, st->text->sell);
curl_off = text_get_span_wrap(
st, region, static_cast<TextLine *>(st->text->lines.first), st->text->curl);
sell_off = text_get_span_wrap(
st, region, static_cast<TextLine *>(st->text->lines.first), st->text->sell);
lhlstart = MIN2(curl_off, sell_off);
lhlend = MAX2(curl_off, sell_off);
@ -1013,16 +1016,13 @@ static void draw_textscroll(const SpaceText *st, rcti *scroll, rcti *back)
BLI_rcti_size_y(&st->runtime.scroll_region_select));
UI_GetThemeColor3fv(TH_HILITE, col);
col[3] = 0.18f;
UI_draw_roundbox_aa(
&(const rctf){
.xmin = st->runtime.scroll_region_select.xmin + 1,
.xmax = st->runtime.scroll_region_select.xmax - 1,
.ymin = st->runtime.scroll_region_select.ymin,
.ymax = st->runtime.scroll_region_select.ymax,
},
true,
rad,
col);
rctf rect;
rect.xmin = st->runtime.scroll_region_select.xmin + 1;
rect.xmax = st->runtime.scroll_region_select.xmax - 1;
rect.ymin = st->runtime.scroll_region_select.ymin;
rect.ymax = st->runtime.scroll_region_select.ymax;
UI_draw_roundbox_aa(&rect, true, rad, col);
}
/** \} */
@ -1117,7 +1117,7 @@ static void draw_documentation(const SpaceText *st, ARegion *region)
buf[i] = '\0';
if (lines >= 0) {
y -= st->runtime.lheight_px;
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, NULL);
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, nullptr);
}
i = 0;
br = DOC_WIDTH;
@ -1128,7 +1128,7 @@ static void draw_documentation(const SpaceText *st, ARegion *region)
buf[br] = '\0';
if (lines >= 0) {
y -= st->runtime.lheight_px;
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, NULL);
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, nullptr);
}
p -= i - br - 1; /* Rewind pointer to last break */
i = 0;
@ -1177,7 +1177,8 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
top = texttool_suggest_top();
wrap_offset(st, region, st->text->curl, st->text->curc, &offl, &offc);
vcurl = txt_get_span(st->text->lines.first, st->text->curl) - st->top + offl;
vcurl = txt_get_span(static_cast<TextLine *>(st->text->lines.first), st->text->curl) - st->top +
offl;
vcurc = text_get_char_pos(st, st->text->curl->line, st->text->curc) - st->left + offc;
x = TXT_BODY_LEFT(st) + (vcurc * st->runtime.cwidth_px);
@ -1196,14 +1197,14 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
}
/* not needed but stands out nicer */
UI_draw_box_shadow(
&(const rctf){
.xmin = x,
.xmax = x + boxw,
.ymin = y - boxh,
.ymax = y,
},
220);
{
rctf rect;
rect.xmin = x;
rect.xmax = x + boxw;
rect.ymin = y - boxh;
rect.ymax = y;
UI_draw_box_shadow(&rect, 220);
}
uint pos = GPU_vertformat_attr_add(
immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
@ -1222,7 +1223,7 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
}
for (i = 0; i < SUGG_LIST_SIZE && item; i++, item = item->next) {
int len = txt_utf8_forward_columns(item->name, SUGG_LIST_WIDTH, NULL) - item->name;
int len = txt_utf8_forward_columns(item->name, SUGG_LIST_WIDTH, nullptr) - item->name;
y -= lheight;
@ -1242,7 +1243,7 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
}
format_draw_color(tdc, item->type);
text_draw(st, tdc, str, 0, 0, x + margin_x, y - 1, NULL);
text_draw(st, tdc, str, 0, 0, x + margin_x, y - 1, nullptr);
if (item == last) {
break;
@ -1266,7 +1267,7 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
/* Convert to view space character coordinates to determine if cursor is hidden */
wrap_offset(st, region, text->sell, text->selc, &offl, &offc);
vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
vsell = txt_get_span(static_cast<TextLine *>(text->lines.first), text->sell) - st->top + offl;
vselc = text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
if (vselc < 0) {
@ -1287,7 +1288,7 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
if (text->curl != text->sell || text->curc != text->selc) {
/* Convert all to view space character coordinates */
wrap_offset(st, region, text->curl, text->curc, &offl, &offc);
vcurl = txt_get_span(text->lines.first, text->curl) - st->top + offl;
vcurl = txt_get_span(static_cast<TextLine *>(text->lines.first), text->curl) - st->top + offl;
vcurc = text_get_char_pos(st, text->curl->line, text->curc) - st->left + offc;
if (vcurc < 0) {
@ -1449,7 +1450,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
linep = startl;
c = startc;
fc = BLI_str_utf8_offset_to_index(linep->line, startc);
endl = NULL;
endl = nullptr;
endc = -1;
find = -b;
stack = 0;
@ -1559,7 +1560,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
viewc = text_get_char_pos(st, startl->line, startc) - st->left + offc;
if (viewc >= 0) {
viewl = txt_get_span(text->lines.first, startl) - st->top + offl;
viewl = txt_get_span(static_cast<TextLine *>(text->lines.first), startl) - st->top + offl;
text_font_draw_character(
tdc, x + viewc * st->runtime.cwidth_px, y - viewl * TXT_LINE_HEIGHT(st), ch);
@ -1573,7 +1574,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
viewc = text_get_char_pos(st, endl->line, endc) - st->left + offc;
if (viewc >= 0) {
viewl = txt_get_span(text->lines.first, endl) - st->top + offl;
viewl = txt_get_span(static_cast<TextLine *>(text->lines.first), endl) - st->top + offl;
text_font_draw_character(
tdc, x + viewc * st->runtime.cwidth_px, y - viewl * TXT_LINE_HEIGHT(st), ch);
@ -1609,10 +1610,10 @@ void draw_text_main(SpaceText *st, ARegion *region)
st->runtime.lheight_px = (U.widget_unit * st->lheight) / 20;
/* don't draw lines below this */
const int clip_min_y = -(int)(st->runtime.lheight_px - 1);
const int clip_min_y = -int(st->runtime.lheight_px - 1);
st->runtime.viewlines = (st->runtime.lheight_px) ?
(int)(region->winy - clip_min_y) / TXT_LINE_HEIGHT(st) :
int(region->winy - clip_min_y) / TXT_LINE_HEIGHT(st) :
0;
text_draw_context_init(st, &tdc);
@ -1629,7 +1630,7 @@ void draw_text_main(SpaceText *st, ARegion *region)
/* update syntax formatting if needed */
tft = ED_text_format_get(text);
tmp = text->lines.first;
tmp = static_cast<TextLine *>(text->lines.first);
lineno = 0;
for (i = 0; i < st->top && tmp; i++) {
if (tdc.syntax_highlight && !tmp->format) {
@ -1658,7 +1659,7 @@ void draw_text_main(SpaceText *st, ARegion *region)
text_font_begin(&tdc);
tdc.cwidth_px = max_ii((int)BLF_fixed_width(tdc.font_id), 1);
tdc.cwidth_px = max_ii(int(BLF_fixed_width(tdc.font_id)), 1);
st->runtime.cwidth_px = tdc.cwidth_px;
/* draw line numbers background */
@ -1759,7 +1760,7 @@ void text_update_character_width(SpaceText *st)
text_font_begin(&tdc);
st->runtime.cwidth_px = BLF_fixed_width(tdc.font_id);
st->runtime.cwidth_px = MAX2(st->runtime.cwidth_px, (char)1);
st->runtime.cwidth_px = MAX2(st->runtime.cwidth_px, char(1));
text_font_end(&tdc);
}
@ -1767,7 +1768,7 @@ bool ED_text_activate_in_screen(bContext *C, Text *text)
{
ScrArea *area = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TEXT, 0);
if (area) {
SpaceText *st = area->spacedata.first;
SpaceText *st = static_cast<SpaceText *>(area->spacedata.first);
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
st->text = text;
if (region) {
@ -1785,7 +1786,7 @@ void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
Text *text;
int i, x, winx = region->winx;
if (ELEM(NULL, st, st->text, st->text->curl)) {
if (ELEM(nullptr, st, st->text, st->text->curl)) {
return;
}
@ -1793,7 +1794,7 @@ void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
text_update_character_width(st);
i = txt_get_span(text->lines.first, text->sell);
i = txt_get_span(static_cast<TextLine *>(text->lines.first), text->sell);
if (st->wordwrap) {
int offl, offc;
wrap_offset(st, region, text->sell, text->selc, &offl, &offc);
@ -1851,7 +1852,7 @@ void text_scroll_to_cursor__area(SpaceText *st, ScrArea *area, const bool center
{
ARegion *region;
if (ELEM(NULL, st, st->text, st->text->curl)) {
if (ELEM(nullptr, st, st->text, st->text->curl)) {
return;
}
@ -1875,13 +1876,13 @@ bool ED_text_region_location_from_cursor(SpaceText *st,
const int cursor_co[2],
int r_pixel_co[2])
{
TextLine *line = NULL;
TextLine *line = nullptr;
if (!st->text) {
goto error;
}
line = BLI_findlink(&st->text->lines, cursor_co[0]);
line = static_cast<TextLine *>(BLI_findlink(&st->text->lines, cursor_co[0]));
if (!line || (cursor_co[1] < 0) || (cursor_co[1] > line->len)) {
goto error;
}

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -18,7 +18,7 @@
#include "ED_text.h"
#include "text_format.h"
#include "text_format.hh"
/****************** flatten string **********************/
@ -31,8 +31,8 @@ static void flatten_string_append(FlattenString *fs, const char *c, int accum, i
int *naccum;
fs->len *= 2;
nbuf = MEM_callocN(sizeof(*fs->buf) * fs->len, "fs->buf");
naccum = MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum");
nbuf = static_cast<char *>(MEM_callocN(sizeof(*fs->buf) * fs->len, "fs->buf"));
naccum = static_cast<int *>(MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum"));
memcpy(nbuf, fs->buf, fs->pos * sizeof(*fs->buf));
memcpy(naccum, fs->accum, fs->pos * sizeof(*fs->accum));
@ -99,7 +99,7 @@ void flatten_string_free(FlattenString *fs)
int flatten_string_strlen(FlattenString *fs, const char *str)
{
const int len = (fs->pos - (int)(str - fs->buf)) - 1;
const int len = (fs->pos - int(str - fs->buf)) - 1;
BLI_assert(strlen(str) == len);
return len;
}
@ -109,14 +109,14 @@ int text_check_format_len(TextLine *line, uint len)
if (line->format) {
if (strlen(line->format) < len) {
MEM_freeN(line->format);
line->format = MEM_mallocN(len + 2, "SyntaxFormat");
line->format = static_cast<char *>(MEM_mallocN(len + 2, "SyntaxFormat"));
if (!line->format) {
return 0;
}
}
}
else {
line->format = MEM_mallocN(len + 2, "SyntaxFormat");
line->format = static_cast<char *>(MEM_mallocN(len + 2, "SyntaxFormat"));
if (!line->format) {
return 0;
}
@ -164,7 +164,7 @@ void text_format_fill_ascii(const char **str_p, char **fmt_p, const char type, c
}
/* *** Registration *** */
static ListBase tft_lb = {NULL, NULL};
static ListBase tft_lb = {nullptr, nullptr};
void ED_text_format_register(TextFormatType *tft)
{
BLI_addtail(&tft_lb, tft);
@ -179,7 +179,7 @@ TextFormatType *ED_text_format_get(Text *text)
if (text_ext) {
text_ext++; /* skip the '.' */
/* Check all text formats in the static list */
for (tft = tft_lb.first; tft; tft = tft->next) {
for (tft = static_cast<TextFormatType *>(tft_lb.first); tft; tft = tft->next) {
/* All formats should have an ext, but just in case */
const char **ext;
for (ext = tft->ext; *ext; ext++) {
@ -193,11 +193,11 @@ TextFormatType *ED_text_format_get(Text *text)
/* If we make it here we never found an extension that worked - return
* the "default" text format */
return tft_lb.first;
return static_cast<TextFormatType *>(tft_lb.first);
}
/* Return the "default" text format */
return tft_lb.first;
return static_cast<TextFormatType *>(tft_lb.first);
}
const char *ED_text_format_comment_line_prefix(Text *text)
@ -208,14 +208,14 @@ const char *ED_text_format_comment_line_prefix(Text *text)
bool ED_text_is_syntax_highlight_supported(Text *text)
{
if (text == NULL) {
if (text == nullptr) {
return false;
}
TextFormatType *tft;
const char *text_ext = BLI_path_extension(text->id.name + 2);
if (text_ext == NULL) {
if (text_ext == nullptr) {
/* Extensionless data-blocks are considered highlightable as Python. */
return true;
}
@ -226,7 +226,7 @@ bool ED_text_is_syntax_highlight_supported(Text *text)
}
/* Check all text formats in the static list */
for (tft = tft_lb.first; tft; tft = tft->next) {
for (tft = static_cast<TextFormatType *>(tft_lb.first); tft; tft = tft->next) {
/* All formats should have an ext, but just in case */
const char **ext;
for (ext = tft->ext; *ext; ext++) {

View File

@ -8,18 +8,20 @@
#pragma once
struct Text;
/* *** Flatten String *** */
typedef struct FlattenString {
struct FlattenString {
char fixedbuf[256];
int fixedaccum[256];
char *buf;
int *accum;
int pos, len;
} FlattenString;
};
/**
* Format continuation flags (stored just after the NULL terminator).
* Format continuation flags (stored just after the null terminator).
*/
enum {
FMT_CONT_NOP = 0, /* no continuation */
@ -75,7 +77,7 @@ typedef struct TextFormatType {
*/
void (*format_line)(SpaceText *st, TextLine *line, bool do_next);
const char **ext; /* NULL terminated extensions */
const char **ext; /* Null terminated extensions. */
/** The prefix of a single-line line comment (without trailing space). */
const char *comment_line;
@ -104,15 +106,34 @@ enum {
FMT_TYPE_DEFAULT = 'q',
};
TextFormatType *ED_text_format_get(Text *text);
TextFormatType *ED_text_format_get(struct Text *text);
void ED_text_format_register(TextFormatType *tft);
/* formatters */
void ED_text_format_register_py(void);
void ED_text_format_register_osl(void);
void ED_text_format_register_lua(void);
void ED_text_format_register_pov(void);
void ED_text_format_register_pov_ini(void);
void ED_text_format_register_py();
void ED_text_format_register_osl();
void ED_text_format_register_lua();
void ED_text_format_register_pov();
void ED_text_format_register_pov_ini();
#define STR_LITERAL_STARTSWITH(str, str_literal, len_var) \
(strncmp(str, str_literal, len_var = (sizeof(str_literal) - 1)) == 0)
/* Workaround `C1061` with MSVC (looks like a bug),
* this can be removed if the issue is resolved.
*
* Add #MSVC_WORKAROUND_BREAK to break up else-if's blocks to be under 128.
* `_keep_me` just ensures #MSVC_WORKAROUND_BREAK follows an #MSVC_WORKAROUND_INIT. */
#ifdef _MSC_VER
# define MSVC_WORKAROUND_INIT(i) \
char _keep_me = 0; \
i = -1; \
((void)0)
# define MSVC_WORKAROUND_BREAK(i) \
} \
((void)_keep_me); \
if (i != -1) {
#else
# define MSVC_WORKAROUND_INIT(i) ((void)0)
# define MSVC_WORKAROUND_BREAK(i)
#endif

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** Lua Keywords (for format_line) *** */
@ -173,7 +173,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -183,7 +183,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -258,7 +258,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Single line comment */
else if (*str == '-' && *(str + 1) == '-') {
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
else if (ELEM(*str, '"', '\'')) {
/* Strings */
@ -336,10 +336,10 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
flatten_string_free(&fs);
}
void ED_text_format_register_lua(void)
void ED_text_format_register_lua()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"lua", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"lua", nullptr};
tft.format_identifier = txtfmt_lua_format_identifier;
tft.format_line = txtfmt_lua_format_line;

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** Local Functions (for format_line) *** */
@ -199,7 +199,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -209,7 +209,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -271,7 +271,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
/* Deal with comments first */
if (*str == '/' && *(str + 1) == '/') {
/* fill the remaining line */
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
/* C-Style (multi-line) comments */
else if (*str == '/' && *(str + 1) == '*') {
@ -354,10 +354,10 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
flatten_string_free(&fs);
}
void ED_text_format_register_osl(void)
void ED_text_format_register_osl()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"osl", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"osl", nullptr};
tft.format_identifier = txtfmt_osl_format_identifier;
tft.format_line = txtfmt_osl_format_line;

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** POV Keywords (for format_line) *** */
@ -88,6 +88,7 @@ static int txtfmt_pov_find_reserved_keywords(const char *string)
/* Keep aligned args for readability. */
/* clang-format off */
MSVC_WORKAROUND_INIT(i);
/* Float Functions */
if (STR_LITERAL_STARTSWITH(string, "conserve_energy", len)) { i = len;
@ -185,6 +186,7 @@ static int txtfmt_pov_find_reserved_keywords(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "sky", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "up", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "ln", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Color Identifiers */
} else if (STR_LITERAL_STARTSWITH(string, "transmit", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "filter", len)) { i = len;
@ -248,6 +250,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
/* Keep aligned args for readability. */
/* clang-format off */
MSVC_WORKAROUND_INIT(i);
/* Language Keywords */
if (STR_LITERAL_STARTSWITH(string, "reflection_exponent", len)) { i = len;
@ -319,6 +322,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "now", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "pot", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "type", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Animation Options */
} else if (STR_LITERAL_STARTSWITH(string, "global_settings", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "input_file_name", len)) { i = len;
@ -332,6 +336,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "clock_delta", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "clock_on", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "clock", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Spline Identifiers */
} else if (STR_LITERAL_STARTSWITH(string, "extended_x_spline", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "general_x_spline", len)) { i = len;
@ -347,6 +352,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "linear_sweep", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "conic_sweep", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "b_spline", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Patterns */
} else if (STR_LITERAL_STARTSWITH(string, "pigment_pattern", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "image_pattern", len)) { i = len;
@ -399,6 +405,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "wood", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "agate", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "aoi", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Objects */
} else if (STR_LITERAL_STARTSWITH(string, "superellipsoid", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "bicubic_patch", len)) { i = len;
@ -467,13 +474,12 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else { i = 0;
}
/* clang-format off */
/* clang-format on */
/* If next source char is an identifier (eg. 'i' in "definite") no match */
return (i == 0 || text_check_identifier(string[i])) ? -1 : i;
}
/**
* Checks the specified source string for a POV modifiers. This
* name must start at the beginning of the source string and must be followed
@ -488,6 +494,11 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
static int txtfmt_pov_find_specialvar(const char *string)
{
int i, len;
/* Keep aligned args for readability. */
/* clang-format off */
MSVC_WORKAROUND_INIT(i);
/* Modifiers */
if (STR_LITERAL_STARTSWITH(string, "dispersion_samples", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "projected_through", len)) { i = len;
@ -579,6 +590,7 @@ static int txtfmt_pov_find_specialvar(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "distance", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "autostop", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "caustics", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
} else if (STR_LITERAL_STARTSWITH(string, "octaves", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "aa_level", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "frequency", len)) { i = len;
@ -633,6 +645,7 @@ static int txtfmt_pov_find_specialvar(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "ratio", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "open", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "ior", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Light Types and options. */
} else if (STR_LITERAL_STARTSWITH(string, "area_light", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "looks_like", len)) { i = len;
@ -643,6 +656,7 @@ static int txtfmt_pov_find_specialvar(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "point_at", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "falloff", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "radius", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Camera Types and options. */
} else if (STR_LITERAL_STARTSWITH(string, "omni_directional_stereo", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "lambert_cylindrical", len)) { i = len;
@ -687,6 +701,8 @@ static int txtfmt_pov_find_specialvar(const char *string)
} else { i = 0;
}
/* clang-format on */
/* If next source char is an identifier (eg. 'i' in "definite") no match */
return (i == 0 || text_check_identifier(string[i])) ? -1 : i;
}
@ -772,7 +788,7 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -782,7 +798,7 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -851,7 +867,7 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Single line comment */
else if (*str == '/' && *(str + 1) == '/') {
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
else if (ELEM(*str, '"', '\'')) {
/* Strings */
@ -931,10 +947,10 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
flatten_string_free(&fs);
}
void ED_text_format_register_pov(void)
void ED_text_format_register_pov()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"pov", "inc", "mcr", "mac", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"pov", "inc", "mcr", "mac", nullptr};
tft.format_identifier = txtfmt_pov_format_identifier;
tft.format_line = txtfmt_pov_format_line;

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** POV INI Keywords (for format_line) *** */
@ -95,7 +95,7 @@ static int txtfmt_ini_find_reserved(const char *string)
/* Keep aligned args for readability. */
/* clang-format off */
MSVC_WORKAROUND_INIT(i);
/* POV-Ray Built-in INI Variables
* list is from...
* http://www.povray.org/documentation/view/3.7.0/212/
@ -158,6 +158,7 @@ static int txtfmt_ini_find_reserved(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "Bounding_Method", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Create_Ini", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Display_Gamma", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
} else if (STR_LITERAL_STARTSWITH(string, "Display", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Version", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Pause_When_Done", len)) { i = len;
@ -208,6 +209,7 @@ static int txtfmt_ini_find_reserved(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "WarningColour", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "ErrorColour", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "BackgroundColour", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
} else if (STR_LITERAL_STARTSWITH(string, "DropToEditor", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "LastRenderName", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "LastRenderPath", len)) { i = len;
@ -268,6 +270,7 @@ static int txtfmt_ini_find_reserved(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "Dither", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Flags", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Font", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* File-types. */
} else if (STR_LITERAL_STARTSWITH(string, "df3", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "exr", len)) { i = len;
@ -357,7 +360,7 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -367,7 +370,7 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -429,7 +432,7 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
/* Multi-line comments not supported */
/* Single line comment */
if (*str == ';') {
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
else if (ELEM(*str, '"', '\'')) {
/* Strings */
@ -507,10 +510,10 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
flatten_string_free(&fs);
}
void ED_text_format_register_pov_ini(void)
void ED_text_format_register_pov_ini()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"ini", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"ini", nullptr};
tft.format_identifier = txtfmt_pov_ini_format_identifier;
tft.format_line = txtfmt_pov_ini_format_line;

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** Local Functions (for format_line) *** */
@ -239,7 +239,7 @@ static uint txtfmt_py_numeral_string_count_zeros(const char *string)
static int txtfmt_py_find_numeral_inner(const char *string)
{
if (string == NULL || *string == '\0') {
if (string == nullptr || *string == '\0') {
return -1;
}
@ -281,7 +281,7 @@ static int txtfmt_py_find_numeral_inner(const char *string)
static int txtfmt_py_literal_numeral(const char *string, char prev_fmt)
{
if (string == NULL || *string == '\0') {
if (string == nullptr || *string == '\0') {
return -1;
}
@ -339,7 +339,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -349,7 +349,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -411,7 +411,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n
/* Deal with comments first */
if (*str == '#') {
/* fill the remaining line */
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
else if (ELEM(*str, '"', '\'')) {
/* Strings */
@ -546,10 +546,10 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n
flatten_string_free(&fs);
}
void ED_text_format_register_py(void)
void ED_text_format_register_py()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"py", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"py", nullptr};
tft.format_identifier = txtfmt_py_format_identifier;
tft.format_line = txtfmt_py_format_line;

View File

@ -21,7 +21,7 @@
#include "UI_interface.h"
#include "text_intern.h"
#include "text_intern.hh"
/* ************************ header area region *********************** */
@ -40,11 +40,11 @@ static ARegion *text_has_properties_region(ScrArea *area)
region = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
/* is error! */
if (region == NULL) {
return NULL;
if (region == nullptr) {
return nullptr;
}
arnew = MEM_callocN(sizeof(ARegion), "properties region");
arnew = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "properties region"));
BLI_insertlinkafter(&area->regionbase, region, arnew);
arnew->regiontype = RGN_TYPE_UI;
@ -57,10 +57,10 @@ static ARegion *text_has_properties_region(ScrArea *area)
static bool text_properties_poll(bContext *C)
{
return (CTX_wm_space_text(C) != NULL);
return (CTX_wm_space_text(C) != nullptr);
}
static int text_text_search_exec(bContext *C, wmOperator *UNUSED(op))
static int text_text_search_exec(bContext *C, wmOperator * /*op*/)
{
ScrArea *area = CTX_wm_area(C);
ARegion *region = text_has_properties_region(area);

View File

@ -6,8 +6,8 @@
* \ingroup sptext
*/
#include <errno.h>
#include <string.h>
#include <cerrno>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -45,8 +45,8 @@
# include "BPY_extern_run.h"
#endif
#include "text_format.h"
#include "text_intern.h"
#include "text_format.hh"
#include "text_intern.hh"
static void txt_screen_clamp(SpaceText *st, ARegion *region);
@ -118,7 +118,7 @@ static char *buf_tabs_to_spaces(const char *in_buf, const int tab_size, int *r_o
/* Allocate output before with extra space for expanded tabs. */
const int out_size = strlen(in_buf) + num_tabs * (tab_size - 1) + 1;
char *out_buf = MEM_mallocN(out_size * sizeof(char), __func__);
char *out_buf = static_cast<char *>(MEM_mallocN(out_size * sizeof(char), __func__));
/* Fill output buffer. */
int spaces_until_tab = 0;
@ -169,8 +169,8 @@ static void text_select_update_primary_clipboard(const Text *text)
if (!txt_has_sel(text)) {
return;
}
char *buf = txt_sel_to_buf(text, NULL);
if (buf == NULL) {
char *buf = txt_sel_to_buf(text, nullptr);
if (buf == nullptr) {
return;
}
WM_clipboard_text_set(buf, true);
@ -183,7 +183,7 @@ static void text_select_update_primary_clipboard(const Text *text)
/** \name Operator Poll
* \{ */
static bool text_new_poll(bContext *UNUSED(C))
static bool text_new_poll(bContext * /*C*/)
{
return true;
}
@ -272,7 +272,7 @@ void text_update_edited(Text *text)
{
TextLine *line;
for (line = text->lines.first; line; line = line->next) {
for (line = static_cast<TextLine *>(text->lines.first); line; line = line->next) {
text_update_line_edited(line);
}
}
@ -283,7 +283,7 @@ void text_update_edited(Text *text)
/** \name New Operator
* \{ */
static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
static int text_new_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Main *bmain = CTX_data_main(C);
@ -298,7 +298,7 @@ static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
if (prop) {
RNA_id_pointer_create(&text->id, &idptr);
RNA_property_pointer_set(&ptr, prop, idptr, NULL);
RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
RNA_property_update(C, &ptr, prop);
}
else if (st) {
@ -338,13 +338,14 @@ void TEXT_OT_new(wmOperatorType *ot)
static void text_open_init(bContext *C, wmOperator *op)
{
PropertyPointerRNA *pprop;
PropertyPointerRNA *pprop = static_cast<PropertyPointerRNA *>(
MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA"));
op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
op->customdata = pprop;
UI_context_active_but_prop_get_templateID(C, &pprop->ptr, &pprop->prop);
}
static void text_open_cancel(bContext *UNUSED(C), wmOperator *op)
static void text_open_cancel(bContext * /*C*/, wmOperator *op)
{
MEM_freeN(op->customdata);
}
@ -375,11 +376,11 @@ static int text_open_exec(bContext *C, wmOperator *op)
}
/* hook into UI */
pprop = op->customdata;
pprop = static_cast<PropertyPointerRNA *>(op->customdata);
if (pprop->prop) {
RNA_id_pointer_create(&text->id, &idptr);
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr, NULL);
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr, nullptr);
RNA_property_update(C, &pprop->ptr, pprop->prop);
}
else if (st) {
@ -398,7 +399,7 @@ static int text_open_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int text_open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_open_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
Main *bmain = CTX_data_main(C);
Text *text = CTX_data_edit_text(C);
@ -440,7 +441,7 @@ void TEXT_OT_open(wmOperatorType *ot)
FILE_DEFAULTDISPLAY,
FILE_SORT_DEFAULT); /* TODO: relative_path. */
RNA_def_boolean(
ot->srna, "internal", 0, "Make Internal", "Make text file internal after loading");
ot->srna, "internal", false, "Make Internal", "Make text file internal after loading");
}
/** \} */
@ -462,7 +463,7 @@ static int text_reload_exec(bContext *C, wmOperator *op)
/* Don't make this part of 'poll', since 'Alt-R' will type 'R',
* if poll checks for the filename. */
if (text->filepath == NULL) {
if (text->filepath == nullptr) {
BKE_report(op->reports, RPT_ERROR, "This text has not been saved");
return OPERATOR_CANCELLED;
}
@ -516,10 +517,10 @@ void TEXT_OT_reload(wmOperatorType *ot)
static bool text_unlink_poll(bContext *C)
{
/* it should be possible to unlink texts if they're lib-linked in... */
return CTX_data_edit_text(C) != NULL;
return CTX_data_edit_text(C) != nullptr;
}
static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
static int text_unlink_exec(bContext *C, wmOperator * /*op*/)
{
Main *bmain = CTX_data_main(C);
SpaceText *st = CTX_wm_space_text(C);
@ -528,11 +529,11 @@ static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
/* make the previous text active, if its not there make the next text active */
if (st) {
if (text->id.prev) {
st->text = text->id.prev;
st->text = static_cast<Text *>(text->id.prev);
text_update_cursor_moved(C);
}
else if (text->id.next) {
st->text = text->id.next;
st->text = static_cast<Text *>(text->id.next);
text_update_cursor_moved(C);
}
}
@ -540,7 +541,7 @@ static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
BKE_id_delete(bmain, text);
text_drawcache_tag_update(st, true);
WM_event_add_notifier(C, NC_TEXT | NA_REMOVED, NULL);
WM_event_add_notifier(C, NC_TEXT | NA_REMOVED, nullptr);
return OPERATOR_FINISHED;
}
@ -567,7 +568,7 @@ void TEXT_OT_unlink(wmOperatorType *ot)
/** \name Make Internal Operator
* \{ */
static int text_make_internal_exec(bContext *C, wmOperator *UNUSED(op))
static int text_make_internal_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -620,7 +621,7 @@ static void txt_write_file(Main *bmain, Text *text, ReportList *reports)
}
fp = BLI_fopen(filepath, "w");
if (fp == NULL) {
if (fp == nullptr) {
BKE_reportf(reports,
RPT_ERROR,
"Unable to save '%s': %s",
@ -629,7 +630,7 @@ static void txt_write_file(Main *bmain, Text *text, ReportList *reports)
return;
}
for (tmp = text->lines.first; tmp; tmp = tmp->next) {
for (tmp = static_cast<TextLine *>(text->lines.first); tmp; tmp = tmp->next) {
fputs(tmp->line, fp);
if (tmp->next) {
fputc('\n', fp);
@ -674,8 +675,8 @@ static int text_save_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Text *text = CTX_data_edit_text(C);
/* Internal and texts without a filepath will go to "Save As". */
if (text->filepath == NULL || (text->flags & TXT_ISMEM)) {
WM_operator_name_call(C, "TEXT_OT_save_as", WM_OP_INVOKE_DEFAULT, NULL, event);
if (text->filepath == nullptr || (text->flags & TXT_ISMEM)) {
WM_operator_name_call(C, "TEXT_OT_save_as", WM_OP_INVOKE_DEFAULT, nullptr, event);
return OPERATOR_CANCELLED;
}
return text_save_exec(C, op);
@ -726,7 +727,7 @@ static int text_save_as_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int text_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_save_as_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
Main *bmain = CTX_data_main(C);
Text *text = CTX_data_edit_text(C);
@ -784,7 +785,7 @@ static int text_run_script(bContext *C, ReportList *reports)
{
#ifdef WITH_PYTHON
Text *text = CTX_data_edit_text(C);
const bool is_live = (reports == NULL);
const bool is_live = (reports == nullptr);
/* only for comparison */
void *curl_prev = text->curl;
@ -793,7 +794,7 @@ static int text_run_script(bContext *C, ReportList *reports)
if (BPY_run_text(C, text, reports, !is_live)) {
if (is_live) {
/* for nice live updates */
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, nullptr);
}
return OPERATOR_FINISHED;
}
@ -852,7 +853,7 @@ void TEXT_OT_run_script(wmOperatorType *ot)
/** \name Refresh Pyconstraints Operator
* \{ */
static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
static int text_refresh_pyconstraints_exec(bContext * /*C*/, wmOperator * /*op*/)
{
#ifdef WITH_PYTHON
# if 0
@ -955,7 +956,7 @@ static int text_paste_exec(bContext *C, wmOperator *op)
/* run the script while editing, evil but useful */
if (st->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -979,7 +980,7 @@ void TEXT_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);
@ -991,7 +992,7 @@ void TEXT_OT_paste(wmOperatorType *ot)
/** \name Duplicate Operator
* \{ */
static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op))
static int text_duplicate_line_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1003,7 +1004,7 @@ static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op))
/* run the script while editing, evil but useful */
if (CTX_wm_space_text(C)->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -1038,15 +1039,15 @@ static void txt_copy_clipboard(Text *text)
return;
}
buf = txt_sel_to_buf(text, NULL);
buf = txt_sel_to_buf(text, nullptr);
if (buf) {
WM_clipboard_text_set(buf, 0);
WM_clipboard_text_set(buf, false);
MEM_freeN(buf);
}
}
static int text_copy_exec(bContext *C, wmOperator *UNUSED(op))
static int text_copy_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1073,7 +1074,7 @@ void TEXT_OT_copy(wmOperatorType *ot)
/** \name Cut Operator
* \{ */
static int text_cut_exec(bContext *C, wmOperator *UNUSED(op))
static int text_cut_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -1090,7 +1091,7 @@ static int text_cut_exec(bContext *C, wmOperator *UNUSED(op))
/* run the script while editing, evil but useful */
if (st->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -1117,16 +1118,16 @@ void TEXT_OT_cut(wmOperatorType *ot)
/** \name Indent or Autocomplete Operator
* \{ */
static int text_indent_or_autocomplete_exec(bContext *C, wmOperator *UNUSED(op))
static int text_indent_or_autocomplete_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
TextLine *line = text->curl;
bool text_before_cursor = text->curc != 0 && !ELEM(line->line[text->curc - 1], ' ', '\t');
if (text_before_cursor && (txt_has_sel(text) == false)) {
WM_operator_name_call(C, "TEXT_OT_autocomplete", WM_OP_INVOKE_DEFAULT, NULL, NULL);
WM_operator_name_call(C, "TEXT_OT_autocomplete", WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
}
else {
WM_operator_name_call(C, "TEXT_OT_indent", WM_OP_EXEC_DEFAULT, NULL, NULL);
WM_operator_name_call(C, "TEXT_OT_indent", WM_OP_EXEC_DEFAULT, nullptr, nullptr);
}
return OPERATOR_FINISHED;
}
@ -1152,7 +1153,7 @@ void TEXT_OT_indent_or_autocomplete(wmOperatorType *ot)
/** \name Indent Operator
* \{ */
static int text_indent_exec(bContext *C, wmOperator *UNUSED(op))
static int text_indent_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -1198,7 +1199,7 @@ void TEXT_OT_indent(wmOperatorType *ot)
/** \name Unindent Operator
* \{ */
static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op))
static int text_unindent_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -1239,7 +1240,7 @@ void TEXT_OT_unindent(wmOperatorType *ot)
/** \name Line Break Operator
* \{ */
static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op))
static int text_line_break_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -1336,10 +1337,10 @@ static int text_comment_exec(bContext *C, wmOperator *op)
void TEXT_OT_comment_toggle(wmOperatorType *ot)
{
static const EnumPropertyItem comment_items[] = {
{0, "TOGGLE", 0, "Toggle Comments", NULL},
{1, "COMMENT", 0, "Comment", NULL},
{-1, "UNCOMMENT", 0, "Un-Comment", NULL},
{0, NULL, 0, NULL, NULL},
{0, "TOGGLE", 0, "Toggle Comments", nullptr},
{1, "COMMENT", 0, "Comment", nullptr},
{-1, "UNCOMMENT", 0, "Un-Comment", nullptr},
{0, nullptr, 0, nullptr, nullptr},
};
/* identifiers */
@ -1356,7 +1357,7 @@ void TEXT_OT_comment_toggle(wmOperatorType *ot)
/* properties */
PropertyRNA *prop;
prop = RNA_def_enum(ot->srna, "type", comment_items, 0, "Type", "Add or remove comments");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
}
/** \} */
@ -1367,9 +1368,9 @@ void TEXT_OT_comment_toggle(wmOperatorType *ot)
enum { TO_SPACES, TO_TABS };
static const EnumPropertyItem whitespace_type_items[] = {
{TO_SPACES, "SPACES", 0, "To Spaces", NULL},
{TO_TABS, "TABS", 0, "To Tabs", NULL},
{0, NULL, 0, NULL, NULL},
{TO_SPACES, "SPACES", 0, "To Spaces", nullptr},
{TO_TABS, "TABS", 0, "To Tabs", nullptr},
{0, nullptr, 0, nullptr, nullptr},
};
static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
@ -1383,7 +1384,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
/* first convert to all space, this make it a lot easier to convert to tabs
* because there is no mixtures of ' ' && '\t' */
for (tmp = text->lines.first; tmp; tmp = tmp->next) {
for (tmp = static_cast<TextLine *>(text->lines.first); tmp; tmp = tmp->next) {
char *new_line;
BLI_assert(tmp->line);
@ -1400,16 +1401,16 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
/* Put new_line in the tmp->line spot still need to try and set the curc correctly. */
tmp->line = new_line;
tmp->len = strlen(new_line);
tmp->format = NULL;
tmp->format = nullptr;
if (tmp->len > max_len) {
max_len = tmp->len;
}
}
if (type == TO_TABS) {
char *tmp_line = MEM_mallocN(sizeof(*tmp_line) * (max_len + 1), __func__);
char *tmp_line = static_cast<char *>(MEM_mallocN(sizeof(*tmp_line) * (max_len + 1), __func__));
for (tmp = text->lines.first; tmp; tmp = tmp->next) {
for (tmp = static_cast<TextLine *>(text->lines.first); tmp; tmp = tmp->next) {
const char *text_check_line = tmp->line;
const int text_check_line_len = tmp->len;
char *tmp_line_cur = tmp_line;
@ -1476,7 +1477,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
* still need to try and set the curc correctly. */
tmp->line = BLI_strdup(tmp_line);
tmp->len = strlen(tmp_line);
tmp->format = NULL;
tmp->format = nullptr;
}
}
@ -1520,7 +1521,7 @@ void TEXT_OT_convert_whitespace(wmOperatorType *ot)
/** \name Select All Operator
* \{ */
static int text_select_all_exec(bContext *C, wmOperator *UNUSED(op))
static int text_select_all_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1552,7 +1553,7 @@ void TEXT_OT_select_all(wmOperatorType *ot)
/** \name Select Line Operator
* \{ */
static int text_select_line_exec(bContext *C, wmOperator *UNUSED(op))
static int text_select_line_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1584,7 +1585,7 @@ void TEXT_OT_select_line(wmOperatorType *ot)
/** \name Select Word Operator
* \{ */
static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op))
static int text_select_word_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1631,7 +1632,7 @@ static int move_lines_exec(bContext *C, wmOperator *op)
/* run the script while editing, evil but useful */
if (CTX_wm_space_text(C)->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -1642,7 +1643,7 @@ void TEXT_OT_move_lines(wmOperatorType *ot)
static const EnumPropertyItem direction_items[] = {
{TXT_MOVE_LINE_UP, "UP", 0, "Up", ""},
{TXT_MOVE_LINE_DOWN, "DOWN", 0, "Down", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
/* identifiers */
@ -1680,7 +1681,7 @@ static const EnumPropertyItem move_type_items[] = {
{NEXT_LINE, "NEXT_LINE", 0, "Next Line", ""},
{PREV_PAGE, "PREVIOUS_PAGE", 0, "Previous Page", ""},
{NEXT_PAGE, "NEXT_PAGE", 0, "Next Page", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
/* get cursor position in line by relative wrapped line and column positions */
@ -2170,7 +2171,7 @@ static int text_move_cursor(bContext *C, int type, bool select)
/* ensure we have the right region, it's optional */
if (region && region->regiontype != RGN_TYPE_WINDOW) {
region = NULL;
region = nullptr;
}
switch (type) {
@ -2263,7 +2264,7 @@ static int text_move_cursor(bContext *C, int type, bool select)
cursor_skip(st, region, st->text, -st->runtime.viewlines, select);
}
else {
cursor_skip(NULL, NULL, text, -10, select);
cursor_skip(nullptr, nullptr, text, -10, select);
}
break;
@ -2272,7 +2273,7 @@ static int text_move_cursor(bContext *C, int type, bool select)
cursor_skip(st, region, st->text, st->runtime.viewlines, select);
}
else {
cursor_skip(NULL, NULL, text, 10, select);
cursor_skip(nullptr, nullptr, text, 10, select);
}
break;
}
@ -2291,7 +2292,7 @@ static int text_move_exec(bContext *C, wmOperator *op)
{
int type = RNA_enum_get(op->ptr, "type");
return text_move_cursor(C, type, 0);
return text_move_cursor(C, type, false);
}
void TEXT_OT_move(wmOperatorType *ot)
@ -2319,7 +2320,7 @@ static int text_move_select_exec(bContext *C, wmOperator *op)
{
int type = RNA_enum_get(op->ptr, "type");
return text_move_cursor(C, type, 1);
return text_move_cursor(C, type, true);
}
void TEXT_OT_move_select(wmOperatorType *ot)
@ -2352,16 +2353,18 @@ static int text_jump_exec(bContext *C, wmOperator *op)
{
Text *text = CTX_data_edit_text(C);
int line = RNA_int_get(op->ptr, "line");
short nlines = txt_get_span(text->lines.first, text->lines.last) + 1;
short nlines = txt_get_span(static_cast<TextLine *>(text->lines.first),
static_cast<TextLine *>(text->lines.last)) +
1;
if (line < 1) {
txt_move_toline(text, 1, 0);
txt_move_toline(text, 1, false);
}
else if (line > nlines) {
txt_move_toline(text, nlines - 1, 0);
txt_move_toline(text, nlines - 1, false);
}
else {
txt_move_toline(text, line - 1, 0);
txt_move_toline(text, line - 1, false);
}
text_update_cursor_moved(C);
@ -2370,7 +2373,7 @@ static int text_jump_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int text_jump_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_jump_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
return WM_operator_props_dialog_popup(C, op, 200);
}
@ -2405,7 +2408,7 @@ static const EnumPropertyItem 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 text_delete_exec(bContext *C, wmOperator *op)
@ -2492,7 +2495,7 @@ static int text_delete_exec(bContext *C, wmOperator *op)
/* run the script while editing, evil but useful */
if (st->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -2520,7 +2523,7 @@ void TEXT_OT_delete(wmOperatorType *ot)
DEL_NEXT_CHAR,
"Type",
"Which part of the text to delete");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
}
/** \} */
@ -2529,7 +2532,7 @@ void TEXT_OT_delete(wmOperatorType *ot)
/** \name Toggle Overwrite Operator
* \{ */
static int text_toggle_overwrite_exec(bContext *C, wmOperator *UNUSED(op))
static int text_toggle_overwrite_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
@ -2588,7 +2591,7 @@ enum eScrollZone {
SCROLLHANDLE_MAX_OUTSIDE,
};
typedef struct TextScroll {
struct TextScroll {
int mval_prev[2];
int mval_delta[2];
@ -2605,7 +2608,7 @@ typedef struct TextScroll {
} state;
int ofs_delta[2];
int ofs_delta_px[2];
} TextScroll;
};
static void text_scroll_state_init(TextScroll *tsc, SpaceText *st, ARegion *region)
{
@ -2624,7 +2627,7 @@ static bool text_scroll_poll(bContext *C)
{
/* it should be possible to still scroll linked texts to read them,
* even if they can't be edited... */
return CTX_data_edit_text(C) != NULL;
return CTX_data_edit_text(C) != nullptr;
}
static int text_scroll_exec(bContext *C, wmOperator *op)
@ -2648,7 +2651,7 @@ static int text_scroll_exec(bContext *C, wmOperator *op)
static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
{
SpaceText *st = CTX_wm_space_text(C);
TextScroll *tsc = op->customdata;
TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
const int mval[2] = {event->xy[0], event->xy[1]};
text_update_character_width(st);
@ -2737,7 +2740,7 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
static void scroll_exit(bContext *C, wmOperator *op)
{
SpaceText *st = CTX_wm_space_text(C);
TextScroll *tsc = op->customdata;
TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
st->flags &= ~ST_SCROLL_SELECT;
@ -2754,7 +2757,7 @@ static void scroll_exit(bContext *C, wmOperator *op)
static int text_scroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
TextScroll *tsc = op->customdata;
TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
SpaceText *st = CTX_wm_space_text(C);
ARegion *region = CTX_wm_region(C);
@ -2800,7 +2803,7 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return text_scroll_exec(C, op);
}
tsc = MEM_callocN(sizeof(TextScroll), "TextScroll");
tsc = static_cast<TextScroll *>(MEM_callocN(sizeof(TextScroll), "TextScroll"));
tsc->is_first = true;
tsc->zone = SCROLLHANDLE_BAR;
@ -2868,14 +2871,14 @@ static bool text_region_scroll_poll(bContext *C)
ARegion *region = CTX_wm_region(C);
if (!st || !text) {
return 0;
return false;
}
if (!region || region->regiontype != RGN_TYPE_WINDOW) {
return 0;
return false;
}
return 1;
return true;
}
static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@ -2915,7 +2918,7 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev
return OPERATOR_PASS_THROUGH;
}
tsc = MEM_callocN(sizeof(TextScroll), "TextScroll");
tsc = static_cast<TextScroll *>(MEM_callocN(sizeof(TextScroll), "TextScroll"));
tsc->is_first = true;
tsc->is_scrollbar = true;
tsc->zone = zone;
@ -2969,11 +2972,11 @@ void TEXT_OT_scroll_bar(wmOperatorType *ot)
/** \name Set Selection Operator
* \{ */
typedef struct SetSelection {
struct SetSelection {
int selc, sell;
short mval_prev[2];
wmTimer *timer; /* needed for scrolling when mouse at region bounds */
} SetSelection;
};
static int flatten_width(SpaceText *st, const char *str)
{
@ -3016,11 +3019,11 @@ static int flatten_column_to_offset(SpaceText *st, const char *str, int index)
static TextLine *get_line_pos_wrapped(SpaceText *st, ARegion *region, int *y)
{
TextLine *linep = st->text->lines.first;
TextLine *linep = static_cast<TextLine *>(st->text->lines.first);
int i, lines;
if (*y < -st->top) {
return NULL; /* We are beyond the first line... */
return nullptr; /* We are beyond the first line... */
}
for (i = -st->top; i <= *y && linep; linep = linep->next, i += lines) {
@ -3142,11 +3145,11 @@ static void text_cursor_set_to_pos_wrapped(
}
}
else if (y < 0) { /* Before start of text. */
linep = st->text->lines.first;
linep = static_cast<TextLine *>(st->text->lines.first);
charp = 0;
}
else { /* Beyond end of text */
linep = st->text->lines.last;
linep = static_cast<TextLine *>(st->text->lines.last);
charp = linep->len;
}
@ -3191,7 +3194,7 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *region, int x, int y,
charp = &text->curc;
}
y -= txt_get_span(text->lines.first, *linep) - st->top;
y -= txt_get_span(static_cast<TextLine *>(text->lines.first), *linep) - st->top;
if (y > 0) {
while (y-- != 0) {
@ -3223,7 +3226,7 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *region, int x, int y,
static void text_cursor_timer_ensure(bContext *C, SetSelection *ssel)
{
if (ssel->timer == NULL) {
if (ssel->timer == nullptr) {
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = CTX_wm_window(C);
@ -3239,20 +3242,20 @@ static void text_cursor_timer_remove(bContext *C, SetSelection *ssel)
WM_event_remove_timer(wm, win, ssel->timer);
}
ssel->timer = NULL;
ssel->timer = nullptr;
}
static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *event)
{
SpaceText *st = CTX_wm_space_text(C);
ARegion *region = CTX_wm_region(C);
SetSelection *ssel = op->customdata;
SetSelection *ssel = static_cast<SetSelection *>(op->customdata);
if (event->mval[1] < 0 || event->mval[1] > region->winy) {
text_cursor_timer_ensure(C, ssel);
if (event->type == TIMER) {
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], 1);
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], true);
ED_text_scroll_to_cursor(st, region, false);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
@ -3262,7 +3265,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
if (event->type == TIMER) {
text_cursor_set_to_pos(
st, region, CLAMPIS(event->mval[0], 0, region->winx), event->mval[1], 1);
st, region, CLAMPIS(event->mval[0], 0, region->winx), event->mval[1], true);
ED_text_scroll_to_cursor(st, region, false);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
@ -3271,7 +3274,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
text_cursor_timer_remove(C, ssel);
if (event->type != TIMER) {
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], 1);
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], true);
ED_text_scroll_to_cursor(st, region, false);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
@ -3284,7 +3287,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
static void text_cursor_set_exit(bContext *C, wmOperator *op)
{
SpaceText *st = CTX_wm_space_text(C);
SetSelection *ssel = op->customdata;
SetSelection *ssel = static_cast<SetSelection *>(op->customdata);
text_update_cursor_moved(C);
text_select_update_primary_clipboard(st->text);
@ -3305,12 +3308,12 @@ static int text_selection_set_invoke(bContext *C, wmOperator *op, const wmEvent
}
op->customdata = MEM_callocN(sizeof(SetSelection), "SetCursor");
ssel = op->customdata;
ssel = static_cast<SetSelection *>(op->customdata);
ssel->mval_prev[0] = event->mval[0];
ssel->mval_prev[1] = event->mval[1];
ssel->sell = txt_get_span(st->text->lines.first, st->text->sell);
ssel->sell = txt_get_span(static_cast<TextLine *>(st->text->lines.first), st->text->sell);
ssel->selc = st->text->selc;
WM_event_add_modal_handler(C, op);
@ -3369,7 +3372,7 @@ static int text_cursor_set_exec(bContext *C, wmOperator *op)
int x = RNA_int_get(op->ptr, "x");
int y = RNA_int_get(op->ptr, "y");
text_cursor_set_to_pos(st, region, x, y, 0);
text_cursor_set_to_pos(st, region, x, y, false);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
@ -3414,7 +3417,7 @@ void TEXT_OT_cursor_set(wmOperatorType *ot)
/** \name Line Number Operator
* \{ */
static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
static int text_line_number_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -3448,9 +3451,9 @@ static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), const wm
}
jump_to *= 10;
jump_to += (int)(event_ascii - '0');
jump_to += int(event_ascii - '0');
txt_move_toline(text, jump_to - 1, 0);
txt_move_toline(text, jump_to - 1, false);
last_jump = time;
text_update_cursor_moved(C);
@ -3489,7 +3492,7 @@ static int text_insert_exec(bContext *C, wmOperator *op)
text_drawcache_tag_update(st, false);
str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, &str_len);
str = RNA_string_get_alloc(op->ptr, "text", nullptr, 0, &str_len);
ED_text_undo_push_init(C);
@ -3561,7 +3564,7 @@ static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* run the script while editing, evil but useful */
if (ret == OPERATOR_FINISHED && st->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return ret;
@ -3586,7 +3589,7 @@ void TEXT_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);
}
@ -3597,8 +3600,10 @@ void TEXT_OT_insert(wmOperatorType *ot)
* \{ */
/* mode */
#define TEXT_FIND 0
#define TEXT_REPLACE 1
enum {
TEXT_FIND = 0,
TEXT_REPLACE = 1,
};
static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
{
@ -3620,7 +3625,7 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
/* Replace current */
if (mode != TEXT_FIND && txt_has_sel(text)) {
tmp = txt_sel_to_buf(text, NULL);
tmp = txt_sel_to_buf(text, nullptr);
if (flags & ST_MATCH_CASE) {
found = STREQ(st->findstr, tmp);
@ -3635,7 +3640,7 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
txt_insert_buf(text, st->replacestr, strlen(st->replacestr));
if (text->curl && text->curl->format) {
MEM_freeN(text->curl->format);
text->curl->format = NULL;
text->curl->format = nullptr;
}
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
@ -3643,7 +3648,7 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
}
}
MEM_freeN(tmp);
tmp = NULL;
tmp = nullptr;
}
/* Find next */
@ -3653,12 +3658,12 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
}
else if (flags & ST_FIND_ALL) {
if (text->id.next) {
text = st->text = text->id.next;
text = st->text = static_cast<Text *>(text->id.next);
}
else {
text = st->text = bmain->texts.first;
text = st->text = static_cast<Text *>(bmain->texts.first);
}
txt_move_toline(text, 0, 0);
txt_move_toline(text, 0, false);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
}
@ -3719,7 +3724,7 @@ static int text_replace_all(bContext *C)
txt_insert_buf(text, st->replacestr, strlen(st->replacestr));
if (text->curl && text->curl->format) {
MEM_freeN(text->curl->format);
text->curl->format = NULL;
text->curl->format = nullptr;
}
found = txt_find_string(text, st->findstr, 0, flags & ST_MATCH_CASE);
} while (found);
@ -3762,7 +3767,7 @@ void TEXT_OT_replace(wmOperatorType *ot)
/* properties */
PropertyRNA *prop;
prop = RNA_def_boolean(ot->srna, "all", false, "Replace All", "Replace all occurrences");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
}
/** \} */
@ -3777,7 +3782,7 @@ static int text_find_set_selected_exec(bContext *C, wmOperator *op)
Text *text = CTX_data_edit_text(C);
char *tmp;
tmp = txt_sel_to_buf(text, NULL);
tmp = txt_sel_to_buf(text, nullptr);
STRNCPY(st->findstr, tmp);
MEM_freeN(tmp);
@ -3806,13 +3811,13 @@ void TEXT_OT_find_set_selected(wmOperatorType *ot)
/** \name Replace Set Selected
* \{ */
static int text_replace_set_selected_exec(bContext *C, wmOperator *UNUSED(op))
static int text_replace_set_selected_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
char *tmp;
tmp = txt_sel_to_buf(text, NULL);
tmp = txt_sel_to_buf(text, nullptr);
STRNCPY(st->replacestr, tmp);
MEM_freeN(tmp);
@ -3851,7 +3856,7 @@ static int text_jump_to_file_at_point_internal_exec(bContext *C, wmOperator *op)
const int column = RNA_int_get(op->ptr, "column");
Main *bmain = CTX_data_main(C);
Text *text = NULL;
Text *text = nullptr;
LISTBASE_FOREACH (Text *, text_iter, &bmain->texts) {
if (text_iter->filepath && BLI_path_cmp(text_iter->filepath, filepath) == 0) {
@ -3860,11 +3865,11 @@ static int text_jump_to_file_at_point_internal_exec(bContext *C, wmOperator *op)
}
}
if (text == NULL) {
if (text == nullptr) {
text = BKE_text_load(bmain, filepath, BKE_main_blendfile_path(bmain));
}
if (text == NULL) {
if (text == nullptr) {
BKE_reportf(op->reports, RPT_WARNING, "File '%s' cannot be opened", filepath);
return OPERATOR_CANCELLED;
}
@ -3897,12 +3902,12 @@ void TEXT_OT_jump_to_file_at_point_internal(wmOperatorType *ot)
/* flags */
ot->flag = 0;
prop = RNA_def_string(ot->srna, "filepath", NULL, FILE_MAX, "Filepath", "");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
prop = RNA_def_string(ot->srna, "filepath", nullptr, FILE_MAX, "Filepath", "");
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
prop = RNA_def_int(ot->srna, "line", 0, 0, INT_MAX, "Line", "Line to jump to", 1, 10000);
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
prop = RNA_def_int(ot->srna, "column", 0, 0, INT_MAX, "Column", "Column to jump to", 1, 10000);
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
}
/** \} */
@ -3917,7 +3922,7 @@ static const EnumPropertyItem resolution_items[] = {
{RESOLVE_RELOAD, "RELOAD", 0, "Reload", ""},
{RESOLVE_SAVE, "SAVE", 0, "Save", ""},
{RESOLVE_MAKE_INTERNAL, "MAKE_INTERNAL", 0, "Make Internal", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
static bool text_resolve_conflict_poll(bContext *C)
@ -3928,7 +3933,7 @@ static bool text_resolve_conflict_poll(bContext *C)
return false;
}
return ((text->filepath != NULL) && !(text->flags & TXT_ISMEM));
return ((text->filepath != nullptr) && !(text->flags & TXT_ISMEM));
}
static int text_resolve_conflict_exec(bContext *C, wmOperator *op)
@ -3951,7 +3956,7 @@ static int text_resolve_conflict_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
static int text_resolve_conflict_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_resolve_conflict_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
Text *text = CTX_data_edit_text(C);
uiPopupMenu *pup;
@ -4065,7 +4070,7 @@ void TEXT_OT_to_3d_object(wmOperatorType *ot)
/* properties */
RNA_def_boolean(
ot->srna, "split_lines", 0, "Split Lines", "Create one object per line in the text");
ot->srna, "split_lines", false, "Split Lines", "Create one object per line in the text");
}
/** \} */

View File

@ -6,8 +6,8 @@
* \ingroup sptext
*/
#include <errno.h>
#include <string.h>
#include <cerrno>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -40,8 +40,8 @@
#include "RNA_access.h"
#include "RNA_define.h"
#include "text_format.h"
#include "text_intern.h"
#include "text_format.hh"
#include "text_intern.hh"
/* -------------------------------------------------------------------- */
/** \name Implements ED Undo System
@ -52,12 +52,12 @@
/**
* Only stores the state of a text buffer.
*/
typedef struct TextState {
struct TextState {
BArrayState *buf_array_state;
int cursor_line, cursor_line_select;
int cursor_column, cursor_column_select;
} TextState;
};
static void text_state_encode(TextState *state, Text *text, BArrayStore *buffer_store)
{
@ -106,7 +106,7 @@ static void text_state_decode(TextState *state, Text *text)
/** \name Implements ED Undo System
* \{ */
typedef struct TextUndoStep {
struct TextUndoStep {
UndoStep step;
UndoRefID_Text text_ref;
/**
@ -114,7 +114,7 @@ typedef struct TextUndoStep {
* the second is the state after the operation is done.
*/
TextState states[2];
} TextUndoStep;
};
static struct {
BArrayStore *buffer_store;

View File

@ -119,7 +119,9 @@ static float transdata_get_time_shuffle_offset_side(ListBase *trans_datas, const
}
total_offset += offset;
} while (!IS_EQF(offset, 0.0f));
} while (!IS_EQT(offset, 0.0f, 1e-4));
/* Needs a eps greater than FLT_EPS because strip->start/end could be non-integral, and after
* those calculations, `offset` could fall outside of FLT_EPS. */
return total_offset;
}

View File

@ -1385,7 +1385,7 @@ eSnapMode snapObjectsTransform(
SnapObjectParams snap_object_params{};
snap_object_params.snap_target_select = t->tsnap.target_operation;
snap_object_params.edit_mode_type = (t->flag & T_EDIT) != 0 ? SNAP_GEOM_EDIT : SNAP_GEOM_FINAL;
snap_object_params.use_occlusion_test = t->settings->snap_mode != SCE_SNAP_MODE_FACE;
snap_object_params.use_occlusion_test = true;
snap_object_params.use_backface_culling = (t->tsnap.flag & SCE_SNAP_BACKFACE_CULLING) != 0;
float *target = (t->tsnap.status & SNAP_SOURCE_FOUND) ? t->tsnap.snap_source : t->center_global;

View File

@ -969,7 +969,8 @@ struct RaycastObjUserData {
/* read/write args */
float *ray_depth;
bool use_occlusion_test;
uint use_occlusion_test : 1;
uint use_occlusion_test_edit : 1;
};
/**
@ -986,21 +987,17 @@ static eSnapMode raycast_obj_fn(SnapObjectContext *sctx,
{
RaycastObjUserData *dt = static_cast<RaycastObjUserData *>(data);
const uint ob_index = dt->ob_index++;
bool use_occlusion_test = dt->use_occlusion_test;
/* read/write args */
float *ray_depth = dt->ray_depth;
bool retval = false;
bool is_edit = false;
if (use_occlusion_test) {
if (ELEM(ob_eval->dt, OB_BOUNDBOX, OB_WIRE)) {
/* Do not hit objects that are in wire or bounding box
* display mode. */
return SCE_SNAP_MODE_NONE;
}
}
if (ob_data == nullptr) {
if (dt->use_occlusion_test_edit && ELEM(ob_eval->dt, OB_BOUNDBOX, OB_WIRE)) {
/* Do not hit objects that are in wire or bounding box display mode. */
return SCE_SNAP_MODE_NONE;
}
if (ob_eval->type == OB_MESH) {
BMEditMesh *em = BKE_editmesh_from_object(ob_eval);
if (UNLIKELY(!em)) { /* See #mesh_for_snap doc-string. */
@ -1028,6 +1025,10 @@ static eSnapMode raycast_obj_fn(SnapObjectContext *sctx,
return SCE_SNAP_MODE_NONE;
}
}
else if (dt->use_occlusion_test && ELEM(ob_eval->dt, OB_BOUNDBOX, OB_WIRE)) {
/* Do not hit objects that are in wire or bounding box display mode. */
return SCE_SNAP_MODE_NONE;
}
else if (GS(ob_data->name) != ID_ME) {
return SCE_SNAP_MODE_NONE;
}
@ -1080,26 +1081,20 @@ static bool raycastObjects(SnapObjectContext *sctx,
const SnapObjectParams *params,
const float ray_start[3],
const float ray_dir[3],
const bool use_occlusion_test,
const bool use_occlusion_test_edit,
/* read/write args */
/* Parameters below cannot be const, because they are assigned to a
* non-const variable (readability-non-const-parameter). */
float *ray_depth /* NOLINT */)
{
const View3D *v3d = sctx->runtime.v3d;
if (params->use_occlusion_test && v3d && XRAY_FLAG_ENABLED(v3d)) {
/* General testing of occlusion geometry is disabled if the snap is not intended for the edit
* cage. */
if (params->edit_mode_type == SNAP_GEOM_EDIT) {
return false;
}
}
RaycastObjUserData data = {};
data.ray_start = ray_start;
data.ray_dir = ray_dir;
data.ob_index = 0;
data.ray_depth = ray_depth;
data.use_occlusion_test = params->use_occlusion_test;
data.use_occlusion_test = use_occlusion_test;
data.use_occlusion_test_edit = use_occlusion_test_edit;
return iter_snap_objects(sctx, params, raycast_obj_fn, &data) != SCE_SNAP_MODE_NONE;
}
@ -3117,7 +3112,14 @@ bool ED_transform_snap_object_project_ray_ex(SnapObjectContext *sctx,
sctx->ret.dist_sq = FLT_MAX;
sctx->ret.is_edit = false;
if (raycastObjects(sctx, params, ray_start, ray_normal, ray_depth)) {
if (raycastObjects(sctx,
params,
ray_start,
ray_normal,
params->use_occlusion_test,
params->use_occlusion_test,
ray_depth))
{
copy_v3_v3(r_loc, sctx->ret.loc);
if (r_no) {
copy_v3_v3(r_no, sctx->ret.no);
@ -3167,7 +3169,14 @@ bool ED_transform_snap_object_project_ray_all(SnapObjectContext *sctx,
float ray_depth_prev = ray_depth;
#endif
if (raycastObjects(sctx, params, ray_start, ray_normal, &ray_depth)) {
if (raycastObjects(sctx,
params,
ray_start,
ray_normal,
params->use_occlusion_test,
params->use_occlusion_test,
&ray_depth))
{
if (sort) {
BLI_listbase_sort(r_hit_list, hit_depth_cmp);
}
@ -3275,17 +3284,21 @@ static eSnapMode transform_snap_context_project_view3d_mixed_impl(SnapObjectCont
const RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
if (snap_to_flag & (SCE_SNAP_MODE_FACE | SCE_SNAP_MODE_FACE_NEAREST)) {
if (params->use_occlusion_test && XRAY_ENABLED(v3d)) {
/* Remove Snap to Face with Occlusion Test as they are not visible in wireframe mode. */
snap_to_flag &= ~(SCE_SNAP_MODE_FACE | SCE_SNAP_MODE_FACE_NEAREST);
}
else if (prev_co == nullptr || init_co == nullptr) {
/* No location to work with #SCE_SNAP_MODE_FACE_NEAREST. */
snap_to_flag &= ~SCE_SNAP_MODE_FACE_NEAREST;
bool use_occlusion_test = params->use_occlusion_test;
if (use_occlusion_test && XRAY_ENABLED(v3d) && (snap_to_flag & SCE_SNAP_MODE_FACE)) {
if (snap_to_flag != SCE_SNAP_MODE_FACE) {
/* In theory everything is visible in X-Ray except faces. */
snap_to_flag &= ~SCE_SNAP_MODE_FACE;
use_occlusion_test = false;
}
}
if ((snap_to_flag & SCE_SNAP_MODE_FACE_NEAREST) && ELEM(nullptr, prev_co, init_co)) {
/* No location to work with #SCE_SNAP_MODE_FACE_NEAREST. */
snap_to_flag &= ~SCE_SNAP_MODE_FACE_NEAREST;
}
/* NOTE: if both face ray-cast and face nearest are enabled, first find result of nearest, then
* override with ray-cast. */
if ((snap_to_flag & SCE_SNAP_MODE_FACE_NEAREST) && !has_hit) {
@ -3310,8 +3323,6 @@ static eSnapMode transform_snap_context_project_view3d_mixed_impl(SnapObjectCont
}
}
bool use_occlusion_test = params->use_occlusion_test && !XRAY_ENABLED(v3d);
if ((snap_to_flag & SCE_SNAP_MODE_FACE) || use_occlusion_test) {
float ray_start[3], ray_normal[3];
if (!ED_view3d_win_to_ray_clipped_ex(
@ -3322,7 +3333,13 @@ static eSnapMode transform_snap_context_project_view3d_mixed_impl(SnapObjectCont
float dummy_ray_depth = BVH_RAYCAST_DIST_MAX;
has_hit = raycastObjects(sctx, params, ray_start, ray_normal, &dummy_ray_depth);
has_hit = raycastObjects(sctx,
params,
ray_start,
ray_normal,
use_occlusion_test,
use_occlusion_test && (snap_to_flag & SCE_SNAP_MODE_FACE) == 0,
&dummy_ray_depth);
if (has_hit) {
if (r_face_nor) {

View File

@ -1780,7 +1780,7 @@ static float pack_islands_scale_margin(const Span<PackIsland *> islands,
}
/* If some of the islands are locked, we build a summary about them here. */
rctf locked_bounds; /* AABB of islands which can't translate. */
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];

View File

@ -316,32 +316,32 @@ typedef struct GPUSamplerState {
/* The sampler state is of type PARAMETERS, so serialize the parameters. */
BLI_assert(this->type == GPU_SAMPLER_STATE_TYPE_PARAMETERS);
std::string serialized_paramaters;
std::string serialized_parameters;
if (this->filtering & GPU_SAMPLER_FILTERING_LINEAR) {
serialized_paramaters += "linear-filter_";
serialized_parameters += "linear-filter_";
}
if (this->filtering & GPU_SAMPLER_FILTERING_MIPMAP) {
serialized_paramaters += "mipmap_";
serialized_parameters += "mipmap_";
}
if (this->filtering & GPU_SAMPLER_FILTERING_ANISOTROPIC) {
serialized_paramaters += "anisotropic_";
serialized_parameters += "anisotropic_";
}
switch (this->extend_x) {
case GPU_SAMPLER_EXTEND_MODE_EXTEND:
serialized_paramaters += "extend-x_";
serialized_parameters += "extend-x_";
break;
case GPU_SAMPLER_EXTEND_MODE_REPEAT:
serialized_paramaters += "repeat-x_";
serialized_parameters += "repeat-x_";
break;
case GPU_SAMPLER_EXTEND_MODE_MIRRORED_REPEAT:
serialized_paramaters += "mirrored-repeat-x_";
serialized_parameters += "mirrored-repeat-x_";
break;
case GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER:
serialized_paramaters += "clamp-to-border-x_";
serialized_parameters += "clamp-to-border-x_";
break;
default:
BLI_assert_unreachable();
@ -349,16 +349,16 @@ typedef struct GPUSamplerState {
switch (this->extend_yz) {
case GPU_SAMPLER_EXTEND_MODE_EXTEND:
serialized_paramaters += "extend-y_";
serialized_parameters += "extend-y_";
break;
case GPU_SAMPLER_EXTEND_MODE_REPEAT:
serialized_paramaters += "repeat-y_";
serialized_parameters += "repeat-y_";
break;
case GPU_SAMPLER_EXTEND_MODE_MIRRORED_REPEAT:
serialized_paramaters += "mirrored-repeat-y_";
serialized_parameters += "mirrored-repeat-y_";
break;
case GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER:
serialized_paramaters += "clamp-to-border-y_";
serialized_parameters += "clamp-to-border-y_";
break;
default:
BLI_assert_unreachable();
@ -366,22 +366,22 @@ typedef struct GPUSamplerState {
switch (this->extend_yz) {
case GPU_SAMPLER_EXTEND_MODE_EXTEND:
serialized_paramaters += "extend-z";
serialized_parameters += "extend-z";
break;
case GPU_SAMPLER_EXTEND_MODE_REPEAT:
serialized_paramaters += "repeat-z";
serialized_parameters += "repeat-z";
break;
case GPU_SAMPLER_EXTEND_MODE_MIRRORED_REPEAT:
serialized_paramaters += "mirrored-repeat-z";
serialized_parameters += "mirrored-repeat-z";
break;
case GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER:
serialized_paramaters += "clamp-to-border-z";
serialized_parameters += "clamp-to-border-z";
break;
default:
BLI_assert_unreachable();
}
return serialized_paramaters;
return serialized_parameters;
}
bool operator==(GPUSamplerState const &rhs) const

View File

@ -382,8 +382,7 @@ void MTLImmediate::end()
/* SSBO vertex fetch - Nullify elements buffer. */
if (rps.cached_vertex_buffer_bindings[MTL_SSBO_VERTEX_FETCH_IBO_INDEX].metal_buffer ==
nil)
{
nil) {
rps.bind_vertex_buffer(null_buffer, 0, MTL_SSBO_VERTEX_FETCH_IBO_INDEX);
}

View File

@ -306,18 +306,19 @@ void MTLBufferPool::update_memory_pools()
deletion_time_threshold_s = 2;
}
else
/* Spare pool memory >= 1GB. */
if (allocations_in_pool_ >= MEMORY_SIZE_1GB) {
deletion_time_threshold_s = 4;
}
/* Spare pool memory >= 512MB.*/
else if (allocations_in_pool_ >= MEMORY_SIZE_512MB) {
deletion_time_threshold_s = 15;
}
/* Spare pool memory >= 256MB. */
else if (allocations_in_pool_ >= MEMORY_SIZE_256MB) {
deletion_time_threshold_s = 60;
}
/* Spare pool memory >= 1GB. */
if (allocations_in_pool_ >= MEMORY_SIZE_1GB)
{
deletion_time_threshold_s = 4;
}
/* Spare pool memory >= 512MB.*/
else if (allocations_in_pool_ >= MEMORY_SIZE_512MB) {
deletion_time_threshold_s = 15;
}
/* Spare pool memory >= 256MB. */
else if (allocations_in_pool_ >= MEMORY_SIZE_256MB) {
deletion_time_threshold_s = 60;
}
if (time_passed > deletion_time_threshold_s) {

View File

@ -338,8 +338,7 @@ bool MTLShader::finalize(const shader::ShaderCreateInfo *info)
if (error) {
/* Only exit out if genuine error and not warning. */
if ([[error localizedDescription] rangeOfString:@"Compilation succeeded"].location ==
NSNotFound)
{
NSNotFound) {
const char *errors_c_str = [[error localizedDescription] UTF8String];
const char *sources_c_str = shd_builder_->glsl_fragment_source_.c_str();
@ -877,8 +876,7 @@ MTLRenderPipelineStateInstance *MTLShader::bake_pipeline_state(
}
else {
for (const uint i :
IndexRange(pipeline_descriptor.vertex_descriptor.max_attribute_value + 1))
{
IndexRange(pipeline_descriptor.vertex_descriptor.max_attribute_value + 1)) {
/* Metal back-end attribute descriptor state. */
const MTLVertexAttributeDescriptorPSO &attribute_desc =
@ -1071,8 +1069,7 @@ MTLRenderPipelineStateInstance *MTLShader::bake_pipeline_state(
bool null_pointsize = true;
float MTL_pointsize = pipeline_descriptor.point_size;
if (pipeline_descriptor.vertex_descriptor.prim_topology_class ==
MTLPrimitiveTopologyClassPoint)
{
MTLPrimitiveTopologyClassPoint) {
/* `if pointsize is > 0.0`, PROGRAM_POINT_SIZE is enabled, and `gl_PointSize` shader keyword
* overrides the value. Otherwise, if < 0.0, use global constant point size. */
if (MTL_pointsize < 0.0) {
@ -1144,8 +1141,7 @@ MTLRenderPipelineStateInstance *MTLShader::bake_pipeline_state(
/* Setup pixel format state */
for (int color_attachment = 0; color_attachment < GPU_FB_MAX_COLOR_ATTACHMENT;
color_attachment++)
{
color_attachment++) {
/* Fetch color attachment pixel format in back-end pipeline state. */
MTLPixelFormat pixel_format = pipeline_descriptor.color_attachment_format[color_attachment];
/* Populate MTL API PSO attachment descriptor. */
@ -1386,8 +1382,7 @@ bool MTLShader::bake_compute_pipeline_state(MTLContext *ctx)
/* Only exit out if genuine error and not warning */
if ([[error localizedDescription] rangeOfString:@"Compilation succeeded"].location ==
NSNotFound)
{
NSNotFound) {
BLI_assert(false);
return false;
}

View File

@ -1892,7 +1892,7 @@ bool gpu::MTLTexture::texture_is_baked()
void gpu::MTLTexture::prepare_internal()
{
/* Metal: Texture clearing is done using frame-buffer clear. This has no performance impact or
* bandwidth implications for lossless compression and is considered best-practise.
* bandwidth implications for lossless compression and is considered best-practice.
*
* Attachment usage also required for depth-stencil attachment targets, for depth-update support.
*/

View File

@ -289,8 +289,6 @@ static void test_texture_roundtrip__GPU_DATA_FLOAT__GPU_RGB10_A2UI()
GPU_TEST(texture_roundtrip__GPU_DATA_FLOAT__GPU_RGB10_A2UI);
#endif
#endif
static void test_texture_roundtrip__GPU_DATA_FLOAT__GPU_R11F_G11F_B10F()
{
texture_create_upload_read_with_bias<GPU_R11F_G11F_B10F, GPU_DATA_FLOAT>(0.0009f);
@ -654,18 +652,18 @@ static void test_texture_roundtrip__GPU_DATA_UINT__GPU_RGB32UI()
GPU_TEST(texture_roundtrip__GPU_DATA_UINT__GPU_RGB32UI);
#endif
static void test_texture_roundtrip__GPU_DATA_UINT__GPU_DEPTH_COMPONENT24()
{
texture_create_upload_read<GPU_DEPTH_COMPONENT24, GPU_DATA_UINT, uint32_t>();
}
GPU_TEST(texture_roundtrip__GPU_DATA_UINT__GPU_DEPTH_COMPONENT24);
static void test_texture_roundtrip__GPU_DATA_UINT__GPU_DEPTH_COMPONENT32F()
{
texture_create_upload_read<GPU_DEPTH_COMPONENT32F, GPU_DATA_UINT, uint32_t>();
}
GPU_TEST(texture_roundtrip__GPU_DATA_UINT__GPU_DEPTH_COMPONENT32F);
static void test_texture_roundtrip__GPU_DATA_UINT__GPU_DEPTH_COMPONENT24()
{
texture_create_upload_read<GPU_DEPTH_COMPONENT24, GPU_DATA_UINT, uint32_t>();
}
GPU_TEST(texture_roundtrip__GPU_DATA_UINT__GPU_DEPTH_COMPONENT24);
#if RUN_COMPONENT_UNIMPLEMENTED
static void test_texture_roundtrip__GPU_DATA_UINT__GPU_DEPTH_COMPONENT16()
{

View File

@ -75,12 +75,14 @@ void VKBackend::platform_init(const VKDevice &device)
void VKBackend::detect_workarounds(VKDevice &device)
{
device.workarounds_.depth_component_24 = false;
VKWorkarounds workarounds;
/* */
/* AMD GPUs don't support texture formats that use are aligned to 24 or 48 bits. */
if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
device.workarounds_.depth_component_24 = true;
workarounds.not_aligned_pixel_formats = true;
}
device.workarounds_ = workarounds;
}
void VKBackend::platform_exit()

View File

@ -78,8 +78,13 @@ void pop_marker(VkCommandBuffer vk_command_buffer);
void push_marker(const VKDevice &device, const char *name);
void set_marker(const VKDevice &device, const char *name);
void pop_marker(const VKDevice &device);
/* how to use : debug::raise_message(0xB41ca2,VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,"This
* is a raise message. %llx", (uintptr_t)vk_object); */
/**
* How to use:
* \code{.cc}
* debug::raise_message(0xB41ca2, VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,
* "This is a raise message. %llx", (uintptr_t)vk_object);
* \endcode
*/
void raise_message(int32_t id_number,
VkDebugUtilsMessageSeverityFlagBitsEXT vk_severity_flag_bits,
const char *fmt,

View File

@ -17,6 +17,16 @@
namespace blender::gpu {
class VKBackend;
struct VKWorkarounds {
/**
* Some devices don't support pixel formats that are aligned to 24 and 48 bits.
* In this case we need to use a different texture format.
*
* If set to true we should work around this issue by using a different texture format.
*/
bool not_aligned_pixel_formats = false;
};
class VKDevice : public NonCopyable {
private:
/** Copies of the handles owned by the GHOST context. */
@ -37,11 +47,7 @@ class VKDevice : public NonCopyable {
debug::VKDebuggingTools debugging_tools_;
/* Workarounds */
struct {
bool depth_component_24 = false;
bool texture_format_rgb16f = false;
} workarounds_;
VKWorkarounds workarounds_;
public:
VkPhysicalDevice physical_device_get() const
@ -103,14 +109,9 @@ class VKDevice : public NonCopyable {
std::string vendor_name() const;
std::string driver_version() const;
/**
* Some devices don't support `GPU_DEPTH_COMPONENT_24` texture formats.
*
* Check with this function if the workaround should be used to work around this issue.
*/
bool get_component_24_workaround() const
const VKWorkarounds &workarounds_get() const
{
return workarounds_.depth_component_24;
return workarounds_;
}
private:

View File

@ -266,10 +266,11 @@ bool VKTexture::init_internal()
* allocation of the texture on the device. */
const VKDevice &device = VKBackend::get().device_get();
if (format_ == GPU_DEPTH_COMPONENT24 && device.get_component_24_workaround()) {
const VKWorkarounds &workarounds = device.workarounds_get();
if (format_ == GPU_DEPTH_COMPONENT24 && workarounds.not_aligned_pixel_formats) {
format_ = GPU_DEPTH_COMPONENT32F;
}
if (format_ == GPU_DEPTH24_STENCIL8 && device.get_component_24_workaround()) {
if (format_ == GPU_DEPTH24_STENCIL8 && workarounds.not_aligned_pixel_formats) {
format_ = GPU_DEPTH32F_STENCIL8;
}

View File

@ -72,7 +72,6 @@ set(SRC
intern/usd_asset_utils.cc
intern/usd_capi_export.cc
intern/usd_capi_import.cc
intern/usd_common.cc
intern/usd_hierarchy_iterator.cc
intern/usd_writer_abstract.cc
intern/usd_writer_camera.cc
@ -101,7 +100,6 @@ set(SRC
usd.h
intern/usd_asset_utils.h
intern/usd_common.h
intern/usd_exporter_context.h
intern/usd_hierarchy_iterator.h
intern/usd_writer_abstract.h
@ -161,8 +159,6 @@ if(WITH_GTESTS)
tests/usd_curves_test.cc
tests/usd_export_test.cc
tests/usd_stage_creation_test.cc
tests/usd_tests_common.cc
tests/usd_tests_common.h
tests/usd_usdz_export_test.cc
intern/usd_writer_material.h
)

View File

@ -3,7 +3,6 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "usd.h"
#include "usd_common.h"
#include "usd_hierarchy_iterator.h"
#include <pxr/base/plug/registry.h>

View File

@ -4,7 +4,6 @@
#include "IO_types.h"
#include "usd.h"
#include "usd_common.h"
#include "usd_hierarchy_iterator.h"
#include "usd_reader_geom.h"
#include "usd_reader_prim.h"
@ -409,11 +408,6 @@ static void import_freejob(void *user_data)
using namespace blender::io::usd;
void USD_ensure_plugin_path_registered()
{
blender::io::usd::ensure_usd_plugin_path_registered();
}
bool USD_import(struct bContext *C,
const char *filepath,
const USDImportParams *params,

View File

@ -1,36 +0,0 @@
/* SPDX-FileCopyrightText: 2021 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "usd_common.h"
#include <pxr/base/plug/registry.h>
#include "BKE_appdir.h"
namespace blender::io::usd {
void ensure_usd_plugin_path_registered()
{
/* If #PXR_PYTHON_SUPPORT_ENABLED is defined, we *must* be dynamic and
* the plugins are placed relative to the USD shared library hence no
* hinting is required. */
#ifndef PXR_PYTHON_SUPPORT_ENABLED
static bool plugin_path_registered = false;
if (plugin_path_registered) {
return;
}
plugin_path_registered = true;
/* Tell USD which directory to search for its JSON files. If 'datafiles/usd'
* does not exist, the USD library will not be able to read or write any files. */
const char *blender_usd_datafiles = BKE_appdir_folder_id(BLENDER_DATAFILES, "usd");
if (blender_usd_datafiles) {
const std::string blender_usd_data_folder = blender_usd_datafiles;
/* The trailing slash indicates to the USD library that the path is a directory. */
pxr::PlugRegistry::GetInstance().RegisterPlugins(blender_usd_data_folder + SEP_STR);
}
#endif
}
} // namespace blender::io::usd

View File

@ -1,10 +0,0 @@
/* SPDX-FileCopyrightText: 2021 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
namespace blender::io::usd {
void ensure_usd_plugin_path_registered();
} // namespace blender::io::usd

View File

@ -41,7 +41,6 @@
#include "WM_api.h"
#include "usd.h"
#include "usd_tests_common.h"
namespace blender::io::usd {
@ -86,10 +85,6 @@ class UsdCurvesTest : public BlendfileLoadingBaseTest {
virtual void SetUp() override
{
BlendfileLoadingBaseTest::SetUp();
std::string usd_plugin_path = register_usd_plugins_for_tests();
if (usd_plugin_path.empty()) {
FAIL();
}
}
virtual void TearDown() override

View File

@ -38,7 +38,6 @@
#include "WM_api.h"
#include "usd.h"
#include "usd_tests_common.h"
#include "usd_writer_material.h"
namespace blender::io::usd {
@ -73,10 +72,6 @@ class UsdExportTest : public BlendfileLoadingBaseTest {
virtual void SetUp() override
{
BlendfileLoadingBaseTest::SetUp();
std::string usd_plugin_path = register_usd_plugins_for_tests();
if (usd_plugin_path.empty()) {
FAIL() << "Unable to find the USD Plugins path.";
}
}
virtual void TearDown() override

View File

@ -3,8 +3,6 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "testing/testing.h"
#include "usd_tests_common.h"
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdGeom/capsule.h>
#include <pxr/usdImaging/usdImaging/capsuleAdapter.h>
@ -21,13 +19,6 @@ TEST_F(USDImagingTest, CapsuleAdapterTest)
* We create a capsule shape on an in-memory stage and attempt
* to access the shape's points and topology. */
/* We must register USD plugin paths before creating the stage
* to avoid a crash in the USD asset resolver initialization code. */
if (register_usd_plugins_for_tests().empty()) {
FAIL();
return;
}
pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory();
if (!stage) {

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