Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_brush.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_brush.c57
1 files changed, 35 insertions, 22 deletions
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index c35b64de991..d877ea03c5d 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -44,6 +44,8 @@
#include "BLI_rand.h"
#include "BLI_utildefines.h"
+#include "PIL_time.h"
+
#include "BLT_translation.h"
#include "DNA_scene_types.h"
@@ -74,8 +76,9 @@
#include "ED_screen.h"
#include "ED_view3d.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_state.h"
#include "gpencil_intern.h"
@@ -138,6 +141,8 @@ typedef struct tGP_BrushEditData {
/* Timer for in-place accumulation of brush effect */
wmTimer *timer;
bool timerTick; /* is this event from a timer */
+
+ RNG *rng;
} tGP_BrushEditData;
@@ -404,7 +409,7 @@ static void gp_brush_grab_calc_dvec(tGP_BrushEditData *gso)
if (gso->sa->spacetype == SPACE_VIEW3D) {
View3D *v3d = gso->sa->spacedata.first;
RegionView3D *rv3d = gso->ar->regiondata;
- float *rvec = ED_view3d_cursor3d_get(gso->scene, v3d);
+ float *rvec = ED_view3d_cursor3d_get(gso->scene, v3d)->location;
float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
float mval_f[2];
@@ -504,7 +509,7 @@ static void gp_brush_calc_midpoint(tGP_BrushEditData *gso)
*/
View3D *v3d = gso->sa->spacedata.first;
RegionView3D *rv3d = gso->ar->regiondata;
- float *rvec = ED_view3d_cursor3d_get(gso->scene, v3d);
+ float *rvec = ED_view3d_cursor3d_get(gso->scene, v3d)->location;
float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
float mval_f[2] = {UNPACK2(gso->mval)};
@@ -658,7 +663,7 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso, bGPDstroke *gps, in
* as well as the strength of the brush
*/
const float inf = gp_brush_influence_calc(gso, radius, co) / 2.0f;
- const float fac = BLI_frand() * inf;
+ const float fac = BLI_rng_get_float(gso->rng) * inf;
/* need one flag enabled by default */
if ((gso->settings->flag & (GP_BRUSHEDIT_FLAG_APPLY_POSITION |
GP_BRUSHEDIT_FLAG_APPLY_STRENGTH |
@@ -685,7 +690,7 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso, bGPDstroke *gps, in
svec[1] = mvec[0];
/* scale the displacement by the random displacement, and apply */
- if (BLI_frand() > 0.5f) {
+ if (BLI_rng_get_float(gso->rng) > 0.5f) {
mul_v2_fl(svec, -fac);
}
else {
@@ -724,7 +729,7 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso, bGPDstroke *gps, in
}
/* apply random to strength */
if (gso->settings->flag & GP_BRUSHEDIT_FLAG_APPLY_STRENGTH) {
- if (BLI_frand() > 0.5f) {
+ if (BLI_rng_get_float(gso->rng) > 0.5f) {
pt->strength += fac;
}
else {
@@ -735,7 +740,7 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso, bGPDstroke *gps, in
}
/* apply random to thickness (use pressure) */
if (gso->settings->flag & GP_BRUSHEDIT_FLAG_APPLY_THICKNESS) {
- if (BLI_frand() > 0.5f) {
+ if (BLI_rng_get_float(gso->rng) > 0.5f) {
pt->pressure += fac;
}
else {
@@ -980,26 +985,26 @@ static void gp_brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customda
GP_EditBrush_Data *brush = gpsculpt_get_brush(CTX_data_scene(C));
if (brush) {
- glPushMatrix();
-
- glTranslatef((float)x, (float)y, 0.0f);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
+ GPU_line_smooth(true);
+ GPU_blend(true);
/* Inner Ring: Light color for action of the brush */
/* TODO: toggle between add and remove? */
- glColor4ub(255, 255, 255, 200);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, brush->size, 40);
+ immUniformColor4ub(255, 255, 255, 200);
+ imm_draw_circle_wire_2d(pos, x, y, brush->size, 40);
/* Outer Ring: Dark color for contrast on light backgrounds (e.g. gray on white) */
- glColor3ub(30, 30, 30);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, brush->size + 1, 40);
+ immUniformColor3ub(30, 30, 30);
+ imm_draw_circle_wire_2d(pos, x, y, brush->size + 1, 40);
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
+ immUnbindProgram();
- glPopMatrix();
+ GPU_blend(false);
+ GPU_line_smooth(false);
}
}
@@ -1038,7 +1043,7 @@ static void gpsculpt_brush_header_set(bContext *C, tGP_BrushEditData *gso)
" | Shift-Wheel Up/Down for Strength"),
(brush_name) ? brush_name : "<?>");
- ED_area_headerprint(CTX_wm_area(C), str);
+ ED_workspace_status_text(C, str);
}
/* ************************************************ */
@@ -1061,6 +1066,10 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op)
gso->brush_type = gso->settings->brushtype;
+ /* Random generator, only init once. */
+ uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
+ rng_seed ^= GET_UINT_FROM_POINTER(gso);
+ gso->rng = BLI_rng_new(rng_seed);
gso->is_painting = false;
gso->first = true;
@@ -1163,8 +1172,12 @@ static void gpsculpt_brush_exit(bContext *C, wmOperator *op)
WM_event_remove_timer(CTX_wm_manager(C), win, gso->timer);
}
+ if (gso->rng != NULL) {
+ BLI_rng_free(gso->rng);
+ }
+
/* disable cursor and headerprints */
- ED_area_headerprint(CTX_wm_area(C), NULL);
+ ED_workspace_status_text(C, NULL);
WM_cursor_modal_restore(win);
gpencil_toggle_brush_cursor(C, false);