Initial Grease Pencil 3.0 stage #106848

Merged
Falk David merged 224 commits from filedescriptor/blender:grease-pencil-v3 into main 2023-05-30 11:14:22 +02:00
216 changed files with 4382 additions and 1774 deletions
Showing only changes of commit fcca4e04fa - 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

@ -56,8 +56,8 @@ class BoundBox {
__forceinline void grow(const BoundBox &bbox)
{
grow(bbox.min);
grow(bbox.max);
min = ccl::min(bbox.min, min);
max = ccl::max(bbox.max, max);
}
__forceinline void grow_safe(const float3 &pt)
@ -81,8 +81,12 @@ class BoundBox {
__forceinline void grow_safe(const BoundBox &bbox)
{
grow_safe(bbox.min);
grow_safe(bbox.max);
if (isfinite_safe(bbox.min)) {
min = ccl::min(bbox.min, min);
}
if (isfinite_safe(bbox.max)) {
max = ccl::max(bbox.max, max);
}
}
__forceinline void intersect(const BoundBox &bbox)

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

@ -2350,6 +2350,7 @@ class USERPREF_PT_experimental_prototypes(ExperimentalPanel, Panel):
({"property": "use_full_frame_compositor"}, ("blender/blender/issues/88150", "#88150")),
({"property": "enable_eevee_next"}, ("blender/blender/issues/93220", "#93220")),
({"property": "enable_workbench_next"}, ("blender/blender/issues/101619", "#101619")),
({"property": "enable_gpencil_next"}, ("blender/blender/issues/102506", "#102506")),
),
)

View File

@ -32,7 +32,7 @@ std::string AssetIdentifier::full_library_path() const
std::string asset_path = full_path();
char blend_path[1090 /*FILE_MAX_LIBEXTRA*/];
if (!BKE_library_path_explode(asset_path.c_str(), blend_path, nullptr, nullptr)) {
if (!BKE_blendfile_library_path_explode(asset_path.c_str(), blend_path, nullptr, nullptr)) {
return {};
}

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

@ -26,7 +26,7 @@ struct bContext;
* \param str: The path to check.
* \return true is this path ends with a blender file extension.
*/
bool BKE_has_bfile_extension(const char *str);
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).
@ -40,7 +40,10 @@ bool BKE_has_bfile_extension(const char *str);
* NULL.
* \return true if path contains a blend file.
*/
bool BKE_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name);
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,

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

@ -67,13 +67,16 @@
/** \name Blend/Library Paths
* \{ */
bool BKE_has_bfile_extension(const char *str)
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_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name)
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,
@ -98,7 +101,7 @@ bool BKE_library_path_explode(const char *path, char *r_dir, char **r_group, cha
while ((slash = (char *)BLI_path_slash_rfind(r_dir))) {
char tc = *slash;
*slash = '\0';
if (BKE_has_bfile_extension(r_dir) && BLI_is_file(r_dir)) {
if (BKE_blendfile_extension_check(r_dir) && BLI_is_file(r_dir)) {
break;
}
if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) {

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

@ -118,6 +118,7 @@ class Vector {
return std::is_nothrow_move_constructible_v<T>;
}
}
public:
/**
* Create an empty vector.

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

@ -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

@ -186,9 +186,11 @@ set(SRC
engines/gpencil/gpencil_cache_utils.c
engines/gpencil/gpencil_draw_data.c
engines/gpencil/gpencil_engine.c
engines/gpencil/gpencil_engine.cc
engines/gpencil/gpencil_engine.h
engines/gpencil/gpencil_render.c
engines/gpencil/gpencil_shader.c
engines/gpencil/gpencil_shader.cc
engines/gpencil/gpencil_shader_fx.c
engines/select/select_draw_utils.c
engines/select/select_engine.c

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

@ -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

@ -0,0 +1,154 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. */
filedescriptor marked this conversation as resolved Outdated

2023

2023
/** \file
* \ingroup draw
*/
#pragma once
#include "BKE_gpencil_legacy.h"
#include "BKE_image.h"
#include "DRW_gpu_wrapper.hh"
#include "DRW_render.h"
#include "draw_manager.hh"
#include "draw_pass.hh"
#include "gpencil_shader.hh"
#include "smaa_textures.h"
namespace blender::gpencil {

It looks like this should be in the blender::draw:: namespace first, given the file path. Since greasepencil isn't a top-level module, a blender::greasepencil namespace probably doesn't make sense in general.

Same with elsewhere in this diff.

It looks like this should be in the `blender::draw::` namespace first, given the file path. Since `greasepencil` isn't a top-level module, a `blender::greasepencil` namespace probably doesn't make sense in general. Same with elsewhere in this diff.
using namespace draw;
/** Final anti-aliasing post processing and compositing on top of render. */
class AntiAliasing {
private:
ShaderModule &shaders_;
Texture smaa_search_tx_ = {"smaa_search",
GPU_R8,
GPU_TEXTURE_USAGE_SHADER_READ,
int2(SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT)};
Texture smaa_area_tx_ = {
"smaa_area", GPU_RG8, GPU_TEXTURE_USAGE_SHADER_READ, int2(AREATEX_WIDTH, AREATEX_HEIGHT)};
TextureFromPool edge_detect_tx_ = {"edge_detect_tx"};
Framebuffer edge_detect_fb_ = {"edge_detect_fb"};
PassSimple edge_detect_ps_ = {"edge_detect_ps"};
TextureFromPool blend_weight_tx_ = {"blend_weight_tx"};
Framebuffer blend_weight_fb_ = {"blend_weight_fb"};
PassSimple blend_weight_ps_ = {"blend_weight_ps"};
Framebuffer output_fb_ = {"output_fb"};
PassSimple resolve_ps_ = {"resolve_ps"};
bool draw_wireframe_ = false;
float luma_weight_ = 1.0f;
bool anti_aliasing_enabled_ = true;
public:
AntiAliasing(ShaderModule &shaders) : shaders_(shaders)
{
GPU_texture_update(smaa_search_tx_, GPU_DATA_UBYTE, searchTexBytes);
GPU_texture_update(smaa_area_tx_, GPU_DATA_UBYTE, areaTexBytes);
GPU_texture_filter_mode(smaa_search_tx_, true);
GPU_texture_filter_mode(smaa_area_tx_, true);
}
void init(const View3D *v3d, const Scene *scene)
{
if (v3d) {
draw_wireframe_ = (v3d->shading.type == OB_WIRE);
}
luma_weight_ = scene->grease_pencil_settings.smaa_threshold;
anti_aliasing_enabled_ = GPENCIL_SIMPLIFY_AA(scene);
}
void begin_sync(TextureFromPool &color_tx, TextureFromPool &reveal_tx)
{
/* TODO(fclem): No global access. */
const float *size = DRW_viewport_size_get();
const float *sizeinv = DRW_viewport_invert_size_get();
const float4 metrics = {sizeinv[0], sizeinv[1], size[0], size[1]};
if (anti_aliasing_enabled_) {

I would totally split the code into smaller functions. I do not see what are we winning from such inlined code.

I would totally split the code into smaller functions. I do not see what are we winning from such inlined code.
/* Stage 1: Edge detection. */
PassSimple &pass = edge_detect_ps_;
pass.init();
pass.framebuffer_set(&edge_detect_fb_);
pass.state_set(DRW_STATE_WRITE_COLOR);
pass.shader_set(shaders_.static_shader_get(ANTIALIASING_EDGE_DETECT));
pass.bind_texture("colorTex", &color_tx);
pass.bind_texture("revealTex", &reveal_tx);
pass.push_constant("viewportMetrics", metrics);
pass.push_constant("lumaWeight", luma_weight_);
pass.clear_color(float4(0.0f));
pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
}
if (anti_aliasing_enabled_) {
/* Stage 2: Blend Weight/Coord. */
PassSimple &pass = blend_weight_ps_;
pass.init();
pass.framebuffer_set(&blend_weight_fb_);
pass.state_set(DRW_STATE_WRITE_COLOR);
pass.shader_set(shaders_.static_shader_get(ANTIALIASING_BLEND_WEIGHT));
pass.bind_texture("edgesTex", &edge_detect_tx_);
pass.bind_texture("areaTex", smaa_area_tx_);
pass.bind_texture("searchTex", smaa_search_tx_);
pass.push_constant("viewportMetrics", metrics);
pass.clear_color(float4(0.0f));
pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
}
{
/* Stage 3: Resolve. */
PassSimple &pass = resolve_ps_;
pass.init();
pass.framebuffer_set(&output_fb_);
pass.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM);
pass.shader_set(shaders_.static_shader_get(ANTIALIASING_RESOLVE));
/** \note use color_tx as dummy if AA is diabled. */
pass.bind_texture("blendTex", anti_aliasing_enabled_ ? &blend_weight_tx_ : &color_tx);
pass.bind_texture("colorTex", &color_tx);
pass.bind_texture("revealTex", &reveal_tx);
pass.push_constant("doAntiAliasing", anti_aliasing_enabled_);
pass.push_constant("onlyAlpha", draw_wireframe_);
pass.push_constant("viewportMetrics", metrics);
pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
}
}
void draw(Manager &manager, GPUTexture *dst_color_tx)
{
int2 render_size = {GPU_texture_width(dst_color_tx), GPU_texture_height(dst_color_tx)};
DRW_stats_group_start("Anti-Aliasing");
if (anti_aliasing_enabled_) {
edge_detect_tx_.acquire(render_size, GPU_RG8);
edge_detect_fb_.ensure(GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(edge_detect_tx_));
manager.submit(edge_detect_ps_);
}
if (anti_aliasing_enabled_) {

Why this extra check is needed?

Why this extra check is needed?
blend_weight_tx_.acquire(render_size, GPU_RGBA8);
blend_weight_fb_.ensure(GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(blend_weight_tx_));
manager.submit(blend_weight_ps_);
edge_detect_tx_.release();
}
output_fb_.ensure(GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(dst_color_tx));
manager.submit(resolve_ps_);
blend_weight_tx_.release();
DRW_stats_group_end();
}
};
} // namespace blender::gpencil

View File

@ -6,3 +6,16 @@
/* High bits are used to pass material ID to fragment shader. */
#define GPENCIl_MATID_SHIFT 16u
/* Textures */
#define GPENCIL_SCENE_DEPTH_TEX_SLOT 2
#define GPENCIL_MASK_TEX_SLOT 3
#define GPENCIL_FILL_TEX_SLOT 4
#define GPENCIL_STROKE_TEX_SLOT 5
/* SSBOs */
#define GPENCIL_OBJECT_SLOT 0
#define GPENCIL_LAYER_SLOT 1
#define GPENCIL_MATERIAL_SLOT 2
#define GPENCIL_LIGHT_SLOT 3
/* UBOs */
#define GPENCIL_SCENE_SLOT 2

View File

@ -396,7 +396,7 @@ static void gpencil_sbuffer_cache_populate(gpIterPopulateData *iter)
* Remember, sbuffer stroke indices start from 0. So we add last index to avoid
* masking issues. */
iter->grp = DRW_shgroup_create_sub(iter->grp);
DRW_shgroup_uniform_block(iter->grp, "materials", iter->ubo_mat);
DRW_shgroup_uniform_block(iter->grp, "gp_materials", iter->ubo_mat);
DRW_shgroup_uniform_float_copy(iter->grp, "gpStrokeIndexOffset", iter->stroke_index_last);
const DRWContextState *ctx = DRW_context_state_get();
@ -444,8 +444,8 @@ static void gpencil_layer_cache_populate(bGPDlayer *gpl,
/* Iterator dependent uniforms. */
DRWShadingGroup *grp = iter->grp = tgp_layer->base_shgrp;
DRW_shgroup_uniform_block(grp, "lights", iter->ubo_lights);
DRW_shgroup_uniform_block(grp, "materials", iter->ubo_mat);
DRW_shgroup_uniform_block(grp, "gp_lights", iter->ubo_lights);
DRW_shgroup_uniform_block(grp, "gp_materials", iter->ubo_mat);
DRW_shgroup_uniform_texture(grp, "gpFillTexture", iter->tex_fill);
DRW_shgroup_uniform_texture(grp, "gpStrokeTexture", iter->tex_stroke);
DRW_shgroup_uniform_int_copy(grp, "gpMaterialOffset", iter->mat_ofs);
@ -492,7 +492,7 @@ static void gpencil_stroke_cache_populate(bGPDlayer *gpl,
iter->grp = DRW_shgroup_create_sub(iter->grp);
if (iter->ubo_mat != ubo_mat) {
DRW_shgroup_uniform_block(iter->grp, "materials", ubo_mat);
DRW_shgroup_uniform_block(iter->grp, "gp_materials", ubo_mat);
iter->ubo_mat = ubo_mat;
}
if (tex_fill) {

View File

@ -0,0 +1,323 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. */
filedescriptor marked this conversation as resolved Outdated

2023

2023
/** \file
* \ingroup draw
*/
#include "BKE_gpencil_legacy.h"
#include "BKE_gpencil_modifier_legacy.h"
#include "BLI_listbase_wrapper.hh"
#include "DEG_depsgraph_query.h"
#include "DNA_shader_fx_types.h"
#include "DRW_engine.h"
#include "DRW_render.h"
#include "ED_screen.h"
#include "ED_view3d.h"
#include "GPU_capabilities.h"
#include "IMB_imbuf_types.h"
#include "draw_manager.hh"
#include "draw_pass.hh"
Review

What is this about?

What is this about?
#define GP_LIGHT
#include "gpencil_antialiasing.hh"
#include "gpencil_defines.h"
#include "gpencil_engine.h"
#include "gpencil_layer.hh"
#include "gpencil_light.hh"
#include "gpencil_material.hh"
#include "gpencil_object.hh"
#include "gpencil_shader.hh"
#include "gpencil_shader_shared.h"
#include "gpencil_vfx.hh"
namespace blender::gpencil {
using namespace draw;
class Instance {
private:
ShaderModule &shaders;
LayerModule layers;
MaterialModule materials;
ObjectModule objects;
LightModule lights;
VfxModule vfx;
AntiAliasing anti_aliasing;
/** Contains all gpencil objects in the scene as well as their effect sub-passes. */
PassSortable main_ps_ = {"gp_main_ps"};
/** Contains all composited GPencil object. */
TextureFromPool depth_tx_ = {"gp_depth_tx"};
TextureFromPool color_tx_ = {"gp_color_tx"};
TextureFromPool reveal_tx_ = {"gp_reveal_tx"};
Framebuffer main_fb_ = {"gp_main_fb"};
/** Texture format for all intermediate buffers. */
eGPUTextureFormat texture_format_ = GPU_RGBA16F;
UniformBuffer<gpScene> scene_buf_;
/** Dummy textures. */
static constexpr float dummy_px_[4] = {1.0f, 0.0f, 1.0f, 1.0f};
Texture dummy_depth_tx_ = {"dummy_depth",
GPU_DEPTH_COMPONENT32F,
GPU_TEXTURE_USAGE_SHADER_READ,
int2(1),
(float *)dummy_px_};
Texture dummy_color_tx_ = {
"dummy_color", GPU_RGBA16F, GPU_TEXTURE_USAGE_SHADER_READ, int2(1), (float *)dummy_px_};
/** Scene depth used for manual depth testing. Default to dummy depth to skip depth test. */
GPUTexture *scene_depth_tx_ = dummy_depth_tx_;
/** Context. */
Depsgraph *depsgraph_ = nullptr;
Object *camera_ = nullptr;
/** \note Needs not to be temporary variable since it is dereferenced later. */
std::array<float4, 2> clear_colors_ = {float4(0.0f, 0.0f, 0.0f, 0.0f),
float4(1.0f, 1.0f, 1.0f, 1.0f)};
public:
Instance()
: shaders(*ShaderModule::module_get()),
objects(layers, materials, shaders),
vfx(shaders),
anti_aliasing(shaders){};
void init(Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d)
{
depsgraph_ = depsgraph;
const Scene *scene = DEG_get_evaluated_scene(depsgraph_);
const bool is_viewport = (v3d != nullptr);
if (is_viewport) {
/* Use lower precision for viewport. */
texture_format_ = GPU_R11F_G11F_B10F;
camera_ = (rv3d->persp == RV3D_CAMOB) ? v3d->camera : nullptr;
}
objects.init(v3d, scene);
lights.init(v3d);
/* TODO(fclem): Vfx. */
// vfx.init(use_vfx_, camera_, rv3d);
anti_aliasing.init(v3d, scene);
}
void begin_sync(Manager & /* manager */)
{
/* TODO(fclem): Remove global draw manager access. */
View main_view("GPencil_MainView", DRW_view_default_get());
objects.begin_sync(depsgraph_, main_view);
layers.begin_sync();
materials.begin_sync();
lights.begin_sync(depsgraph_);
main_ps_.init();
PassMain::Sub &sub = main_ps_.sub("InitSubpass", -FLT_MAX);
sub.framebuffer_set(&main_fb_);
sub.clear_multi(clear_colors_);
/* TODO(fclem): Textures. */
sub.bind_texture(GPENCIL_SCENE_DEPTH_TEX_SLOT, &dummy_depth_tx_);
sub.bind_texture(GPENCIL_MASK_TEX_SLOT, &dummy_color_tx_);
sub.bind_texture(GPENCIL_FILL_TEX_SLOT, &dummy_color_tx_);
sub.bind_texture(GPENCIL_STROKE_TEX_SLOT, &dummy_color_tx_);
sub.bind_ubo(GPENCIL_SCENE_SLOT, &scene_buf_);
objects.bind_resources(sub);
layers.bind_resources(sub);
materials.bind_resources(sub);
lights.bind_resources(sub);
anti_aliasing.begin_sync(color_tx_, reveal_tx_);
}
void object_sync(Manager &manager, ObjectRef &object_ref)
{
switch (object_ref.object->type) {
case OB_GPENCIL_LEGACY:
objects.sync_gpencil(manager, object_ref, main_fb_, main_ps_);
break;
case OB_LAMP:
lights.sync(object_ref);
break;
default:
break;
}
}
void end_sync(Manager & /* manager */)
{
objects.end_sync();
layers.end_sync();
materials.end_sync();
lights.end_sync();
}
void draw_viewport(Manager &manager,
View &view,
GPUTexture *dst_depth_tx,
GPUTexture *dst_color_tx)
{
if (!objects.scene_has_visible_gpencil_object()) {
return;
}
int2 render_size = {GPU_texture_width(dst_depth_tx), GPU_texture_height(dst_depth_tx)};
depth_tx_.acquire(render_size, GPU_DEPTH24_STENCIL8);
color_tx_.acquire(render_size, texture_format_);
reveal_tx_.acquire(render_size, texture_format_);
main_fb_.ensure(GPU_ATTACHMENT_TEXTURE(depth_tx_),
GPU_ATTACHMENT_TEXTURE(color_tx_),
GPU_ATTACHMENT_TEXTURE(reveal_tx_));
scene_buf_.render_size = float2(render_size);
scene_buf_.push_update();
objects.acquire_temporary_buffers(render_size, texture_format_);
manager.submit(main_ps_, view);
objects.release_temporary_buffers();
anti_aliasing.draw(manager, dst_color_tx);
depth_tx_.release();
color_tx_.release();
reveal_tx_.release();
}
};
} // namespace blender::gpencil
/* -------------------------------------------------------------------- */
/** \name Interface with legacy C DRW manager
* \{ */
using namespace blender;
Review

This struct name is interesting... I guess it's temporary though :P

This struct name is interesting... I guess it's temporary though :P
Review

Yes it is :)

Yes it is :)
struct GPENCIL_NEXT_Data {
DrawEngineType *engine_type;
DRWViewportEmptyList *fbl;
DRWViewportEmptyList *txl;
DRWViewportEmptyList *psl;
DRWViewportEmptyList *stl;
gpencil::Instance *instance;
char info[GPU_INFO_SIZE];
};
static void gpencil_engine_init(void *vedata)
{
/* TODO(fclem): Remove once it is minimum required. */
if (!GPU_shader_storage_buffer_objects_support()) {
return;
}
GPENCIL_NEXT_Data *ved = reinterpret_cast<GPENCIL_NEXT_Data *>(vedata);
if (ved->instance == nullptr) {
ved->instance = new gpencil::Instance();
}
const DRWContextState *ctx_state = DRW_context_state_get();
ved->instance->init(ctx_state->depsgraph, ctx_state->v3d, ctx_state->rv3d);
}
static void gpencil_draw_scene(void *vedata)
{
GPENCIL_NEXT_Data *ved = reinterpret_cast<GPENCIL_NEXT_Data *>(vedata);
if (!GPU_shader_storage_buffer_objects_support()) {
STRNCPY(ved->info, "Error: No shader storage buffer support");
return;
}
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
const DRWView *default_view = DRW_view_default_get();
draw::Manager *manager = DRW_manager_get();
draw::View view("DefaultView", default_view);
ved->instance->draw_viewport(*manager, view, dtxl->depth, dtxl->color);
}
static void gpencil_cache_init(void *vedata)
{
if (!GPU_shader_storage_buffer_objects_support()) {
return;
}
draw::Manager *manager = DRW_manager_get();
reinterpret_cast<GPENCIL_NEXT_Data *>(vedata)->instance->begin_sync(*manager);
}
static void gpencil_cache_populate(void *vedata, Object *object)
{
if (!GPU_shader_storage_buffer_objects_support()) {
return;
}
draw::Manager *manager = DRW_manager_get();
draw::ObjectRef ref;
ref.object = object;
ref.dupli_object = DRW_object_get_dupli(object);
ref.dupli_parent = DRW_object_get_dupli_parent(object);
reinterpret_cast<GPENCIL_NEXT_Data *>(vedata)->instance->object_sync(*manager, ref);
}
static void gpencil_cache_finish(void *vedata)
{
if (!GPU_shader_storage_buffer_objects_support()) {
return;
}
draw::Manager *manager = DRW_manager_get();
reinterpret_cast<GPENCIL_NEXT_Data *>(vedata)->instance->end_sync(*manager);
}
static void gpencil_instance_free(void *instance)
{
if (!GPU_shader_storage_buffer_objects_support()) {
return;
}
delete reinterpret_cast<gpencil::Instance *>(instance);
}
static void gpencil_engine_free()
{
blender::gpencil::ShaderModule::module_free();
}
static void gpencil_render_to_image(void *vedata,
struct RenderEngine *engine,
struct RenderLayer *layer,
const struct rcti * /*rect*/)
{
UNUSED_VARS(vedata, engine, layer);
}
Review

Commented argument names instead of this macro here

Commented argument names instead of this macro here
extern "C" {
static const DrawEngineDataSize gpencil_data_size = DRW_VIEWPORT_DATA_SIZE(GPENCIL_NEXT_Data);
DrawEngineType draw_engine_gpencil_next_type = {
nullptr,
nullptr,
N_("Gpencil"),
&gpencil_data_size,
&gpencil_engine_init,
&gpencil_engine_free,
&gpencil_instance_free,
&gpencil_cache_init,
&gpencil_cache_populate,
&gpencil_cache_finish,
&gpencil_draw_scene,
nullptr,
nullptr,
&gpencil_render_to_image,
nullptr,
};
}
/** \} */

View File

@ -25,6 +25,7 @@ extern "C" {
#include "gpencil_shader_shared.h"
extern DrawEngineType draw_engine_gpencil_type;
extern DrawEngineType draw_engine_gpencil_next_type;
struct GPENCIL_Data;
struct GPENCIL_StorageList;
@ -309,7 +310,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

@ -0,0 +1,64 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. */

Check everywhere else :)

2023. Check everywhere else :)
/** \file
* \ingroup draw
*/
#pragma once
#include "BKE_gpencil_legacy.h"
#include "BKE_image.h"
filedescriptor marked this conversation as resolved
Review

I am not sure all of those are needed here.
I.e. I do not see any BKE_image API used in this header. Might be missing something.

I am not sure all of those are needed here. I.e. I do not see any `BKE_image` API used in this header. Might be missing something.
#include "DRW_gpu_wrapper.hh"
#include "DRW_render.h"
#include "draw_manager.hh"
#include "draw_pass.hh"
namespace blender::gpencil {
using namespace draw;
class LayerModule {
private:
/** Contains all Objects in the scene. Indexed by gpObject.layer_offset + layer_id. */
StorageVectorBuffer<gpLayer> layers_buf_ = "gp_layers_buf";
public:
void begin_sync()
{
layers_buf_.clear();
}
void sync(const Object *object, const bGPDlayer *gpl, bool &do_layer_blending)
{
UNUSED_VARS(object, gpl);

In C++ use void sync(const Object * /*object*/, const bke::greasepencil::Layer & /*layer*/, bool &do_layer_blending)

In C++ use `void sync(const Object * /*object*/, const bke::greasepencil::Layer & /*layer*/, bool &do_layer_blending)`
/* TODO(fclem): All of this is placeholder. */
gpLayer layer;
layer.vertex_color_opacity = 0.0f;
layer.opacity = 1.0f;
layer.thickness_offset = 0.0f;
layer.tint = float4(1.0f, 1.0f, 1.0f, 0.0f);
layers_buf_.append(layer);
do_layer_blending = false;
}
void end_sync()
{
layers_buf_.push_update();
}
void bind_resources(PassMain::Sub &sub)
{
sub.bind_ssbo(GPENCIL_LAYER_SLOT, &layers_buf_);
}
uint object_offset_get() const
{
return layers_buf_.size();
}
};
} // namespace blender::gpencil

View File

@ -0,0 +1,130 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. */
/** \file
* \ingroup draw
*/
#pragma once
#include "BKE_gpencil_legacy.h"
#include "BKE_image.h"
#include "DRW_gpu_wrapper.hh"
#include "DRW_render.h"
#include "draw_manager.hh"
#include "draw_pass.hh"
namespace blender::gpencil {
using namespace draw;
class LightModule {
private:
/** Contains all lights in the scene. */
StorageVectorBuffer<gpLight> lights_buf_ = "gp_lights_buf";
float studiolight_intensity_ = 1.0f;
bool use_scene_lights_ = true;
bool use_scene_world_ = true;
public:
void init(const View3D *v3d)
{
if (v3d != nullptr) {
use_scene_lights_ = V3D_USES_SCENE_LIGHTS(v3d);
use_scene_world_ = V3D_USES_SCENE_WORLD(v3d);
studiolight_intensity_ = v3d->shading.studiolight_intensity;
}
}
void begin_sync(Depsgraph *depsgraph)
{
lights_buf_.clear();
World *world = DEG_get_evaluated_scene(depsgraph)->world;
if (world != nullptr && use_scene_world_) {
ambient_sync(float3(world->horr, world->horg, world->horb));
}
else {
ambient_sync(float3(studiolight_intensity_));
}
}
void sync(ObjectRef &object_ref)
{
if (!use_scene_lights_) {
return;
}
const Object *ob = object_ref.object;
const Light *la = static_cast<Light *>(ob->data);
float light_power;
if (la->type == LA_AREA) {
light_power = 1.0f / (4.0f * M_PI);
}
else if (ELEM(la->type, LA_SPOT, LA_LOCAL)) {
light_power = 1.0f / (4.0f * M_PI * M_PI);
}
else {
light_power = 1.0f / M_PI;
}
gpLight light;
float4x4 &mat = *reinterpret_cast<float4x4 *>(&light.right);
switch (la->type) {
case LA_SPOT:
light.type = GP_LIGHT_TYPE_SPOT;
light.spot_size = cosf(la->spotsize * 0.5f);
light.spot_blend = (1.0f - light.spot_size) * la->spotblend;
mat = float4x4(ob->world_to_object);
break;
case LA_AREA:
/* Simulate area lights using a spot light. */
light.type = GP_LIGHT_TYPE_SPOT;
light.spot_size = cosf(M_PI_2);
light.spot_blend = (1.0f - light.spot_size) * 1.0f;
normalize_m4_m4(mat.ptr(), ob->object_to_world);
invert_m4(mat.ptr());
break;
case LA_SUN:
light.forward = math::normalize(float3(ob->object_to_world[2]));
light.type = GP_LIGHT_TYPE_SUN;
break;
default:
light.type = GP_LIGHT_TYPE_POINT;
break;
}
light.position = float3(object_ref.object->object_to_world[3]);
light.color = float3(la->r, la->g, la->b) * (la->energy * light_power);
lights_buf_.append(light);
}
void end_sync()
{
/* Tag light list end. */
gpLight light;
light.color[0] = -1.0f;
lights_buf_.append(light);
lights_buf_.push_update();
}
void bind_resources(PassMain::Sub &sub)
{
sub.bind_ssbo(GPENCIL_LIGHT_SLOT, &lights_buf_);
}
private:
void ambient_sync(float3 color)
{
gpLight light;
light.type = GP_LIGHT_TYPE_AMBIENT;
light.color = color;
lights_buf_.append(light);
}
};
} // namespace blender::gpencil

View File

@ -0,0 +1,313 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. */
/** \file
* \ingroup draw
*/
#pragma once
#include "BKE_gpencil_legacy.h"
#include "BKE_image.h"
#include "DRW_gpu_wrapper.hh"
#include "DRW_render.h"
#include "draw_manager.hh"
#include "draw_pass.hh"
namespace blender::gpencil {
using namespace draw;
class MaterialModule {
private:
/** Contains all materials in the scene. Indexed by gpObject.material_offset + mat_id. */
StorageVectorBuffer<gpMaterial> materials_buf_ = "gp_materials_buf";
/** List of all the texture used. */
Vector<GPUTexture *> texture_pool_;
int v3d_color_type_ = -1;
int v3d_lighting_mode_ = V3D_LIGHTING_STUDIO;
float v3d_xray_alpha_ = 1.0f;
float3 v3d_single_color_ = {1.0f, 1.0f, 1.0f};
public:
void init(const View3D *v3d)
{
if (v3d != nullptr) {
const bool shading_mode_supports_xray = (v3d->shading.type <= OB_SOLID);
v3d_color_type_ = (v3d->shading.type == OB_SOLID) ? v3d->shading.color_type : -1;
v3d_lighting_mode_ = v3d->shading.light;
v3d_xray_alpha_ = (shading_mode_supports_xray && XRAY_ENABLED(v3d)) ? XRAY_ALPHA(v3d) : 1.0f;
v3d_single_color_ = float3(v3d->shading.single_color);
}
}
void begin_sync()
{
materials_buf_.clear();
texture_pool_.clear();
}
void sync(const Object *object, const int mat_slot, bool &do_mat_holdout)
{
const MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings((Object *)object,
mat_slot + 1);
MaterialGPencilStyle gp_style_override;
gp_style = material_override(object, &gp_style_override, gp_style);
/* Material with holdout. */
if (gp_style->flag & GP_MATERIAL_IS_STROKE_HOLDOUT) {
do_mat_holdout = true;
}
if (gp_style->flag & GP_MATERIAL_IS_FILL_HOLDOUT) {
do_mat_holdout = true;
}
materials_buf_.append(material_sync(gp_style));
}
void end_sync()
{
materials_buf_.push_update();
}
void bind_resources(PassMain::Sub &sub)
{
sub.bind_ssbo(GPENCIL_MATERIAL_SLOT, &materials_buf_);
}
uint object_offset_get() const
{
return materials_buf_.size();
}
private:
/* Returns the correct flag for this texture. */
gpMaterialFlag texture_sync(::Image *image, gpMaterialFlag use_flag, gpMaterialFlag premul_flag)
{
ImBuf *ibuf;
ImageUser iuser = {nullptr};
GPUTexture *gpu_tex = nullptr;
void *lock;
bool premul = false;
if (image == nullptr) {
texture_pool_.append(nullptr);
return GP_FLAG_NONE;
}
ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
if (ibuf != nullptr && ibuf->rect != nullptr) {
gpu_tex = BKE_image_get_gpu_texture(image, &iuser, ibuf);
premul = (image->alpha_mode == IMA_ALPHA_PREMUL) != 0;
}
BKE_image_release_ibuf(image, ibuf, lock);
texture_pool_.append(gpu_tex);
return gpMaterialFlag(use_flag | (premul ? premul_flag : GP_FLAG_NONE));
}
void uv_transform_sync(const float ofs[2],
const float scale[2],
const float rotation,
float r_rot_scale[2][2],
float r_offset[2])
{
/* OPTI this could use 3x2 matrices and reduce the number of operations drastically. */
float mat[4][4];
unit_m4(mat);
/* Offset to center. */
translate_m4(mat, 0.5f, 0.5f, 0.0f);
/* Reversed order. */
float3 tmp = {1.0f / scale[0], 1.0f / scale[1], 0.0};
rescale_m4(mat, tmp);
rotate_m4(mat, 'Z', -rotation);
translate_m4(mat, ofs[0], ofs[1], 0.0f);
/* Convert to 3x2 */
copy_v2_v2(r_rot_scale[0], mat[0]);
copy_v2_v2(r_rot_scale[1], mat[1]);
copy_v2_v2(r_offset, mat[3]);
}
/* Amend object fill color in order to avoid completely flat look. */
void material_shade_color(float color[3])
{
if (v3d_lighting_mode_ == V3D_LIGHTING_FLAT) {
return;
}
/* This is scene referred color, not gamma corrected and not per perceptual.
* So we lower the threshold a bit. (1.0 / 3.0) */
if (color[0] + color[1] + color[2] > 1.1) {
add_v3_fl(color, -0.25f);
}
else {
add_v3_fl(color, 0.15f);
}
CLAMP3(color, 0.0f, 1.0f);
}
const MaterialGPencilStyle *material_override(const Object *object,
MaterialGPencilStyle *gp_style_override,
const MaterialGPencilStyle *gp_style)
{
switch (v3d_color_type_) {
case V3D_SHADING_MATERIAL_COLOR:
case V3D_SHADING_RANDOM_COLOR:
/* Random uses a random color per layer and this is done using the layer tint.
* A simple color by object, like meshes, is not practical in grease pencil. */
copy_v4_v4(gp_style_override->stroke_rgba, gp_style->stroke_rgba);
copy_v4_v4(gp_style_override->fill_rgba, gp_style->fill_rgba);
gp_style = gp_style_override;
gp_style_override->stroke_style = GP_MATERIAL_STROKE_STYLE_SOLID;
gp_style_override->fill_style = GP_MATERIAL_FILL_STYLE_SOLID;
break;
case V3D_SHADING_TEXTURE_COLOR:
*gp_style_override = blender::dna::shallow_copy(*gp_style);
gp_style = gp_style_override;
if ((gp_style_override->stroke_style == GP_MATERIAL_STROKE_STYLE_TEXTURE) &&
(gp_style_override->sima)) {
copy_v4_fl(gp_style_override->stroke_rgba, 1.0f);
gp_style_override->mix_stroke_factor = 0.0f;
}
if ((gp_style_override->fill_style == GP_MATERIAL_FILL_STYLE_TEXTURE) &&
(gp_style_override->ima)) {
copy_v4_fl(gp_style_override->fill_rgba, 1.0f);
gp_style_override->mix_factor = 0.0f;
}
else if (gp_style_override->fill_style == GP_MATERIAL_FILL_STYLE_GRADIENT) {
/* gp_style_override->fill_rgba is needed for correct gradient. */
gp_style_override->mix_factor = 0.0f;
}
break;
case V3D_SHADING_SINGLE_COLOR:
gp_style = gp_style_override;
gp_style_override->stroke_style = GP_MATERIAL_STROKE_STYLE_SOLID;
gp_style_override->fill_style = GP_MATERIAL_FILL_STYLE_SOLID;
copy_v3_v3(gp_style_override->fill_rgba, v3d_single_color_);
gp_style_override->fill_rgba[3] = 1.0f;
copy_v4_v4(gp_style_override->stroke_rgba, gp_style_override->fill_rgba);
material_shade_color(gp_style_override->fill_rgba);
break;
case V3D_SHADING_OBJECT_COLOR:
gp_style = gp_style_override;
gp_style_override->stroke_style = GP_MATERIAL_STROKE_STYLE_SOLID;
gp_style_override->fill_style = GP_MATERIAL_FILL_STYLE_SOLID;
copy_v4_v4(gp_style_override->fill_rgba, object->color);
copy_v4_v4(gp_style_override->stroke_rgba, object->color);
material_shade_color(gp_style_override->fill_rgba);
break;
case V3D_SHADING_VERTEX_COLOR:
gp_style = gp_style_override;
gp_style_override->stroke_style = GP_MATERIAL_STROKE_STYLE_SOLID;
gp_style_override->fill_style = GP_MATERIAL_FILL_STYLE_SOLID;
copy_v4_fl(gp_style_override->fill_rgba, 1.0f);
copy_v4_fl(gp_style_override->stroke_rgba, 1.0f);
break;
default:
break;
}
return gp_style;
}
gpMaterial material_sync(const MaterialGPencilStyle *gp_style)
{
gpMaterial material;
material.flag = 0;
/* Dots/Square alignment. */
if (gp_style->mode != GP_MATERIAL_MODE_LINE) {
switch (gp_style->alignment_mode) {
case GP_MATERIAL_FOLLOW_PATH:
material.flag = GP_STROKE_ALIGNMENT_STROKE;
break;
case GP_MATERIAL_FOLLOW_OBJ:
material.flag = GP_STROKE_ALIGNMENT_OBJECT;
break;
case GP_MATERIAL_FOLLOW_FIXED:
default:
material.flag = GP_STROKE_ALIGNMENT_FIXED;
break;
}
if (gp_style->mode == GP_MATERIAL_MODE_DOT) {
material.flag |= GP_STROKE_DOTS;
}
}
/* Overlap. */
if ((gp_style->mode != GP_MATERIAL_MODE_LINE) ||
(gp_style->flag & GP_MATERIAL_DISABLE_STENCIL)) {
material.flag |= GP_STROKE_OVERLAP;
}
/* Material with holdout. */
if (gp_style->flag & GP_MATERIAL_IS_STROKE_HOLDOUT) {
material.flag |= GP_STROKE_HOLDOUT;
}
if (gp_style->flag & GP_MATERIAL_IS_FILL_HOLDOUT) {
material.flag |= GP_FILL_HOLDOUT;
}
/* Dots or Squares rotation. */
material.alignment_rot[0] = cosf(gp_style->alignment_rotation);
material.alignment_rot[1] = sinf(gp_style->alignment_rotation);
/* Stroke Style */
if ((gp_style->stroke_style == GP_MATERIAL_STROKE_STYLE_TEXTURE) && (gp_style->sima)) {
material.flag |= texture_sync(
gp_style->sima, GP_STROKE_TEXTURE_USE, GP_STROKE_TEXTURE_PREMUL);
copy_v4_v4(material.stroke_color, gp_style->stroke_rgba);
material.stroke_texture_mix = 1.0f - gp_style->mix_stroke_factor;
material.stroke_u_scale = 500.0f / gp_style->texture_pixsize;
}
else /* if (gp_style->stroke_style == GP_MATERIAL_STROKE_STYLE_SOLID) */ {
texture_sync(nullptr, GP_FLAG_NONE, GP_FLAG_NONE);
material.flag &= ~GP_STROKE_TEXTURE_USE;
copy_v4_v4(material.stroke_color, gp_style->stroke_rgba);
material.stroke_texture_mix = 0.0f;
}
/* Fill Style */
if ((gp_style->fill_style == GP_MATERIAL_FILL_STYLE_TEXTURE) && (gp_style->ima)) {
material.flag |= texture_sync(gp_style->ima, GP_FILL_TEXTURE_USE, GP_FILL_TEXTURE_PREMUL);
material.flag |= (gp_style->flag & GP_MATERIAL_TEX_CLAMP) ? GP_FILL_TEXTURE_CLIP : 0;
uv_transform_sync(gp_style->texture_offset,
gp_style->texture_scale,
gp_style->texture_angle,
(float(*)[2]) & material.fill_uv_rot_scale[0],
material.fill_uv_offset);
copy_v4_v4(material.fill_color, gp_style->fill_rgba);
material.fill_texture_mix = 1.0f - gp_style->mix_factor;
}
else if (gp_style->fill_style == GP_MATERIAL_FILL_STYLE_GRADIENT) {
texture_sync(nullptr, GP_FLAG_NONE, GP_FLAG_NONE);
bool use_radial = (gp_style->gradient_type == GP_MATERIAL_GRADIENT_RADIAL);
material.flag |= GP_FILL_GRADIENT_USE;
material.flag |= use_radial ? GP_FILL_GRADIENT_RADIAL : 0;
uv_transform_sync(gp_style->texture_offset,
gp_style->texture_scale,
gp_style->texture_angle,
(float(*)[2]) & material.fill_uv_rot_scale[0],
material.fill_uv_offset);
copy_v4_v4(material.fill_color, gp_style->fill_rgba);
copy_v4_v4(material.fill_mix_color, gp_style->mix_rgba);
material.fill_texture_mix = 1.0f - gp_style->mix_factor;
if (gp_style->flag & GP_MATERIAL_FLIP_FILL) {
swap_v4_v4(material.fill_color, material.fill_mix_color);
}
}
else /* if (gp_style->fill_style == GP_MATERIAL_FILL_STYLE_SOLID) */ {
texture_sync(nullptr, GP_FLAG_NONE, GP_FLAG_NONE);
copy_v4_v4(material.fill_color, gp_style->fill_rgba);
material.fill_texture_mix = 0.0f;
}
return material;
}
};
} // namespace blender::gpencil

View File

@ -0,0 +1,304 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. */
/** \file
* \ingroup draw
*/
#pragma once
#include "BKE_gpencil_legacy.h"
#include "BKE_image.h"
#include "DRW_gpu_wrapper.hh"
#include "DRW_render.h"
#include "draw_manager.hh"
#include "draw_pass.hh"
#include "gpencil_layer.hh"
#include "gpencil_material.hh"
#include "gpencil_shader.hh"
namespace blender::gpencil {
using namespace draw;
class ObjectModule {
private:
/* TODO(fclem): This is a workaround to the current GPencil data structure.
* Rendering is much easier if we have frame containing layers. */
struct LayerData {
/* Layer / Frame tuple representing a layer inside a frame. */
const bGPDlayer *gpl;
const bGPDframe *gpf;
};
struct FrameData {
/* First layer frame to access frame members. */
const bGPDframe *gpf;
Vector<LayerData, 8> layers;
};
LayerModule &layers_;
MaterialModule &materials_;
ShaderModule &shaders_;
/** Contains all Objects in the scene. Indexed by drw_ResourceID. */
StorageArrayBuffer<gpObject> objects_buf_ = "gp_objects_buf";
/** Contains all gpencil objects in the scene as well as their effect sub-passes. */
PassSortable main_ps_ = {"gp_main_ps"};
/** Contains all composited GPencil layers from one object if is uses VFX. */
TextureFromPool object_color_tx_ = {"gp_color_object_tx"};
TextureFromPool object_reveal_tx_ = {"gp_reveal_object_tx"};
Framebuffer object_fb_ = {"gp_object_fb"};
bool is_object_fb_needed_ = false;
/** Contains all strokes from one layer if is uses blending. (also used as target for VFX) */
TextureFromPool layer_color_tx_ = {"gp_color_layer_tx"};
TextureFromPool layer_reveal_tx_ = {"gp_reveal_layer_tx"};
Framebuffer layer_fb_ = {"gp_layer_fb"};
bool is_layer_fb_needed_ = false;
bool use_onion_ = true;
bool use_stroke_fill_ = true;
bool use_vfx_ = true;
bool is_render_ = true;
/** Forward vector used to sort gpencil objects. */
float3 camera_forward_;
/** Scene current frame. */
float current_frame_ = 0;
/** \note Needs not to be temporary variable since it is dereferenced later. */
std::array<float4, 2> clear_colors_ = {float4(0.0f, 0.0f, 0.0f, 0.0f),
float4(1.0f, 1.0f, 1.0f, 1.0f)};
public:
ObjectModule(LayerModule &layers, MaterialModule &materials, ShaderModule &shaders)
: layers_(layers), materials_(materials), shaders_(shaders){};
void init(const View3D *v3d, const Scene *scene)
{
const bool is_viewport = (v3d != nullptr);
if (is_viewport) {
/* TODO(fclem): Avoid access to global DRW. */
const struct bContext *evil_C = DRW_context_state_get()->evil_C;
const bool playing = (evil_C != nullptr) ?
ED_screen_animation_playing(CTX_wm_manager(evil_C)) != nullptr :
false;
const bool hide_overlay = ((v3d->flag2 & V3D_HIDE_OVERLAYS) != 0);
const bool show_onion = ((v3d->gp_flag & V3D_GP_SHOW_ONION_SKIN) != 0);
use_onion_ = show_onion && !hide_overlay && !playing;
use_stroke_fill_ = GPENCIL_SIMPLIFY_FILL(scene, playing);
use_vfx_ = GPENCIL_SIMPLIFY_FX(scene, playing);
is_render_ = false;
}
else {
use_stroke_fill_ = GPENCIL_SIMPLIFY_FILL(scene, false);
use_vfx_ = GPENCIL_SIMPLIFY_FX(scene, false);
}
}
void begin_sync(Depsgraph *depsgraph, const View &main_view)
{
camera_forward_ = float3(main_view.viewinv()[2]);
current_frame_ = DEG_get_ctime(depsgraph);
is_object_fb_needed_ = false;
is_layer_fb_needed_ = false;
/* TODO(fclem): Shrink buffer. */
// objects_buf_.shrink();
}
void sync_gpencil(Manager &manager,
ObjectRef &object_ref,
Framebuffer &main_fb,
PassSortable &main_ps)
{
Object *object = object_ref.object;
bGPdata *gpd = static_cast<bGPdata *>(object->data);
ListBaseWrapper<const bGPDlayer> layers(&gpd->layers);
if (BLI_listbase_is_empty(&gpd->layers)) {
return;
}
const bool is_stroke_order_3d = (gpd->draw_mode == GP_DRAWMODE_3D);
bool do_material_holdout = false;
bool do_layer_blending = false;
bool object_has_vfx = false; // TODO vfx.object_has_vfx(gpd);
uint material_offset = materials_.object_offset_get();
for (auto i : IndexRange(BKE_object_material_count_eval(object))) {
materials_.sync(object, i, do_material_holdout);
}
uint layer_offset = layers_.object_offset_get();
for (const bGPDlayer *layer : layers) {
layers_.sync(object, layer, do_layer_blending);
}
/* Order rendering using camera Z distance. */
float3 position = float3(object->object_to_world[3]);
float camera_z = math::dot(position, camera_forward_);
PassMain::Sub &object_subpass = main_ps.sub("GPObject", camera_z);
object_subpass.framebuffer_set((object_has_vfx) ? &object_fb_ : &main_fb);
object_subpass.clear_depth(is_stroke_order_3d ? 1.0f : 0.0f);
if (object_has_vfx) {
object_subpass.clear_multi(clear_colors_);
}
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_BLEND_ALPHA_PREMUL;
/* For 2D mode, we render all strokes with uniform depth (increasing with stroke id). */
state |= (is_stroke_order_3d) ? DRW_STATE_DEPTH_LESS_EQUAL : DRW_STATE_DEPTH_GREATER;
/* Always write stencil. Only used as optimization for blending. */
state |= DRW_STATE_WRITE_STENCIL | DRW_STATE_STENCIL_ALWAYS;
object_subpass.state_set(state);
object_subpass.shader_set(shaders_.static_shader_get(GREASE_PENCIL));
Vector<FrameData, 5> frames;
displayed_frame_select(frames, layers);
for (const FrameData &frame : frames) {
/* TODO(fclem): Pass per frame object matrix here. */

Typically dead code is discouraged.
Not sure what is it part of, so can't really give strong suggestions.

Typically dead code is discouraged. Not sure what is it part of, so can't really give strong suggestions.
ResourceHandle handle = manager.resource_handle(object_ref);
gpObject &ob = objects_buf_.get_or_resize(handle.resource_index());
ob.is_shadeless = false;
ob.stroke_order3d = false;
ob.tint = frame_tint_get(gpd, frame.gpf, current_frame_);
ob.layer_offset = layer_offset;
ob.material_offset = material_offset;
GPUVertBuf *position_tx = DRW_cache_gpencil_position_buffer_get(object, frame.gpf->framenum);
GPUVertBuf *color_tx = DRW_cache_gpencil_color_buffer_get(object, frame.gpf->framenum);
GPUBatch *geom = DRW_cache_gpencil_get(object, frame.gpf->framenum);
if (do_layer_blending) {
for (const LayerData &layer : frame.layers) {
UNUSED_VARS(layer);
// if (has_blending(layer)) {
// object_subpass.framebuffer_set(*vfx_fb.current());
// }
/* TODO(fclem): Only draw subrange of geometry for this layer. */
object_subpass.draw(geom, handle);
Review

Add a comment what is this about, or remove.

Add a comment what is this about, or remove.
// if (has_blending(layer)) {
// layer_blend_sync(object_ref, object_subpass);
// }
}
}
else {
/* Fast path. */
object_subpass.bind_texture("gp_pos_tx", position_tx);
object_subpass.bind_texture("gp_col_tx", color_tx);
object_subpass.draw(geom, handle);
}
}
#if 0
if (object_has_vfx) {
VfxContext vfx_ctx(object_subpass,
layer_fb_,
object_fb_,
object_color_tx_,
layer_color_tx_,
object_reveal_tx_,
layer_reveal_tx_,
is_render_);
/* \note Update this boolean as the actual number of vfx drawn might differ. */
object_has_vfx = vfx.object_sync(main_fb_, object_ref, vfx_ctx, do_material_holdout);
if (object_has_vfx || do_layer_blending) {
is_layer_fb_needed_ = true;
}
}
#endif
}
void end_sync()
{
objects_buf_.push_update();
}
void bind_resources(PassMain::Sub &sub)
{
sub.bind_ssbo(GPENCIL_OBJECT_SLOT, &objects_buf_);
}
void acquire_temporary_buffers(int2 render_size, eGPUTextureFormat format)
{
object_color_tx_.acquire(render_size, format);
object_reveal_tx_.acquire(render_size, format);
object_fb_.ensure(GPU_ATTACHMENT_NONE,
GPU_ATTACHMENT_TEXTURE(object_color_tx_),
GPU_ATTACHMENT_TEXTURE(object_reveal_tx_));
if (is_layer_fb_needed_) {
layer_color_tx_.acquire(render_size, format);
layer_reveal_tx_.acquire(render_size, format);
layer_fb_.ensure(GPU_ATTACHMENT_NONE,
GPU_ATTACHMENT_TEXTURE(layer_color_tx_),
GPU_ATTACHMENT_TEXTURE(layer_reveal_tx_));
}
}
void release_temporary_buffers()
{

Same as above.

Same as above.
object_color_tx_.release();
object_reveal_tx_.release();
layer_color_tx_.release();
layer_reveal_tx_.release();
}
bool scene_has_visible_gpencil_object() const
{
return objects_buf_.size() > 0;
}
private:
static float4 frame_tint_get(const bGPdata *gpd, const bGPDframe *gpf, int /* current_frame */)
{
/* TODO(fclem): Onion color should rely on time and or frame id and not on runtime.onion_id.
* This should be evaluated at draw time as it is just a way of displaying the data. */
const bool use_onion_custom_col = (gpd->onion_flag & GP_ONION_GHOST_PREVCOL) != 0;
const bool use_onion_fade = (gpd->onion_flag & GP_ONION_FADE) != 0;
const bool use_next_col = gpf->runtime.onion_id > 0.0f;
const float *onion_col_custom = (use_onion_custom_col) ?
(use_next_col ? gpd->gcolor_next : gpd->gcolor_prev) :
U.gpencil_new_layer_col;
float4 tint = {UNPACK3(onion_col_custom), 1.0f};
tint[3] = use_onion_fade ? (1.0f / abs(gpf->runtime.onion_id)) : 0.5f;
tint[3] *= gpd->onion_factor;
tint[3] = (gpd->onion_factor > 0.0f) ? clamp_f(tint[3], 0.1f, 1.0f) :
clamp_f(tint[3], 0.01f, 1.0f);
return tint;
}
void displayed_frame_select(Vector<FrameData, 5> &frames,
ListBaseWrapper<const bGPDlayer> layers)
{
/* TODO(fclem): Select onion skin frames. */
/** \note Change data layout to be Frame major instead of Layer major.
* Hopefully the GPencil data layout will be closer to that in the future. */
FrameData frame_data;
frame_data.gpf = layers.get(0)->actframe;
for (const bGPDlayer *layer : layers) {
LayerData layer_data;
layer_data.gpf = layer->actframe;
layer_data.gpl = layer;
frame_data.layers.append(layer_data);
}
frames.append(frame_data);
}
};
} // namespace blender::gpencil

View File

@ -0,0 +1,115 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. */
/** \file
* \ingroup draw
*/
#include "gpencil_shader.hh"
namespace blender::gpencil {
ShaderModule *ShaderModule::g_shader_module = nullptr;
ShaderModule *ShaderModule::module_get()
{
if (g_shader_module == nullptr) {
/* TODO(@fclem) thread-safety. */
g_shader_module = new ShaderModule();
}
return g_shader_module;
}
void ShaderModule::module_free()
{
if (g_shader_module != nullptr) {
/* TODO(@fclem) thread-safety. */
delete g_shader_module;
g_shader_module = nullptr;
}
}
ShaderModule::ShaderModule()
{
for (GPUShader *&shader : shaders_) {
shader = nullptr;
}
#ifdef DEBUG
/* Ensure all shader are described. */
for (auto i : IndexRange(MAX_SHADER_TYPE)) {
const char *name = static_shader_create_info_name_get(eShaderType(i));
if (name == nullptr) {
std::cerr << "GPencil: Missing case for eShaderType(" << i
<< ") in static_shader_create_info_name_get().";

<< std::endl to put new line and flush the output buffer.

Also, why not to assert the details in the static_shader_create_info_name_get() ? It is a bit weird to print an error about mistake in some other code.

P.S. I think we should implement Glog style of checkers: DCHECK_NE(name, nullptr) << "GPencil: Missing case for eShaderType(" << i << ") in static_shader_create_info_name_get()."

`<< std::endl` to put new line and flush the output buffer. Also, why not to assert the details in the `static_shader_create_info_name_get()` ? It is a bit weird to print an error about mistake in some other code. P.S. I think we should implement Glog style of checkers: `DCHECK_NE(name, nullptr) << "GPencil: Missing case for eShaderType(" << i << ") in static_shader_create_info_name_get()."`
BLI_assert(0);
}
const GPUShaderCreateInfo *create_info = GPU_shader_create_info_get(name);
BLI_assert_msg(create_info != nullptr, "GPencil: Missing create info for static shader.");
}
#endif
}
ShaderModule::~ShaderModule()
{
for (GPUShader *&shader : shaders_) {
DRW_SHADER_FREE_SAFE(shader);
}
}
const char *ShaderModule::static_shader_create_info_name_get(eShaderType shader_type)
{
switch (shader_type) {
case ANTIALIASING_EDGE_DETECT:
return "gpencil_antialiasing_stage_0";
case ANTIALIASING_BLEND_WEIGHT:
return "gpencil_antialiasing_stage_1";
case ANTIALIASING_RESOLVE:
return "gpencil_antialiasing_stage_2";
case GREASE_PENCIL:
return "gpencil_geometry_next";
case LAYER_BLEND:
return "gpencil_layer_blend";
case DEPTH_MERGE:
return "gpencil_depth_merge";
case MASK_INVERT:
return "gpencil_mask_invert";
case FX_COMPOSITE:
return "gpencil_fx_composite";
case FX_COLORIZE:
return "gpencil_fx_colorize";
case FX_BLUR:
return "gpencil_fx_blur";
case FX_GLOW:
return "gpencil_fx_glow";
case FX_PIXEL:
return "gpencil_fx_pixelize";
case FX_RIM:
return "gpencil_fx_rim";
case FX_SHADOW:
return "gpencil_fx_shadow";
case FX_TRANSFORM:
return "gpencil_fx_transform";
/* To avoid compiler warning about missing case. */
case MAX_SHADER_TYPE:
return "";
}
return "";
}
GPUShader *ShaderModule::static_shader_get(eShaderType shader_type)
{
if (shaders_[shader_type] == nullptr) {
const char *shader_name = static_shader_create_info_name_get(shader_type);
shaders_[shader_type] = GPU_shader_create_from_info_name(shader_name);
if (shaders_[shader_type] == nullptr) {
fprintf(stderr, "GPencil: error: Could not compile static shader \"%s\"\n", shader_name);

Pick a side between fprintf and std::cerr ;)

Pick a side between `fprintf` and `std::cerr` ;)
}
BLI_assert(shaders_[shader_type] != nullptr);
}
return shaders_[shader_type];
}
} // namespace blender::gpencil

View File

@ -0,0 +1,65 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. */
/** \file
* \ingroup draw
*/
#pragma once
#include "DRW_render.h"
namespace blender::gpencil {
enum eShaderType {
/* SMAA antialiasing */
ANTIALIASING_EDGE_DETECT = 0,
ANTIALIASING_BLEND_WEIGHT,
ANTIALIASING_RESOLVE,
/* GPencil Object rendering */
GREASE_PENCIL,
/* All layer blend types in one shader! */
LAYER_BLEND,
/* Merge the final object depth to the depth buffer. */
DEPTH_MERGE,
/* Invert the content of the mask buffer. */
MASK_INVERT,
/* Final Compositing over rendered background. */
FX_COMPOSITE,
/* Effects. */
FX_COLORIZE,
FX_BLUR,
FX_GLOW,
FX_PIXEL,
FX_RIM,
FX_SHADOW,
FX_TRANSFORM,
MAX_SHADER_TYPE,
};
/**
* Shader module. shared between instances.
*/
class ShaderModule {
private:
std::array<GPUShader *, MAX_SHADER_TYPE> shaders_;
/** Shared shader module across all engine instances. */
static ShaderModule *g_shader_module;
public:
ShaderModule();
~ShaderModule();
GPUShader *static_shader_get(eShaderType shader_type);
/** Only to be used by Instance constructor. */
static ShaderModule *module_get();
static void module_free();
private:
const char *static_shader_create_info_name_get(eShaderType shader_type);
};
} // namespace blender::gpencil

View File

@ -1,11 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef GPU_SHADER
# pragma once
# include "GPU_shader_shared_utils.h"
# ifndef __cplusplus
typedef struct gpScene gpScene;
typedef struct gpMaterial gpMaterial;
typedef struct gpLight gpLight;
typedef struct gpObject gpObject;
typedef struct gpLayer gpLayer;
typedef enum gpMaterialFlag gpMaterialFlag;
# ifdef GP_LIGHT
typedef enum gpLightType gpLightType;
@ -14,6 +19,7 @@ typedef enum gpLightType gpLightType;
#endif
enum gpMaterialFlag {
GP_FLAG_NONE = 0u,
GP_STROKE_ALIGNMENT_STROKE = 1u,
GP_STROKE_ALIGNMENT_OBJECT = 2u,
GP_STROKE_ALIGNMENT_FIXED = 3u,
@ -50,6 +56,12 @@ enum gpLightType {
# define gpLightType uint
#endif
struct gpScene {
float2 render_size;
float2 _pad0;
};
BLI_STATIC_ASSERT_ALIGN(gpScene, 16)
struct gpMaterial {
float4 stroke_color;
float4 fill_color;
@ -116,6 +128,38 @@ struct gpLight {
BLI_STATIC_ASSERT_ALIGN(gpLight, 16)
#endif
struct gpObject {
/** Wether or not to apply lighting to the GPencil object. */
bool1 is_shadeless;
/** Switch between 2d and 3D stroke order. */
bool1 stroke_order3d;
/** Offset inside the layer buffer to the first layer data of this object. */
uint layer_offset;
/** Offset inside the material buffer to the first material data of this object. */
uint material_offset;
/** Color to multiply to the final mixed color. */
float4 tint;
/** Color to multiply to the final mixed color. */
float3 normal;
float _pad0;
};
BLI_STATIC_ASSERT_ALIGN(gpObject, 16)
struct gpLayer {
/** Amount of vertex color to blend with actual material color. */
float vertex_color_opacity;
/** Thickness change of all the strokes. */
float thickness_offset;
/** Thickness change of all the strokes. */
float opacity;
/** Offset to apply to stroke index to be able to insert a currently drawn stroke in between. */
float stroke_index_offset;
/** Color to multiply to the final mixed color. */
float4 tint;
};
BLI_STATIC_ASSERT_ALIGN(gpLayer, 16)
#ifndef GPU_SHADER
# undef gpMaterialFlag
# undef gpLightType

View File

@ -0,0 +1,334 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2017 Blender Foundation. */
/** \file
* \ingroup draw
*/
#include "BKE_camera.h"
#include "BLI_listbase_wrapper.hh"
#include "DNA_camera_types.h"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_shader_fx_types.h"
#include "draw_manager.hh"
#include "draw_pass.hh"
#include "gpencil_engine.h"
#include "gpencil_shader.hh"
#include "gpencil_shader_shared.h"
namespace blender::gpencil {
using namespace draw;
struct VfxContext {
PassMain::Sub *object_subpass;
SwapChain<GPUFrameBuffer **, 2> vfx_fb;
SwapChain<GPUTexture **, 2> color_tx;
SwapChain<GPUTexture **, 2> reveal_tx;
bool is_viewport;
VfxContext(PassMain::Sub &object_subpass_,
Framebuffer &layer_fb,
Framebuffer &object_fb,
TextureFromPool &object_color_tx,
TextureFromPool &layer_color_tx,
TextureFromPool &object_reveal_tx,
TextureFromPool &layer_reveal_tx,
bool is_render_)
{
object_subpass = &object_subpass_;
/* These may not be allocated yet, use address of future pointer. */
vfx_fb.current() = &layer_fb;
vfx_fb.next() = &object_fb;
color_tx.current() = &object_color_tx;
color_tx.next() = &layer_color_tx;
reveal_tx.current() = &object_reveal_tx;
reveal_tx.next() = &layer_reveal_tx;
is_viewport = (is_render_ == false);
}
PassMain::Sub &create_vfx_pass(const char *name, GPUShader *shader)
{
PassMain::Sub &sub = object_subpass->sub(name);
sub.framebuffer_set(vfx_fb.current());
sub.shader_set(shader);
sub.bind_texture("colorBuf", color_tx.current());
sub.bind_texture("revealBuf", reveal_tx.current());
vfx_fb.swap();
color_tx.swap();
reveal_tx.swap();
return sub;
}
/* Verify if the given fx is active. */
bool effect_is_active(const bGPdata *gpd, const ShaderFxData *fx)
{
if (fx == NULL) {
return false;
}
if (gpd == NULL) {
return false;
}
bool is_edit = GPENCIL_ANY_EDIT_MODE(gpd);
if (((fx->mode & eShaderFxMode_Editmode) == 0) && (is_edit) && (is_viewport)) {
return false;
}
if (((fx->mode & eShaderFxMode_Realtime) && (is_viewport == true)) ||
((fx->mode & eShaderFxMode_Render) && (is_viewport == false))) {
return true;
}
return false;
}
};
class VfxModule {
private:
ShaderModule &shaders;
/* Global switch for all vfx. */
bool vfx_enabled_ = false;
/* Global switch for all Depth Of Field blur. */
bool dof_enabled_ = false;
/* Pseudo depth of field parameter. Used to scale blur radius. */
float dof_parameters_[2];
public:
VfxModule(ShaderModule &shaders_) : shaders(shaders_){};
void init(bool enable, const Object *camera_object, const RegionView3D *rv3d)
{
vfx_enabled_ = enable;
const Camera *camera = (camera_object != nullptr) ?
static_cast<const Camera *>(camera_object->data) :
nullptr;
/* Pseudo DOF setup. */
if (camera && (camera->dof.flag & CAM_DOF_ENABLED)) {
const float *vp_size = DRW_viewport_size_get();
float fstop = camera->dof.aperture_fstop;
float sensor = BKE_camera_sensor_size(
camera->sensor_fit, camera->sensor_x, camera->sensor_y);
float focus_dist = BKE_camera_object_dof_distance(camera_object);
float focal_len = camera->lens;
const float scale_camera = 0.001f;
/* We want radius here for the aperture number. */
float aperture = 0.5f * scale_camera * focal_len / fstop;
float focal_len_scaled = scale_camera * focal_len;
float sensor_scaled = scale_camera * sensor;
if (rv3d != nullptr) {
sensor_scaled *= rv3d->viewcamtexcofac[0];
}
dof_parameters_[1] = aperture * fabsf(focal_len_scaled / (focus_dist - focal_len_scaled));
dof_parameters_[1] *= vp_size[0] / sensor_scaled;
dof_parameters_[0] = -focus_dist * dof_parameters_[1];
}
else {
/* Disable DoF blur scaling. Produce Circle of Confusion of 0 pixel. */
dof_parameters_[0] = dof_parameters_[1] = 0.0f;
}
}
/* Return true if any vfx is needed */
bool object_sync(Framebuffer &main_fb,
ObjectRef &object_ref,
VfxContext &vfx_ctx,
bool do_material_holdout)
{
Object *object = object_ref.object;
bGPdata *gpd = (bGPdata *)object->data;
int vfx_count = 0;
if (vfx_enabled_) {
for (const ShaderFxData *fx : ListBaseWrapper<const ShaderFxData>(&object->shader_fx)) {
if (!vfx_ctx.effect_is_active(gpd, fx)) {
continue;
}
switch (fx->type) {
case eShaderFxType_Blur:
vfx_count += vfx_blur(*(const BlurShaderFxData *)fx, object, vfx_ctx);
break;
case eShaderFxType_Colorize:
vfx_count += vfx_colorize(*(const ColorizeShaderFxData *)fx, object, vfx_ctx);
break;
case eShaderFxType_Flip:
vfx_count += vfx_flip(*(const FlipShaderFxData *)fx, object, vfx_ctx);
break;
case eShaderFxType_Pixel:
vfx_count += vfx_pixelize(*(const PixelShaderFxData *)fx, object, vfx_ctx);
break;
case eShaderFxType_Rim:
vfx_count += vfx_rim(*(const RimShaderFxData *)fx, object, vfx_ctx);
break;
case eShaderFxType_Shadow:
vfx_count += vfx_shadow(*(const ShadowShaderFxData *)fx, object, vfx_ctx);
break;
case eShaderFxType_Glow:
vfx_count += vfx_glow(*(const GlowShaderFxData *)fx, object, vfx_ctx);
break;
case eShaderFxType_Swirl:
vfx_count += vfx_swirl(*(const SwirlShaderFxData *)fx, object, vfx_ctx);
break;
case eShaderFxType_Wave:
vfx_count += vfx_wave(*(const WaveShaderFxData *)fx, object, vfx_ctx);
break;
default:
break;
}
}
}
if (do_material_holdout) {
vfx_count += 1;
}
if (vfx_count > 0) {
/* We need an extra pass to combine result to main buffer. */
merge_sync(main_fb, vfx_ctx);
}
return vfx_count > 0;
}
private:
int vfx_blur(const BlurShaderFxData &fx, const Object *object, VfxContext &vfx_ctx)
{
if ((fx.flag & FX_BLUR_DOF_MODE) && !dof_enabled_) {
/* No blur outside camera view (or when DOF is disabled on the camera). */
return 0;
}
float winmat[4][4], persmat[4][4];
float2 blur_size = {fx.radius[0], fx.radius[1]};
/* TODO(fclem): Replace by draw::View. */
DRW_view_persmat_get(nullptr, persmat, false);
const float w = fabsf(mul_project_m4_v3_zfac(persmat, object->object_to_world[3]));
if (fx.flag & FX_BLUR_DOF_MODE) {
/* Compute circle of confusion size. */
float coc = (dof_parameters_[0] / -w) - dof_parameters_[1];
blur_size = float2(fabsf(coc));
}
else {
/* Modify by distance to camera and object scale. */
/* TODO(fclem): Replace by draw::View. */
DRW_view_winmat_get(nullptr, winmat, false);
/* TODO(fclem): Replace by this->render_size. */
const float *vp_size = DRW_viewport_size_get();
float world_pixel_scale = 1.0f / GPENCIL_PIXEL_FACTOR;
float scale = mat4_to_scale(object->object_to_world);
float distance_factor = world_pixel_scale * scale * winmat[1][1] * vp_size[1] / w;
blur_size *= distance_factor;
}
if ((fx.samples == 0.0f) || (blur_size[0] == 0.0f && blur_size[1] == 0.0f)) {
return 0;
}
GPUShader *sh = shaders.static_shader_get(eShaderType::FX_BLUR);
const float rot_sin = sin(fx.rotation);
const float rot_cos = cos(fx.rotation);
if (blur_size[0] > 0.0f) {
PassMain::Sub &sub = vfx_ctx.create_vfx_pass("Fx Blur H", sh);
sub.state_set(DRW_STATE_WRITE_COLOR);
sub.push_constant("offset", float2(blur_size[0] * rot_cos, blur_size[0] * rot_sin));
sub.push_constant("sampCount", max_ii(1, min_ii(fx.samples, blur_size[0])));
sub.draw_procedural(GPU_PRIM_TRIS, 1, 3);
}
if (blur_size[1] > 0.0f) {
PassMain::Sub &sub = vfx_ctx.create_vfx_pass("Fx Blur V", sh);
sub.state_set(DRW_STATE_WRITE_COLOR);
sub.push_constant("offset", float2(-blur_size[1] * rot_sin, blur_size[1] * rot_cos));
sub.push_constant("sampCount", max_ii(1, min_ii(fx.samples, blur_size[1])));
sub.draw_procedural(GPU_PRIM_TRIS, 1, 3);
}
/* Return number of passes. */
return int(blur_size[0] > 0.0f) + int(blur_size[1] > 0.0f);
}
int vfx_colorize(const ColorizeShaderFxData &fx, const Object *object, VfxContext &vfx_ctx)
{
UNUSED_VARS(fx, object, vfx_ctx);
return 0;
}
int vfx_flip(const FlipShaderFxData &fx, const Object *object, VfxContext &vfx_ctx)
{
UNUSED_VARS(fx, object, vfx_ctx);
return 0;
}
int vfx_pixelize(const PixelShaderFxData &fx, const Object *object, VfxContext &vfx_ctx)
{
UNUSED_VARS(fx, object, vfx_ctx);
return 0;
}
int vfx_rim(const RimShaderFxData &fx, const Object *object, VfxContext &vfx_ctx)
{
UNUSED_VARS(fx, object, vfx_ctx);
return 0;
}
int vfx_shadow(const ShadowShaderFxData &fx, const Object *object, VfxContext &vfx_ctx)
{
UNUSED_VARS(fx, object, vfx_ctx);
return 0;
}
int vfx_glow(const GlowShaderFxData &fx, const Object *object, VfxContext &vfx_ctx)
{
UNUSED_VARS(fx, object, vfx_ctx);
return 0;
}
int vfx_swirl(const SwirlShaderFxData &fx, const Object *object, VfxContext &vfx_ctx)
{
UNUSED_VARS(fx, object, vfx_ctx);
return 0;
}
int vfx_wave(const WaveShaderFxData &fx, const Object *object, VfxContext &vfx_ctx)
{
UNUSED_VARS(fx, object, vfx_ctx);
return 0;
}
void merge_sync(Framebuffer &main_fb, VfxContext &vfx_ctx)
{
PassMain::Sub &sub = vfx_ctx.object_subpass->sub("GPencil Object Composite");
sub.framebuffer_set(&main_fb);
sub.shader_set(shaders.static_shader_get(FX_COMPOSITE));
sub.bind_texture("colorBuf", vfx_ctx.color_tx.current());
sub.bind_texture("revealBuf", vfx_ctx.reveal_tx.current());
sub.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_MUL);
sub.push_constant("isFirstPass", true);
sub.draw_procedural(GPU_PRIM_TRIS, 1, 3);
/* We cannot do custom blending on multi-target frame-buffers.
* Workaround by doing 2 passes. */
sub.state_set(DRW_STATE_WRITE_COLOR, DRW_STATE_BLEND_ADD_FULL);
sub.push_constant("isFirstPass", false);
sub.draw_procedural(GPU_PRIM_TRIS, 1, 3);
}
};
} // namespace blender::gpencil

View File

@ -15,19 +15,19 @@ vec3 gpencil_lighting(void)
{
vec3 light_accum = vec3(0.0);
for (int i = 0; i < GPENCIL_LIGHT_BUFFER_LEN; i++) {
if (lights[i]._color.x == -1.0) {
if (gp_lights[i]._color.x == -1.0) {
break;
}
vec3 L = lights[i]._position - gp_interp.pos;
vec3 L = gp_lights[i]._position - gp_interp.pos;
float vis = 1.0;
gpLightType type = floatBitsToUint(lights[i]._type);
gpLightType type = floatBitsToUint(gp_lights[i]._type);
/* Spot Attenuation. */
if (type == GP_LIGHT_TYPE_SPOT) {
mat3 rot_scale = mat3(lights[i]._right, lights[i]._up, lights[i]._forward);
mat3 rot_scale = mat3(gp_lights[i]._right, gp_lights[i]._up, gp_lights[i]._forward);
vec3 local_L = rot_scale * L;
local_L /= abs(local_L.z);
float ellipse = inversesqrt(length_squared(local_L));
vis *= smoothstep(0.0, 1.0, (ellipse - lights[i]._spot_size) / lights[i]._spot_blend);
vis *= smoothstep(0.0, 1.0, (ellipse - gp_lights[i]._spot_size) / gp_lights[i]._spot_blend);
/* Also mask +Z cone. */
vis *= step(0.0, local_L.z);
}
@ -37,7 +37,7 @@ vec3 gpencil_lighting(void)
vis /= L_len_sqr;
}
else {
L = lights[i]._forward;
L = gp_lights[i]._forward;
L_len_sqr = 1.0;
}
/* Lambertian falloff */
@ -45,7 +45,7 @@ vec3 gpencil_lighting(void)
L /= sqrt(L_len_sqr);
vis *= clamp(dot(gpNormal, L), 0.0, 1.0);
}
light_accum += vis * lights[i]._color;
light_accum += vis * gp_lights[i]._color;
}
/* Clamp to avoid NaNs. */
return clamp(light_accum, 0.0, 1e10);
@ -68,7 +68,7 @@ void main()
bool radial = flag_test(gp_interp.mat_flag, GP_FILL_GRADIENT_RADIAL);
float fac = clamp(radial ? length(gp_interp.uv * 2.0 - 1.0) : gp_interp.uv.x, 0.0, 1.0);
uint matid = gp_interp.mat_flag >> GPENCIl_MATID_SHIFT;
col = mix(materials[matid].fill_color, materials[matid].fill_mix_color, fac);
col = mix(gp_materials[matid].fill_color, gp_materials[matid].fill_mix_color, fac);
}
else /* SOLID */ {
col = vec4(1.0);

View File

@ -27,12 +27,14 @@ void gpencil_color_output(vec4 stroke_col, vec4 vert_col, float vert_strength, f
void main()
{
PASS_RESOURCE_ID
float vert_strength;
vec4 vert_color;
vec3 vert_N;
ivec4 ma1 = floatBitsToInt(texelFetch(gp_pos_tx, gpencil_stroke_point_id() * 3 + 1));
gpMaterial gp_mat = materials[ma1.x + gpMaterialOffset];
gpMaterial gp_mat = gp_materials[ma1.x + gpMaterialOffset];
gpMaterialFlag gp_flag = floatBitsToUint(gp_mat._flag);
gl_Position = gpencil_vertex(vec4(viewportSize, 1.0 / viewportSize),

View File

@ -2,6 +2,8 @@
#include "gpu_shader_create_info.hh"
#include "gpencil_defines.h"
/* -------------------------------------------------------------------- */
/** \name GPencil Object rendering
* \{ */
@ -26,8 +28,8 @@ GPU_SHADER_CREATE_INFO(gpencil_geometry)
.sampler(3, ImageType::FLOAT_2D, "gpStrokeTexture")
.sampler(4, ImageType::DEPTH_2D, "gpSceneDepthTexture")
.sampler(5, ImageType::FLOAT_2D, "gpMaskTexture")
.uniform_buf(4, "gpMaterial", "materials[GPENCIL_MATERIAL_BUFFER_LEN]", Frequency::BATCH)
.uniform_buf(3, "gpLight", "lights[GPENCIL_LIGHT_BUFFER_LEN]", Frequency::BATCH)
.uniform_buf(4, "gpMaterial", "gp_materials[GPENCIL_MATERIAL_BUFFER_LEN]", Frequency::BATCH)
.uniform_buf(3, "gpLight", "gp_lights[GPENCIL_LIGHT_BUFFER_LEN]", Frequency::BATCH)
.push_constant(Type::VEC2, "viewportSize")
/* Per Object */
.push_constant(Type::VEC3, "gpNormal")
@ -46,6 +48,38 @@ GPU_SHADER_CREATE_INFO(gpencil_geometry)
.depth_write(DepthWrite::ANY)
.additional_info("draw_gpencil");
GPU_SHADER_CREATE_INFO(gpencil_geometry_next)
.do_static_compilation(true)
.define("GP_LIGHT")
.typedef_source("gpencil_defines.h")
.sampler(GPENCIL_SCENE_DEPTH_TEX_SLOT, ImageType::DEPTH_2D, "gpSceneDepthTexture")
.sampler(GPENCIL_MASK_TEX_SLOT, ImageType::FLOAT_2D, "gpMaskTexture")
.sampler(GPENCIL_FILL_TEX_SLOT, ImageType::FLOAT_2D, "gpFillTexture")
.sampler(GPENCIL_STROKE_TEX_SLOT, ImageType::FLOAT_2D, "gpStrokeTexture")
.storage_buf(GPENCIL_OBJECT_SLOT, Qualifier::READ, "gpObject", "gp_object[]")
.storage_buf(GPENCIL_LAYER_SLOT, Qualifier::READ, "gpLayer", "gp_layer[]")
.storage_buf(GPENCIL_MATERIAL_SLOT, Qualifier::READ, "gpMaterial", "gp_materials[]")
.storage_buf(GPENCIL_LIGHT_SLOT, Qualifier::READ, "gpLight", "gp_lights[]")
.uniform_buf(GPENCIL_SCENE_SLOT, "gpScene", "gp_scene")
/* Per Scene */
.define("viewportSize", "gp_scene.render_size")
/* Per Object */
.define("gpNormal", "gp_object[resource_id].normal")
.define("gpStrokeOrder3d", "gp_object[resource_id].stroke_order3d")
.define("gpMaterialOffset", "gp_object[resource_id].material_offset")
/* Per Layer */
.define("layer_id", "gp_object[resource_id].layer_offset") /* TODO */
.define("gpVertexColorOpacity", "gp_layer[layer_id].vertex_color_opacity")
.define("gpLayerTint", "gp_layer[layer_id].tint")
.define("gpLayerOpacity", "gp_layer[layer_id].opacity")
.define("gpStrokeIndexOffset", "gp_layer[layer_id].stroke_index_offset")
.fragment_out(0, Type::VEC4, "fragColor")
.fragment_out(1, Type::VEC4, "revealColor")
.vertex_out(gpencil_geometry_iface)
.vertex_source("gpencil_vert.glsl")
.fragment_source("gpencil_frag.glsl")
.additional_info("draw_gpencil_new");
/** \} */
/* -------------------------------------------------------------------- */

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

@ -1283,7 +1283,8 @@ static void drw_engines_enable(ViewLayer *UNUSED(view_layer),
drw_engines_enable_from_engine(engine_type, drawtype);
if (gpencil_engine_needed && ((drawtype >= OB_SOLID) || !use_xray)) {
use_drw_engine(&draw_engine_gpencil_type);
use_drw_engine(((U.experimental.enable_gpencil_next) ? &draw_engine_gpencil_next_type :
&draw_engine_gpencil_type));
}
if (is_compositor_enabled()) {
@ -1891,10 +1892,13 @@ static void DRW_render_gpencil_to_image(RenderEngine *engine,
struct RenderLayer *render_layer,
const rcti *rect)
{
if (draw_engine_gpencil_type.render_to_image) {
DrawEngineType *draw_engine = U.experimental.enable_gpencil_next ?
&draw_engine_gpencil_next_type :
&draw_engine_gpencil_type;
if (draw_engine->render_to_image) {
ViewportEngineData *gpdata = DRW_view_data_engine_data_get_ensure(DST.view_data_active,
&draw_engine_gpencil_type);
draw_engine_gpencil_type.render_to_image(gpdata, engine, render_layer, rect);
draw_engine);
draw_engine->render_to_image(gpdata, engine, render_layer, rect);
}
}
@ -2460,7 +2464,8 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph,
else if (!draw_surface) {
/* grease pencil selection */
if (drw_gpencil_engine_needed(depsgraph, v3d)) {
use_drw_engine(&draw_engine_gpencil_type);
use_drw_engine(((U.experimental.enable_gpencil_next) ? &draw_engine_gpencil_next_type :
&draw_engine_gpencil_type));
}
drw_engines_enable_overlays();
@ -2470,7 +2475,8 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph,
drw_engines_enable_basic();
/* grease pencil selection */
if (drw_gpencil_engine_needed(depsgraph, v3d)) {
use_drw_engine(&draw_engine_gpencil_type);
use_drw_engine(((U.experimental.enable_gpencil_next) ? &draw_engine_gpencil_next_type :
&draw_engine_gpencil_type));
}
drw_engines_enable_overlays();
@ -2635,7 +2641,8 @@ void DRW_draw_depth_loop(struct Depsgraph *depsgraph,
drw_manager_init(&DST, viewport, NULL);
if (use_gpencil) {
use_drw_engine(&draw_engine_gpencil_type);
use_drw_engine(((U.experimental.enable_gpencil_next) ? &draw_engine_gpencil_next_type :
&draw_engine_gpencil_type));
}
if (use_basic) {
drw_engines_enable_basic();
@ -3006,6 +3013,7 @@ void DRW_engines_register(void)
RE_engines_register(&DRW_engine_viewport_workbench_type);
DRW_engine_register(&draw_engine_gpencil_type);
DRW_engine_register(&draw_engine_gpencil_next_type);
DRW_engine_register(&draw_engine_overlay_type);
DRW_engine_register(&draw_engine_select_type);

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

@ -139,6 +139,22 @@ GPU_SHADER_CREATE_INFO(draw_gpencil)
.push_constant(Type::FLOAT, "gpThicknessOffset")
.additional_info("draw_modelmat", "draw_object_infos");
GPU_SHADER_CREATE_INFO(draw_gpencil_new)
.typedef_source("gpencil_shader_shared.h")
.define("DRW_GPENCIL_INFO")
.sampler(0, ImageType::FLOAT_BUFFER, "gp_pos_tx")
.sampler(1, ImageType::FLOAT_BUFFER, "gp_col_tx")
/* Per Object */
.define("gpThicknessScale", "1.0") /* TODO(fclem): Replace with object info. */
.define("gpThicknessWorldScale", "1.0 / 2000.0") /* TODO(fclem): Same as above. */
.define("gpThicknessIsScreenSpace", "(gpThicknessWorldScale < 0.0)")
/* Per Layer */
.define("gpThicknessOffset", "0.0") /* TODO(fclem): Remove. */
.additional_info("draw_modelmat_new",
"draw_resource_id_varying",
"draw_view",
"draw_object_infos_new");
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -5264,7 +5264,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

@ -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

@ -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

@ -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. */
@ -2494,13 +2494,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

@ -5689,7 +5689,7 @@ void uiTemplateColorPicker(uiLayout *layout,
"",
WHEEL_SIZE + 6,
0,
14 * UI_DPI_FAC,
14 * UI_SCALE_FAC,
WHEEL_SIZE,
ptr,
prop,
@ -5710,7 +5710,7 @@ void uiTemplateColorPicker(uiLayout *layout,
0,
4,
WHEEL_SIZE,
18 * UI_DPI_FAC,
18 * UI_SCALE_FAC,
ptr,
prop,
-1,
@ -5730,7 +5730,7 @@ void uiTemplateColorPicker(uiLayout *layout,
0,
4,
WHEEL_SIZE,
18 * UI_DPI_FAC,
18 * UI_SCALE_FAC,
ptr,
prop,
-1,
@ -5750,7 +5750,7 @@ void uiTemplateColorPicker(uiLayout *layout,
0,
4,
WHEEL_SIZE,
18 * UI_DPI_FAC,
18 * UI_SCALE_FAC,
ptr,
prop,
-1,
@ -5772,7 +5772,7 @@ void uiTemplateColorPicker(uiLayout *layout,
"",
WHEEL_SIZE + 6,
0,
14 * UI_DPI_FAC,
14 * UI_SCALE_FAC,
WHEEL_SIZE,
ptr,
prop,
@ -6360,7 +6360,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);
@ -6371,7 +6371,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,
@ -6387,7 +6387,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,
@ -6411,7 +6411,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,
@ -6998,7 +6998,7 @@ int uiTemplateRecentFiles(uiLayout *layout, int rows)
uiItemFullO(layout,
"WM_OT_open_mainfile",
filename,
BKE_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)

View File

@ -221,7 +221,7 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g
navgroup->state.rect_visible = *rect_visible;
const float icon_size = GIZMO_SIZE;
const float icon_offset_mini = icon_size * GIZMO_MINI_OFFSET_FAC * UI_DPI_FAC;
const float icon_offset_mini = icon_size * GIZMO_MINI_OFFSET_FAC * UI_SCALE_FAC;
const float co[2] = {
roundf(rect_visible->xmax - (icon_offset_mini * 0.75f)),
roundf(rect_visible->ymax - (icon_offset_mini * 0.75f)),

View File

@ -976,8 +976,8 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
const bool zoom_to_pos = use_cursor_init && vzd->zoom_to_mouse_pos;
/* get amount to move view by */
float dx = RNA_float_get(op->ptr, "deltax") / U.dpi_fac;
float dy = RNA_float_get(op->ptr, "deltay") / U.dpi_fac;
float dx = RNA_float_get(op->ptr, "deltax") / UI_SCALE_FAC;
float dy = RNA_float_get(op->ptr, "deltay") / UI_SCALE_FAC;
/* Check if the 'timer' is initialized, as zooming with the trackpad
* never uses the "Continuous" zoom method, and the 'timer' is not initialized. */

View File

@ -145,7 +145,7 @@ void AbstractTreeViewItem::add_indent(uiLayout &row) const
uiLayout *subrow = uiLayoutRow(&row, true);
uiLayoutSetFixedSize(subrow, true);
const float indent_size = count_parents() * UI_DPI_ICON_SIZE;
const float indent_size = count_parents() * UI_ICON_SIZE;
uiDefBut(block, UI_BTYPE_SEPR, 0, "", 0, 0, indent_size, 0, nullptr, 0.0, 0.0, 0, 0, "");
/* Indent items without collapsing icon some more within their parent. Makes it clear that they

View File

@ -469,7 +469,8 @@ static void mask_draw_curve_type(const bContext *C,
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 */
immUniform4fv("color", colors[0]);
@ -806,7 +807,7 @@ void ED_mask_draw_frames(
int height = (frame == cfra) ? 22 : 10;
int x = (frame - sfra) * framelen;
immVertex2i(pos, x, region_bottom);
immVertex2i(pos, x, region_bottom + height * UI_DPI_FAC);
immVertex2i(pos, x, region_bottom + height * UI_SCALE_FAC);
}
immEnd();
immUnbindProgram();

View File

@ -66,7 +66,7 @@
/* Detect isolated holes and fill them. */
#define USE_NET_ISLAND_CONNECT
#define KMAXDIST (10 * U.dpi_fac) /* Max mouse distance from edge before not detecting it. */
#define KMAXDIST (10 * UI_SCALE_FAC) /* Max mouse distance from edge before not detecting it. */
/* WARNING: Knife float precision is fragile:
* Be careful before making changes here see: (#43229, #42864, #42459, #41164).
@ -495,7 +495,7 @@ static void knifetool_draw_visible_distances(const KnifeTool_OpData *kcd)
char numstr[256];
float numstr_size[2];
float posit[2];
const float bg_margin = 4.0f * U.dpi_fac;
const float bg_margin = 4.0f * UI_SCALE_FAC;
const float font_size = 14.0f;
const int distance_precision = 4;
@ -517,7 +517,7 @@ static void knifetool_draw_visible_distances(const KnifeTool_OpData *kcd)
}
BLF_enable(blf_mono_font, BLF_ROTATION);
BLF_size(blf_mono_font, font_size * U.dpi_fac);
BLF_size(blf_mono_font, font_size * UI_SCALE_FAC);
BLF_rotation(blf_mono_font, 0.0f);
BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
@ -563,9 +563,9 @@ static void knifetool_draw_angle(const KnifeTool_OpData *kcd,
{
const RegionView3D *rv3d = kcd->region->regiondata;
const int arc_steps = 24;
const float arc_size = 64.0f * U.dpi_fac;
const float bg_margin = 4.0f * U.dpi_fac;
const float cap_size = 4.0f * U.dpi_fac;
const float arc_size = 64.0f * UI_SCALE_FAC;
const float bg_margin = 4.0f * UI_SCALE_FAC;
const float cap_size = 4.0f * UI_SCALE_FAC;
const float font_size = 14.0f;
const int angle_precision = 3;
@ -647,7 +647,7 @@ static void knifetool_draw_angle(const KnifeTool_OpData *kcd,
}
BLF_enable(blf_mono_font, BLF_ROTATION);
BLF_size(blf_mono_font, font_size * U.dpi_fac);
BLF_size(blf_mono_font, font_size * UI_SCALE_FAC);
BLF_rotation(blf_mono_font, 0.0f);
BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
@ -907,7 +907,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
if (kcd->prev.vert) {
immUniformColor3ubv(kcd->colors.point);
GPU_point_size(11 * UI_DPI_FAC);
GPU_point_size(11 * UI_SCALE_FAC);
immBegin(GPU_PRIM_POINTS, 1);
immVertex3fv(pos, kcd->prev.cage);
@ -916,7 +916,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
if (kcd->prev.bmface || kcd->prev.edge) {
immUniformColor3ubv(kcd->colors.curpoint);
GPU_point_size(9 * UI_DPI_FAC);
GPU_point_size(9 * UI_SCALE_FAC);
immBegin(GPU_PRIM_POINTS, 1);
immVertex3fv(pos, kcd->prev.cage);
@ -925,7 +925,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
if (kcd->curr.vert) {
immUniformColor3ubv(kcd->colors.point);
GPU_point_size(11 * UI_DPI_FAC);
GPU_point_size(11 * UI_SCALE_FAC);
immBegin(GPU_PRIM_POINTS, 1);
immVertex3fv(pos, kcd->curr.cage);
@ -943,7 +943,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
if (kcd->curr.bmface || kcd->curr.edge) {
immUniformColor3ubv(kcd->colors.curpoint);
GPU_point_size(9 * UI_DPI_FAC);
GPU_point_size(9 * UI_SCALE_FAC);
immBegin(GPU_PRIM_POINTS, 1);
immVertex3fv(pos, kcd->curr.cage);
@ -984,7 +984,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
KnifeVert *kfv;
immUniformColor3ubv(kcd->colors.point);
GPU_point_size(5.0 * UI_DPI_FAC);
GPU_point_size(5.0 * UI_SCALE_FAC);
GPUBatch *batch = immBeginBatchAtMost(GPU_PRIM_POINTS, BLI_mempool_len(kcd->kverts));
@ -1040,7 +1040,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
/* Draw any snapped verts first. */
rgba_uchar_to_float(fcol, kcd->colors.point_a);
GPU_batch_uniform_4fv(batch, "color", fcol);
GPU_point_size(11 * UI_DPI_FAC);
GPU_point_size(11 * UI_SCALE_FAC);
if (snapped_verts_count > 0) {
GPU_batch_draw_range(batch, 0, snapped_verts_count);
}
@ -1048,7 +1048,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
/* Now draw the rest. */
rgba_uchar_to_float(fcol, kcd->colors.curpoint_a);
GPU_batch_uniform_4fv(batch, "color", fcol);
GPU_point_size(7 * UI_DPI_FAC);
GPU_point_size(7 * UI_SCALE_FAC);
if (other_verts_count > 0) {
GPU_batch_draw_range(batch, snapped_verts_count, other_verts_count);
}

View File

@ -354,7 +354,7 @@ static void voxel_size_edit_draw(const bContext *C, ARegion * /*region*/, void *
GPU_matrix_push();
GPU_matrix_mul(cd->text_mat);
BLF_size(fontid, 10.0f * fstyle_points * U.dpi_fac);
BLF_size(fontid, 10.0f * fstyle_points * UI_SCALE_FAC);
BLF_color3f(fontid, 1.0f, 1.0f, 1.0f);
BLF_width_and_height(fontid, str, strdrawlen, &strwidth, &strheight);
BLF_position(fontid, -0.5f * strwidth, -0.5f * strheight, 0.0f);

View File

@ -134,8 +134,8 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
int sizex, sizey;
BKE_render_resolution(&scene->r, false, &sizex, &sizey);
sizex += 30 * UI_DPI_FAC;
sizey += 60 * UI_DPI_FAC;
sizex += 30 * UI_SCALE_FAC;
sizey += 60 * UI_SCALE_FAC;
/* arbitrary... miniature image window views don't make much sense */
if (sizex < 320) {

View File

@ -183,7 +183,7 @@ static void area_draw_azone_fullscreen(short /*x1*/, short /*y1*/, short x2, sho
UI_icon_draw_ex(x2 - U.widget_unit,
y2 - U.widget_unit,
ICON_FULLSCREEN_EXIT,
U.inv_dpi_fac,
UI_INV_SCALE_FAC,
min_ff(alpha, 0.75f),
0.0f,
nullptr,
@ -359,7 +359,7 @@ static void region_draw_status_text(ScrArea *area, ARegion *region)
const float y = 0.4f * UI_UNIT_Y;
if (overlap) {
const float pad = 2.0f * UI_DPI_FAC;
const float pad = 2.0f * UI_SCALE_FAC;
const float x1 = x - (UI_UNIT_X - pad);
const float x2 = x + width + (UI_UNIT_X - pad);
const float y1 = pad;
@ -1301,13 +1301,13 @@ static void region_rect_recursive(
}
/* `prefsizex/y`, taking into account DPI. */
int prefsizex = UI_DPI_FAC *
int prefsizex = UI_SCALE_FAC *
((region->sizex > 1) ? region->sizex + 0.5f : region->type->prefsizex);
int prefsizey;
if (region->flag & RGN_FLAG_PREFSIZE_OR_HIDDEN) {
prefsizex = UI_DPI_FAC * region->type->prefsizex;
prefsizey = UI_DPI_FAC * region->type->prefsizey;
prefsizex = UI_SCALE_FAC * region->type->prefsizex;
prefsizey = UI_SCALE_FAC * region->type->prefsizey;
}
else if (region->regiontype == RGN_TYPE_HEADER) {
prefsizey = ED_area_headersize();
@ -1322,7 +1322,8 @@ static void region_rect_recursive(
prefsizey = ED_region_global_size_y();
}
else {
prefsizey = UI_DPI_FAC * (region->sizey > 1 ? region->sizey + 0.5f : region->type->prefsizey);
prefsizey = UI_SCALE_FAC *
(region->sizey > 1 ? region->sizey + 0.5f : region->type->prefsizey);
}
if (region->flag & RGN_FLAG_HIDDEN) {
@ -1510,12 +1511,12 @@ static void region_rect_recursive(
region->winy = BLI_rcti_size_y(&region->winrct) + 1;
/* If region opened normally, we store this for hide/reveal usage. */
/* Prevent rounding errors for UI_DPI_FAC multiply and divide. */
/* Prevent rounding errors for UI_SCALE_FAC multiply and divide. */
if (region->winx > 1) {
region->sizex = (region->winx + 0.5f) / UI_DPI_FAC;
region->sizex = (region->winx + 0.5f) / UI_SCALE_FAC;
}
if (region->winy > 1) {
region->sizey = (region->winy + 0.5f) / UI_DPI_FAC;
region->sizey = (region->winy + 0.5f) / UI_SCALE_FAC;
}
/* exception for multiple overlapping regions on same spot */
@ -3024,8 +3025,8 @@ void ED_region_panels_layout_ex(const bContext *C,
Panel *panel = static_cast<Panel *>(region->panels.last);
if (panel != nullptr) {
const int size_dyn[2] = {
int(UI_UNIT_X * (UI_panel_is_closed(panel) ? 8 : 14) / UI_DPI_FAC),
int(UI_panel_size_y(panel) / UI_DPI_FAC),
int(UI_UNIT_X * (UI_panel_is_closed(panel) ? 8 : 14) / UI_SCALE_FAC),
int(UI_panel_size_y(panel) / UI_SCALE_FAC),
};
/* region size is layout based and needs to be updated */
if ((region->sizex != size_dyn[0]) || (region->sizey != size_dyn[1])) {
@ -3033,7 +3034,7 @@ void ED_region_panels_layout_ex(const bContext *C,
region->sizey = size_dyn[1];
area->flag |= AREA_FLAG_REGION_SIZE_UPDATE;
}
y = fabsf(region->sizey * UI_DPI_FAC - 1);
y = fabsf(region->sizey * UI_SCALE_FAC - 1);
}
}
else {
@ -3288,7 +3289,7 @@ void ED_region_header_layout(const bContext *C, ARegion *region)
bool region_layout_based = region->flag & RGN_FLAG_DYNAMIC_SIZE;
/* Height of buttons and scaling needed to achieve it. */
const int buttony = min_ii(UI_UNIT_Y, region->winy - 2 * UI_DPI_FAC);
const int buttony = min_ii(UI_UNIT_Y, region->winy - 2 * UI_SCALE_FAC);
const float buttony_scale = buttony / float(UI_UNIT_Y);
/* Vertically center buttons. */
@ -3342,7 +3343,7 @@ void ED_region_header_layout(const bContext *C, ARegion *region)
maxco = xco;
}
int new_sizex = (maxco + UI_HEADER_OFFSET) / UI_DPI_FAC;
int new_sizex = (maxco + UI_HEADER_OFFSET) / UI_SCALE_FAC;
if (region_layout_based && (region->sizex != new_sizex)) {
/* region size is layout based and needs to be updated */
@ -3402,7 +3403,7 @@ void ED_region_header_init(ARegion *region)
int ED_area_headersize(void)
{
/* Accommodate widget and padding. */
return U.widget_unit + int(UI_DPI_FAC * HEADER_PADDING_Y);
return U.widget_unit + int(UI_SCALE_FAC * HEADER_PADDING_Y);
}
int ED_area_footersize(void)
@ -3413,17 +3414,17 @@ int ED_area_footersize(void)
int ED_area_global_size_y(const ScrArea *area)
{
BLI_assert(ED_area_is_global(area));
return round_fl_to_int(area->global->cur_fixed_height * UI_DPI_FAC);
return round_fl_to_int(area->global->cur_fixed_height * UI_SCALE_FAC);
}
int ED_area_global_min_size_y(const ScrArea *area)
{
BLI_assert(ED_area_is_global(area));
return round_fl_to_int(area->global->size_min * UI_DPI_FAC);
return round_fl_to_int(area->global->size_min * UI_SCALE_FAC);
}
int ED_area_global_max_size_y(const ScrArea *area)
{
BLI_assert(ED_area_is_global(area));
return round_fl_to_int(area->global->size_max * UI_DPI_FAC);
return round_fl_to_int(area->global->size_max * UI_SCALE_FAC);
}
bool ED_area_is_global(const ScrArea *area)
@ -3510,7 +3511,7 @@ void ED_region_info_draw_multiline(ARegion *region,
rcti rect = *ED_region_visible_rect(region);
/* Needed in case scripts leave the font size at an unexpected value, see: #102213. */
BLF_size(fontid, style->widget.points * U.dpi_fac);
BLF_size(fontid, style->widget.points * UI_SCALE_FAC);
/* Box fill entire width or just around text. */
if (!full_redraw) {
@ -3764,7 +3765,7 @@ void ED_region_cache_draw_background(ARegion *region)
immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformColor4ub(128, 128, 255, 64);
immRecti(pos, 0, region_bottom, region->winx, region_bottom + 8 * UI_DPI_FAC);
immRecti(pos, 0, region_bottom, region->winx, region_bottom + 8 * UI_SCALE_FAC);
immUnbindProgram();
}
@ -3776,7 +3777,7 @@ void ED_region_cache_draw_curfra_label(const int framenr, const float x, const f
float font_dims[2] = {0.0f, 0.0f};
/* frame number */
BLF_size(fontid, 11.0f * U.dpi_fac);
BLF_size(fontid, 11.0f * UI_SCALE_FAC);
BLI_snprintf(numstr, sizeof(numstr), "%d", framenr);
BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
@ -3810,7 +3811,7 @@ void ED_region_cache_draw_cached_segments(
float x1 = float(points[a * 2] - sfra) / (efra - sfra + 1) * region->winx;
float x2 = float(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * region->winx;
immRecti(pos, x1, region_bottom, x2, region_bottom + 8 * UI_DPI_FAC);
immRecti(pos, x1, region_bottom, x2, region_bottom + 8 * UI_SCALE_FAC);
/* TODO(merwin): use primitive restart to draw multiple rects more efficiently */
}

View File

@ -629,8 +629,8 @@ int ED_draw_imbuf_method(ImBuf *ibuf)
void immDrawBorderCorners(uint pos, const rcti *border, float zoomx, float zoomy)
{
float delta_x = 4.0f * UI_DPI_FAC / zoomx;
float delta_y = 4.0f * UI_DPI_FAC / zoomy;
float delta_x = 4.0f * UI_SCALE_FAC / zoomx;
float delta_y = 4.0f * UI_SCALE_FAC / zoomy;
delta_x = min_ff(delta_x, border->xmax - border->xmin);
delta_y = min_ff(delta_y, border->ymax - border->ymin);

View File

@ -1064,7 +1064,7 @@ static void screen_global_area_refresh(wmWindow *win,
static int screen_global_header_size(void)
{
return (int)ceilf(ED_area_headersize() / UI_DPI_FAC);
return (int)ceilf(ED_area_headersize() / UI_SCALE_FAC);
}
static void screen_global_topbar_area_refresh(wmWindow *win, bScreen *screen)

View File

@ -284,7 +284,7 @@ short screen_geom_find_area_split_point(const ScrArea *area,
{
const int cur_area_width = screen_geom_area_width(area);
const int cur_area_height = screen_geom_area_height(area);
const short area_min_x = AREAMINX * U.dpi_fac;
const short area_min_x = AREAMINX * UI_SCALE_FAC;
const short area_min_y = ED_area_headersize();
/* area big enough? */

View File

@ -46,13 +46,13 @@ typedef enum eScreenAxis {
#define AZONEFADEOUT (6.5f * U.widget_unit) /* when we start seeing the #AZone */
/* Edges must be within these to allow joining. */
#define AREAJOINTOLERANCEX (AREAMINX * U.dpi_fac)
#define AREAJOINTOLERANCEY (HEADERY * U.dpi_fac)
#define AREAJOINTOLERANCEX (AREAMINX * UI_SCALE_FAC)
#define AREAJOINTOLERANCEY (HEADERY * UI_SCALE_FAC)
/**
* Expanded interaction influence of area borders.
*/
#define BORDERPADDING ((2.0f * U.dpi_fac) + U.pixelsize)
#define BORDERPADDING ((2.0f * UI_SCALE_FAC) + U.pixelsize)
/* area.cc */

View File

@ -1207,7 +1207,7 @@ static ScrEdge *screen_area_edge_from_cursor(const bContext *C,
if (actedge == NULL) {
return NULL;
}
int borderwidth = (4 * UI_DPI_FAC);
int borderwidth = (4 * UI_SCALE_FAC);
ScrArea *sa1, *sa2;
if (screen_geom_edge_is_horizontal(actedge)) {
sa1 = BKE_screen_find_area_xy(
@ -1638,7 +1638,7 @@ static void area_move_set_limits(wmWindow *win,
}
}
else {
int areamin = AREAMINX * U.dpi_fac;
int areamin = AREAMINX * UI_SCALE_FAC;
if (area->v1->vec.x > window_rect.xmin) {
areamin += U.pixelsize;
@ -1847,7 +1847,7 @@ static void area_move_apply_do(const bContext *C,
if (area->v1->editflag || area->v2->editflag || area->v3->editflag || area->v4->editflag) {
if (ED_area_is_global(area)) {
/* Snap to minimum or maximum for global areas. */
int height = round_fl_to_int(screen_geom_area_height(area) / UI_DPI_FAC);
int height = round_fl_to_int(screen_geom_area_height(area) / UI_SCALE_FAC);
if (abs(height - area->global->size_min) < abs(height - area->global->size_max)) {
area->global->cur_fixed_height = area->global->size_min;
}
@ -2061,7 +2061,7 @@ static bool area_split_allowed(const ScrArea *area, const eScreenAxis dir_axis)
return false;
}
if ((dir_axis == SCREEN_AXIS_V && area->winx <= 2 * AREAMINX * U.dpi_fac) ||
if ((dir_axis == SCREEN_AXIS_V && area->winx <= 2 * AREAMINX * UI_SCALE_FAC) ||
(dir_axis == SCREEN_AXIS_H && area->winy <= 2 * ED_area_headersize())) {
/* Must be at least double minimum sizes to split into two. */
return false;
@ -2639,7 +2639,7 @@ static int area_max_regionsize(ScrArea *area, ARegion *scale_region, AZEdge edge
}
}
dist /= UI_DPI_FAC;
dist /= UI_SCALE_FAC;
return dist;
}
@ -2731,7 +2731,7 @@ static void region_scale_validate_size(RegionMoveData *rmd)
size = &rmd->region->sizey;
}
maxsize = rmd->maxsize - (UI_UNIT_Y / UI_DPI_FAC);
maxsize = rmd->maxsize - (UI_UNIT_Y / UI_SCALE_FAC);
if (*size > maxsize && maxsize > 0) {
*size = maxsize;
@ -2781,7 +2781,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
/* region sizes now get multiplied */
delta /= UI_DPI_FAC;
delta /= UI_SCALE_FAC;
const int size_no_snap = rmd->origval + delta;
rmd->region->sizex = size_no_snap;
@ -2814,7 +2814,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
/* region sizes now get multiplied */
delta /= UI_DPI_FAC;
delta /= UI_SCALE_FAC;
const int size_no_snap = rmd->origval + delta;
rmd->region->sizey = size_no_snap;
@ -5044,8 +5044,8 @@ static int userpref_show_exec(bContext *C, wmOperator *op)
wmWindow *win_cur = CTX_wm_window(C);
/* Use eventstate, not event from _invoke, so this can be called through exec(). */
const wmEvent *event = win_cur->eventstate;
int sizex = (500 + UI_NAVIGATION_REGION_WIDTH) * UI_DPI_FAC;
int sizey = 520 * UI_DPI_FAC;
int sizex = (500 + UI_NAVIGATION_REGION_WIDTH) * UI_SCALE_FAC;
int sizey = 520 * UI_SCALE_FAC;
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "section");
if (prop && RNA_property_is_set(op->ptr, prop)) {
@ -5124,8 +5124,8 @@ static int drivers_editor_show_exec(bContext *C, wmOperator *op)
/* Use eventstate, not event from _invoke, so this can be called through exec(). */
const wmEvent *event = win_cur->eventstate;
int sizex = 900 * UI_DPI_FAC;
int sizey = 580 * UI_DPI_FAC;
int sizex = 900 * UI_SCALE_FAC;
int sizey = 580 * UI_SCALE_FAC;
/* Get active property to show driver for
* - Need to grab it first, or else this info disappears
@ -5201,8 +5201,8 @@ static int info_log_show_exec(bContext *C, wmOperator *op)
wmWindow *win_cur = CTX_wm_window(C);
/* Use eventstate, not event from _invoke, so this can be called through exec(). */
const wmEvent *event = win_cur->eventstate;
int sizex = 900 * UI_DPI_FAC;
int sizey = 580 * UI_DPI_FAC;
int sizex = 900 * UI_SCALE_FAC;
int sizey = 580 * UI_SCALE_FAC;
int shift_y = 480;
/* changes context! */

View File

@ -1508,7 +1508,7 @@ static int sculpt_cloth_filter_modal(bContext *C, wmOperator *op, const wmEvent
}
const float len = event->prev_press_xy[0] - event->xy[0];
filter_strength = filter_strength * -len * 0.001f * UI_DPI_FAC;
filter_strength = filter_strength * -len * 0.001f * UI_SCALE_FAC;
SCULPT_vertex_random_access_ensure(ss);

View File

@ -810,7 +810,7 @@ static void sculpt_mesh_update_strength(wmOperator *op,
{
const float len = prev_press_mouse[0] - mouse[0];
float filter_strength = ss->filter_cache->start_filter_strength * -len * 0.001f * UI_DPI_FAC;
float filter_strength = ss->filter_cache->start_filter_strength * -len * 0.001f * UI_SCALE_FAC;
RNA_float_set(op->ptr, "strength", filter_strength);
}
static void sculpt_mesh_filter_apply_with_history(bContext *C, wmOperator *op)

View File

@ -645,7 +645,7 @@ void timeline_draw_cache(SpaceAction *saction, Object *ob, Scene *scene)
/* Iterate over pointcaches on the active object, and draw each one's range. */
float y_offset = 0.0f;
const float cache_draw_height = 4.0f * UI_DPI_FAC * U.pixelsize;
const float cache_draw_height = 4.0f * UI_SCALE_FAC * U.pixelsize;
LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) {
if (timeline_cache_is_hidden_by_setting(saction, pid)) {
continue;

View File

@ -340,7 +340,7 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *region)
/* second pass: text */
y = float(CHANNEL_FIRST);
BLF_size(fontid, 11.0f * U.dpi_fac);
BLF_size(fontid, 11.0f * UI_SCALE_FAC);
LISTBASE_FOREACH (MovieTrackingDopesheetChannel *, channel, &dopesheet->channels) {
float yminc = float(y - CHANNEL_HEIGHT_HALF);

View File

@ -59,11 +59,11 @@ static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int wid
if (width == 1) {
immBegin(GPU_PRIM_LINES, 2);
immVertex2i(pos, x, 0);
immVertex2i(pos, x, height * UI_DPI_FAC);
immVertex2i(pos, x, height * UI_SCALE_FAC);
immEnd();
}
else {
immRecti(pos, x, 0, x + width, height * UI_DPI_FAC);
immRecti(pos, x, 0, x + width, height * UI_SCALE_FAC);
}
}
@ -191,7 +191,7 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *region, MovieClip *clip
(i - sfra + clip->start_frame - 1) * framelen,
0,
(i - sfra + clip->start_frame) * framelen,
4 * UI_DPI_FAC);
4 * UI_SCALE_FAC);
}
}
}
@ -223,7 +223,7 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *region, MovieClip *clip
(i - sfra + clip->start_frame - 1) * framelen,
0,
(i - sfra + clip->start_frame) * framelen,
8 * UI_DPI_FAC);
8 * UI_SCALE_FAC);
}
}
}
@ -234,11 +234,11 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *region, MovieClip *clip
x = (sc->user.framenr - sfra) / (efra - sfra + 1) * region->winx;
immUniformThemeColor(TH_CFRAME);
immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_SCALE_FAC);
immUnbindProgram();
ED_region_cache_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC);
ED_region_cache_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_SCALE_FAC);
pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
@ -368,7 +368,8 @@ static void draw_stabilization_border(
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", 0); /* "simple" mode */
immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f);
@ -743,7 +744,7 @@ static void draw_marker_areas(SpaceClip *sc,
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", 0); /* "simple" mode */
@ -954,11 +955,11 @@ static void draw_marker_slide_zones(SpaceClip *sc,
dy = 6.0f / height / sc->zoom;
side = get_shortest_pattern_side(marker);
patdx = min_ff(dx * 2.0f / 3.0f, side / 6.0f) * UI_DPI_FAC;
patdy = min_ff(dy * 2.0f / 3.0f, side * width / height / 6.0f) * UI_DPI_FAC;
patdx = min_ff(dx * 2.0f / 3.0f, side / 6.0f) * UI_SCALE_FAC;
patdy = min_ff(dy * 2.0f / 3.0f, side * width / height / 6.0f) * UI_SCALE_FAC;
searchdx = min_ff(dx, (marker->search_max[0] - marker->search_min[0]) / 6.0f) * UI_DPI_FAC;
searchdy = min_ff(dy, (marker->search_max[1] - marker->search_min[1]) / 6.0f) * UI_DPI_FAC;
searchdx = min_ff(dx, (marker->search_max[0] - marker->search_min[0]) / 6.0f) * UI_SCALE_FAC;
searchdy = min_ff(dy, (marker->search_max[1] - marker->search_min[1]) / 6.0f) * UI_SCALE_FAC;
px[0] = 1.0f / sc->zoom / width / sc->scale;
px[1] = 1.0f / sc->zoom / height / sc->scale;
@ -1035,7 +1036,7 @@ static void draw_marker_texts(SpaceClip *sc,
return;
}
BLF_size(fontid, 11.0f * U.dpi_fac);
BLF_size(fontid, 11.0f * UI_SCALE_FAC);
fontsize = BLF_height_max(fontid);
if (marker->flag & MARKER_DISABLED) {
@ -1288,7 +1289,8 @@ static void draw_plane_marker_ex(SpaceClip *sc,
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", 0); /* "simple" mode */

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