Blender V5.3
annotate_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cfloat>
10#include <cmath>
11#include <cstdlib>
12#include <cstring>
13
14#include "BLI_sys_types.hh"
15
16#include "BLI_listbase.hh"
17#include "BLI_math_vector_c.hh"
18#include "BLI_utildefines.hh"
19
21#include "DNA_scene_types.h"
22#include "DNA_screen_types.h"
23#include "DNA_space_types.h"
24#include "DNA_userdef_types.h"
25#include "DNA_view3d_types.h"
26
27#include "BKE_annotations.h"
28#include "BKE_camera.h"
29#include "BKE_context.hh"
30#include "BKE_global.hh"
31
32#include "WM_api.hh"
33
34#include "GPU_immediate.hh"
35#include "GPU_matrix.hh"
36#include "GPU_state.hh"
37
38#include "ED_gpencil_legacy.hh"
39#include "ED_screen.hh"
40#include "ED_view3d.hh"
41
42#include "UI_resources.hh"
43
44namespace blender {
45
46/* ************************************************** */
47/* GREASE PENCIL DRAWING */
48
49/* ----- General Defines ------ */
50/* flags for sflag */
67
68/* ----- Tool Buffer Drawing ------ */
69
71 const float *corner_point,
72 const float *arrow_coords,
73 const int arrow_style)
74{
76
77 switch (arrow_style) {
79 immVertex2f(pos, arrow_coords[0], arrow_coords[1]);
80 immVertex2f(pos, arrow_coords[2], arrow_coords[3]);
81 break;
83 immVertex2f(pos, arrow_coords[0], arrow_coords[1]);
84 immVertex2f(pos, arrow_coords[2], arrow_coords[3]);
85 immVertex2f(pos, arrow_coords[4], arrow_coords[5]);
86 immVertex2f(pos, arrow_coords[0], arrow_coords[1]);
87 break;
89 immVertex2f(pos, arrow_coords[0], arrow_coords[1]);
90 immVertex2f(pos, corner_point[0], corner_point[1]);
91 immVertex2f(pos, arrow_coords[2], arrow_coords[3]);
92 break;
94 immVertex2f(pos, corner_point[0], corner_point[1]);
95 immVertex2f(pos, arrow_coords[0], arrow_coords[1]);
96 immVertex2f(pos, arrow_coords[4], arrow_coords[5]);
97 immVertex2f(pos, arrow_coords[6], arrow_coords[7]);
98 immVertex2f(pos, arrow_coords[2], arrow_coords[3]);
99 immVertex2f(pos, corner_point[0], corner_point[1]);
100 break;
101 default:
102 break;
103 }
104 immEnd();
105}
106
111 short thickness,
112 short dflag,
113 const float ink[4])
114{
116 const tGPspoint *points = static_cast<const tGPspoint *>(runtime.sbuffer);
117 int totpoints = runtime.sbuffer_used;
118 short sflag = runtime.sbuffer_sflag;
119
120 int draw_points = 0;
121
122 /* error checking */
123 if ((points == nullptr) || (totpoints <= 0)) {
124 return;
125 }
126
127 /* check if buffer can be drawn */
128 if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D)) {
129 return;
130 }
131
132 if (sflag & GP_STROKE_ERASER) {
133 /* don't draw stroke at all! */
134 return;
135 }
136
137 GPUVertFormat *format = immVertexFormat();
138 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
139
140 const tGPspoint *pt = points;
141
142 if (totpoints == 1) {
143 /* if drawing a single point, draw it larger */
144 GPU_point_size(float(thickness + 2) * points->pressure);
146 immUniformColor3fvAlpha(ink, ink[3]);
148 immVertex2fv(pos, pt->m_xy);
149 }
150 else {
151 float oldpressure = points[0].pressure;
152
153 /* draw stroke curve */
155
156 float viewport[4];
157 GPU_viewport_size_get_f(viewport);
158 immUniform2fv("viewportSize", &viewport[2]);
159
160 immUniform1f("lineWidth", max_ff(oldpressure * thickness, 1.0) * U.pixelsize);
161
162 immUniformColor3fvAlpha(ink, ink[3]);
163
165
166 for (int i = 0; i < totpoints; i++, pt++) {
167 /* If there was a significant pressure change,
168 * stop the curve, change the thickness of the stroke,
169 * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP).
170 */
171 if (fabsf(pt->pressure - oldpressure) > 0.2f) {
172 /* need to have 2 points to avoid immEnd assert error */
173 if (draw_points < 2) {
174 immVertex2fv(pos, (pt - 1)->m_xy);
175 }
176
177 immEnd();
178 draw_points = 0;
179
180 immUniform1f("lineWidth", max_ff(pt->pressure * thickness, 1.0) * U.pixelsize);
181 immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints - i + 1);
182
183 /* need to roll-back one point to ensure that there are no gaps in the stroke */
184 if (i != 0) {
185 immVertex2fv(pos, (pt - 1)->m_xy);
186 draw_points++;
187 }
188
189 oldpressure = pt->pressure; /* reset our threshold */
190 }
191
192 /* now the point we want */
193 immVertex2fv(pos, pt->m_xy);
194 draw_points++;
195 }
196 /* need to have 2 points to avoid immEnd assert error */
197 if (draw_points < 2) {
198 immVertex2fv(pos, (pt - 1)->m_xy);
199 }
200 }
201
202 immEnd();
203
204 /* Draw arrow stroke. */
205 if (totpoints > 1) {
206 /* Draw ending arrow stroke. */
207 if ((sflag & GP_STROKE_USE_ARROW_END) &&
209 {
210 float end[2];
211 copy_v2_v2(end, points[1].m_xy);
213 }
214 /* Draw starting arrow stroke. */
215 if ((sflag & GP_STROKE_USE_ARROW_START) &&
217 {
218 float start[2];
219 copy_v2_v2(start, points[0].m_xy);
221 pos, start, runtime.arrow_start, runtime.arrow_start_style);
222 }
223 }
224
226}
227
228/* --------- 2D Stroke Drawing Helpers --------- */
229/* change in parameter list */
231 const float pt[3], short sflag, int offsx, int offsy, int winx, int winy, float r_co[2])
232{
233 if (sflag & GP_STROKE_2DSPACE) {
234 r_co[0] = pt[0];
235 r_co[1] = pt[1];
236 }
237 else if (sflag & GP_STROKE_2DIMAGE) {
238 const float x = float((pt[0] * winx) + offsx);
239 const float y = float((pt[1] * winy) + offsy);
240
241 r_co[0] = x;
242 r_co[1] = y;
243 }
244 else {
245 const float x = float(pt[0] / 100 * winx) + offsx;
246 const float y = float(pt[1] / 100 * winy) + offsy;
247
248 r_co[0] = x;
249 r_co[1] = y;
250 }
251}
252
253/* ----- Existing Strokes Drawing (3D and Point) ------ */
254
255/* draw a given stroke - just a single dot (only one point) */
256static void annotation_draw_stroke_point(const bGPDspoint *points,
257 short thickness,
258 short sflag,
259 int offsx,
260 int offsy,
261 int winx,
262 int winy,
263 const float ink[4])
264{
265 const bGPDspoint *pt = points;
266
267 /* get final position using parent matrix */
268 float fpt[3];
269 copy_v3_v3(fpt, &pt->x);
270
271 GPUVertFormat *format = immVertexFormat();
272 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
273
274 if (sflag & GP_STROKE_3DSPACE) {
276 }
277 else {
279
280 /* get 2D coordinates of point */
281 float co[3] = {0.0f};
282 annotation_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co);
283 copy_v3_v3(fpt, co);
284 }
285
286 /* set color */
287 immUniformColor3fvAlpha(ink, ink[3]);
288
289 /* set point thickness (since there's only one of these) */
290 immUniform1f("size", float(thickness + 2) * pt->pressure);
291
293 immVertex3fv(pos, fpt);
294 immEnd();
295
297}
298
303 const bGPDspoint *points, int totpoints, short thickness, const float ink[4], bool cyclic)
304{
305 float curpressure = points[0].pressure;
306 float cyclic_fpt[3];
307 int draw_points = 0;
308
309 /* if cyclic needs one vertex more */
310 int cyclic_add = 0;
311 if (cyclic) {
312 cyclic_add++;
313 }
314
315 GPUVertFormat *format = immVertexFormat();
316 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
317
319
320 float viewport[4];
321 GPU_viewport_size_get_f(viewport);
322 immUniform2fv("viewportSize", &viewport[2]);
323
324 immUniform1f("lineWidth", max_ff(curpressure * thickness, 1.0) * U.pixelsize);
325
326 immUniformColor3fvAlpha(ink, ink[3]);
327
328 /* draw stroke curve */
329 immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints + cyclic_add);
330 const bGPDspoint *pt = points;
331 for (int i = 0; i < totpoints; i++, pt++) {
332 /* If there was a significant pressure change, stop the curve,
333 * change the thickness of the stroke, and continue drawing again
334 * (since line-width cannot change in middle of GL_LINE_STRIP)
335 * NOTE: we want more visible levels of pressures when thickness is bigger.
336 */
337 if (fabsf(pt->pressure - curpressure) > 0.2f / float(thickness)) {
338 /* if the pressure changes before get at least 2 vertices,
339 * need to repeat last point to avoid assert in immEnd() */
340 if (draw_points < 2) {
341 const bGPDspoint *pt2 = pt - 1;
342 immVertex3fv(pos, &pt2->x);
343 }
344 immEnd();
345 draw_points = 0;
346
347 curpressure = pt->pressure;
348 immUniform1f("lineWidth", max_ff(curpressure * thickness, 1.0) * U.pixelsize);
349 immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints - i + 1 + cyclic_add);
350
351 /* need to roll-back one point to ensure that there are no gaps in the stroke */
352 if (i != 0) {
353 const bGPDspoint *pt2 = pt - 1;
354 immVertex3fv(pos, &pt2->x);
355 draw_points++;
356 }
357 }
358
359 /* now the point we want */
360 immVertex3fv(pos, &pt->x);
361 draw_points++;
362
363 if (cyclic && i == 0) {
364 /* save first point to use in cyclic */
365 copy_v3_v3(cyclic_fpt, &pt->x);
366 }
367 }
368
369 if (cyclic) {
370 /* draw line to first point to complete the cycle */
371 immVertex3fv(pos, cyclic_fpt);
372 draw_points++;
373 }
374
375 /* if less of two points, need to repeat last point to avoid assert in immEnd() */
376 if (draw_points < 2) {
377 const bGPDspoint *pt2 = pt - 1;
378 immVertex3fv(pos, &pt2->x);
379 }
380
381 immEnd();
383}
384
385/* Draw a given stroke in 2d. */
386static void annotation_draw_stroke_2d(const bGPDspoint *points,
387 int totpoints,
388 short thickness_s,
389 short sflag,
390 int offsx,
391 int offsy,
392 int winx,
393 int winy,
394 const float ink[4])
395{
396 if (totpoints == 0) {
397 return;
398 }
399 float thickness = float(thickness_s);
400
401 GPUVertFormat *format = immVertexFormat();
402 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
403
404 const bGPDspoint *pt;
405 const bGPDspoint *pt_prev;
406 int draw_points = 0;
407 float co[2];
408 float oldpressure = points[0].pressure;
409 if (totpoints == 1) {
410 /* if drawing a single point, draw it larger */
411 GPU_point_size(float(thickness + 2) * points->pressure);
413 immUniformColor3fvAlpha(ink, ink[3]);
415
416 annotation_calc_2d_stroke_fxy(&points->x, sflag, offsx, offsy, winx, winy, co);
417 immVertex2fv(pos, co);
418 }
419 else {
420 /* draw stroke curve */
422 immUniformColor3fvAlpha(ink, ink[3]);
423
424 float viewport[4];
425 GPU_viewport_size_get_f(viewport);
426 immUniform2fv("viewportSize", &viewport[2]);
427
428 immUniform1f("lineWidth", max_ff(oldpressure * thickness, 1.0) * U.pixelsize);
429
431
432 for (int i = 0; i < totpoints; i++) {
433 pt = &points[i];
434 /* If there was a significant pressure change,
435 * stop the curve, change the thickness of the stroke,
436 * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP).
437 */
438 if (fabsf(pt->pressure - oldpressure) > 0.2f) {
439 /* need to have 2 points to avoid immEnd assert error */
440 if (draw_points < 2) {
441 pt_prev = &points[i - 1];
442 annotation_calc_2d_stroke_fxy(&pt_prev->x, sflag, offsx, offsy, winx, winy, co);
443 immVertex2fv(pos, co);
444 }
445
446 immEnd();
447 draw_points = 0;
448
449 immUniform1f("lineWidth", max_ff(pt->pressure * thickness, 1.0) * U.pixelsize);
450
451 immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints - i + 1);
452
453 /* need to roll-back one point to ensure that there are no gaps in the stroke */
454 if (i != 0) {
455 pt_prev = &points[i - 1];
456 annotation_calc_2d_stroke_fxy(&pt_prev->x, sflag, offsx, offsy, winx, winy, co);
457 immVertex2fv(pos, co);
458 draw_points++;
459 }
460
461 oldpressure = pt->pressure; /* reset our threshold */
462 }
463
464 /* now the point we want */
465 annotation_calc_2d_stroke_fxy(&pt->x, sflag, offsx, offsy, winx, winy, co);
466 immVertex2fv(pos, co);
467 draw_points++;
468 }
469 /* need to have 2 points to avoid immEnd assert error */
470 if (draw_points < 2) {
471 pt_prev = &points[0];
472 annotation_calc_2d_stroke_fxy(&pt_prev->x, sflag, offsx, offsy, winx, winy, co);
473 immVertex2fv(pos, co);
474 }
475 }
476
477 immEnd();
479}
480
481/* ----- Strokes Drawing ------ */
482
483/* Helper for doing all the checks on whether a stroke can be drawn */
484static bool annotation_can_draw_stroke(const bGPDstroke *gps, const int dflag)
485{
486 /* skip stroke if it isn't in the right display space for this drawing context */
487 /* 1) 3D Strokes */
488 if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE)) {
489 return false;
490 }
491 if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) {
492 return false;
493 }
494
495 /* 2) Screen Space 2D Strokes */
496 if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) {
497 return false;
498 }
499 if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) {
500 return false;
501 }
502
503 /* 3) Image Space (2D) */
504 if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE)) {
505 return false;
506 }
507 if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE)) {
508 return false;
509 }
510
511 /* skip stroke if it doesn't have any valid data */
512 if ((gps->points == nullptr) || (gps->totpoints < 1)) {
513 return false;
514 }
515
516 /* stroke can be drawn */
517 return true;
518}
519
520/* draw a set of strokes */
521static void annotation_draw_strokes(const bGPDframe *gpf,
522 int offsx,
523 int offsy,
524 int winx,
525 int winy,
526 int dflag,
527 short lthick,
528 const float color[4])
529{
531
532 for (bGPDstroke &gps : gpf->strokes) {
533 /* check if stroke can be drawn */
534 if (annotation_can_draw_stroke(&gps, dflag) == false) {
535 continue;
536 }
537
538 /* check which stroke-drawer to use */
539 if (dflag & GP_DRAWDATA_ONLY3D) {
540 const int no_xray = (dflag & GP_DRAWDATA_NO_XRAY);
541
542 if (no_xray) {
544
545 /* first arg is normally rv3d->dist, but this isn't
546 * available here and seems to work quite well without */
547 GPU_polygon_offset(1.0f, 1.0f);
548 }
549
550 /* 3D Lines - OpenGL primitives-based */
551 if (gps.totpoints == 1) {
553 gps.points, lthick, gps.flag, offsx, offsy, winx, winy, color);
554 }
555 else {
557 gps.points, gps.totpoints, lthick, color, gps.flag & GP_STROKE_CYCLIC);
558 }
559
560 if (no_xray) {
562
563 GPU_polygon_offset(0.0f, 0.0f);
564 }
565 }
566 else {
567 /* 2D Strokes... */
568 if (gps.totpoints == 1) {
570 gps.points, lthick, gps.flag, offsx, offsy, winx, winy, color);
571 }
572 else {
574 gps.points, gps.totpoints, lthick, gps.flag, offsx, offsy, winx, winy, color);
575 }
576 }
577 }
578
580}
581
582/* ----- General Drawing ------ */
583/* draw onion-skinning for a layer */
585 bGPDlayer *gpl, bGPDframe *gpf, int offsx, int offsy, int winx, int winy, int dflag)
586{
587 const float alpha = 1.0f;
588 float color[4];
589
590 /* 1) Draw Previous Frames First */
593 }
594 else {
596 }
597
598 if (gpl->gstep > 0) {
599 bGPDframe *gf;
600 float fac;
601
602 /* draw previous frames first */
603 for (gf = gpf->prev; gf; gf = gf->prev) {
604 /* check if frame is drawable */
605 if ((gpf->framenum - gf->framenum) <= gpl->gstep) {
606 /* Alpha decreases with distance from current-frame index. */
607 fac = 1.0f - (float(gpf->framenum - gf->framenum) / float(gpl->gstep + 1));
608 color[3] = alpha * fac * 0.66f;
609 annotation_draw_strokes(gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
610 }
611 else {
612 break;
613 }
614 }
615 }
616 else if (gpl->gstep == 0) {
617 /* draw the strokes for the ghost frames (at half of the alpha set by user) */
618 if (gpf->prev) {
619 color[3] = (alpha / 7);
620 annotation_draw_strokes(gpf->prev, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
621 }
622 }
623 else {
624 /* don't draw - disabled */
625 }
626
627 /* 2) Now draw next frames */
630 }
631 else {
633 }
634
635 if (gpl->gstep_next > 0) {
636 bGPDframe *gf;
637 float fac;
638
639 /* now draw next frames */
640 for (gf = gpf->next; gf; gf = gf->next) {
641 /* check if frame is drawable */
642 if ((gf->framenum - gpf->framenum) <= gpl->gstep_next) {
643 /* Alpha decreases with distance from current-frame index. */
644 fac = 1.0f - (float(gf->framenum - gpf->framenum) / float(gpl->gstep_next + 1));
645 color[3] = alpha * fac * 0.66f;
646 annotation_draw_strokes(gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
647 }
648 else {
649 break;
650 }
651 }
652 }
653 else if (gpl->gstep_next == 0) {
654 /* draw the strokes for the ghost frames (at half of the alpha set by user) */
655 if (gpf->next) {
656 color[3] = (alpha / 4);
657 annotation_draw_strokes(gpf->next, offsx, offsy, winx, winy, dflag, gpl->thickness, color);
658 }
659 }
660 else {
661 /* don't draw - disabled */
662 }
663}
664
665/* loop over gpencil data layers, drawing them */
667 bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag)
668{
669 float ink[4];
670
671 for (bGPDlayer &gpl : gpd->layers) {
672 /* verify never thickness is less than 1 */
673 CLAMP_MIN(gpl.thickness, 1.0f);
674 short lthick = gpl.thickness;
675
676 /* apply layer opacity */
677 copy_v3_v3(ink, gpl.color);
678 ink[3] = gpl.opacity;
679
680 /* don't draw layer if hidden */
681 if (gpl.flag & GP_LAYER_HIDE) {
682 continue;
683 }
684
685 /* get frame to draw */
687 if (gpf == nullptr) {
688 continue;
689 }
690
691 /* Add layer drawing settings to the set of "draw flags"
692 * NOTE: If the setting doesn't apply, it *must* be cleared,
693 * as dflag's carry over from the previous layer
694 */
695
696 /* xray... */
698
699 /* Draw 'onionskins' (frame left + right) */
700 if (gpl.onion_flag & GP_LAYER_ONIONSKIN) {
701 annotation_draw_onionskins(&gpl, gpf, offsx, offsy, winx, winy, dflag);
702 }
703
704 /* draw the strokes already in active frame */
705 annotation_draw_strokes(gpf, offsx, offsy, winx, winy, dflag, lthick, ink);
706
707 /* Check if may need to draw the active stroke cache, only if this layer is the active layer
708 * that is being edited. (Stroke buffer is currently stored in gp-data)
709 */
710 if ((gpl.flag & GP_LAYER_ACTIVE) && (gpf->flag & GP_FRAME_PAINT)) {
711 /* Buffer stroke needs to be drawn with a different line-style
712 * to help differentiate them from normal strokes.
713 *
714 * It should also be noted that #bGPdata_Runtime::sbuffer contains temporary point types
715 * i.e. #tGPspoints NOT #bGPDspoints. */
716 annotation_draw_stroke_buffer(gpd, lthick, dflag, ink);
717 }
718 }
719}
720
721/* draw grease-pencil datablock */
723 bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag)
724{
725 /* turn on smooth lines (i.e. anti-aliasing) */
726 GPU_line_smooth(true);
727
728 /* turn on alpha-blending */
730
731 /* Do not write to depth (avoid self-occlusion). */
732 bool prev_depth_mask = GPU_depth_mask_get();
733 GPU_depth_mask(false);
734
735 /* draw! */
736 annotation_draw_data_layers(gpd, offsx, offsy, winx, winy, cfra, dflag);
737
738 /* turn off alpha blending, then smooth lines */
739 GPU_blend(GPU_BLEND_NONE); /* alpha blending */
740 GPU_line_smooth(false); /* smooth lines */
741
742 GPU_depth_mask(prev_depth_mask);
743}
744
745/* if we have strokes for scenes (3d view)/clips (movie clip editor)
746 * and objects/tracks, multiple data blocks have to be drawn */
748 bGPdata *gpd,
749 int offsx,
750 int offsy,
751 int winx,
752 int winy,
753 int cfra,
754 int dflag,
755 const eSpace_Type space_type)
756{
757 bGPdata *gpd_source = nullptr;
758
759 if (scene) {
760 if (space_type == SPACE_VIEW3D) {
761 gpd_source = (scene->gpd ? scene->gpd : nullptr);
762 }
763 else if (space_type == SPACE_CLIP && scene->clip) {
764 /* currently drawing only gpencil data from either clip or track,
765 * but not both - XXX fix logic behind */
766 gpd_source = (scene->clip->gpd ? scene->clip->gpd : nullptr);
767 }
768
769 if (gpd_source) {
770 annotation_draw_data(gpd_source, offsx, offsy, winx, winy, cfra, dflag);
771 }
772 }
773
774 /* scene/clip data has already been drawn, only object/track data is drawn here
775 * if gpd_source == gpd, we don't have any object/track data and we can skip */
776 if (gpd_source == nullptr || (gpd_source && gpd_source != gpd)) {
777 annotation_draw_data(gpd, offsx, offsy, winx, winy, cfra, dflag);
778 }
779}
780
781/* ----- Annotation Sketches Drawing API ------ */
782
784{
786 ScrArea *area = CTX_wm_area(C);
787 ARegion *region = CTX_wm_region(C);
788 Scene *scene = CTX_data_scene(C);
789
790 int offsx, offsy, sizex, sizey;
791 int dflag = GP_DRAWDATA_NOSTATUS;
792
794 if (gpd == nullptr) {
795 return;
796 }
797
798 /* calculate rect */
799 switch (area->spacetype) {
800 case SPACE_IMAGE: /* image */
801 case SPACE_CLIP: /* clip */
802 {
803 /* just draw using standard scaling (settings here are currently ignored anyways) */
804 /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way,
805 * so disabled. */
806 offsx = 0;
807 offsy = 0;
808 sizex = region->winx;
809 sizey = region->winy;
810
811 wmOrtho2(
812 region->v2d.cur.xmin, region->v2d.cur.xmax, region->v2d.cur.ymin, region->v2d.cur.ymax);
813
815 break;
816 }
817 case SPACE_SEQ: /* sequence */
818 {
819 /* just draw using standard scaling (settings here are currently ignored anyways) */
820 offsx = 0;
821 offsy = 0;
822 sizex = region->winx;
823 sizey = region->winy;
824
825 /* NOTE: I2D was used in 2.4x, but the old settings for that have been deprecated
826 * and everything moved to standard View2d
827 */
828 dflag |= GP_DRAWDATA_ONLYV2D;
829 break;
830 }
831 default: /* for spacetype not yet handled */
832 offsx = 0;
833 offsy = 0;
834 sizex = region->winx;
835 sizey = region->winy;
836
837 dflag |= GP_DRAWDATA_ONLYI2D;
838 break;
839 }
840
842 /* Don't show onion-skins during animation playback/scrub (i.e. it obscures the poses)
843 * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes). */
844 dflag |= GP_DRAWDATA_NO_ONIONS;
845 }
846
847 /* draw it! */
849 scene, gpd, offsx, offsy, sizex, sizey, scene->r.cfra, dflag, eSpace_Type(area->spacetype));
850}
851
852void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d)
853{
855 ScrArea *area = CTX_wm_area(C);
856 ARegion *region = CTX_wm_region(C);
857 Scene *scene = CTX_data_scene(C);
858 int dflag = 0;
859
860 /* check that we have grease-pencil stuff to draw */
861 if (area == nullptr) {
862 return;
863 }
865 if (gpd == nullptr) {
866 return;
867 }
868
869 /* special hack for Image Editor */
870 /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way,
871 * so disabled. */
872 if (ELEM(area->spacetype, SPACE_IMAGE, SPACE_CLIP)) {
873 dflag |= GP_DRAWDATA_IEDITHACK;
874 }
875
876 /* draw it! */
877 if (onlyv2d) {
879 }
881 dflag |= GP_DRAWDATA_NO_ONIONS;
882 }
883
885 gpd,
886 0,
887 0,
888 region->winx,
889 region->winy,
890 scene->r.cfra,
891 dflag,
892 eSpace_Type(area->spacetype));
893}
894
896 Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, bool only3d)
897{
898 int dflag = 0;
899 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
900 int offsx, offsy, winx, winy;
901
902 /* check that we have grease-pencil stuff to draw */
903 /* XXX: Hardcoded reference here may get out of sync if we change how we fetch annotation data
904 */
905 bGPdata *gpd = scene->gpd;
906 if (gpd == nullptr) {
907 return;
908 }
909
910 /* When rendering to the off-screen buffer we don't want to
911 * deal with the camera border, otherwise map the coords to the camera border. */
912 if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_FLAG_RENDER_VIEWPORT)) {
913 rctf rectf;
915 scene, depsgraph, v3d, rv3d, region->winx, region->winy, true, false, true);
916
917 offsx = round_fl_to_int(rectf.xmin);
918 offsy = round_fl_to_int(rectf.ymin);
919 winx = round_fl_to_int(rectf.xmax - rectf.xmin);
920 winy = round_fl_to_int(rectf.ymax - rectf.ymin);
921 }
922 else {
923 offsx = 0;
924 offsy = 0;
925 winx = region->winx;
926 winy = region->winy;
927 }
928
929 /* set flags */
930 if (only3d) {
931 /* 3D strokes/3D space:
932 * - only 3D space points
933 * - don't status text either (as it's the wrong space)
934 */
936 }
937
938 if (v3d->flag2 & V3D_HIDE_OVERLAYS) {
939 /* don't draw status text when "only render" flag is set */
940 dflag |= GP_DRAWDATA_NOSTATUS;
941 }
942
943 /* draw it! */
945 scene, gpd, offsx, offsy, winx, winy, scene->r.cfra, dflag, eSpace_Type(v3d->spacetype));
946}
947
949 Scene *scene, bGPdata *gpd, int winx, int winy, const int cfra, const char spacetype)
950{
952
953 annotation_draw_data_all(scene, gpd, 0, 0, winx, winy, cfra, dflag, eSpace_Type(spacetype));
954}
955
956/* ************************************************** */
957
958} // namespace blender
Camera data-block and utility functions.
#define C
Definition RandGen.cpp:29
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define CLAMP_MIN(a, b)
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
void get_color_3fv(int colorid, float col[3])
BMesh Iterators.
UserDef U
Definition blender.cc:58
static void annotation_draw_onionskins(bGPDlayer *gpl, bGPDframe *gpf, int offsx, int offsy, int winx, int winy, int dflag)
ScrArea * CTX_wm_area(const bContext *C)
void immEnd()
void ED_annotation_draw_2dimage(const bContext *C)
struct bGPDframe * BKE_annotations_layer_frame_get(struct bGPDlayer *gpl, int cframe, eGP_GetFrame_Mode addnew)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static void annotation_draw_stroke_point(const bGPDspoint *points, short thickness, short sflag, int offsx, int offsy, int winx, int winy, const float ink[4])
static void annotation_draw_stroke_arrow_buffer(uint pos, const float *corner_point, const float *arrow_coords, const int arrow_style)
MINLINE int round_fl_to_int(float a)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
void ED_annotation_draw_view3d(Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, bool only3d)
void GPU_point_size(float size)
Definition gpu_state.cc:157
void immBegin(GPUPrimType, uint vertex_len)
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
@ GPU_PRIM_LINE_STRIP
void GPU_depth_mask(bool depth)
Definition gpu_state.cc:107
void immUnbindProgram()
static bool annotation_can_draw_stroke(const bGPDstroke *gps, const int dflag)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
static void annotation_draw_data(bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag)
static void annotation_draw_data_layers(bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag)
Global G
Definition blender.cc:57
static void annotation_calc_2d_stroke_fxy(const float pt[3], short sflag, int offsx, int offsy, int winx, int winy, float r_co[2])
void wmOrtho2(float x1, float x2, float y1, float y2)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void immUniform1f(const char *name, float x)
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:135
void immVertex2f(uint attr_id, float x, float y)
static void annotation_draw_data_all(Scene *scene, bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag, const eSpace_Type space_type)
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
@ GP_DRAWDATA_NO_XRAY
@ GP_DRAWDATA_ONLY3D
@ GP_DRAWDATA_NOSTATUS
@ GP_DRAWDATA_IEDITHACK
@ GP_DRAWDATA_ONLYI2D
@ GP_DRAWDATA_ONLYV2D
@ GP_DRAWDATA_NO_ONIONS
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
wmWindowManager * CTX_wm_manager(const bContext *C)
bool GPU_depth_mask_get()
Definition gpu_state.cc:272
rctf BKE_camera_view_border(const struct Scene *scene, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, int winx, int winy, bool no_shift, bool no_zoom, bool no_roll)
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:165
bGPdata * ED_annotation_data_get_active(const bContext *C)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void immVertex3fv(uint attr_id, const float data[3])
@ G_FLAG_RENDER_VIEWPORT
MINLINE float max_ff(float a, float b)
static void annotation_draw_stroke_3d(const bGPDspoint *points, int totpoints, short thickness, const float ink[4], bool cyclic)
static void annotation_draw_stroke_buffer(bGPdata *gps, short thickness, short dflag, const float ink[4])
void ED_annotation_draw_ex(Scene *scene, bGPdata *gpd, int winx, int winy, const int cfra, const char spacetype)
static void annotation_draw_stroke_2d(const bGPDspoint *points, int totpoints, short thickness_s, short sflag, int offsx, int offsy, int winx, int winy, const float ink[4])
Scene * CTX_data_scene(const bContext *C)
void immUniform2fv(const char *name, const float data[2])
void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d)
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void GPU_polygon_offset(float viewdist, float dist)
void immVertex2fv(uint attr_id, const float data[2])
void immUniformColor3fvAlpha(const float rgb[3], float a)
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
ARegion * CTX_wm_region(const bContext *C)
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
static void annotation_draw_strokes(const bGPDframe *gpf, int offsx, int offsy, int winx, int winy, int dflag, short lthick, const float color[4])
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eRegionView3D_Persp persp
struct bGPdata * gpd
struct MovieClip * clip
struct RenderData r
eView3D_Flag2 flag2
ListBaseT< bGPDstroke > strokes
eGPDlayer_OnionFlag onion_flag
eGPDstroke_Arrowstyle arrow_end_style
eGPDstroke_Arrowstyle arrow_start_style
ListBaseT< bGPDlayer > layers