Alternative Upload geometry data in parallel to multiple GPUs using the "Multi-Device" #107552

Open
William Leeson wants to merge 137 commits from leesonw/blender-cluster:upload_changed into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
220 changed files with 2134 additions and 954 deletions
Showing only changes of commit 0bd30b175a - Show all commits

View File

@ -1555,6 +1555,9 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
# add_check_c_compiler_flag(C_WARNINGS C_WARN_UNUSED_MACROS -Wunused-macros)
# add_check_cxx_compiler_flag(CXX_WARNINGS CXX_WARN_UNUSED_MACROS -Wunused-macros)
add_check_c_compiler_flag(C_WARNINGS C_WARN_ERROR_UNGUARDED_AVAILABILITY_NEW -Werror=unguarded-availability-new)
add_check_c_compiler_flag(CXX_WARNINGS CXX_WARN_ERROR_UNGUARDED_AVAILABILITY_NEW -Werror=unguarded-availability-new)
# ---------------------
# Suppress Strict Flags

View File

@ -1,20 +0,0 @@
if NOT exist "%BLENDER_DIR%\source\tools\.git" (
echo Checking out sub-modules
if not "%GIT%" == "" (
"%GIT%" submodule update --init --recursive --progress
if errorlevel 1 goto FAIL
"%GIT%" submodule foreach git checkout main
if errorlevel 1 goto FAIL
"%GIT%" submodule foreach git pull --rebase origin main
if errorlevel 1 goto FAIL
goto EOF
) else (
echo Blender submodules not found, and git not found in path to retrieve them.
goto FAIL
)
)
goto EOF
:FAIL
exit /b 1
:EOF

View File

@ -14,7 +14,7 @@ if NOT EXIST %PYTHON% (
exit /b 1
)
set FORMAT_PATHS=%BLENDER_DIR%\source\tools\utils_maintenance\clang_format_paths.py
set FORMAT_PATHS=%BLENDER_DIR%\tools\utils_maintenance\clang_format_paths.py
REM The formatting script expects clang-format to be in the current PATH.
set PATH=%CF_PATH%;%PATH%

View File

@ -41,7 +41,7 @@ static const char *FRAGMENT_SHADER =
"void main()\n"
"{\n"
" vec4 rgba = texture(image_texture, texCoord_interp);\n"
/* Harcoded Rec.709 gamma, should use OpenColorIO eventually. */
/* Hard-coded Rec.709 gamma, should use OpenColorIO eventually. */
" fragColor = pow(rgba, vec4(0.45, 0.45, 0.45, 1.0));\n"
"}\n\0";

View File

@ -128,9 +128,8 @@ void RenderScheduler::reset(const BufferParams &buffer_params, int num_samples,
state_.resolution_divider = 1;
}
else {
/* NOTE: Divide by 2 because of the way how scheduling works: it advances resolution divider
* first and then initialized render work. */
state_.resolution_divider = start_resolution_divider_ * 2;
state_.user_is_navigating = true;
state_.resolution_divider = start_resolution_divider_;
}
state_.num_rendered_samples = 0;
@ -312,7 +311,21 @@ RenderWork RenderScheduler::get_render_work()
RenderWork render_work;
if (state_.resolution_divider != pixel_size_) {
state_.resolution_divider = max(state_.resolution_divider / 2, pixel_size_);
if (state_.user_is_navigating) {
/* Don't progress the resolution divider as the user is currently navigating in the scene. */
state_.user_is_navigating = false;
}
else {
/* If the resolution divider is greater than or equal to default_start_resolution_divider_,
* drop the resolution divider down to 4. This is so users with slow hardware and thus high
* resolution dividers (E.G. 16), get an update to let them know something is happening
* rather than having to wait for the full 1:1 render to show up. */
state_.resolution_divider = state_.resolution_divider > default_start_resolution_divider_ ?
(4 * pixel_size_) :
1;
}
state_.resolution_divider = max(state_.resolution_divider, pixel_size_);
state_.num_rendered_samples = 0;
state_.last_display_update_sample = -1;
}
@ -1058,10 +1071,16 @@ void RenderScheduler::update_start_resolution_divider()
return;
}
/* Calculate the maximum resolution divider possible while keeping the long axis of the viewport
* above our prefered minimum axis size (128) */
const int long_viewport_axis = max(buffer_params_.width, buffer_params_.height);
const int max_res_divider_for_desired_size = long_viewport_axis / 128;
if (start_resolution_divider_ == 0) {
/* Resolution divider has never been calculated before: use default resolution, so that we have
* somewhat good initial behavior, giving a chance to collect real numbers. */
start_resolution_divider_ = default_start_resolution_divider_;
/* Resolution divider has never been calculated before: start with a high resolution divider so
* that we have a somewhat good initial behavior, giving a chance to collect real numbers. */
start_resolution_divider_ = min(default_start_resolution_divider_,
max_res_divider_for_desired_size);
VLOG_WORK << "Initial resolution divider is " << start_resolution_divider_;
return;
}
@ -1089,8 +1108,7 @@ void RenderScheduler::update_start_resolution_divider()
/* Don't let resolution drop below the desired one. It's better to be slow than provide an
* unreadable viewport render. */
start_resolution_divider_ = min(resolution_divider_for_update,
default_start_resolution_divider_);
start_resolution_divider_ = min(resolution_divider_for_update, max_res_divider_for_desired_size);
VLOG_WORK << "Calculated resolution divider is " << start_resolution_divider_;
}

View File

@ -332,6 +332,8 @@ class RenderScheduler {
};
struct {
bool user_is_navigating = false;
int resolution_divider = 1;
/* Number of rendered samples on top of the start sample. */

View File

@ -153,6 +153,16 @@ static float3 output_estimate_emission(ShaderOutput *output, bool &is_constant)
estimate *= node->get_float(strength_in->socket_type);
}
/* Lower importance of emission nodes from automatic value/color to shader
* conversion, as these are likely used for previewing and can be slow to
* build a light tree for on dense meshes. */
if (node->type == EmissionNode::get_node_type()) {
EmissionNode *emission_node = static_cast<EmissionNode *>(node);
if (emission_node->from_auto_conversion) {
estimate *= 0.1f;
}
}
return estimate;
}
else if (node->type == LightFalloffNode::get_node_type() ||

View File

@ -260,6 +260,7 @@ void ShaderGraph::connect(ShaderOutput *from, ShaderInput *to)
if (to->type() == SocketType::CLOSURE) {
EmissionNode *emission = create_node<EmissionNode>();
emission->from_auto_conversion = true;
emission->set_color(one_float3());
emission->set_strength(1.0f);
convert = add(emission);

View File

@ -723,6 +723,8 @@ class EmissionNode : public ShaderNode {
NODE_SOCKET_API(float3, color)
NODE_SOCKET_API(float, strength)
NODE_SOCKET_API(float, surface_mix_weight)
bool from_auto_conversion = false;
};
class BackgroundNode : public ShaderNode {

View File

@ -113,9 +113,6 @@ if "%TEST%" == "1" (
goto EOF
)
call "%BLENDER_DIR%\build_files\windows\check_submodules.cmd"
if errorlevel 1 goto EOF
if "%BUILD_WITH_NINJA%" == "" (
call "%BLENDER_DIR%\build_files\windows\configure_msbuild.cmd"
if errorlevel 1 goto EOF

View File

@ -66,8 +66,8 @@ const UserDef U_default = {
/** Default so DPI is detected automatically. */
.dpi = 0,
.dpi_fac = 0.0,
.inv_dpi_fac = 0.0, /* run-time. */
.scale_factor = 0.0,
.inv_scale_factor = 0.0, /* run-time. */
.pixelsize = 1,
.virtual_pixel = 0,

View File

@ -25,6 +25,7 @@ class AssetIdentifier {
AssetIdentifier(const AssetIdentifier &) = default;
std::string full_path() const;
std::string full_library_path() const;
};
} // namespace blender::asset_system

View File

@ -21,6 +21,8 @@ const char *AS_asset_representation_name_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
struct ID *AS_asset_representation_local_id_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
bool AS_asset_representation_is_local_id(const AssetRepresentation *asset) ATTR_WARN_UNUSED_RESULT;
bool AS_asset_representation_is_never_link(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;

View File

@ -82,6 +82,9 @@ class AssetRepresentation {
* #get_import_method(). Also returns true if there is no predefined import method
* (when #get_import_method() returns no value). */
bool may_override_import_method() const;
/** If this asset is stored inside this current file (#is_local_id() is true), this returns the
* ID's pointer, otherwise null. */
ID *local_id() const;
/** Returns if this asset is stored inside this current file, and as such fully editable. */
bool is_local_id() const;
const AssetLibrary &owner_asset_library() const;
@ -92,7 +95,11 @@ class AssetRepresentation {
/* C-Handle */
struct AssetRepresentation;
const std::string AS_asset_representation_full_path_get(const ::AssetRepresentation *asset);
std::string AS_asset_representation_full_path_get(const ::AssetRepresentation *asset);
/** Get the absolute path to the .blend file containing the given asset. String will be empty if
* the asset could not be mapped to a valid .blend file path. Valid in this case also means that
* the file needs to exist on disk. */
std::string AS_asset_representation_full_library_path_get(const ::AssetRepresentation *asset);
std::optional<eAssetImportMethod> AS_asset_representation_import_method_get(
const ::AssetRepresentation *asset_handle);
bool AS_asset_representation_may_override_import_method(const ::AssetRepresentation *asset_handle);

View File

@ -4,8 +4,11 @@
* \ingroup asset_system
*/
#include <string>
#include "BKE_blendfile.h"
#include "BLI_path_util.h"
#include <iostream>
#include "AS_asset_identifier.hh"
@ -24,4 +27,16 @@ std::string AssetIdentifier::full_path() const
return path;
}
std::string AssetIdentifier::full_library_path() const
{
std::string asset_path = full_path();
char blend_path[1090 /*FILE_MAX_LIBEXTRA*/];
if (!BKE_blendfile_library_path_explode(asset_path.c_str(), blend_path, nullptr, nullptr)) {
return {};
}
return blend_path;
}
} // namespace blender::asset_system

View File

@ -97,6 +97,11 @@ bool AssetRepresentation::may_override_import_method() const
return owner_asset_library_->may_override_import_method_;
}
ID *AssetRepresentation::local_id() const
{
return is_local_id_ ? local_asset_id_ : nullptr;
}
bool AssetRepresentation::is_local_id() const
{
return is_local_id_;
@ -111,7 +116,7 @@ const AssetLibrary &AssetRepresentation::owner_asset_library() const
using namespace blender;
const std::string AS_asset_representation_full_path_get(const AssetRepresentation *asset_handle)
std::string AS_asset_representation_full_path_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
@ -119,6 +124,13 @@ const std::string AS_asset_representation_full_path_get(const AssetRepresentatio
return identifier.full_path();
}
std::string AS_asset_representation_full_library_path_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->get_identifier().full_library_path();
}
std::optional<eAssetImportMethod> AS_asset_representation_import_method_get(
const AssetRepresentation *asset_handle)
{
@ -152,6 +164,13 @@ AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *a
return &asset->get_metadata();
}
ID *AS_asset_representation_local_id_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->local_id();
}
bool AS_asset_representation_is_local_id(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =

View File

@ -45,7 +45,7 @@ int BLF_set_default(void)
{
ASSERT_DEFAULT_SET;
BLF_size(global_font_default, global_font_size * U.dpi_fac);
BLF_size(global_font_default, global_font_size * UI_SCALE_FAC);
return global_font_default;
}
@ -53,7 +53,7 @@ int BLF_set_default(void)
void BLF_draw_default(float x, float y, float z, const char *str, const size_t str_len)
{
ASSERT_DEFAULT_SET;
BLF_size(global_font_default, global_font_size * U.dpi_fac);
BLF_size(global_font_default, global_font_size * UI_SCALE_FAC);
BLF_position(global_font_default, x, y, z);
BLF_draw(global_font_default, str, str_len);
}

View File

@ -19,6 +19,32 @@ struct ReportList;
struct UserDef;
struct bContext;
/**
* Check whether given path ends with a blend file compatible extension
* (`.blend`, `.ble` or `.blend.gz`).
*
* \param str: The path to check.
* \return true is this path ends with a blender file extension.
*/
bool BKE_blendfile_extension_check(const char *str);
/**
* Try to explode given path into its 'library components'
* (i.e. a .blend file, id type/group, and data-block itself).
*
* \param path: the full path to explode.
* \param r_dir: the string that'll contain path up to blend file itself ('library' path).
* WARNING! Must be at least #FILE_MAX_LIBEXTRA long (it also stores group and name strings)!
* \param r_group: a pointer within `r_dir` to the 'group' part of the path, if any ('\0'
* terminated). May be NULL.
* \param r_name: a pointer within `r_dir` to the data-block name, if any ('\0' terminated). May be
* NULL.
* \return true if path contains a blend file.
*/
bool BKE_blendfile_library_path_explode(const char *path,
char *r_dir,
char **r_group,
char **r_name);
/**
* Shared setup function that makes the data from `bfd` into the current blend file,
* replacing the contents of #G.main.

View File

@ -381,6 +381,8 @@ bool CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list);
const struct AssetLibraryReference *CTX_wm_asset_library_ref(const bContext *C);
struct AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid);
struct AssetRepresentation *CTX_wm_asset(const bContext *C);
bool CTX_wm_interface_locked(const bContext *C);
/**

View File

@ -486,6 +486,8 @@ const char *CustomData_get_active_layer_name(const struct CustomData *data, int
*/
const char *CustomData_get_render_layer_name(const struct CustomData *data, int type);
bool CustomData_layer_is_anonymous(const struct CustomData *data, int type, int n);
void CustomData_bmesh_set(const struct CustomData *data,
void *block,
int type,

View File

@ -44,7 +44,7 @@ typedef struct CfraElem {
/* ************** F-Curve Modifiers *************** */
/**
* F-Curve Modifier Type-Info (fmi):
* F-Curve Modifier Type-Info (`fmi`):
* This struct provides function pointers for runtime, so that functions can be
* written more generally (with fewer/no special exceptions for various modifiers).
*

View File

@ -256,8 +256,8 @@ struct NodeData {
MEM_delete(node_data);
}
};
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/** \name Fix non-manifold edge bleeding.
* \{ */

View File

@ -122,11 +122,11 @@ typedef struct PTCacheID {
/* flags defined in DNA_object_force_types.h */
unsigned int data_types, info_types;
/* copies point data to cache data */
/* Copies point data to cache data. */
int (*write_point)(int index, void *calldata, void **data, int cfra);
/* copies cache cata to point data */
/* Copies cache data to point data. */
void (*read_point)(int index, void *calldata, void **data, float cfra, const float *old_data);
/* interpolated between previously read point data and cache data */
/* Interpolated between previously read point data and cache data. */
void (*interpolate_point)(int index,
void *calldata,
void **data,

View File

@ -14,6 +14,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_workspace_types.h"
#include "BLI_fileops.h"
@ -62,6 +63,81 @@
# include "BPY_extern.h"
#endif
/* -------------------------------------------------------------------- */
/** \name Blend/Library Paths
* \{ */
bool BKE_blendfile_extension_check(const char *str)
{
const char *ext_test[4] = {".blend", ".ble", ".blend.gz", nullptr};
return BLI_path_extension_check_array(str, ext_test);
}
bool BKE_blendfile_library_path_explode(const char *path,
char *r_dir,
char **r_group,
char **r_name)
{
/* We might get some data names with slashes,
* so we have to go up in path until we find blend file itself,
* then we know next path item is group, and everything else is data name. */
char *slash = nullptr, *prev_slash = nullptr, c = '\0';
r_dir[0] = '\0';
if (r_group) {
*r_group = nullptr;
}
if (r_name) {
*r_name = nullptr;
}
/* if path leads to an existing directory, we can be sure we're not (in) a library */
if (BLI_is_dir(path)) {
return false;
}
BLI_strncpy(r_dir, path, FILE_MAX_LIBEXTRA);
while ((slash = (char *)BLI_path_slash_rfind(r_dir))) {
char tc = *slash;
*slash = '\0';
if (BKE_blendfile_extension_check(r_dir) && BLI_is_file(r_dir)) {
break;
}
if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) {
break;
}
if (prev_slash) {
*prev_slash = c;
}
prev_slash = slash;
c = tc;
}
if (!slash) {
return false;
}
if (slash[1] != '\0') {
BLI_assert(strlen(slash + 1) < BLO_GROUP_MAX);
if (r_group) {
*r_group = slash + 1;
}
}
if (prev_slash && (prev_slash[1] != '\0')) {
BLI_assert(strlen(prev_slash + 1) < MAX_ID_NAME - 2);
if (r_name) {
*r_name = prev_slash + 1;
}
}
return true;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Blend File IO (High Level)
* \{ */

View File

@ -1493,6 +1493,11 @@ AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid)
return AssetHandle{nullptr};
}
AssetRepresentation *CTX_wm_asset(const bContext *C)
{
return static_cast<AssetRepresentation *>(ctx_data_pointer_get(C, "asset"));
}
Depsgraph *CTX_data_depsgraph_pointer(const bContext *C)
{
Main *bmain = CTX_data_main(C);

View File

@ -2686,6 +2686,15 @@ void CustomData_clear_layer_flag(CustomData *data, const int type, const int fla
}
}
bool CustomData_layer_is_anonymous(const struct CustomData *data, int type, int n)
{
const int layer_index = CustomData_get_layer_index_n(data, type, n);
BLI_assert(layer_index >= 0);
return data->layers[layer_index].anonymous_id != nullptr;
}
static bool customData_resize(CustomData *data, const int amount)
{
CustomDataLayer *tmp = static_cast<CustomDataLayer *>(

View File

@ -387,7 +387,7 @@ TEST(BKE_fcurve, BKE_fcurve_calc_range)
/* Curve samples. */
const int sample_start = 1;
const int sample_end = 20;
fcurve_store_samples(fcu, NULL, sample_start, sample_end, fcurve_samplingcb_evalcurve);
fcurve_store_samples(fcu, nullptr, sample_start, sample_end, fcurve_samplingcb_evalcurve);
success = BKE_fcurve_calc_range(fcu, &min, &max, true);
EXPECT_TRUE(success) << "FCurve samples should have a range.";
@ -421,8 +421,11 @@ TEST(BKE_fcurve, BKE_fcurve_calc_bounds)
bool success;
/* All keys. */
success = BKE_fcurve_calc_bounds(
fcu, false /* select only */, false /* include handles */, NULL /* frame range */, &bounds);
success = BKE_fcurve_calc_bounds(fcu,
false /* select only */,
false /* include handles */,
nullptr /* frame range */,
&bounds);
EXPECT_TRUE(success) << "A non-empty FCurve should have bounds.";
EXPECT_FLOAT_EQ(fcu->bezt[0].vec[1][0], bounds.xmin);
EXPECT_FLOAT_EQ(fcu->bezt[4].vec[1][0], bounds.xmax);
@ -430,16 +433,22 @@ TEST(BKE_fcurve, BKE_fcurve_calc_bounds)
EXPECT_FLOAT_EQ(fcu->bezt[2].vec[1][1], bounds.ymax);
/* Only selected. */
success = BKE_fcurve_calc_bounds(
fcu, true /* select only */, false /* include handles */, NULL /* frame range */, &bounds);
success = BKE_fcurve_calc_bounds(fcu,
true /* select only */,
false /* include handles */,
nullptr /* frame range */,
&bounds);
EXPECT_FALSE(success)
<< "Using selected keyframes only should not find bounds if nothing is selected.";
fcu->bezt[1].f2 |= SELECT;
fcu->bezt[3].f2 |= SELECT;
success = BKE_fcurve_calc_bounds(
fcu, true /* select only */, false /* include handles */, NULL /* frame range */, &bounds);
success = BKE_fcurve_calc_bounds(fcu,
true /* select only */,
false /* include handles */,
nullptr /* frame range */,
&bounds);
EXPECT_TRUE(success) << "Selected keys should have been found.";
EXPECT_FLOAT_EQ(fcu->bezt[1].vec[1][0], bounds.xmin);
EXPECT_FLOAT_EQ(fcu->bezt[3].vec[1][0], bounds.xmax);
@ -447,8 +456,11 @@ TEST(BKE_fcurve, BKE_fcurve_calc_bounds)
EXPECT_FLOAT_EQ(fcu->bezt[3].vec[1][1], bounds.ymax);
/* Including handles. */
success = BKE_fcurve_calc_bounds(
fcu, false /* select only */, true /* include handles */, NULL /* frame range */, &bounds);
success = BKE_fcurve_calc_bounds(fcu,
false /* select only */,
true /* include handles */,
nullptr /* frame range */,
&bounds);
EXPECT_TRUE(success) << "A non-empty FCurve should have bounds including handles.";
EXPECT_FLOAT_EQ(fcu->bezt[0].vec[0][0], bounds.xmin);
EXPECT_FLOAT_EQ(fcu->bezt[4].vec[2][0], bounds.xmax);
@ -499,10 +511,13 @@ TEST(BKE_fcurve, BKE_fcurve_calc_bounds)
/* Curve samples. */
const int sample_start = 1;
const int sample_end = 20;
fcurve_store_samples(fcu, NULL, sample_start, sample_end, fcurve_samplingcb_evalcurve);
fcurve_store_samples(fcu, nullptr, sample_start, sample_end, fcurve_samplingcb_evalcurve);
success = BKE_fcurve_calc_bounds(
fcu, false /* select only */, false /* include handles */, NULL /* frame range */, &bounds);
success = BKE_fcurve_calc_bounds(fcu,
false /* select only */,
false /* include handles */,
nullptr /* frame range */,
&bounds);
EXPECT_TRUE(success) << "FCurve samples should have a range.";
EXPECT_FLOAT_EQ(sample_start, bounds.xmin);

View File

@ -983,7 +983,7 @@ static float *gpencil_stroke_points_from_editcurve_fixed_resolu(bGPDcurve_point
bool is_cyclic,
int *r_points_len)
{
/* One stride contains: x, y, z, pressure, strength, Vr, Vg, Vb, Vmix_factor */
/* One stride contains: `x, y, z, pressure, strength, Vr, Vg, Vb, Vmix_factor`. */
const uint stride = sizeof(float[9]);
const uint array_last = curve_point_array_len - 1;
const uint resolu_stride = resolution * stride;

View File

@ -156,7 +156,29 @@ template<size_t Size, size_t Alignment> class AlignedBuffer {
*/
template<typename T, int64_t Size = 1> class TypedBuffer {
private:
BLI_NO_UNIQUE_ADDRESS AlignedBuffer<sizeof(T) * size_t(Size), alignof(T)> buffer_;
/** Required so that `sizeof(T)` is not required when `Size` is 0. */
static constexpr size_t get_size()
{
if constexpr (Size == 0) {
return 0;
}
else {
return sizeof(T) * size_t(Size);
}
}
/** Required so that `alignof(T)` is not required when `Size` is 0. */
static constexpr size_t get_alignment()
{
if constexpr (Size == 0) {
return 1;
}
else {
return alignof(T);
}
}
BLI_NO_UNIQUE_ADDRESS AlignedBuffer<get_size(), get_alignment()> buffer_;
public:
operator T *()

View File

@ -108,6 +108,17 @@ class Vector {
template<typename OtherT, int64_t OtherInlineBufferCapacity, typename OtherAllocator>
friend class Vector;
/** Required in case `T` is an incomplete type. */
static constexpr bool is_nothrow_move_constructible()
{
if constexpr (InlineBufferCapacity == 0) {
return true;
}
else {
return std::is_nothrow_move_constructible_v<T>;
}
}
public:
/**
* Create an empty vector.
@ -234,7 +245,7 @@ class Vector {
*/
template<int64_t OtherInlineBufferCapacity>
Vector(Vector<T, OtherInlineBufferCapacity, Allocator> &&other) noexcept(
std::is_nothrow_move_constructible_v<T>)
is_nothrow_move_constructible())
: Vector(NoExceptConstructor(), other.allocator_)
{
const int64_t size = other.size();

View File

@ -63,18 +63,12 @@ TEST(math_rotation_types, Euler3Order)
/* Asserts those match.
* Do not do it in the header to avoid including the DNA header everywhere.
*/
BLI_STATIC_ASSERT(
static_cast<int>(EulerOrder::XYZ) == static_cast<int>(eRotationModes::ROT_MODE_XYZ), "");
BLI_STATIC_ASSERT(
static_cast<int>(EulerOrder::XZY) == static_cast<int>(eRotationModes::ROT_MODE_XZY), "");
BLI_STATIC_ASSERT(
static_cast<int>(EulerOrder::YXZ) == static_cast<int>(eRotationModes::ROT_MODE_YXZ), "");
BLI_STATIC_ASSERT(
static_cast<int>(EulerOrder::YZX) == static_cast<int>(eRotationModes::ROT_MODE_YZX), "");
BLI_STATIC_ASSERT(
static_cast<int>(EulerOrder::ZXY) == static_cast<int>(eRotationModes::ROT_MODE_ZXY), "");
BLI_STATIC_ASSERT(
static_cast<int>(EulerOrder::ZYX) == static_cast<int>(eRotationModes::ROT_MODE_ZYX), "");
BLI_STATIC_ASSERT(int(EulerOrder::XYZ) == int(eRotationModes::ROT_MODE_XYZ), "");
BLI_STATIC_ASSERT(int(EulerOrder::XZY) == int(eRotationModes::ROT_MODE_XZY), "");
BLI_STATIC_ASSERT(int(EulerOrder::YXZ) == int(eRotationModes::ROT_MODE_YXZ), "");
BLI_STATIC_ASSERT(int(EulerOrder::YZX) == int(eRotationModes::ROT_MODE_YZX), "");
BLI_STATIC_ASSERT(int(EulerOrder::ZXY) == int(eRotationModes::ROT_MODE_ZXY), "");
BLI_STATIC_ASSERT(int(EulerOrder::ZYX) == int(eRotationModes::ROT_MODE_ZYX), "");
EXPECT_EQ(float3(Euler3(0, 1, 2, EulerOrder::XYZ).ijk()), float3(0, 1, 2));
EXPECT_EQ(float3(Euler3(0, 1, 2, EulerOrder::XZY).ijk()), float3(0, 2, 1));

View File

@ -859,4 +859,14 @@ TEST(vector, RemoveChunkExceptions)
EXPECT_EQ(vec.size(), 7);
}
struct RecursiveType {
Vector<RecursiveType, 0> my_vector;
};
TEST(vector, RecursiveStructure)
{
RecursiveType my_recursive_type;
my_recursive_type.my_vector.append({});
}
} // namespace blender::tests

View File

@ -313,27 +313,6 @@ void BLO_read_invalidate_message(BlendHandle *bh, struct Main *bmain, const char
#define BLO_GROUP_MAX 32
#define BLO_EMBEDDED_STARTUP_BLEND "<startup.blend>"
/**
* Check whether given path ends with a blend file compatible extension
* (`.blend`, `.ble` or `.blend.gz`).
*
* \param str: The path to check.
* \return true is this path ends with a blender file extension.
*/
bool BLO_has_bfile_extension(const char *str);
/**
* Try to explode given path into its 'library components'
* (i.e. a .blend file, id type/group, and data-block itself).
*
* \param path: the full path to explode.
* \param r_dir: the string that'll contain path up to blend file itself ('library' path).
* WARNING! Must be #FILE_MAX_LIBEXTRA long (it also stores group and name strings)!
* \param r_group: the string that'll contain 'group' part of the path, if any. May be NULL.
* \param r_name: the string that'll contain data's name part of the path, if any. May be NULL.
* \return true if path contains a blend file.
*/
bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name);
/* -------------------------------------------------------------------- */
/** \name BLO Blend File Linking API
* \{ */

View File

@ -1306,76 +1306,6 @@ void blo_filedata_free(FileData *fd)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Public Utilities
* \{ */
bool BLO_has_bfile_extension(const char *str)
{
const char *ext_test[4] = {".blend", ".ble", ".blend.gz", nullptr};
return BLI_path_extension_check_array(str, ext_test);
}
bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name)
{
/* We might get some data names with slashes,
* so we have to go up in path until we find blend file itself,
* then we know next path item is group, and everything else is data name. */
char *slash = nullptr, *prev_slash = nullptr, c = '\0';
r_dir[0] = '\0';
if (r_group) {
*r_group = nullptr;
}
if (r_name) {
*r_name = nullptr;
}
/* if path leads to an existing directory, we can be sure we're not (in) a library */
if (BLI_is_dir(path)) {
return false;
}
strcpy(r_dir, path);
while ((slash = (char *)BLI_path_slash_rfind(r_dir))) {
char tc = *slash;
*slash = '\0';
if (BLO_has_bfile_extension(r_dir) && BLI_is_file(r_dir)) {
break;
}
if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) {
break;
}
if (prev_slash) {
*prev_slash = c;
}
prev_slash = slash;
c = tc;
}
if (!slash) {
return false;
}
if (slash[1] != '\0') {
BLI_assert(strlen(slash + 1) < BLO_GROUP_MAX);
if (r_group) {
*r_group = slash + 1;
}
}
if (prev_slash && (prev_slash[1] != '\0')) {
BLI_assert(strlen(prev_slash + 1) < MAX_ID_NAME - 2);
if (r_name) {
*r_name = prev_slash + 1;
}
}
return true;
}
BlendThumbnail *BLO_thumbnail_from_file(const char *filepath)
{
FileData *fd;

View File

@ -5,6 +5,9 @@
* \ingroup depsgraph
*/
#include <memory>
#include <mutex>
#include "intern/depsgraph_registry.h"
#include "BLI_utildefines.h"
@ -13,7 +16,19 @@
namespace blender::deg {
using GraphRegistry = Map<Main *, VectorSet<Depsgraph *>>;
/* Global registry for dependency graphs associated with a main database.
*
* Threads may add or remove depsgraphs for different mains concurrently
* (for example for preview rendering), but not the same main. */
/* Use pointer for map value to ensure span returned by get_all_registered_graphs
* remains unchanged as other mains are added or removed. */
typedef std::unique_ptr<VectorSet<Depsgraph *>> GraphSetPtr;
struct GraphRegistry {
Map<Main *, GraphSetPtr> map;
std::mutex mutex;
};
static GraphRegistry &get_graph_registry()
{
static GraphRegistry graph_registry;
@ -22,28 +37,37 @@ static GraphRegistry &get_graph_registry()
void register_graph(Depsgraph *depsgraph)
{
GraphRegistry &graph_registry = get_graph_registry();
Main *bmain = depsgraph->bmain;
get_graph_registry().lookup_or_add_default(bmain).add_new(depsgraph);
std::lock_guard<std::mutex> lock{graph_registry.mutex};
graph_registry.map
.lookup_or_add_cb(bmain, []() { return std::make_unique<VectorSet<Depsgraph *>>(); })
->add_new(depsgraph);
}
void unregister_graph(Depsgraph *depsgraph)
{
Main *bmain = depsgraph->bmain;
GraphRegistry &graph_registry = get_graph_registry();
VectorSet<Depsgraph *> &graphs = graph_registry.lookup(bmain);
graphs.remove(depsgraph);
std::lock_guard<std::mutex> lock{graph_registry.mutex};
GraphSetPtr &graphs = graph_registry.map.lookup(bmain);
graphs->remove(depsgraph);
/* If this was the last depsgraph associated with the main, remove the main entry as well. */
if (graphs.is_empty()) {
graph_registry.remove(bmain);
if (graphs->is_empty()) {
graph_registry.map.remove(bmain);
}
}
Span<Depsgraph *> get_all_registered_graphs(Main *bmain)
{
VectorSet<Depsgraph *> *graphs = get_graph_registry().lookup_ptr(bmain);
if (graphs != nullptr) {
return *graphs;
GraphRegistry &graph_registry = get_graph_registry();
std::lock_guard<std::mutex> lock{graph_registry.mutex};
GraphSetPtr *graphs = graph_registry.map.lookup_ptr(bmain);
if (graphs) {
return **graphs;
}
return {};
}

View File

@ -144,6 +144,7 @@ set(SRC
engines/eevee_next/eevee_film.cc
engines/eevee_next/eevee_hizbuffer.cc
engines/eevee_next/eevee_instance.cc
engines/eevee_next/eevee_irradiance_cache.cc
engines/eevee_next/eevee_light.cc
engines/eevee_next/eevee_material.cc
engines/eevee_next/eevee_motion_blur.cc
@ -275,6 +276,7 @@ set(SRC
engines/eevee_next/eevee_film.hh
engines/eevee_next/eevee_hizbuffer.hh
engines/eevee_next/eevee_instance.hh
engines/eevee_next/eevee_irradiance_cache.hh
engines/eevee_next/eevee_light.hh
engines/eevee_next/eevee_material.hh
engines/eevee_next/eevee_motion_blur.hh
@ -425,6 +427,8 @@ set(GLSL_SRC
engines/eevee_next/shaders/eevee_colorspace_lib.glsl
engines/eevee_next/shaders/eevee_cryptomatte_lib.glsl
engines/eevee_next/shaders/eevee_transparency_lib.glsl
engines/eevee_next/shaders/eevee_debug_surfels_vert.glsl
engines/eevee_next/shaders/eevee_debug_surfels_frag.glsl
engines/eevee_next/shaders/eevee_depth_of_field_accumulator_lib.glsl
engines/eevee_next/shaders/eevee_depth_of_field_bokeh_lut_comp.glsl
engines/eevee_next/shaders/eevee_depth_of_field_downsample_comp.glsl

View File

@ -107,14 +107,14 @@ void EEVEE_lookdev_init(EEVEE_Data *vedata)
/* Make the viewport width scale the lookdev spheres a bit.
* Scale between 1000px and 2000px. */
const float viewport_scale = clamp_f(
BLI_rcti_size_x(rect) / (2000.0f * U.dpi_fac), 0.5f, 1.0f);
const int sphere_size = U.lookdev_sphere_size * U.dpi_fac * viewport_scale;
BLI_rcti_size_x(rect) / (2000.0f * UI_SCALE_FAC), 0.5f, 1.0f);
const int sphere_size = U.lookdev_sphere_size * UI_SCALE_FAC * viewport_scale;
if (sphere_size != effects->sphere_size || rect->xmax != effects->anchor[0] ||
rect->ymin != effects->anchor[1]) {
/* Make sphere resolution adaptive to viewport_scale, DPI and #U.lookdev_sphere_size. */
float res_scale = clamp_f(
(U.lookdev_sphere_size / 400.0f) * viewport_scale * U.dpi_fac, 0.1f, 1.0f);
(U.lookdev_sphere_size / 400.0f) * viewport_scale * UI_SCALE_FAC, 0.1f, 1.0f);
if (res_scale > 0.7f) {
effects->sphere_lod = DRW_LOD_HIGH;

View File

@ -607,7 +607,7 @@ void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderLayer *rl
GPU_framebuffer_bind(fbl->main_fb);
GPU_framebuffer_clear_color_depth_stencil(fbl->main_fb, clear_col, clear_depth, clear_stencil);
/* Depth prepass */
/* Depth pre-pass. */
DRW_draw_pass(psl->depth_ps);
/* Create minmax texture */
EEVEE_create_minmax_buffer(vedata, dtxl->depth, -1);

View File

@ -70,6 +70,7 @@ void Instance::init(const int2 &output_res,
shadows.init();
motion_blur.init();
main_view.init();
irradiance_cache.init();
}
void Instance::set_time(float time)
@ -117,6 +118,7 @@ void Instance::begin_sync()
main_view.sync();
world.sync();
film.sync();
irradiance_cache.sync();
}
void Instance::scene_sync()

View File

@ -20,6 +20,7 @@
#include "eevee_depth_of_field.hh"
#include "eevee_film.hh"
#include "eevee_hizbuffer.hh"
#include "eevee_irradiance_cache.hh"
#include "eevee_light.hh"
#include "eevee_material.hh"
#include "eevee_motion_blur.hh"
@ -60,6 +61,7 @@ class Instance {
RenderBuffers render_buffers;
MainView main_view;
World world;
IrradianceCache irradiance_cache;
/** Input data. */
Depsgraph *depsgraph;
@ -103,7 +105,8 @@ class Instance {
film(*this),
render_buffers(*this),
main_view(*this),
world(*this){};
world(*this),
irradiance_cache(*this){};
~Instance(){};
void init(const int2 &output_res,

View File

@ -0,0 +1,65 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_rand.hh"
#include "eevee_instance.hh"
#include "eevee_irradiance_cache.hh"
namespace blender::eevee {
void IrradianceCache::generate_random_surfels()
{
const int surfels_len = 256;
debug_surfels.resize(surfels_len);
RandomNumberGenerator rng;
rng.seed(0);
for (DebugSurfel &surfel : debug_surfels) {
float3 random = rng.get_unit_float3();
surfel.position = random * 3.0f;
surfel.normal = random;
surfel.color = float4(rng.get_float(), rng.get_float(), rng.get_float(), 1.0f);
}
debug_surfels.push_update();
}
void IrradianceCache::init()
{
if (debug_surfels_sh_ == nullptr) {
debug_surfels_sh_ = inst_.shaders.static_shader_get(DEBUG_SURFELS);
}
/* TODO: Remove this. */
generate_random_surfels();
}
void IrradianceCache::sync()
{
debug_pass_sync();
}
void IrradianceCache::debug_pass_sync()
{
if (inst_.debug_mode == eDebugMode::DEBUG_IRRADIANCE_CACHE_SURFELS) {
debug_surfels_ps_.init();
debug_surfels_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
DRW_STATE_DEPTH_LESS_EQUAL);
debug_surfels_ps_.shader_set(debug_surfels_sh_);
debug_surfels_ps_.bind_ssbo("surfels_buf", debug_surfels);
debug_surfels_ps_.push_constant("surfel_radius", 0.25f);
debug_surfels_ps_.draw_procedural(GPU_PRIM_TRI_STRIP, debug_surfels.size(), 4);
}
}
void IrradianceCache::debug_draw(View &view, GPUFrameBuffer *view_fb)
{
if (inst_.debug_mode == eDebugMode::DEBUG_IRRADIANCE_CACHE_SURFELS) {
inst_.info = "Debug Mode: Irradiance Cache Surfels";
GPU_framebuffer_bind(view_fb);
inst_.manager->submit(debug_surfels_ps_, view);
}
}
} // namespace blender::eevee

View File

@ -0,0 +1,33 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "eevee_shader_shared.hh"
namespace blender::eevee {
class Instance;
class IrradianceCache {
private:
Instance &inst_;
DebugSurfelBuf debug_surfels;
PassSimple debug_surfels_ps_ = {"IrradianceCache.Debug"};
GPUShader *debug_surfels_sh_ = nullptr;
/* TODO: Remove this. */
void generate_random_surfels();
public:
IrradianceCache(Instance &inst) : inst_(inst){};
~IrradianceCache(){};
void init();
void sync();
void debug_pass_sync();
void debug_draw(View &view, GPUFrameBuffer *view_fb);
};
} // namespace blender::eevee

View File

@ -98,6 +98,8 @@ const char *ShaderModule::static_shader_create_info_name_get(eShaderType shader_
return "eevee_motion_blur_tiles_flatten_render";
case MOTION_BLUR_TILE_FLATTEN_VIEWPORT:
return "eevee_motion_blur_tiles_flatten_viewport";
case DEBUG_SURFELS:
return "eevee_debug_surfels";
case DOF_BOKEH_LUT:
return "eevee_depth_of_field_bokeh_lut";
case DOF_DOWNSAMPLE:

View File

@ -30,6 +30,8 @@ enum eShaderType {
FILM_COMP,
FILM_CRYPTOMATTE_POST,
DEBUG_SURFELS,
DOF_BOKEH_LUT,
DOF_DOWNSAMPLE,
DOF_FILTER,

View File

@ -48,6 +48,10 @@ enum eDebugMode : uint32_t {
* Show incorrectly downsample tiles in red.
*/
DEBUG_HIZ_VALIDATION = 2u,
/**
* Display IrradianceCache surfels.
*/
DEBUG_IRRADIANCE_CACHE_SURFELS = 3u,
/**
* Show tiles depending on their status.
*/
@ -821,6 +825,21 @@ static inline ShadowTileDataPacked shadow_tile_pack(ShadowTileData tile)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Debug
* \{ */
struct DebugSurfel {
packed_float3 position;
int _pad0;
packed_float3 normal;
int _pad1;
float4 color;
};
BLI_STATIC_ASSERT_ALIGN(DebugSurfel, 16)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Hierarchical-Z Buffer
* \{ */
@ -928,6 +947,7 @@ using DepthOfFieldDataBuf = draw::UniformBuffer<DepthOfFieldData>;
using DepthOfFieldScatterListBuf = draw::StorageArrayBuffer<ScatterRect, 16, true>;
using DrawIndirectBuf = draw::StorageBuffer<DrawCommand, true>;
using FilmDataBuf = draw::UniformBuffer<FilmData>;
using DebugSurfelBuf = draw::StorageArrayBuffer<DebugSurfel, 64>;
using HiZDataBuf = draw::UniformBuffer<HiZData>;
using LightCullingDataBuf = draw::StorageBuffer<LightCullingData>;
using LightCullingKeyBuf = draw::StorageArrayBuffer<uint, LIGHT_CHUNK, true>;

View File

@ -136,6 +136,8 @@ void ShadingView::render()
inst_.hiz_buffer.debug_draw(render_view_new_, combined_fb_);
inst_.shadows.debug_draw(render_view_new_, combined_fb_);
inst_.irradiance_cache.debug_draw(render_view_new_, combined_fb_);
GPUTexture *combined_final_tx = render_postfx(rbufs.combined_tx);
inst_.film.accumulate(sub_view_, combined_final_tx);

View File

@ -0,0 +1,21 @@
void main()
{
DebugSurfel surfel = surfels_buf[surfel_index];
out_color = surfel.color;
/* Display surfels as circles. */
if (distance(P, surfel.position) > surfel_radius) {
discard;
return;
}
/* Display backfacing surfels with a transparent checkerboard grid. */
if (!gl_FrontFacing) {
ivec2 grid_uv = ivec2(gl_FragCoord) / 5;
if ((grid_uv.x + grid_uv.y) % 2 == 0) {
discard;
return;
}
}
}

View File

@ -0,0 +1,38 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
void main()
{
surfel_index = gl_InstanceID;
DebugSurfel surfel = surfels_buf[surfel_index];
vec3 lP;
switch (gl_VertexID) {
case 0:
lP = vec3(-1, 1, 0);
break;
case 1:
lP = vec3(-1, -1, 0);
break;
case 2:
lP = vec3(1, 1, 0);
break;
case 3:
lP = vec3(1, -1, 0);
break;
}
vec3 N = surfel.normal;
vec3 T, B;
make_orthonormal_basis(N, T, B);
mat4 model_matrix = mat4(vec4(T * surfel_radius, 0),
vec4(B * surfel_radius, 0),
vec4(N * surfel_radius, 0),
vec4(surfel.position, 1));
P = (model_matrix * vec4(lP, 1)).xyz;
gl_Position = point_world_to_ndc(P);
}

View File

@ -0,0 +1,16 @@
#include "eevee_defines.hh"
#include "gpu_shader_create_info.hh"
GPU_SHADER_INTERFACE_INFO(eeve_debug_surfel_iface, "")
.smooth(Type::VEC3, "P")
.flat(Type::INT, "surfel_index");
GPU_SHADER_CREATE_INFO(eevee_debug_surfels)
.additional_info("eevee_shared", "draw_view")
.vertex_source("eevee_debug_surfels_vert.glsl")
.vertex_out(eeve_debug_surfel_iface)
.fragment_source("eevee_debug_surfels_frag.glsl")
.fragment_out(0, Type::VEC4, "out_color")
.storage_buf(0, Qualifier::READ, "DebugSurfel", "surfels_buf[]")
.push_constant(Type::FLOAT, "surfel_radius")
.do_static_compilation(true);

View File

@ -221,7 +221,7 @@ static void external_cache_populate(void *vedata, Object *ob)
}
struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
if (geom) {
/* Depth Prepass */
/* Depth Pre-pass. */
DRW_shgroup_call(stl->g_data->depth_shgrp, geom, ob);
}
}

View File

@ -309,7 +309,7 @@ typedef struct GPENCIL_PrivateData {
float fade_3d_object_opacity;
/* Mask opacity uniform. */
float mask_opacity;
/* Xray transparency in solid mode. */
/* X-ray transparency in solid mode. */
float xray_alpha;
/* Mask invert uniform. */
int mask_invert;

View File

@ -158,7 +158,7 @@ void OVERLAY_edit_uv_init(OVERLAY_Data *vedata)
pd->edit_uv.uv_opacity = sima->uv_opacity;
pd->edit_uv.do_tiled_image_overlay = show_overlays && is_image_type && is_tiled_image;
pd->edit_uv.do_tiled_image_border_overlay = is_image_type && is_tiled_image;
pd->edit_uv.dash_length = 4.0f * UI_DPI_FAC;
pd->edit_uv.dash_length = 4.0f * UI_SCALE_FAC;
pd->edit_uv.line_style = edit_uv_line_style_from_space_image(sima);
pd->edit_uv.do_smooth_wire = ((U.gpu_flag & USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE) != 0);
pd->edit_uv.do_stencil_overlay = show_overlays && do_stencil_overlay;
@ -237,7 +237,7 @@ void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata)
GPUShader *sh = OVERLAY_shader_edit_uv_verts_get();
pd->edit_uv_verts_grp = DRW_shgroup_create(sh, psl->edit_uv_verts_ps);
const float point_size = UI_GetThemeValuef(TH_VERTEX_SIZE) * U.dpi_fac;
const float point_size = UI_GetThemeValuef(TH_VERTEX_SIZE) * UI_SCALE_FAC;
DRW_shgroup_uniform_block(pd->edit_uv_verts_grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_float_copy(
@ -261,7 +261,7 @@ void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata)
/* uv face dots */
if (pd->edit_uv.do_face_dots) {
const float point_size = UI_GetThemeValuef(TH_FACEDOT_SIZE) * U.dpi_fac;
const float point_size = UI_GetThemeValuef(TH_FACEDOT_SIZE) * UI_SCALE_FAC;
GPUShader *sh = OVERLAY_shader_edit_uv_face_dots_get();
pd->edit_uv_face_dots_grp = DRW_shgroup_create(sh, psl->edit_uv_verts_ps);
DRW_shgroup_uniform_block(pd->edit_uv_face_dots_grp, "globalsBlock", G_draw.block_ubo);

View File

@ -358,7 +358,7 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Object *object,
CustomData_get_named_layer(cd_ldata, CD_PROP_FLOAT2, name) :
CustomData_get_render_layer(cd_ldata, CD_PROP_FLOAT2);
}
if (layer != -1) {
if (layer != -1 && !CustomData_layer_is_anonymous(cd_ldata, CD_PROP_FLOAT2, layer)) {
cd_used.uv |= (1 << layer);
}
break;

View File

@ -838,8 +838,12 @@ static DRWSubdivCache *mesh_batch_cache_ensure_subdiv_cache(MeshBatchCache *mbc)
static void draw_subdiv_invalidate_evaluator_for_orco(Subdiv *subdiv, Mesh *mesh)
{
if (!(subdiv && subdiv->evaluator)) {
return;
}
const bool has_orco = CustomData_has_layer(&mesh->vdata, CD_ORCO);
if (has_orco && subdiv->evaluator && !subdiv->evaluator->hasVertexData(subdiv->evaluator)) {
if (has_orco && !subdiv->evaluator->hasVertexData(subdiv->evaluator)) {
/* If we suddenly have/need original coordinates, recreate the evaluator if the extra
* source was not created yet. The refiner also has to be recreated as refinement for source
* and vertex data is done only once. */
@ -2113,13 +2117,13 @@ static bool draw_subdiv_create_requested_buffers(Object *ob,
bm = mesh->edit_mesh->bm;
}
draw_subdiv_invalidate_evaluator_for_orco(runtime_data->subdiv_gpu, mesh_eval);
Subdiv *subdiv = BKE_subsurf_modifier_subdiv_descriptor_ensure(runtime_data, mesh_eval, true);
if (!subdiv) {
return false;
}
draw_subdiv_invalidate_evaluator_for_orco(subdiv, mesh_eval);
if (!BKE_subdiv_eval_begin_from_mesh(
subdiv, mesh_eval, nullptr, SUBDIV_EVALUATOR_TYPE_GPU, evaluator_cache)) {
/* This could happen in two situations:

View File

@ -127,7 +127,7 @@ static void drw_text_cache_draw_ex(DRWTextStore *dt, ARegion *region)
const uiStyle *style = UI_style_get();
BLF_size(font_id, style->widget.points * U.dpi_fac);
BLF_size(font_id, style->widget.points * UI_SCALE_FAC);
BLI_memiter_iter_init(dt->cache_strings, &it);
while ((vos = static_cast<ViewCachedString *>(BLI_memiter_iter_step(&it)))) {
@ -249,7 +249,7 @@ void DRW_text_edit_mesh_measure_stats(ARegion *region,
if ((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_INDICES) && (em->selectmode & SCE_SELECT_EDGE)) {
edge_tex_count += 1;
}
const short edge_tex_sep = short((edge_tex_count - 1) * 5.0f * U.dpi_fac);
const short edge_tex_sep = short((edge_tex_count - 1) * 5.0f * UI_SCALE_FAC);
/* Make the precision of the display value proportionate to the grid-size. */

View File

@ -248,7 +248,7 @@ static void extract_edituv_stretch_angle_init_subdiv(const DRWSubdivCache *subdi
/* HACK to fix #68857 */
if (mr->extract_type == MR_EXTRACT_BMESH && cache->cd_used.edit_uv == 1) {
int layer = CustomData_get_active_layer(cd_ldata, CD_PROP_FLOAT2);
if (layer != -1) {
if (layer != -1 && !CustomData_layer_is_anonymous(cd_ldata, CD_PROP_FLOAT2, layer)) {
uv_layers |= (1 << layer);
}
}

View File

@ -31,7 +31,7 @@ static bool mesh_extract_uv_format_init(GPUVertFormat *format,
/* HACK to fix #68857 */
if (extract_type == MR_EXTRACT_BMESH && cache->cd_used.edit_uv == 1) {
int layer = CustomData_get_active_layer(cd_ldata, CD_PROP_FLOAT2);
if (layer != -1) {
if (layer != -1 && !CustomData_layer_is_anonymous(cd_ldata, CD_PROP_FLOAT2, layer)) {
uv_layers |= (1 << layer);
}
}

View File

@ -5262,7 +5262,7 @@ void ANIM_channel_draw_widgets(const bContext *C,
* a callback available (e.g. broken F-Curve rename)
*/
if (acf->name_prop(ale, &ptr, &prop)) {
const short margin_x = 3 * round_fl_to_int(UI_DPI_FAC);
const short margin_x = 3 * round_fl_to_int(UI_SCALE_FAC);
const short width = ac->region->winx - offset - (margin_x * 2);
uiBut *but;

View File

@ -177,8 +177,8 @@ void ANIM_draw_action_framerange(
immUniform4f("color1", color[0], color[1], color[2], color[3]);
immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f);
immUniform1i("size1", 2 * U.dpi_fac);
immUniform1i("size2", 4 * U.dpi_fac);
immUniform1i("size1", 2 * UI_SCALE_FAC);
immUniform1i("size2", 4 * UI_SCALE_FAC);
if (sfra < efra) {
immRectf(pos, v2d->cur.xmin, ymin, sfra, ymax);

View File

@ -251,7 +251,7 @@ static bool region_position_is_over_marker(View2D *v2d, ListBase *markers, float
float pixel_distance = UI_view2d_scale_get_x(v2d) *
fabsf(nearest_marker->frame - frame_at_position);
return pixel_distance <= UI_DPI_ICON_SIZE;
return pixel_distance <= UI_ICON_SIZE;
}
/* --------------------------------- */
@ -419,7 +419,7 @@ static void draw_marker_name(const uchar *text_color,
}
#endif
const int icon_half_width = UI_DPI_ICON_SIZE * 0.6;
const int icon_half_width = UI_ICON_SIZE * 0.6;
const struct uiFontStyleDraw_Params fs_params = {.align = UI_STYLE_TEXT_LEFT, .word_wrap = 0};
const struct rcti rect = {
.xmin = marker_x + icon_half_width,
@ -440,7 +440,7 @@ static void draw_marker_line(const uchar *color, int xpos, int ymin, int ymax)
float viewport_size[4];
GPU_viewport_size_get_f(viewport_size);
immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
immUniform2f("viewport_size", viewport_size[2] / UI_SCALE_FAC, viewport_size[3] / UI_SCALE_FAC);
immUniformColor4ubv(color);
immUniform1i("colors_len", 0); /* "simple" mode */
@ -482,17 +482,17 @@ static void draw_marker(const uiFontStyle *fstyle,
GPU_blend(GPU_BLEND_ALPHA);
draw_marker_line(line_color, xpos, UI_DPI_FAC * 20, region_height);
draw_marker_line(line_color, xpos, UI_SCALE_FAC * 20, region_height);
int icon_id = marker_get_icon_id(marker, flag);
UI_icon_draw(xpos - 0.55f * UI_DPI_ICON_SIZE, UI_DPI_FAC * 18, icon_id);
UI_icon_draw(xpos - 0.55f * UI_ICON_SIZE, UI_SCALE_FAC * 18, icon_id);
GPU_blend(GPU_BLEND_NONE);
float name_y = UI_DPI_FAC * 18;
float name_y = UI_SCALE_FAC * 18;
/* Give an offset to the marker that is elevated. */
if (is_elevated) {
name_y += UI_DPI_FAC * 10;
name_y += UI_SCALE_FAC * 10;
}
draw_marker_name(text_color, fstyle, marker, xpos, xmax, name_y);
}
@ -537,7 +537,7 @@ static void get_marker_region_rect(View2D *v2d, rctf *rect)
static void get_marker_clip_frame_range(View2D *v2d, float xscale, int r_range[2])
{
float font_width_max = (10 * UI_DPI_FAC) / xscale;
float font_width_max = (10 * UI_SCALE_FAC) / xscale;
r_range[0] = v2d->cur.xmin - sizeof(((TimeMarker *)NULL)->name) * font_width_max;
r_range[1] = v2d->cur.xmax + font_width_max;
}

View File

@ -42,7 +42,7 @@ void ED_time_scrub_region_rect_get(const ARegion *region, rcti *rect)
static int get_centered_text_y(const rcti *rect)
{
return BLI_rcti_cent_y(rect) - UI_DPI_FAC * 4;
return BLI_rcti_cent_y(rect) - UI_SCALE_FAC * 4;
}
static void draw_background(const rcti *rect)
@ -84,9 +84,9 @@ static void draw_current_frame(const Scene *scene,
char frame_str[64];
get_current_time_str(scene, display_seconds, current_frame, sizeof(frame_str), frame_str);
float text_width = UI_fontstyle_string_width(fstyle, frame_str);
float box_width = MAX2(text_width + 8 * UI_DPI_FAC, 24 * UI_DPI_FAC);
float box_padding = 3 * UI_DPI_FAC;
const int line_outline = max_ii(1, round_fl_to_int(1 * UI_DPI_FAC));
float box_width = MAX2(text_width + 8 * UI_SCALE_FAC, 24 * UI_SCALE_FAC);
float box_padding = 3 * UI_SCALE_FAC;
const int line_outline = max_ii(1, round_fl_to_int(1 * UI_SCALE_FAC));
float bg_color[4];
UI_GetThemeColorShade4fv(TH_CFRAME, -5, bg_color);
@ -134,7 +134,7 @@ static void draw_current_frame(const Scene *scene,
1.0f,
outline_color,
U.pixelsize,
4 * UI_DPI_FAC);
4 * UI_SCALE_FAC);
uchar text_color[4];
UI_GetThemeColor4ubv(TH_HEADER_TEXT_HI, text_color);
@ -176,7 +176,7 @@ void ED_time_scrub_draw(const ARegion *region,
draw_background(&scrub_region_rect);
rcti numbers_rect = scrub_region_rect;
numbers_rect.ymin = get_centered_text_y(&scrub_region_rect) - 4 * UI_DPI_FAC;
numbers_rect.ymin = get_centered_text_y(&scrub_region_rect) - 4 * UI_SCALE_FAC;
if (discrete_frames) {
UI_view2d_draw_scale_x__discrete_frames_or_seconds(
region, v2d, &numbers_rect, scene, display_seconds, TH_TEXT);
@ -217,8 +217,8 @@ void ED_time_scrub_channel_search_draw(const bContext *C, ARegion *region, bDope
RNA_pointer_create(&CTX_wm_screen(C)->id, &RNA_DopeSheet, dopesheet, &ptr);
const uiStyle *style = UI_style_get_dpi();
const float padding_x = 2 * UI_DPI_FAC;
const float padding_y = UI_DPI_FAC;
const float padding_x = 2 * UI_SCALE_FAC;
const float padding_y = UI_SCALE_FAC;
uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
uiLayout *layout = UI_block_layout(block,

View File

@ -24,6 +24,7 @@ set(SRC
intern/asset_catalog.cc
intern/asset_filter.cc
intern/asset_handle.cc
intern/asset_import.cc
intern/asset_indexer.cc
intern/asset_library_reference.cc
intern/asset_library_reference_enum.cc
@ -37,6 +38,7 @@ set(SRC
ED_asset_catalog.hh
ED_asset_filter.h
ED_asset_handle.h
ED_asset_import.h
ED_asset_indexer.h
ED_asset_library.h
ED_asset_list.h

View File

@ -21,6 +21,7 @@ extern "C" {
struct AssetHandle;
struct AssetRepresentation *ED_asset_handle_get_representation(const struct AssetHandle *asset);
const char *ED_asset_handle_get_name(const struct AssetHandle *asset);
struct AssetMetaData *ED_asset_handle_get_metadata(const struct AssetHandle *asset);
struct ID *ED_asset_handle_get_local_id(const struct AssetHandle *asset);
@ -45,11 +46,4 @@ void ED_asset_handle_get_full_library_path(
std::optional<eAssetImportMethod> ED_asset_handle_get_import_method(
const struct AssetHandle *asset);
namespace blender::ed::asset {
/** If the ID already exists in the database, return it, otherwise add it. */
ID *get_local_id_from_asset_or_append_and_reuse(Main &bmain, AssetHandle asset);
} // namespace blender::ed::asset
#endif

View File

@ -0,0 +1,23 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edasset
*/
#pragma once
#include "DNA_ID_enums.h"
struct AssetRepresentation;
struct Main;
#ifdef __cplusplus
extern "C" {
#endif
struct ID *ED_asset_get_local_id_from_asset_or_append_and_reuse(
struct Main *bmain, const struct AssetRepresentation *asset_c_ptr, ID_Type idtype);
#ifdef __cplusplus
}
#endif

View File

@ -6,11 +6,12 @@
#pragma once
#include "DNA_asset_types.h"
#ifdef __cplusplus
extern "C" {
#endif
struct AssetHandle;
struct AssetLibraryReference;
struct ID;
struct bContext;
@ -49,6 +50,9 @@ void ED_assetlist_storage_id_remap(struct ID *id_old, struct ID *id_new);
*/
void ED_assetlist_storage_exit(void);
AssetHandle ED_assetlist_asset_get_by_index(const AssetLibraryReference *library_reference,
int asset_index);
struct ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle);
/**

View File

@ -30,4 +30,8 @@ blender::asset_system::AssetLibrary *ED_assetlist_library_get_once_available(
/* Can return false to stop iterating. */
using AssetListIterFn = blender::FunctionRef<bool(AssetHandle)>;
/**
* \warning Never keep the asset handle passed to \a fn outside of \a fn's scope. While iterating,
* the file data wrapped by the asset handle can be freed, since the file cache has a maximum size.
*/
void ED_assetlist_iterate(const AssetLibraryReference &library_reference, AssetListIterFn fn);

View File

@ -9,13 +9,20 @@
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "BKE_blendfile.h"
#include "BLI_string.h"
#include "DNA_space_types.h"
#include "BLO_readfile.h"
#include "DNA_space_types.h"
#include "ED_asset_handle.h"
#include "WM_api.h"
AssetRepresentation *ED_asset_handle_get_representation(const AssetHandle *asset)
{
return asset->file_data->asset;
}
const char *ED_asset_handle_get_name(const AssetHandle *asset)
{
@ -53,36 +60,11 @@ void ED_asset_handle_get_full_library_path(const AssetHandle *asset_handle,
{
*r_full_lib_path = '\0';
std::string asset_path = AS_asset_representation_full_path_get(asset_handle->file_data->asset);
if (asset_path.empty()) {
std::string library_path = AS_asset_representation_full_library_path_get(
asset_handle->file_data->asset);
if (library_path.empty()) {
return;
}
BLO_library_path_explode(asset_path.c_str(), r_full_lib_path, nullptr, nullptr);
BLI_strncpy(r_full_lib_path, library_path.c_str(), FILE_MAX);
}
namespace blender::ed::asset {
ID *get_local_id_from_asset_or_append_and_reuse(Main &bmain, const AssetHandle asset)
{
if (ID *local_id = ED_asset_handle_get_local_id(&asset)) {
return local_id;
}
char blend_path[FILE_MAX_LIBEXTRA];
ED_asset_handle_get_full_library_path(&asset, blend_path);
const char *id_name = ED_asset_handle_get_name(&asset);
return WM_file_append_datablock(&bmain,
nullptr,
nullptr,
nullptr,
blend_path,
ED_asset_handle_get_id_type(&asset),
id_name,
BLO_LIBLINK_APPEND_RECURSIVE |
BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR |
BLO_LIBLINK_APPEND_LOCAL_ID_REUSE);
}
} // namespace blender::ed::asset

View File

@ -0,0 +1,44 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edasset
*/
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "BLO_readfile.h"
#include "WM_api.h"
#include "ED_asset_import.h"
using namespace blender;
ID *ED_asset_get_local_id_from_asset_or_append_and_reuse(Main *bmain,
const AssetRepresentation *asset_c_ptr,
ID_Type idtype)
{
const asset_system::AssetRepresentation &asset =
*reinterpret_cast<const asset_system::AssetRepresentation *>(asset_c_ptr);
if (ID *local_id = asset.local_id()) {
return local_id;
}
std::string blend_path = asset.get_identifier().full_library_path();
if (blend_path.empty()) {
return nullptr;
}
return WM_file_append_datablock(bmain,
nullptr,
nullptr,
nullptr,
blend_path.c_str(),
idtype,
asset.get_name().c_str(),
BLO_LIBLINK_APPEND_RECURSIVE |
BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR |
BLO_LIBLINK_APPEND_LOCAL_ID_REUSE);
}

View File

@ -112,6 +112,8 @@ class AssetList : NonCopyable {
void ensurePreviewsJob(const bContext *C);
void clear(bContext *C);
AssetHandle asset_get_by_index(int index) const;
bool needsRefetch() const;
bool isLoaded() const;
asset_system::AssetLibrary *asset_library() const;
@ -139,7 +141,7 @@ void AssetList::setup()
filelist_setlibrary(files, &library_ref_);
filelist_setfilter_options(
files,
false,
true,
true,
true, /* Just always hide parent, prefer to not add an extra user option for this. */
FILE_TYPE_BLENDERLIB,
@ -246,6 +248,11 @@ void AssetList::clear(bContext *C)
WM_main_add_notifier(NC_ASSET | ND_ASSET_LIST, nullptr);
}
AssetHandle AssetList::asset_get_by_index(int index) const
{
return {filelist_file(filelist_, index)};
}
/**
* \return True if the asset-list needs a UI redraw.
*/
@ -472,6 +479,13 @@ asset_system::AssetLibrary *ED_assetlist_library_get_once_available(
return list->asset_library();
}
AssetHandle ED_assetlist_asset_get_by_index(const AssetLibraryReference *library_reference,
int asset_index)
{
const AssetList *list = AssetListStorage::lookup_list(*library_reference);
return list->asset_get_by_index(asset_index);
}
ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle)
{
ImBuf *imbuf = filelist_file_getimage(asset_handle->file_data);

View File

@ -8,9 +8,15 @@
*/
#include <new>
#include <string>
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "DNA_space_types.h"
#include "ED_asset.h"
#include "BKE_report.h"
#include "BLI_utility_mixins.hh"
@ -19,17 +25,16 @@
#include "MEM_guardedalloc.h"
#include "ED_asset_handle.h"
#include "ED_asset_temp_id_consumer.h"
using namespace blender;
class AssetTemporaryIDConsumer : NonCopyable, NonMovable {
const AssetHandle &handle_;
const AssetRepresentation *asset_;
TempLibraryContext *temp_lib_context_ = nullptr;
public:
AssetTemporaryIDConsumer(const AssetHandle &handle) : handle_(handle)
AssetTemporaryIDConsumer(const AssetRepresentation *asset) : asset_(asset)
{
}
~AssetTemporaryIDConsumer()
@ -41,20 +46,20 @@ class AssetTemporaryIDConsumer : NonCopyable, NonMovable {
ID *get_local_id()
{
return ED_asset_handle_get_local_id(&handle_);
return AS_asset_representation_local_id_get(asset_);
}
ID *import_id(ID_Type id_type, Main &bmain, ReportList &reports)
{
const char *asset_name = ED_asset_handle_get_name(&handle_);
char blend_file_path[FILE_MAX_LIBEXTRA];
ED_asset_handle_get_full_library_path(&handle_, blend_file_path);
const char *asset_name = AS_asset_representation_name_get(asset_);
std::string blend_file_path = AS_asset_representation_full_library_path_get(asset_);
temp_lib_context_ = BLO_library_temp_load_id(
&bmain, blend_file_path, id_type, asset_name, &reports);
&bmain, blend_file_path.c_str(), id_type, asset_name, &reports);
if (temp_lib_context_ == nullptr || temp_lib_context_->temp_id == nullptr) {
BKE_reportf(&reports, RPT_ERROR, "Unable to load %s from %s", asset_name, blend_file_path);
BKE_reportf(
&reports, RPT_ERROR, "Unable to load %s from %s", asset_name, blend_file_path.c_str());
return nullptr;
}
@ -70,7 +75,7 @@ AssetTempIDConsumer *ED_asset_temp_id_consumer_create(const AssetHandle *handle)
}
BLI_assert(handle->file_data->asset != nullptr);
return reinterpret_cast<AssetTempIDConsumer *>(
MEM_new<AssetTemporaryIDConsumer>(__func__, *handle));
MEM_new<AssetTemporaryIDConsumer>(__func__, ED_asset_handle_get_representation(handle)));
}
void ED_asset_temp_id_consumer_free(AssetTempIDConsumer **consumer)

View File

@ -665,7 +665,7 @@ static void curve_draw_exec_precalc(wmOperator *op)
selem_prev = selem;
}
scale_px = ((len_3d > 0.0f) && (len_2d > 0.0f)) ? (len_3d / len_2d) : 0.0f;
float error_threshold = (cps->error_threshold * U.dpi_fac) * scale_px;
float error_threshold = (cps->error_threshold * UI_SCALE_FAC) * scale_px;
RNA_property_float_set(op->ptr, prop, error_threshold);
}
@ -684,7 +684,7 @@ static void curve_draw_exec_precalc(wmOperator *op)
}
if (len_squared_v2v2(selem_first->mval, selem_last->mval) <=
square_f(STROKE_CYCLIC_DIST_PX * U.dpi_fac)) {
square_f(STROKE_CYCLIC_DIST_PX * UI_SCALE_FAC)) {
use_cyclic = true;
}
}

View File

@ -126,7 +126,7 @@ static void arrow_draw_geom(const ArrowGizmo3D *arrow,
if (draw_options & ED_GIZMO_ARROW_DRAW_FLAG_STEM) {
const float stem_width = arrow->gizmo.line_width * U.pixelsize +
(select ? ARROW_SELECT_THRESHOLD_PX * U.dpi_fac : 0);
(select ? ARROW_SELECT_THRESHOLD_PX * UI_SCALE_FAC : 0);
immUniform1f("lineWidth", stem_width);
wm_gizmo_vec_draw(color, vec, ARRAY_SIZE(vec), pos, GPU_PRIM_LINE_STRIP);
}

View File

@ -251,14 +251,14 @@ static void button2d_draw_intern(const bContext *C,
if (is_3d) {
const float fac = 2.0f;
GPU_matrix_translate_2f(-(fac / 2), -(fac / 2));
GPU_matrix_scale_2f(fac / (ICON_DEFAULT_WIDTH * UI_DPI_FAC),
fac / (ICON_DEFAULT_HEIGHT * UI_DPI_FAC));
GPU_matrix_scale_2f(fac / (ICON_DEFAULT_WIDTH * UI_SCALE_FAC),
fac / (ICON_DEFAULT_HEIGHT * UI_SCALE_FAC));
pos[0] = 1.0f;
pos[1] = 1.0f;
}
else {
pos[0] = gz->matrix_basis[3][0] - (ICON_DEFAULT_WIDTH / 2.0) * UI_DPI_FAC;
pos[1] = gz->matrix_basis[3][1] - (ICON_DEFAULT_HEIGHT / 2.0) * UI_DPI_FAC;
pos[0] = gz->matrix_basis[3][0] - (ICON_DEFAULT_WIDTH / 2.0) * UI_SCALE_FAC;
pos[1] = gz->matrix_basis[3][1] - (ICON_DEFAULT_HEIGHT / 2.0) * UI_SCALE_FAC;
GPU_matrix_pop();
need_to_pop = false;
}
@ -327,7 +327,7 @@ static int gizmo_button2d_cursor_get(wmGizmo *gz)
static bool gizmo_button2d_bounds(bContext *C, wmGizmo *gz, rcti *r_bounding_box)
{
ScrArea *area = CTX_wm_area(C);
float rad = CIRCLE_RESOLUTION_3D * U.dpi_fac / 2.0f;
float rad = CIRCLE_RESOLUTION_3D * UI_SCALE_FAC / 2.0f;
const float *co = NULL;
float matrix_final[4][4];
float co_proj[3];

View File

@ -25,6 +25,7 @@ void ED_operatortypes_asset(void);
#include "../asset/ED_asset_catalog.h"
#include "../asset/ED_asset_filter.h"
#include "../asset/ED_asset_handle.h"
#include "../asset/ED_asset_import.h"
#include "../asset/ED_asset_library.h"
#include "../asset/ED_asset_list.h"
#include "../asset/ED_asset_mark_clear.h"

View File

@ -48,6 +48,7 @@ struct bPoseChannel;
struct bScreen;
struct rctf;
struct rcti;
struct wmEvent;
struct wmGizmo;
struct wmWindow;
struct wmWindowManager;
@ -863,6 +864,20 @@ int ED_view3d_backbuf_sample_size_clamp(struct ARegion *region, float dist);
void ED_view3d_select_id_validate(struct ViewContext *vc);
/** Check if the last auto-dist can be used. */
bool ED_view3d_autodist_last_check(struct wmWindow *win, const struct wmEvent *event);
/**
* \return true when `r_ofs` is set.
* \warning #ED_view3d_autodist_last_check should be called first to ensure the data is available.
*/
bool ED_view3d_autodist_last_get(struct wmWindow *win, float r_ofs[3]);
void ED_view3d_autodist_last_set(struct wmWindow *win,
const struct wmEvent *event,
const float ofs[3],
const bool has_depth);
/** Clear and free auto-dist data. */
void ED_view3d_autodist_last_clear(struct wmWindow *win);
/**
* Get the world-space 3d location from a screen-space 2d point.
* TODO: Implement #alphaoverride. We don't want to zoom into billboards.

View File

@ -319,12 +319,6 @@ enum {
UI_BUT_CHECKBOX_INVERT = 1 << 25,
};
/* scale fixed button widths by this to account for DPI */
#define UI_DPI_FAC (U.dpi_fac)
/* 16 to copy ICON_DEFAULT_HEIGHT */
#define UI_DPI_ICON_SIZE ((float)16 * UI_DPI_FAC)
/**
* Button types, bits stored in 1 value... and a short even!
* - bits 0-4: #uiBut.bitnr (0-31)

View File

@ -8,6 +8,7 @@
#include <memory>
#include "BLI_function_ref.hh"
#include "BLI_string_ref.hh"
#include "BLI_vector.hh"
@ -17,8 +18,10 @@ namespace blender::nodes::geo_eval_log {
struct GeometryAttributeInfo;
}
struct PointerRNA;
struct StructRNA;
struct uiBlock;
struct uiList;
struct uiSearchItems;
namespace blender::ui {
@ -53,6 +56,60 @@ void attribute_search_add_items(StringRefNull str,
} // namespace blender::ui
enum eUIListFilterResult {
/** Never show this item, even when filter results are inverted (#UILST_FLT_EXCLUDE). */
UI_LIST_ITEM_NEVER_SHOW,
/** Show this item, unless filter results are inverted (#UILST_FLT_EXCLUDE). */
UI_LIST_ITEM_FILTER_MATCHES,
/** Don't show this item, unless filter results are inverted (#UILST_FLT_EXCLUDE). */
UI_LIST_ITEM_FILTER_MISMATCHES,
};
/**
* Function object for UI list item filtering that does the default name comparison with '*'
* wildcards. Create an instance of this once and pass it to #UI_list_filter_and_sort_items(), do
* NOT create an instance for every item, this would be costly.
*/
class uiListNameFilter {
/* Storage with an inline buffer for smaller strings (small buffer optimization). */
struct {
char filter_buff[32];
char *filter_dyn = nullptr;
} storage_;
char *filter_ = nullptr;
public:
uiListNameFilter(uiList &list);
~uiListNameFilter();
eUIListFilterResult operator()(const PointerRNA &itemptr,
blender::StringRefNull name,
int index);
};
using uiListItemFilterFn = blender::FunctionRef<eUIListFilterResult(
const PointerRNA &itemptr, blender::StringRefNull name, int index)>;
using uiListItemGetNameFn =
blender::FunctionRef<std::string(const PointerRNA &itemptr, int index)>;
/**
* Filter list items using \a item_filter_fn and sort the result. This respects the normal UI list
* filter settings like alphabetical sorting (#UILST_FLT_SORT_ALPHA), and result inverting
* (#UILST_FLT_EXCLUDE).
*
* Call this from a #uiListType::filter_items callback with any #item_filter_fn. #uiListNameFilter
* can be used to apply the default name based filtering.
*
* \param get_name_fn: In some cases the name cannot be retrieved via RNA. This function can be set
* to provide the name still.
*/
void UI_list_filter_and_sort_items(uiList *ui_list,
const struct bContext *C,
uiListItemFilterFn item_filter_fn,
PointerRNA *dataptr,
const char *propname,
uiListItemGetNameFn get_name_fn = nullptr);
/**
* Override this for all available view types.
*/

View File

@ -60,11 +60,11 @@ enum eView2D_CommonViewTypes {
#define V2D_SCROLL_MIN_ALPHA (0.4f)
/* Minimum size needs to include outline which varies with line width. */
#define V2D_SCROLL_MIN_WIDTH ((5.0f * U.dpi_fac) + (2.0f * U.pixelsize))
#define V2D_SCROLL_MIN_WIDTH ((5.0f * UI_SCALE_FAC) + (2.0f * U.pixelsize))
/* When to start showing the full-width scroller. */
#define V2D_SCROLL_HIDE_WIDTH (AREAMINX * U.dpi_fac)
#define V2D_SCROLL_HIDE_HEIGHT (HEADERY * U.dpi_fac)
#define V2D_SCROLL_HIDE_WIDTH (AREAMINX * UI_SCALE_FAC)
#define V2D_SCROLL_HIDE_HEIGHT (HEADERY * UI_SCALE_FAC)
/** Scroll bars with 'handles' used for scale (zoom). */
#define V2D_SCROLL_HANDLE_HEIGHT (0.6f * U.widget_unit)
@ -74,7 +74,7 @@ enum eView2D_CommonViewTypes {
#define V2D_SCROLL_HANDLE_SIZE_HOTSPOT (0.6f * U.widget_unit)
/** Don't allow scroll thumb to show below this size (so it's never too small to click on). */
#define V2D_SCROLL_THUMB_SIZE_MIN (30.0 * UI_DPI_FAC)
#define V2D_SCROLL_THUMB_SIZE_MIN (30.0 * UI_SCALE_FAC)
/** \} */
@ -490,8 +490,8 @@ void UI_view2d_smooth_view(const struct bContext *C,
const struct rctf *cur,
int smooth_viewtx);
#define UI_MARKER_MARGIN_Y (42 * UI_DPI_FAC)
#define UI_TIME_SCRUB_MARGIN_Y (23 * UI_DPI_FAC)
#define UI_MARKER_MARGIN_Y (42 * UI_SCALE_FAC)
#define UI_TIME_SCRUB_MARGIN_Y (23 * UI_SCALE_FAC)
/** \} */

View File

@ -280,7 +280,7 @@ static void ui_update_flexible_spacing(const ARegion *region, uiBlock *block)
rcti rect;
ui_but_to_pixelrect(&rect, region, block, static_cast<const uiBut *>(block->buttons.last));
const float buttons_width = float(rect.xmax) + UI_HEADER_OFFSET;
const float region_width = float(region->sizex) * U.dpi_fac;
const float region_width = float(region->sizex) * UI_SCALE_FAC;
if (region_width <= buttons_width) {
return;
@ -469,7 +469,7 @@ void ui_block_bounds_calc(uiBlock *block)
/* hardcoded exception... but that one is annoying with larger safety */
uiBut *bt = static_cast<uiBut *>(block->buttons.first);
const int xof = ((bt && STRPREFIX(bt->str, "ERROR")) ? 10 : 40) * U.dpi_fac;
const int xof = ((bt && STRPREFIX(bt->str, "ERROR")) ? 10 : 40) * UI_SCALE_FAC;
block->safety.xmin = block->rect.xmin - xof;
block->safety.ymin = block->rect.ymin - xof;
@ -4993,7 +4993,7 @@ int UI_preview_tile_size_x(void)
int UI_preview_tile_size_y(void)
{
const uiStyle *style = UI_style_get();
const float font_height = style->widget.points * UI_DPI_FAC;
const float font_height = style->widget.points * UI_SCALE_FAC;
const float pad = PREVIEW_TILE_PAD;
return round_fl_to_int(UI_preview_tile_size_y_no_label() + font_height +

View File

@ -180,8 +180,8 @@ static uiBlock *menu_change_shortcut(bContext *C, ARegion *region, void *arg)
uiItemL(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Change Shortcut"), ICON_HAND);
uiItemR(layout, &ptr, "type", UI_ITEM_R_FULL_EVENT | UI_ITEM_R_IMMEDIATE, "", ICON_NONE);
const int bounds_offset[2] = {int(-100 * U.dpi_fac), int(36 * U.dpi_fac)};
UI_block_bounds_set_popup(block, 6 * U.dpi_fac, bounds_offset);
const int bounds_offset[2] = {int(-100 * UI_SCALE_FAC), int(36 * UI_SCALE_FAC)};
UI_block_bounds_set_popup(block, 6 * UI_SCALE_FAC, bounds_offset);
shortcut_free_operator_property(prop);
@ -241,8 +241,8 @@ static uiBlock *menu_add_shortcut(bContext *C, ARegion *region, void *arg)
uiItemL(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Assign Shortcut"), ICON_HAND);
uiItemR(layout, &ptr, "type", UI_ITEM_R_FULL_EVENT | UI_ITEM_R_IMMEDIATE, "", ICON_NONE);
const int bounds_offset[2] = {int(-100 * U.dpi_fac), int(36 * U.dpi_fac)};
UI_block_bounds_set_popup(block, 6 * U.dpi_fac, bounds_offset);
const int bounds_offset[2] = {int(-100 * UI_SCALE_FAC), int(36 * UI_SCALE_FAC)};
UI_block_bounds_set_popup(block, 6 * UI_SCALE_FAC, bounds_offset);
#ifdef USE_KEYMAP_ADD_HACK
g_kmi_id_hack = kmi_id;

View File

@ -1098,7 +1098,8 @@ static void ui_draw_colorband_handle(uint shdr_pos,
float viewport_size[4];
GPU_viewport_size_get_f(viewport_size);
immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
immUniform2f(
"viewport_size", viewport_size[2] / UI_SCALE_FAC, viewport_size[3] / UI_SCALE_FAC);
immUniform1i("colors_len", 2); /* "advanced" mode */
immUniform4f("color", 0.8f, 0.8f, 0.8f, 1.0f);
@ -1672,7 +1673,7 @@ void ui_draw_but_CURVE(ARegion *region, uiBut *but, const uiWidgetColors *wcol,
}
cmp = cuma->curve;
GPU_point_size(max_ff(1.0f, min_ff(UI_DPI_FAC / but->block->aspect * 4.0f, 4.0f)));
GPU_point_size(max_ff(1.0f, min_ff(UI_SCALE_FAC / but->block->aspect * 4.0f, 4.0f)));
immBegin(GPU_PRIM_POINTS, cuma->totpoint);
for (int a = 0; a < cuma->totpoint; a++) {
const float fx = rect->xmin + zoomx * (cmp[a].x - offsx);
@ -1931,7 +1932,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region,
GPU_line_smooth(false);
if (path_len > 0) {
GPU_blend(GPU_BLEND_NONE);
GPU_point_size(max_ff(3.0f, min_ff(UI_DPI_FAC / but->block->aspect * 5.0f, 5.0f)));
GPU_point_size(max_ff(3.0f, min_ff(UI_SCALE_FAC / but->block->aspect * 5.0f, 5.0f)));
immBegin(GPU_PRIM_POINTS, path_len);
for (int i = 0; i < path_len; i++) {
fx = rect->xmin + zoomx * (pts[i].x - offsx);
@ -1946,7 +1947,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region,
if (selected_free_points > 0) {
GPU_line_smooth(false);
GPU_blend(GPU_BLEND_NONE);
GPU_point_size(max_ff(2.0f, min_ff(UI_DPI_FAC / but->block->aspect * 4.0f, 4.0f)));
GPU_point_size(max_ff(2.0f, min_ff(UI_SCALE_FAC / but->block->aspect * 4.0f, 4.0f)));
immBegin(GPU_PRIM_POINTS, selected_free_points * 2);
for (int i = 0; i < path_len; i++) {
if (point_draw_handles(&pts[i])) {
@ -1968,7 +1969,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region,
pts = profile->segments;
const int segments_len = uint(profile->segments_len);
if (segments_len > 0 && pts) {
GPU_point_size(max_ff(2.0f, min_ff(UI_DPI_FAC / but->block->aspect * 3.0f, 3.0f)));
GPU_point_size(max_ff(2.0f, min_ff(UI_SCALE_FAC / but->block->aspect * 3.0f, 3.0f)));
immBegin(GPU_PRIM_POINTS, segments_len);
for (int i = 0; i < segments_len; i++) {
fx = rect->xmin + zoomx * (pts[i].x - offsx);

View File

@ -3050,7 +3050,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
if (but->flag & UI_HAS_ICON) {
startx += UI_DPI_ICON_SIZE / aspect;
startx += UI_ICON_SIZE / aspect;
}
}
startx += (UI_TEXT_MARGIN_X * U.widget_unit - U.pixelsize) / aspect;
@ -4048,7 +4048,7 @@ static void ui_numedit_begin(uiBut *but, uiHandleButtonData *data)
const double value_step = is_float ?
double(number_but->step_size * UI_PRECISION_FLOAT_SCALE) :
int(number_but->step_size);
const float drag_map_softrange_max = UI_DRAG_MAP_SOFT_RANGE_PIXEL_MAX * UI_DPI_FAC;
const float drag_map_softrange_max = UI_DRAG_MAP_SOFT_RANGE_PIXEL_MAX * UI_SCALE_FAC;
const float softrange_max = min_ff(
softrange,
2 * (is_float ? min_ff(value_step, value_step_float_min) *
@ -5156,7 +5156,7 @@ static bool ui_numedit_but_NUM(uiButNumber *but,
if (is_float == false) {
/* at minimum, moving cursor 2 pixels should change an int button. */
CLAMP_MIN(non_linear_scale, 0.5f * UI_DPI_FAC);
CLAMP_MIN(non_linear_scale, 0.5f * UI_SCALE_FAC);
}
data->dragf += (float(mx - data->draglastx) / deler) * non_linear_scale;
@ -7027,7 +7027,7 @@ static int ui_do_but_COLORBAND(
else {
CBData *cbd;
/* ignore zoom-level for mindist */
int mindist = (50 * UI_DPI_FAC) * block->aspect;
int mindist = (50 * UI_SCALE_FAC) * block->aspect;
int xco;
data->dragstartx = mx;
data->dragstarty = my;
@ -7215,7 +7215,7 @@ static int ui_do_but_CURVE(
CurveMapping *cumap = (CurveMapping *)but->poin;
CurveMap *cuma = cumap->cm + cumap->cur;
const float m_xy[2] = {float(mx), float(my)};
float dist_min_sq = square_f(U.dpi_fac * 14.0f); /* 14 pixels radius */
float dist_min_sq = square_f(UI_SCALE_FAC * 14.0f); /* 14 pixels radius */
int sel = -1;
if (event->modifier & KM_CTRL) {
@ -7249,7 +7249,7 @@ static int ui_do_but_CURVE(
BLI_rctf_transform_pt_v(&but->rect, &cumap->curr, f_xy, &cmp[0].x);
/* with 160px height 8px should translate to the old 0.05 coefficient at no zoom */
dist_min_sq = square_f(U.dpi_fac * 8.0f);
dist_min_sq = square_f(UI_SCALE_FAC * 8.0f);
/* loop through the curve segment table and find what's near the mouse. */
for (int i = 1; i <= CM_TABLE; i++) {
@ -7383,7 +7383,7 @@ static bool ui_numedit_but_CURVEPROFILE(uiBlock *block,
if (snap) {
const float d[2] = {float(mx - data->dragstartx), float(data->dragstarty)};
if (len_squared_v2(d) < (9.0f * U.dpi_fac)) {
if (len_squared_v2(d) < (9.0f * UI_SCALE_FAC)) {
snap = false;
}
}
@ -7529,7 +7529,8 @@ static int ui_do_but_CURVEPROFILE(
/* Check for selecting of a point by finding closest point in radius. */
CurveProfilePoint *pts = profile->path;
float dist_min_sq = square_f(U.dpi_fac * 14.0f); /* 14 pixels radius for selecting points. */
float dist_min_sq = square_f(UI_SCALE_FAC *
14.0f); /* 14 pixels radius for selecting points. */
int i_selected = -1;
short selection_type = 0; /* For handle selection. */
for (int i = 0; i < profile->path_len; i++) {
@ -7571,7 +7572,7 @@ static int ui_do_but_CURVEPROFILE(
CurveProfilePoint *table = profile->table;
BLI_rctf_transform_pt_v(&but->rect, &profile->view_rect, f_xy, &table[0].x);
dist_min_sq = square_f(U.dpi_fac * 8.0f); /* 8 pixel radius from each table point. */
dist_min_sq = square_f(UI_SCALE_FAC * 8.0f); /* 8 pixel radius from each table point. */
/* Loop through the path's high resolution table and find what's near the click. */
for (int i = 1; i <= BKE_curveprofile_table_size(profile); i++) {
@ -10150,7 +10151,7 @@ float ui_block_calc_pie_segment(uiBlock *block, const float event_xy[2])
const float len = normalize_v2_v2(block->pie_data.pie_dir, seg2);
if (len < U.pie_menu_threshold * U.dpi_fac) {
if (len < U.pie_menu_threshold * UI_SCALE_FAC) {
block->pie_data.flags |= UI_PIE_INVALID_DIR;
}
else {
@ -10960,7 +10961,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle
if (!(block->pie_data.flags & UI_PIE_ANIMATION_FINISHED)) {
const double final_time = 0.01 * U.pie_animation_timeout;
float fac = duration / final_time;
const float pie_radius = U.pie_menu_radius * UI_DPI_FAC;
const float pie_radius = U.pie_menu_radius * UI_SCALE_FAC;
if (fac > 1.0f) {
fac = 1.0f;
@ -11035,7 +11036,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle
uiBut *but = ui_region_find_active_but(menu->region);
if (but && (U.pie_menu_confirm > 0) &&
(dist >= U.dpi_fac * (U.pie_menu_threshold + U.pie_menu_confirm))) {
(dist >= UI_SCALE_FAC * (U.pie_menu_threshold + U.pie_menu_confirm))) {
return ui_but_pie_menu_apply(C, menu, but, true);
}
@ -11060,7 +11061,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle
/* here instead, we use the offset location to account for the initial
* direction timeout */
if ((U.pie_menu_confirm > 0) &&
(dist >= U.dpi_fac * (U.pie_menu_threshold + U.pie_menu_confirm))) {
(dist >= UI_SCALE_FAC * (U.pie_menu_threshold + U.pie_menu_confirm))) {
block->pie_data.flags |= UI_PIE_GESTURE_END_WAIT;
copy_v2_v2(block->pie_data.last_pos, event_xy);
block->pie_data.duration_gesture = duration;

View File

@ -1741,7 +1741,7 @@ static void icon_draw_texture(float x,
bool with_border,
const IconTextOverlay *text_overlay)
{
const float zoom_factor = w / UI_DPI_ICON_SIZE;
const float zoom_factor = w / UI_ICON_SIZE;
float text_width = 0.0f;
/* No need to show if too zoomed out, otherwise it just adds noise. */
@ -2492,13 +2492,13 @@ int UI_icon_color_from_collection(const Collection *collection)
void UI_icon_draw(float x, float y, int icon_id)
{
UI_icon_draw_ex(
x, y, icon_id, U.inv_dpi_fac, 1.0f, 0.0f, nullptr, false, UI_NO_ICON_OVERLAY_TEXT);
x, y, icon_id, UI_INV_SCALE_FAC, 1.0f, 0.0f, nullptr, false, UI_NO_ICON_OVERLAY_TEXT);
}
void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha)
{
UI_icon_draw_ex(
x, y, icon_id, U.inv_dpi_fac, alpha, 0.0f, nullptr, false, UI_NO_ICON_OVERLAY_TEXT);
x, y, icon_id, UI_INV_SCALE_FAC, alpha, 0.0f, nullptr, false, UI_NO_ICON_OVERLAY_TEXT);
}
void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size)

View File

@ -26,12 +26,12 @@ static void icon_draw_rect_input_text(
BLF_batch_draw_flush();
const int font_id = BLF_default();
BLF_color4fv(font_id, color);
BLF_size(font_id, font_size * U.dpi_fac);
BLF_size(font_id, font_size * UI_SCALE_FAC);
float width, height;
BLF_width_and_height(font_id, str, BLF_DRAW_STR_DUMMY_MAX, &width, &height);
const float x = trunc(rect->xmin + (((rect->xmax - rect->xmin) - width) / 2.0f));
const float y = rect->ymin + (((rect->ymax - rect->ymin) - height) / 2.0f) +
(v_offset * U.dpi_fac);
(v_offset * UI_SCALE_FAC);
BLF_position(font_id, x, y, 0.0f);
BLF_draw(font_id, str, BLF_DRAW_STR_DUMMY_MAX);
BLF_batch_draw_flush();

View File

@ -50,12 +50,12 @@ struct wmTimer;
#define UI_MENU_WIDTH_MIN (UI_UNIT_Y * 9)
/** Some extra padding added to menus containing sub-menu icons. */
#define UI_MENU_SUBMENU_PADDING (6 * UI_DPI_FAC)
#define UI_MENU_SUBMENU_PADDING (6 * UI_SCALE_FAC)
/* menu scrolling */
#define UI_MENU_SCROLL_ARROW (12 * UI_DPI_FAC)
#define UI_MENU_SCROLL_MOUSE (UI_MENU_SCROLL_ARROW + 2 * UI_DPI_FAC)
#define UI_MENU_SCROLL_PAD (4 * UI_DPI_FAC)
#define UI_MENU_SCROLL_ARROW (12 * UI_SCALE_FAC)
#define UI_MENU_SCROLL_MOUSE (UI_MENU_SCROLL_ARROW + 2 * UI_SCALE_FAC)
#define UI_MENU_SCROLL_PAD (4 * UI_SCALE_FAC)
/** Popover width (multiplied by #U.widget_unit) */
#define UI_POPOVER_WIDTH_UNITS 10
@ -1181,12 +1181,12 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
eFontStyle_Align text_align);
#define UI_TEXT_MARGIN_X 0.4f
#define UI_POPUP_MARGIN (UI_DPI_FAC * 12)
#define UI_POPUP_MARGIN (UI_SCALE_FAC * 12)
/**
* Margin at top of screen for popups.
* Note this value must be sufficient to draw a popover arrow to avoid cropping it.
*/
#define UI_POPUP_MENU_TOP (int)(10 * UI_DPI_FAC)
#define UI_POPUP_MENU_TOP (int)(10 * UI_SCALE_FAC)
#define UI_PIXEL_AA_JITTER 8
extern const float ui_pixel_jitter[UI_PIXEL_AA_JITTER][2];

View File

@ -3962,7 +3962,7 @@ static void ui_litem_layout_radial(uiLayout *litem)
* for radiation, see http://mattebb.com/weblog/radiation/
* also the old code at #5103. */
const int pie_radius = U.pie_menu_radius * UI_DPI_FAC;
const int pie_radius = U.pie_menu_radius * UI_SCALE_FAC;
const int x = litem->x;
const int y = litem->y;
@ -4046,7 +4046,7 @@ static void ui_litem_layout_root_radial(uiLayout *litem)
ui_item_size(item, &itemw, &itemh);
ui_item_position(
item, x - itemw / 2, y + U.dpi_fac * (U.pie_menu_threshold + 9.0f), itemw, itemh);
item, x - itemw / 2, y + UI_SCALE_FAC * (U.pie_menu_threshold + 9.0f), itemw, itemh);
}
}
@ -6125,13 +6125,13 @@ const char *UI_layout_introspect(uiLayout *layout)
uiLayout *uiItemsAlertBox(uiBlock *block, const int size, const eAlertIcon icon)
{
const uiStyle *style = UI_style_get_dpi();
const short icon_size = 64 * U.dpi_fac;
const short icon_size = 64 * UI_SCALE_FAC;
const int text_points_max = MAX2(style->widget.points, style->widgetlabel.points);
const int dialog_width = icon_size + (text_points_max * size * U.dpi_fac);
const int dialog_width = icon_size + (text_points_max * size * UI_SCALE_FAC);
/* By default, the space between icon and text/buttons will be equal to the 'columnspace',
* this extra padding will add some space by increasing the left column width,
* making the icon placement more symmetrical, between the block edge and the text. */
const float icon_padding = 5.0f * U.dpi_fac;
const float icon_padding = 5.0f * UI_SCALE_FAC;
/* Calculate the factor of the fixed icon column depending on the block width. */
const float split_factor = (float(icon_size) + icon_padding) /
float(dialog_width - style->columnspace);

View File

@ -1099,7 +1099,7 @@ static void panel_draw_aligned_widgets(const uiStyle *style,
UI_icon_draw_ex(widget_rect.xmin + size_y * 0.2f,
widget_rect.ymin + size_y * 0.2f,
UI_panel_is_closed(panel) ? ICON_RIGHTARROW : ICON_DOWNARROW_HLT,
aspect * U.inv_dpi_fac,
aspect * UI_INV_SCALE_FAC,
0.7f,
0.0f,
title_color,
@ -1128,7 +1128,7 @@ static void panel_draw_aligned_widgets(const uiStyle *style,
UI_icon_draw_ex(widget_rect.xmax - scaled_unit * 2.2f,
widget_rect.ymin + 5.0f / aspect,
ICON_PINNED,
aspect * U.inv_dpi_fac,
aspect * UI_INV_SCALE_FAC,
1.0f,
0.0f,
title_color,
@ -1288,7 +1288,7 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
const float zoom = 1.0f / aspect;
const int px = U.pixelsize;
const int category_tabs_width = round_fl_to_int(UI_PANEL_CATEGORY_MARGIN_WIDTH * zoom);
const float dpi_fac = UI_DPI_FAC;
const float dpi_fac = UI_SCALE_FAC;
/* Padding of tabs around text. */
const int tab_v_pad_text = round_fl_to_int(TABS_PADDING_TEXT_FACTOR * dpi_fac * zoom) + 2 * px;
/* Padding between tabs. */
@ -1334,7 +1334,7 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
BLF_enable(fontid, BLF_ROTATION);
BLF_rotation(fontid, M_PI_2);
ui_fontscale(&fstyle_points, aspect);
BLF_size(fontid, fstyle_points * U.dpi_fac);
BLF_size(fontid, fstyle_points * UI_SCALE_FAC);
/* Check the region type supports categories to avoid an assert
* for showing 3D view panels in the properties space. */

View File

@ -173,8 +173,8 @@ static void hud_region_layout(const bContext *C, ARegion *region)
if (region->panels.first &&
((area->flag & AREA_FLAG_REGION_SIZE_UPDATE) || (region->sizey != size_y))) {
int winx_new = UI_DPI_FAC * (region->sizex + 0.5f);
int winy_new = UI_DPI_FAC * (region->sizey + 0.5f);
int winx_new = UI_SCALE_FAC * (region->sizex + 0.5f);
int winy_new = UI_SCALE_FAC * (region->sizey + 0.5f);
View2D *v2d = &region->v2d;
if (region->flag & RGN_FLAG_SIZE_CLAMP_X) {

View File

@ -288,8 +288,8 @@ static void ui_popup_block_position(wmWindow *window,
/* when you are outside parent button, safety there should be smaller */
const int s1 = 40 * U.dpi_fac;
const int s2 = 3 * U.dpi_fac;
const int s1 = 40 * UI_SCALE_FAC;
const int s2 = 3 * UI_SCALE_FAC;
/* parent button to left */
if (midx < block->rect.xmin) {

View File

@ -651,7 +651,7 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
if (icon == ICON_BLANK1) {
icon = ICON_NONE;
rect.xmin -= UI_DPI_ICON_SIZE / 4;
rect.xmin -= UI_ICON_SIZE / 4;
}
/* The previous menu item draws the active selection. */
@ -762,7 +762,7 @@ static void ui_searchbox_region_layout_fn(const struct bContext *C, struct ARegi
/* We should make this wider if there is a path or hint on the right. */
if (ui_searchbox_item_separator(data) != UI_MENU_ITEM_SEPARATOR_NONE) {
searchbox_width += 12 * data->fstyle.points * U.dpi_fac;
searchbox_width += 12 * data->fstyle.points * UI_SCALE_FAC;
}
rctf rect_fl;

View File

@ -253,7 +253,7 @@ static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
UI_fontstyle_set(&fstyle_mono);
/* XXX: needed because we don't have mono in 'U.uifonts'. */
BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.dpi_fac);
BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * UI_SCALE_FAC);
rgb_float_to_uchar(drawcol, tip_colors[int(field->format.color_id)]);
UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params);
}
@ -1132,7 +1132,7 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
int font_id;
if (field->format.style == uiTooltipFormat::Style::Mono) {
BLF_size(blf_mono_font, data->fstyle.points * U.dpi_fac);
BLF_size(blf_mono_font, data->fstyle.points * UI_SCALE_FAC);
font_id = blf_mono_font;
}
else {

View File

@ -321,20 +321,20 @@ const uiStyle *UI_style_get_dpi(void)
_style = *style;
_style.paneltitle.shadx = short(UI_DPI_FAC * _style.paneltitle.shadx);
_style.paneltitle.shady = short(UI_DPI_FAC * _style.paneltitle.shady);
_style.grouplabel.shadx = short(UI_DPI_FAC * _style.grouplabel.shadx);
_style.grouplabel.shady = short(UI_DPI_FAC * _style.grouplabel.shady);
_style.widgetlabel.shadx = short(UI_DPI_FAC * _style.widgetlabel.shadx);
_style.widgetlabel.shady = short(UI_DPI_FAC * _style.widgetlabel.shady);
_style.paneltitle.shadx = short(UI_SCALE_FAC * _style.paneltitle.shadx);
_style.paneltitle.shady = short(UI_SCALE_FAC * _style.paneltitle.shady);
_style.grouplabel.shadx = short(UI_SCALE_FAC * _style.grouplabel.shadx);
_style.grouplabel.shady = short(UI_SCALE_FAC * _style.grouplabel.shady);
_style.widgetlabel.shadx = short(UI_SCALE_FAC * _style.widgetlabel.shadx);
_style.widgetlabel.shady = short(UI_SCALE_FAC * _style.widgetlabel.shady);
_style.columnspace = short(UI_DPI_FAC * _style.columnspace);
_style.templatespace = short(UI_DPI_FAC * _style.templatespace);
_style.boxspace = short(UI_DPI_FAC * _style.boxspace);
_style.buttonspacex = short(UI_DPI_FAC * _style.buttonspacex);
_style.buttonspacey = short(UI_DPI_FAC * _style.buttonspacey);
_style.panelspace = short(UI_DPI_FAC * _style.panelspace);
_style.panelouter = short(UI_DPI_FAC * _style.panelouter);
_style.columnspace = short(UI_SCALE_FAC * _style.columnspace);
_style.templatespace = short(UI_SCALE_FAC * _style.templatespace);
_style.boxspace = short(UI_SCALE_FAC * _style.boxspace);
_style.buttonspacex = short(UI_SCALE_FAC * _style.buttonspacex);
_style.buttonspacey = short(UI_SCALE_FAC * _style.buttonspacey);
_style.panelspace = short(UI_SCALE_FAC * _style.panelspace);
_style.panelouter = short(UI_SCALE_FAC * _style.panelouter);
return &_style;
}
@ -351,7 +351,7 @@ int UI_fontstyle_string_width_with_block_aspect(const uiFontStyle *fs,
{
/* FIXME(@ideasman42): the final scale of the font is rounded which should be accounted for.
* Failing to do so causes bad alignment when zoomed out very far in the node-editor. */
fontstyle_set_ex(fs, U.dpi_fac / aspect);
fontstyle_set_ex(fs, UI_SCALE_FAC / aspect);
return int(BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX) * aspect);
}
@ -492,5 +492,5 @@ static void fontstyle_set_ex(const uiFontStyle *fs, const float dpi_fac)
void UI_fontstyle_set(const uiFontStyle *fs)
{
fontstyle_set_ex(fs, U.dpi_fac);
fontstyle_set_ex(fs, UI_SCALE_FAC);
}

View File

@ -24,6 +24,7 @@
#include "RNA_prototypes.h"
#include "UI_interface.h"
#include "UI_interface.hh"
#include "WM_api.h"
#include "WM_types.h"
@ -32,6 +33,7 @@
struct AssetViewListData {
AssetLibraryReference asset_library_ref;
AssetFilterSettings filter_settings;
bScreen *screen;
bool show_names;
};
@ -45,8 +47,6 @@ static void asset_view_item_but_drag_set(uiBut *but, AssetHandle *asset_handle)
}
char blend_path[FILE_MAX_LIBEXTRA];
/* Context can be null here, it's only needed for a File Browser specific hack that should go
* away before too long. */
ED_asset_handle_get_full_library_path(asset_handle, blend_path);
const eAssetImportMethod import_method =
@ -68,19 +68,23 @@ static void asset_view_draw_item(uiList *ui_list,
const bContext * /*C*/,
uiLayout *layout,
PointerRNA * /*dataptr*/,
PointerRNA *itemptr,
PointerRNA * /*itemptr*/,
int /*icon*/,
PointerRNA * /*active_dataptr*/,
const char * /*active_propname*/,
int /*index*/,
int index,
int /*flt_flag*/)
{
AssetViewListData *list_data = (AssetViewListData *)ui_list->dyn_data->customdata;
BLI_assert(RNA_struct_is_a(itemptr->type, &RNA_AssetHandle));
AssetHandle *asset_handle = (AssetHandle *)itemptr->data;
AssetHandle asset_handle = ED_assetlist_asset_get_by_index(&list_data->asset_library_ref, index);
uiLayoutSetContextPointer(layout, "asset_handle", itemptr);
PointerRNA file_ptr;
RNA_pointer_create(&list_data->screen->id,
&RNA_FileSelectEntry,
const_cast<FileDirEntry *>(asset_handle.file_data),
&file_ptr);
uiLayoutSetContextPointer(layout, "active_file", &file_ptr);
uiBlock *block = uiLayoutGetBlock(layout);
const bool show_names = list_data->show_names;
@ -90,8 +94,8 @@ static void asset_view_draw_item(uiList *ui_list,
uiBut *but = uiDefIconTextBut(block,
UI_BTYPE_PREVIEW_TILE,
0,
ED_asset_handle_get_preview_icon_id(asset_handle),
show_names ? ED_asset_handle_get_name(asset_handle) : "",
ED_asset_handle_get_preview_icon_id(&asset_handle),
show_names ? ED_asset_handle_get_name(&asset_handle) : "",
0,
0,
size_x,
@ -103,14 +107,43 @@ static void asset_view_draw_item(uiList *ui_list,
0,
"");
ui_def_but_icon(but,
ED_asset_handle_get_preview_icon_id(asset_handle),
ED_asset_handle_get_preview_icon_id(&asset_handle),
/* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */
UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
if (!ui_list->dyn_data->custom_drag_optype) {
asset_view_item_but_drag_set(but, asset_handle);
asset_view_item_but_drag_set(but, &asset_handle);
}
}
static void asset_view_filter_items(uiList *ui_list,
const bContext *C,
PointerRNA *dataptr,
const char *propname)
{
AssetViewListData *list_data = (AssetViewListData *)ui_list->dyn_data->customdata;
AssetFilterSettings &filter_settings = list_data->filter_settings;
uiListNameFilter name_filter(*ui_list);
UI_list_filter_and_sort_items(
ui_list,
C,
[&name_filter, list_data, &filter_settings](
const PointerRNA &itemptr, blender::StringRefNull name, int index) {
AssetHandle asset = ED_assetlist_asset_get_by_index(&list_data->asset_library_ref, index);
if (!ED_asset_filter_matches_asset(&filter_settings, &asset)) {
return UI_LIST_ITEM_NEVER_SHOW;
}
return name_filter(itemptr, name, index);
},
dataptr,
propname,
[list_data](const PointerRNA & /*itemptr*/, int index) -> std::string {
AssetHandle asset = ED_assetlist_asset_get_by_index(&list_data->asset_library_ref, index);
return ED_asset_handle_get_name(&asset);
});
}
static void asset_view_listener(uiList *ui_list, wmRegionListenerParams *params)
{
AssetViewListData *list_data = (AssetViewListData *)ui_list->dyn_data->customdata;
@ -136,16 +169,15 @@ uiListType *UI_UL_asset_view()
BLI_strncpy(list_type->idname, "UI_UL_asset_view", sizeof(list_type->idname));
list_type->draw_item = asset_view_draw_item;
list_type->filter_items = asset_view_filter_items;
list_type->listener = asset_view_listener;
return list_type;
}
static void asset_view_template_refresh_asset_collection(
const AssetLibraryReference &asset_library_ref,
const AssetFilterSettings &filter_settings,
PointerRNA &assets_dataptr,
const char *assets_propname)
static void populate_asset_collection(const AssetLibraryReference &asset_library_ref,
PointerRNA &assets_dataptr,
const char *assets_propname)
{
PropertyRNA *assets_prop = RNA_struct_find_property(&assets_dataptr, assets_propname);
if (!assets_prop) {
@ -164,17 +196,15 @@ static void asset_view_template_refresh_asset_collection(
RNA_property_collection_clear(&assets_dataptr, assets_prop);
ED_assetlist_iterate(asset_library_ref, [&](AssetHandle asset) {
if (!ED_asset_filter_matches_asset(&filter_settings, &asset)) {
/* Don't do anything else, but return true to continue iterating. */
return true;
}
ED_assetlist_iterate(asset_library_ref, [&](AssetHandle /*asset*/) {
/* XXX creating a dummy #RNA_AssetHandle collection item. It's #file_data will be null. This is
* because the #FileDirEntry may be freed while iterating, there's a cache for them with a
* maximum size. Further code will query as needed it using the collection index. */
PointerRNA itemptr, fileptr;
RNA_property_collection_add(&assets_dataptr, assets_prop, &itemptr);
RNA_pointer_create(
nullptr, &RNA_FileSelectEntry, const_cast<FileDirEntry *>(asset.file_data), &fileptr);
RNA_pointer_create(nullptr, &RNA_FileSelectEntry, nullptr, &fileptr);
RNA_pointer_set(&itemptr, "file_data", fileptr);
return true;
@ -221,12 +251,12 @@ void uiTemplateAssetView(uiLayout *layout,
ED_assetlist_ensure_previews_job(&asset_library_ref, C);
const int tot_items = ED_assetlist_size(&asset_library_ref);
asset_view_template_refresh_asset_collection(
asset_library_ref, *filter_settings, *assets_dataptr, assets_propname);
populate_asset_collection(asset_library_ref, *assets_dataptr, assets_propname);
AssetViewListData *list_data = (AssetViewListData *)MEM_mallocN(sizeof(*list_data),
"AssetViewListData");
list_data->asset_library_ref = asset_library_ref;
list_data->filter_settings = *filter_settings;
list_data->screen = CTX_wm_screen(C);
list_data->show_names = (display_flags & UI_TEMPLATE_ASSET_DRAW_NO_NAMES) == 0;

View File

@ -8,9 +8,11 @@
#include <cstring>
#include "BLI_fnmatch.h"
#include "BLI_function_ref.hh"
#include "BLI_listbase.h"
#include "BLI_math_base.h"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "BLI_utildefines.h"
#include "BKE_screen.h"
@ -26,12 +28,15 @@
#include "RNA_prototypes.h"
#include "UI_interface.h"
#include "UI_interface.hh"
#include "UI_view2d.h"
#include "WM_api.h"
#include "interface_intern.hh"
using namespace blender;
/**
* The validated data that was passed to #uiTemplateList (typically through Python).
* Populated through #ui_template_list_data_retrieve().
@ -148,6 +153,45 @@ static void uilist_draw_filter_default(struct uiList *ui_list,
}
}
uiListNameFilter::uiListNameFilter(uiList &list)
{
const char *filter_raw = list.filter_byname;
if (filter_raw[0]) {
const size_t slen = strlen(filter_raw);
/* Implicitly add heading/trailing wildcards if needed. */
if (slen + 3 <= sizeof(storage_.filter_buff)) {
filter_ = storage_.filter_buff;
}
else {
filter_ = storage_.filter_dyn = static_cast<char *>(
MEM_mallocN((slen + 3) * sizeof(char), "filter_dyn"));
}
BLI_strncpy_ensure_pad(filter_, filter_raw, '*', slen + 3);
}
}
uiListNameFilter::~uiListNameFilter()
{
MEM_SAFE_FREE(storage_.filter_dyn);
}
eUIListFilterResult uiListNameFilter::operator()(const PointerRNA & /* itemptr */,
StringRefNull name,
int /* index */)
{
if (!filter_) {
return UI_LIST_ITEM_FILTER_MATCHES;
}
/* Case-insensitive! */
if (fnmatch(filter_, name.c_str(), FNM_CASEFOLD) == 0) {
return UI_LIST_ITEM_FILTER_MATCHES;
}
return UI_LIST_ITEM_FILTER_MISMATCHES;
}
struct StringCmp {
char name[MAX_IDPROP_NAME];
int org_idx;
@ -159,16 +203,16 @@ static int cmpstringp(const void *p1, const void *p2)
return BLI_strcasecmp(((StringCmp *)p1)->name, ((StringCmp *)p2)->name);
}
static void uilist_filter_items_default(struct uiList *ui_list,
const struct bContext * /*C*/,
struct PointerRNA *dataptr,
const char *propname)
void UI_list_filter_and_sort_items(uiList *ui_list,
const bContext * /*C*/,
uiListItemFilterFn item_filter_fn,
PointerRNA *dataptr,
const char *propname,
uiListItemGetNameFn get_name_fn)
{
uiListDyn *dyn_data = ui_list->dyn_data;
PropertyRNA *prop = RNA_struct_find_property(dataptr, propname);
const char *filter_raw = ui_list->filter_byname;
char *filter = (char *)filter_raw, filter_buff[32], *filter_dyn = nullptr;
const bool filter_exclude = (ui_list->filter_flag & UILST_FLT_EXCLUDE) != 0;
const bool order_by_name = (ui_list->filter_sort_flag & UILST_FLT_SORT_MASK) ==
UILST_FLT_SORT_ALPHA;
@ -176,41 +220,26 @@ static void uilist_filter_items_default(struct uiList *ui_list,
dyn_data->items_shown = dyn_data->items_len = len;
if (len && (order_by_name || filter_raw[0])) {
if (len && (order_by_name || item_filter_fn)) {
StringCmp *names = nullptr;
int order_idx = 0, i = 0;
if (order_by_name) {
names = static_cast<StringCmp *>(MEM_callocN(sizeof(StringCmp) * len, "StringCmp"));
}
if (filter_raw[0]) {
const size_t slen = strlen(filter_raw);
if (item_filter_fn) {
dyn_data->items_filter_flags = static_cast<int *>(
MEM_callocN(sizeof(int) * len, "items_filter_flags"));
dyn_data->items_shown = 0;
/* Implicitly add heading/trailing wildcards if needed. */
if (slen + 3 <= sizeof(filter_buff)) {
filter = filter_buff;
}
else {
filter = filter_dyn = static_cast<char *>(
MEM_mallocN((slen + 3) * sizeof(char), "filter_dyn"));
}
BLI_strncpy_ensure_pad(filter, filter_raw, '*', slen + 3);
}
RNA_PROP_BEGIN (dataptr, itemptr, prop) {
bool do_order = false;
char *namebuf;
if (RNA_struct_is_a(itemptr.type, &RNA_AssetHandle)) {
/* XXX The AssetHandle design is hacky and meant to be temporary. It can't have a proper
* name property, so for now this hardcoded exception is needed. */
AssetHandle *asset_handle = (AssetHandle *)itemptr.data;
const char *asset_name = ED_asset_handle_get_name(asset_handle);
namebuf = BLI_strdup(asset_name);
if (get_name_fn) {
namebuf = BLI_strdup(get_name_fn(itemptr, i).c_str());
}
else {
namebuf = RNA_struct_name_get_alloc(&itemptr, nullptr, 0, nullptr);
@ -218,9 +247,13 @@ static void uilist_filter_items_default(struct uiList *ui_list,
const char *name = namebuf ? namebuf : "";
if (filter[0]) {
/* Case-insensitive! */
if (fnmatch(filter, name, FNM_CASEFOLD) == 0) {
if (item_filter_fn) {
const eUIListFilterResult filter_result = item_filter_fn(itemptr, name, i);
if (filter_result == UI_LIST_ITEM_NEVER_SHOW) {
/* Pass. */
}
else if (filter_result == UI_LIST_ITEM_FILTER_MATCHES) {
dyn_data->items_filter_flags[i] = UILST_FLT_ITEM;
if (!filter_exclude) {
dyn_data->items_shown++;
@ -266,15 +299,30 @@ static void uilist_filter_items_default(struct uiList *ui_list,
}
}
if (filter_dyn) {
MEM_freeN(filter_dyn);
}
if (names) {
MEM_freeN(names);
}
}
}
/**
* Default UI List filtering: Filter by name.
*/
static void uilist_filter_items_default(struct uiList *ui_list,
const struct bContext *C,
struct PointerRNA *dataptr,
const char *propname)
{
if (ui_list->filter_byname[0]) {
uiListNameFilter name_filter(*ui_list);
UI_list_filter_and_sort_items(ui_list, C, name_filter, dataptr, propname);
}
/* Optimization: Skip filtering entirely when there is no filter string set. */
else {
UI_list_filter_and_sort_items(ui_list, C, nullptr, dataptr, propname);
}
}
static void uilist_free_dyn_data(uiList *ui_list)
{
uiListDyn *dyn_data = ui_list->dyn_data;

View File

@ -39,6 +39,7 @@
#include "BLT_translation.h"
#include "BKE_action.h"
#include "BKE_blendfile.h"
#include "BKE_colorband.h"
#include "BKE_colortools.h"
#include "BKE_constraint.h"
@ -79,8 +80,6 @@
#include "WM_api.h"
#include "WM_types.h"
#include "BLO_readfile.h"
#include "UI_interface.h"
#include "UI_interface_icons.h"
#include "UI_view2d.h"
@ -5688,7 +5687,7 @@ void uiTemplateColorPicker(uiLayout *layout,
"",
WHEEL_SIZE + 6,
0,
14 * UI_DPI_FAC,
14 * UI_SCALE_FAC,
WHEEL_SIZE,
ptr,
prop,
@ -5709,7 +5708,7 @@ void uiTemplateColorPicker(uiLayout *layout,
0,
4,
WHEEL_SIZE,
18 * UI_DPI_FAC,
18 * UI_SCALE_FAC,
ptr,
prop,
-1,
@ -5729,7 +5728,7 @@ void uiTemplateColorPicker(uiLayout *layout,
0,
4,
WHEEL_SIZE,
18 * UI_DPI_FAC,
18 * UI_SCALE_FAC,
ptr,
prop,
-1,
@ -5749,7 +5748,7 @@ void uiTemplateColorPicker(uiLayout *layout,
0,
4,
WHEEL_SIZE,
18 * UI_DPI_FAC,
18 * UI_SCALE_FAC,
ptr,
prop,
-1,
@ -5771,7 +5770,7 @@ void uiTemplateColorPicker(uiLayout *layout,
"",
WHEEL_SIZE + 6,
0,
14 * UI_DPI_FAC,
14 * UI_SCALE_FAC,
WHEEL_SIZE,
ptr,
prop,
@ -6359,7 +6358,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
UI_fontstyle_set(&style->widgetlabel);
int width = BLF_width(style->widgetlabel.uifont_id, report->message, report->len);
width = min_ii(int(rti->widthfac * width), width);
width = max_ii(width, 10 * UI_DPI_FAC);
width = max_ii(width, 10 * UI_SCALE_FAC);
UI_block_align_begin(block);
@ -6370,7 +6369,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
"",
0,
0,
UI_UNIT_X + (6 * UI_DPI_FAC),
UI_UNIT_X + (6 * UI_SCALE_FAC),
UI_UNIT_Y,
nullptr,
0.0f,
@ -6386,7 +6385,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
UI_BTYPE_ROUNDBOX,
0,
"",
UI_UNIT_X + (6 * UI_DPI_FAC),
UI_UNIT_X + (6 * UI_SCALE_FAC),
0,
UI_UNIT_X + width,
UI_UNIT_Y,
@ -6410,7 +6409,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
"SCREEN_OT_info_log_show",
WM_OP_INVOKE_REGION_WIN,
UI_icon_from_report_type(report->type),
(3 * UI_DPI_FAC),
(3 * UI_SCALE_FAC),
0,
UI_UNIT_X,
UI_UNIT_Y,
@ -6997,7 +6996,7 @@ int uiTemplateRecentFiles(uiLayout *layout, int rows)
uiItemFullO(layout,
"WM_OT_open_mainfile",
filename,
BLO_has_bfile_extension(filename) ? ICON_FILE_BLEND : ICON_FILE_BACKUP,
BKE_blendfile_extension_check(filename) ? ICON_FILE_BLEND : ICON_FILE_BACKUP,
nullptr,
WM_OP_INVOKE_DEFAULT,
0,

View File

@ -1354,7 +1354,7 @@ static void widget_draw_icon(
return;
}
const float aspect = but->block->aspect * U.inv_dpi_fac;
const float aspect = but->block->aspect * UI_INV_SCALE_FAC;
const float height = ICON_DEFAULT_HEIGHT / aspect;
/* calculate blend color */
@ -1447,7 +1447,7 @@ static void widget_draw_submenu_tria(const uiBut *but,
const rcti *rect,
const uiWidgetColors *wcol)
{
const float aspect = but->block->aspect * U.inv_dpi_fac;
const float aspect = but->block->aspect * UI_INV_SCALE_FAC;
const int tria_height = int(ICON_DEFAULT_HEIGHT / aspect);
const int tria_width = int(ICON_DEFAULT_WIDTH / aspect) - 2 * U.pixelsize;
const int xs = rect->xmax - tria_width;
@ -1641,7 +1641,7 @@ static void ui_text_clip_middle(const uiFontStyle *fstyle, uiBut *but, const rct
int(UI_TEXT_CLIP_MARGIN + 0.5f);
const float okwidth = float(max_ii(BLI_rcti_size_x(rect) - border, 0));
const size_t max_len = sizeof(but->drawstr);
const float minwidth = float(UI_DPI_ICON_SIZE) / but->block->aspect * 2.0f;
const float minwidth = float(UI_ICON_SIZE) / but->block->aspect * 2.0f;
but->ofs = 0;
but->strwidth = UI_text_clip_middle_ex(fstyle, but->drawstr, okwidth, minwidth, max_len, '\0');
@ -1664,7 +1664,7 @@ static void ui_text_clip_middle_protect_right(const uiFontStyle *fstyle,
int(UI_TEXT_CLIP_MARGIN + 0.5f);
const float okwidth = float(max_ii(BLI_rcti_size_x(rect) - border, 0));
const size_t max_len = sizeof(but->drawstr);
const float minwidth = float(UI_DPI_ICON_SIZE) / but->block->aspect * 2.0f;
const float minwidth = float(UI_ICON_SIZE) / but->block->aspect * 2.0f;
but->ofs = 0;
but->strwidth = UI_text_clip_middle_ex(fstyle, but->drawstr, okwidth, minwidth, max_len, rsep);
@ -2297,8 +2297,8 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle,
const BIFIconID icon = BIFIconID(ui_but_icon(but));
const int icon_size_init = is_tool ? ICON_DEFAULT_HEIGHT_TOOLBAR : ICON_DEFAULT_HEIGHT;
const float icon_size = icon_size_init / (but->block->aspect * U.inv_dpi_fac);
const float icon_padding = 2 * UI_DPI_FAC;
const float icon_size = icon_size_init / (but->block->aspect * UI_INV_SCALE_FAC);
const float icon_padding = 2 * UI_SCALE_FAC;
#ifdef USE_UI_TOOLBAR_HACK
if (is_tool) {
@ -4994,11 +4994,11 @@ static void ui_draw_clip_tri(uiBlock *block, rcti *rect, uiWidgetType *wt)
if (block->flag & UI_BLOCK_CLIPTOP) {
/* XXX no scaling for UI here yet */
UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymax - 6 * U.dpi_fac, 't', draw_color);
UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymax - 6 * UI_SCALE_FAC, 't', draw_color);
}
if (block->flag & UI_BLOCK_CLIPBOTTOM) {
/* XXX no scaling for UI here yet */
UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymin + 10 * U.dpi_fac, 'v', draw_color);
UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymin + 10 * UI_SCALE_FAC, 'v', draw_color);
}
}
}
@ -5172,8 +5172,8 @@ void ui_draw_pie_center(uiBlock *block)
float *pie_dir = block->pie_data.pie_dir;
const float pie_radius_internal = U.dpi_fac * U.pie_menu_threshold;
const float pie_radius_external = U.dpi_fac * (U.pie_menu_threshold + 7.0f);
const float pie_radius_internal = UI_SCALE_FAC * U.pie_menu_threshold;
const float pie_radius_external = UI_SCALE_FAC * (U.pie_menu_threshold + 7.0f);
const int subd = 40;
@ -5246,8 +5246,8 @@ void ui_draw_pie_center(uiBlock *block)
if (U.pie_menu_confirm > 0 &&
!(block->pie_data.flags & (UI_PIE_INVALID_DIR | UI_PIE_CLICK_STYLE))) {
const float pie_confirm_radius = U.dpi_fac * (pie_radius_internal + U.pie_menu_confirm);
const float pie_confirm_external = U.dpi_fac *
const float pie_confirm_radius = UI_SCALE_FAC * (pie_radius_internal + U.pie_menu_confirm);
const float pie_confirm_external = UI_SCALE_FAC *
(pie_radius_internal + U.pie_menu_confirm + 7.0f);
const uchar col[4] = {UNPACK3(btheme->tui.wcol_pie_menu.text_sel), 64};
@ -5361,7 +5361,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
if (separator_type == UI_MENU_ITEM_SEPARATOR_SHORTCUT) {
/* Shrink rect to exclude the shortcut string. */
rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + UI_DPI_ICON_SIZE;
rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + UI_ICON_SIZE;
}
else if (separator_type == UI_MENU_ITEM_SEPARATOR_HINT) {
/* Determine max-width for the hint string to leave the name string un-clipped (if there's
@ -5390,7 +5390,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
char drawstr[UI_MAX_DRAW_STR];
const float okwidth = float(BLI_rcti_size_x(rect));
const size_t max_len = sizeof(drawstr);
const float minwidth = float(UI_DPI_ICON_SIZE);
const float minwidth = float(UI_ICON_SIZE);
BLI_strncpy(drawstr, name, sizeof(drawstr));
if (drawstr[0]) {
@ -5439,7 +5439,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
char hint_drawstr[UI_MAX_DRAW_STR];
{
const size_t max_len = sizeof(hint_drawstr);
const float minwidth = float(UI_DPI_ICON_SIZE);
const float minwidth = float(UI_ICON_SIZE);
BLI_strncpy(hint_drawstr, cpoin + 1, sizeof(hint_drawstr));
if (hint_drawstr[0] && (max_hint_width < INT_MAX)) {
@ -5494,7 +5494,7 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
char drawstr[UI_MAX_DRAW_STR];
const float okwidth = float(BLI_rcti_size_x(&trect));
const size_t max_len = sizeof(drawstr);
const float minwidth = float(UI_DPI_ICON_SIZE);
const float minwidth = float(UI_ICON_SIZE);
BLI_strncpy(drawstr, name, sizeof(drawstr));
UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0');

View File

@ -1468,7 +1468,7 @@ void UI_ThemeClearColor(int colorid)
int UI_ThemeMenuShadowWidth()
{
bTheme *btheme = UI_GetTheme();
return int(btheme->tui.menu_shadow_width * UI_DPI_FAC);
return int(btheme->tui.menu_shadow_width * UI_SCALE_FAC);
}
void UI_make_axis_color(const uchar src_col[3], uchar dst_col[3], const char axis)

View File

@ -1288,7 +1288,7 @@ void UI_view2d_dot_grid_draw(const View2D *v2d,
immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR);
/* Scaling the dots fully with the zoom looks too busy, but a bit of size variation is nice. */
const float min_point_size = 2.0f * UI_DPI_FAC;
const float min_point_size = 2.0f * UI_SCALE_FAC;
const float point_size_factor = 1.5f;
const float max_point_size = point_size_factor * min_point_size;

View File

@ -38,7 +38,7 @@
/* Compute display grid resolution
********************************************************/
#define MIN_MAJOR_LINE_DISTANCE (U.v2d_min_gridsize * UI_DPI_FAC)
#define MIN_MAJOR_LINE_DISTANCE (U.v2d_min_gridsize * UI_SCALE_FAC)
static float select_major_distance(const float *possible_distances,
uint amount,
@ -303,7 +303,7 @@ static void draw_horizontal_scale_indicators(const ARegion *region,
BLF_batch_draw_begin();
const float ypos = rect->ymin + 4 * UI_DPI_FAC;
const float ypos = rect->ymin + 4 * UI_SCALE_FAC;
const float xmin = rect->xmin;
const float xmax = rect->xmax;
@ -383,7 +383,7 @@ static void draw_vertical_scale_indicators(const ARegion *region,
BLF_shadow_offset(font_id, 1, -1);
const float x_offset = 8.0f;
const float xpos = (rect->xmin + x_offset) * UI_DPI_FAC;
const float xpos = (rect->xmin + x_offset) * UI_SCALE_FAC;
const float ymin = rect->ymin;
const float ymax = rect->ymax;
const float y_offset = (BLF_height(font_id, "0", 1) / 2.0f) - U.pixelsize;

View File

@ -174,7 +174,7 @@ static float edge_pan_speed(View2DEdgePanData *vpd,
const float zoom_factor = 1.0f + CLAMPIS(vpd->zoom_influence, 0.0f, 1.0f) * (zoomx - 1.0f);
return distance_factor * delay_factor * zoom_factor * vpd->max_speed * U.widget_unit *
float(U.dpi_fac);
float(UI_SCALE_FAC);
}
static void edge_pan_apply_delta(bContext *C, View2DEdgePanData *vpd, float dx, float dy)

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