Blender V5.3
grease_pencil_image_render.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_color_types.hh"
10#include "BLI_math_geom_c.hh"
11#include "BLI_math_matrix.hh"
12#include "BLI_math_vector.hh"
13
14#include "BKE_attribute.hh"
15#include "BKE_camera.h"
16#include "BKE_curves.hh"
17#include "BKE_grease_pencil.hh"
18#include "BKE_image.hh"
19#include "BKE_material.hh"
20
22#include "DNA_material_types.h"
23#include "DNA_object_types.h"
24#include "DNA_scene_types.h"
25#include "DNA_userdef_types.h"
26#include "DNA_view3d_types.h"
27
28#include "ED_grease_pencil.hh"
29#include "ED_view3d.hh"
30
31#include "IMB_imbuf.hh"
32#include "IMB_imbuf_types.hh"
33
34#include "GPU_debug.hh"
35#include "GPU_framebuffer.hh"
36#include "GPU_immediate.hh"
37#include "GPU_matrix.hh"
38#include "GPU_primitive.hh"
39#include "GPU_shader_builtin.hh"
40#include "GPU_shader_shared.hh"
41#include "GPU_state.hh"
42#include "GPU_texture.hh"
43#include "GPU_uniform_buffer.hh"
44#include "GPU_vertex_format.hh"
45
47
48/* Enable GPU debug capture (needs WITH_RENDERDOC option). */
49constexpr const bool enable_debug_gpu_capture = true;
50
51RegionViewData region_init(ARegion &region, const int2 &win_size)
52{
53 RegionView3D &rv3d = *static_cast<RegionView3D *>(region.regiondata);
54
55 const RegionViewData data = {
56 int2{region.winx, region.winy}, region.winrct, ED_view3d_mats_rv3d_backup(&rv3d)};
57
58 /* Resize region. */
59 region.winrct.xmin = 0;
60 region.winrct.ymin = 0;
61 region.winrct.xmax = win_size.x;
62 region.winrct.ymax = win_size.y;
63 region.winx = short(win_size.x);
64 region.winy = short(win_size.y);
65
66 return data;
67}
68
70{
71 RegionView3D &rv3d = *static_cast<RegionView3D *>(region.regiondata);
72
73 region.winx = data.winsize.x;
74 region.winy = data.winsize.y;
75 region.winrct = data.winrct;
76
77 ED_view3d_mats_rv3d_restore(&rv3d, data.rv3d_store);
79}
80
82{
84 GPU_debug_capture_begin("Grease Pencil Image Render");
85 }
86
87 char err_out[256] = "unknown";
88 GPUOffScreen *offscreen = GPU_offscreen_create(win_size.x,
89 win_size.y,
90 true,
91 gpu::TextureFormat::UNORM_8_8_8_8,
93 false,
94 err_out);
95 if (offscreen == nullptr) {
96 return nullptr;
97 }
98
99 GPU_offscreen_bind(offscreen, true);
100
105
106 GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
107 GPU_clear_depth(1.0f);
108
109 return offscreen;
110}
111
113{
116
117 const int2 win_size = {GPU_offscreen_width(buffer), GPU_offscreen_height(buffer)};
118 ImBuf *ibuf = IMB_allocImBuf(win_size.x, win_size.y, ImBufFlags::ByteData);
120
121 Image *ima = BKE_image_add_from_imbuf(&bmain, ibuf, "Grease Pencil Fill");
122 ima->id.tag |= ID_TAG_DOIT;
123
124 BKE_image_release_ibuf(ima, ibuf, nullptr);
125
126 /* Switch back to regular frame-buffer. */
127 GPU_offscreen_unbind(buffer, true);
128 GPU_offscreen_free(buffer);
129
132 }
133
134 return ima;
135}
136
137void compute_view_matrices(const ViewContext &view_context,
138 const Scene &scene,
139 const int2 &win_size,
140 const float2 &zoom,
141 const float2 &offset)
142{
143 rctf viewplane;
144 float clip_start, clip_end;
145 const bool is_ortho = ED_view3d_viewplane_get(view_context.depsgraph,
146 view_context.v3d,
147 view_context.rv3d,
148 win_size.x,
149 win_size.y,
150 &viewplane,
151 &clip_start,
152 &clip_end,
153 nullptr);
154
155 /* Rescale `viewplane` to fit all strokes. */
156 const float2 view_min = float2(viewplane.xmin, viewplane.ymin);
157 const float2 view_max = float2(viewplane.xmax, viewplane.ymax);
158 const float2 view_extent = view_max - view_min;
159 const float2 view_center = 0.5f * (view_max + view_min);
160 const float2 offset_abs = offset * view_extent;
161 const float2 view_min_new = (view_min - view_center) * zoom + view_center + offset_abs;
162 const float2 view_max_new = (view_max - view_center) * zoom + view_center + offset_abs;
163 viewplane.xmin = view_min_new.x;
164 viewplane.ymin = view_min_new.y;
165 viewplane.xmax = view_max_new.x;
166 viewplane.ymax = view_max_new.y;
167
168 float4x4 winmat;
169 if (is_ortho) {
170 orthographic_m4(winmat.ptr(),
171 viewplane.xmin,
172 viewplane.xmax,
173 viewplane.ymin,
174 viewplane.ymax,
175 -clip_end,
176 clip_end);
177 }
178 else {
179 perspective_m4(winmat.ptr(),
180 viewplane.xmin,
181 viewplane.xmax,
182 viewplane.ymin,
183 viewplane.ymax,
184 clip_start,
185 clip_end);
186 }
187
189 &scene,
190 view_context.v3d,
191 view_context.region,
192 nullptr,
193 winmat.ptr(),
194 nullptr,
195 true);
196}
197
199{
201}
202
207
212
217
219 const float3 &position,
220 const float point_size,
221 const ColorGeometry4f &color)
222{
223 GPUVertFormat *format = immVertexFormat();
224 uint attr_pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
225 uint attr_size = GPU_vertformat_attr_add(format, "size", gpu::VertAttrType::SFLOAT_32);
226 uint attr_color = GPU_vertformat_attr_add(
227 format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
228
232 immAttr1f(attr_size, point_size * M_SQRT2);
233 immAttr4fv(attr_color, color);
235 immEnd();
238}
239
241 const IndexRange indices,
242 Span<float3> positions,
243 const VArray<ColorGeometry4f> &colors,
244 const bool cyclic,
245 const float line_width)
246{
247 GPUVertFormat *format = immVertexFormat();
248 const uint attr_pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
249 const uint attr_color = GPU_vertformat_attr_add(
250 format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
252
253 GPU_line_width(line_width);
254 /* If cyclic the curve needs one more vertex. */
255 const int cyclic_add = (cyclic && indices.size() > 2) ? 1 : 0;
256 immBeginAtMost(GPU_PRIM_LINE_STRIP, indices.size() + cyclic_add);
257
258 for (const int point_i : indices) {
259 immAttr4fv(attr_color, colors[point_i]);
260 immVertex3fv(attr_pos, math::transform_point(transform, positions[point_i]));
261 }
262
263 if (cyclic && indices.size() > 2) {
264 const int point_i = indices[0];
265 immAttr4fv(attr_color, colors[point_i]);
266 immVertex3fv(attr_pos, math::transform_point(transform, positions[point_i]));
267 }
268
269 immEnd();
271}
272
274 const int2 &win_size,
275 const Object &object,
276 const eGPDstroke_Caps cap_start,
277 const eGPDstroke_Caps cap_end,
278 const bool is_fill_stroke)
279{
281 copy_v2_v2(data.viewport, float2(win_size));
282 data.pixsize = rv3d.pixsize;
283 data.objscale = math::average(float3(object.scale));
284 data.caps_start = cap_start;
285 data.caps_end = cap_end;
286 data.fill_stroke = is_fill_stroke;
287
288 return GPU_uniformbuf_create_ex(sizeof(GPencilStrokeData), &data, __func__);
289}
290
292 const RegionView3D &rv3d,
293 const int2 &win_size,
294 const Object &object,
295 const IndexRange indices,
296 Span<float3> positions,
297 const VArray<float> &radii,
298 const VArray<ColorGeometry4f> &colors,
299 const bool cyclic,
300 const eGPDstroke_Caps cap_start,
301 const eGPDstroke_Caps cap_end,
302 const bool fill_stroke,
303 const float radius_scale)
304{
305 if (indices.is_empty()) {
306 return;
307 }
308
309 GPUVertFormat *format = immVertexFormat();
310 /* Format is matching shader manual load. Keep in sync with #GreasePencilStrokeData.
311 * Only the name of the first attribute is important. */
312 const uint attr_pos = GPU_vertformat_attr_add(
313 format, "gp_vert_data", gpu::VertAttrType::SFLOAT_32_32_32);
314 const uint attr_thickness = GPU_vertformat_attr_add(
315 format, "thickness", gpu::VertAttrType::SFLOAT_32);
316 const uint attr_color = GPU_vertformat_attr_add(
317 format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
318
321 rv3d, win_size, object, cap_start, cap_end, fill_stroke);
322 immBindUniformBuf("gpencil_stroke_data", ubo);
323
324 /* If cyclic the curve needs one more vertex. */
325 const int cyclic_add = (cyclic && indices.size() > 2) ? 1 : 0;
326
328 indices.size() + cyclic_add + 2);
329
330 auto draw_point = [&](const int point_i) {
331 const float thickness = 2.0f * radii[point_i] * radius_scale;
332
333 immAttr4fv(attr_color, colors[point_i]);
334 immAttr1f(attr_thickness, std::max(thickness, 0.0f));
335 immVertex3fv(attr_pos, math::transform_point(transform, positions[point_i]));
336 };
337
338 /* First point for adjacency (not drawn). */
339 if (cyclic && indices.size() > 2) {
340 draw_point(indices.last() - 1);
341 }
342 else {
343 draw_point(indices.first() + 1);
344 }
345
346 for (const int point_i : indices) {
347 draw_point(point_i);
348 }
349
350 if (cyclic && indices.size() > 2) {
351 draw_point(indices.first());
352 draw_point(indices.first() + 1);
353 }
354 /* Last adjacency point (not drawn). */
355 else {
356 draw_point(indices.last() - 1);
357 }
358
359 immEnd();
360
361 /* Expanded `drawcall`. */
362 GPUPrimType expand_prim_type = GPUPrimType::GPU_PRIM_TRIS;
363 /* Hard-coded in shader. */
364 const uint expand_prim_len = 12;
365 /* Do not count adjacency info for start and end primitives. */
366 const uint final_vert_len = ((batch->vertex_count_get() - 2) * expand_prim_len) * 3;
367
368 if (final_vert_len > 0) {
369 GPU_batch_bind_as_resources(batch, batch->shader);
370
371 /* TODO(fclem): get rid of this dummy VBO. */
372 GPUVertFormat format = {0};
373 GPU_vertformat_attr_add(&format, "dummy", gpu::VertAttrType::SFLOAT_32);
374 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(format);
375 GPU_vertbuf_data_alloc(*vbo, 1);
376
377 gpu::Batch *gpu_batch = GPU_batch_create_ex(
378 expand_prim_type, vbo, nullptr, GPU_BATCH_OWNS_VBO);
379
380 GPU_batch_set_shader(gpu_batch, batch->shader);
381 GPU_batch_draw_advanced(gpu_batch, 0, final_vert_len, 0, 1);
382
383 GPU_batch_discard(gpu_batch);
384 }
385 GPU_batch_discard(batch);
386
388
390}
391
392static void draw_dots(const float4x4 &transform,
393 const RegionView3D &rv3d,
394 const Object &object,
395 const IndexRange indices,
396 Span<float3> positions,
397 const VArray<float> &radii,
398 const VArray<ColorGeometry4f> &colors,
399 const float radius_scale)
400{
401 if (indices.is_empty()) {
402 return;
403 }
404
405 GPUVertFormat *format = immVertexFormat();
406 const uint attr_pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
407 const uint attr_size = GPU_vertformat_attr_add(format, "size", gpu::VertAttrType::SFLOAT_32);
408 const uint attr_color = GPU_vertformat_attr_add(
409 format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
410
413
414 immBegin(GPU_PRIM_POINTS, indices.size());
415
416 /* Includes viewport zoom factor and perspective projection. The point shader does not include
417 * these factors internally, unlike the line shader. */
418 const float objscale = math::average(float3(object.scale));
419 const float pixel_scale = 4.0f * radius_scale * objscale / rv3d.pixsize;
420 for (const int point_i : indices) {
421 const float3 &position = positions[point_i];
422 float perspective_factor = 1.0f;
423 if (rv3d.is_persp) {
424 const float3 view_position = math::transform_point(float4x4(rv3d.persmat), position);
425 perspective_factor = math::safe_rcp(view_position.z);
426 }
427 const float thickness = std::max(radii[point_i] * pixel_scale * perspective_factor, 1.0f);
428
429 immAttr4fv(attr_color, colors[point_i]);
430 immAttr1f(attr_size, thickness);
432 }
433
434 immEnd();
437}
438
440 const IndexRange indices,
441 Span<float3> centers,
442 const VArray<float> &radii,
443 const VArray<ColorGeometry4f> &colors,
444 const float2 &viewport_size,
445 const float line_width,
446 const bool fill)
447{
448 if (indices.is_empty()) {
449 return;
450 }
451
452 constexpr const int segments_num = 32;
453 static const float2 coords[] = {
454 {1.0000f, 0.0000f}, {0.9808f, 0.1951f}, {0.9239f, 0.3827f}, {0.8315f, 0.5556f},
455 {0.7071f, 0.7071f}, {0.5556f, 0.8315f}, {0.3827f, 0.9239f}, {0.1951f, 0.9808f},
456 {0.0000f, 1.0000f}, {-0.1951f, 0.9808f}, {-0.3827f, 0.9239f}, {-0.5556f, 0.8315f},
457 {-0.7071f, 0.7071f}, {-0.8315f, 0.5556f}, {-0.9239f, 0.3827f}, {-0.9808f, 0.1951f},
458 {-1.0000f, 0.0000f}, {-0.9808f, -0.1951f}, {-0.9239f, -0.3827f}, {-0.8315f, -0.5556f},
459 {-0.7071f, -0.7071f}, {-0.5556f, -0.8315f}, {-0.3827f, -0.9239f}, {-0.1951f, -0.9808f},
460 {-0.0000f, -1.0000f}, {0.1951f, -0.9808f}, {0.3827f, -0.9239f}, {0.5556f, -0.8315f},
461 {0.7071f, -0.7071f}, {0.8315f, -0.5556f}, {0.9239f, -0.3827f}, {0.9808f, -0.1951f},
462 };
463
464 GPUVertFormat *format = immVertexFormat();
465 const uint attr_pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
466 const uint attr_color = GPU_vertformat_attr_add(
467 format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
468
470
471 if (fill) {
473
474 for (const int point_i : indices) {
475 const float radius = radii[point_i];
476 const ColorGeometry4f color = colors[point_i];
477 const float3 center = math::transform_point(transform, centers[point_i]);
478
479 immBegin(GPU_PRIM_TRI_STRIP, segments_num);
480
481 for (const int i : IndexRange(segments_num / 2)) {
482 immAttr4fv(attr_color, color);
483 immVertex3fv(attr_pos, center + float3(radius * scale * coords[i], 0.0f));
484 if (segments_num - 1 - i > i) {
485 immAttr4fv(attr_color, color);
486 immVertex3fv(attr_pos,
487 center + float3(radius * scale * coords[segments_num - 1 - i], 0.0f));
488 }
489 }
490
491 immEnd();
492 }
493
495 }
496 else {
498
499 immUniform2fv("viewportSize", viewport_size);
500 immUniform1f("lineWidth", line_width * U.pixelsize);
501
502 for (const int point_i : indices) {
503 const float radius = radii[point_i];
504 const ColorGeometry4f color = colors[point_i];
505 const float3 center = math::transform_point(transform, centers[point_i]);
506
507 immBegin(GPU_PRIM_LINE_STRIP, segments_num + 1);
508
509 for (const int i : IndexRange(segments_num)) {
510 immAttr4fv(attr_color, color);
511 immVertex3fv(attr_pos, center + float3(radius * scale * coords[i], 0.0f));
512 }
513 immAttr4fv(attr_color, color);
514 immVertex3fv(attr_pos, center + float3(radius * scale * coords[0], 0.0f));
515
516 immEnd();
517 }
518
520 }
521}
522
524 IndexRange indices,
525 Span<float3> start_positions,
526 Span<float3> end_positions,
527 const VArray<ColorGeometry4f> &colors,
528 float line_width)
529{
530 GPUVertFormat *format = immVertexFormat();
531 const uint attr_pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
532 const uint attr_color = GPU_vertformat_attr_add(
533 format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
535
536 GPU_line_width(line_width);
537 immBeginAtMost(GPU_PRIM_LINES, 2 * indices.size());
538
539 for (const int point_i : indices) {
540 immAttr4fv(attr_color, colors[point_i]);
541 immVertex3fv(attr_pos, math::transform_point(transform, start_positions[point_i]));
542
543 immAttr4fv(attr_color, colors[point_i]);
544 immVertex3fv(attr_pos, math::transform_point(transform, end_positions[point_i]));
545 }
546
547 immEnd();
549}
550
552{
553 if (curves.is_single_type(CURVE_TYPE_POLY)) {
554 return GVArray::from_span(input);
555 }
556
557 const CPPType &type = input.type();
558 GArray<> out(type, curves.evaluated_points_num());
559 curves.interpolate_to_evaluated(input, out.as_mutable_span());
560 return GVArray::from_garray(std::move(out));
561};
562
564 const int2 &win_size,
565 const Object &object,
566 const bke::greasepencil::Drawing &drawing,
567 const float4x4 &transform,
568 const IndexMask &strokes_mask,
569 const VArray<ColorGeometry4f> &colors,
570 const bool use_xray,
571 const float radius_scale)
572{
573 set_view_matrix(rv3d);
574
576 /* Do not write to depth (avoid self-occlusion). */
577 const bool prev_depth_mask = GPU_depth_mask_get();
578 GPU_depth_mask(false);
579 if (!use_xray) {
581 /* First arg is normally rv3d->dist, but this isn't
582 * available here and seems to work quite well without. */
583 GPU_polygon_offset(1.0f, 1.0f);
584 }
585
586 const bke::CurvesGeometry &curves = drawing.strokes();
587 const OffsetIndices points_by_curve = curves.evaluated_points_by_curve();
588 const Span<float3> positions = curves.evaluated_positions();
589 const bke::AttributeAccessor attributes = curves.attributes();
590 const VArray<bool> cyclic = curves.cyclic();
591
592 curves.ensure_can_interpolate_to_evaluated();
593
594 const VArray<float> radii =
595 attribute_interpolate(VArraySpan(drawing.radii()), curves).typed<float>();
596 const VArray<ColorGeometry4f> eval_colors =
598
599 const VArray<int8_t> stroke_start_caps = *attributes.lookup_or_default<int8_t>(
601 const VArray<int8_t> stroke_end_caps = *attributes.lookup_or_default<int8_t>(
603 const VArray<int> materials = *attributes.lookup_or_default<int>(
604 "material_index", bke::AttrDomain::Curve, 0);
605
606 /* Note: Serial loop since immediate mode drawing can't happen in worker
607 * threads, has to be from the main thread. */
608 strokes_mask.foreach_index([&](const int stroke_i) {
609 /* Check if the color is visible. */
610 const int material_index = materials[stroke_i];
611 const Material *mat = BKE_object_material_get(const_cast<Object *>(&object),
612 material_index + 1);
613 const eMaterialGPencilStyle_Mode stroke_mode = mat && mat->gp_style ?
615 mat->gp_style->mode) :
617
618 if (mat == nullptr || (mat->gp_style->flag & GP_MATERIAL_HIDE)) {
619 return;
620 }
621
622 switch (eMaterialGPencilStyle_Mode(stroke_mode)) {
625 rv3d,
626 win_size,
627 object,
628 points_by_curve[stroke_i],
629 positions,
630 radii,
631 eval_colors,
632 cyclic[stroke_i],
633 eGPDstroke_Caps(stroke_start_caps[stroke_i]),
634 eGPDstroke_Caps(stroke_end_caps[stroke_i]),
635 false,
636 radius_scale);
637 break;
640 /* NOTE: Squares don't have their own shader, render as dots too. */
642 rv3d,
643 object,
644 points_by_curve[stroke_i],
645 positions,
646 radii,
647 eval_colors,
648 radius_scale);
649 break;
650 }
651 });
652
653 if (!use_xray) {
655
656 GPU_polygon_offset(0.0f, 0.0f);
657 }
658 GPU_depth_mask(prev_depth_mask);
661}
662
663} // namespace blender::ed::greasepencil::image_render
Camera data-block and utility functions.
Low-level operations for curves.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
#define M_SQRT2
Object is a sort of wrapper for general info.
const CPPType & type() const
static GVArray from_garray(GArray<> array)
static GVArray from_span(GSpan span)
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr IndexRange()=default
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
const bke::CurvesGeometry & strokes() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
#define point_size
#define position
float3x3 scale(float3x3 mat, float2 scale)
void compute_view_matrices(const ViewContext &view_context, const Scene &scene, const int2 &win_size, const float2 &zoom, const float2 &offset)
void region_reset(ARegion &region, const RegionViewData &data)
static GVArray attribute_interpolate(const GSpan &input, const bke::CurvesGeometry &curves)
void draw_lines(const float4x4 &transform, IndexRange indices, Span< float3 > start_positions, Span< float3 > end_positions, const VArray< ColorGeometry4f > &colors, float line_width)
static gpu::UniformBuf * create_shader_ubo(const RegionView3D &rv3d, const int2 &win_size, const Object &object, const eGPDstroke_Caps cap_start, const eGPDstroke_Caps cap_end, const bool is_fill_stroke)
Image * image_render_end(Main &bmain, GPUOffScreen *buffer)
void draw_grease_pencil_strokes(const RegionView3D &rv3d, const int2 &win_size, const Object &object, const bke::greasepencil::Drawing &drawing, const float4x4 &transform, const IndexMask &strokes_mask, const VArray< ColorGeometry4f > &colors, const bool use_xray, const float radius_scale)
RegionViewData region_init(ARegion &region, const int2 &win_size)
static void draw_grease_pencil_stroke(const float4x4 &transform, const RegionView3D &rv3d, const int2 &win_size, const Object &object, const IndexRange indices, Span< float3 > positions, const VArray< float > &radii, const VArray< ColorGeometry4f > &colors, const bool cyclic, const eGPDstroke_Caps cap_start, const eGPDstroke_Caps cap_end, const bool fill_stroke, const float radius_scale)
static void draw_dots(const float4x4 &transform, const RegionView3D &rv3d, const Object &object, const IndexRange indices, Span< float3 > positions, const VArray< float > &radii, const VArray< ColorGeometry4f > &colors, const float radius_scale)
void draw_circles(const float4x4 &transform, const IndexRange indices, Span< float3 > centers, const VArray< float > &radii, const VArray< ColorGeometry4f > &colors, const float2 &viewport_size, const float line_width, const bool fill)
void draw_dot(const float4x4 &transform, const float3 &position, const float point_size, const ColorGeometry4f &color)
void draw_polyline(const float4x4 &transform, const IndexRange indices, Span< float3 > positions, const VArray< ColorGeometry4f > &colors, const bool cyclic, const float line_width)
GPUOffScreen * image_render_begin(const int2 &win_size)
T safe_rcp(const T &a)
T average(const VecBase< T, Size > &a)
VecBase< T, 3 > to_scale(const MatBase< T, NumCol, NumRow > &mat)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
UserDef U
Definition blender.cc:58
bool ED_view3d_viewplane_get(const Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d, int winx, int winy, rctf *r_viewplane, float *r_clip_start, float *r_clip_end, float *r_pixsize)
void GPU_offscreen_free(GPUOffScreen *offscreen)
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
Definition gpu_batch.cc:53
void immEnd()
void GPU_batch_bind_as_resources(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants=nullptr)
unsigned int uint
Definition BKE_text.h:55
void GPU_uniformbuf_free(gpu::UniformBuf *ubo)
void GPU_clear_color(float red, float green, float blue, float alpha)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
void GPU_debug_capture_begin(const char *title)
Definition gpu_debug.cc:101
void GPU_matrix_identity_set()
MINLINE void copy_v2_v2(float r[2], const float a[2])
Material * BKE_object_material_get(Object *ob, short act)
GPUVertFormat * immVertexFormat()
void GPU_clear_depth(float depth)
void ED_view3d_update_viewmat(const Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, const float viewmat[4][4], const float winmat[4][4], const rcti *rect, bool offscreen)
void immBegin(GPUPrimType, uint vertex_len)
@ GPU_PRIM_TRI_STRIP
@ GPU_PRIM_LINE_STRIP_ADJ
@ GPU_PRIM_LINE_STRIP
void GPU_depth_mask(bool depth)
Definition gpu_state.cc:107
void GPU_batch_discard(gpu::Batch *batch)
void GPU_matrix_identity_projection_set()
void GPU_batch_set_shader(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
gpu::Batch * immBeginBatchAtMost(GPUPrimType, uint vertex_len)
int GPU_offscreen_width(const GPUOffScreen *offscreen)
MatBase< float, 4, 4 > float4x4
void GPU_debug_capture_end()
Definition gpu_debug.cc:116
void immUnbindProgram()
void perspective_m4(float mat[4][4], float left, float right, float bottom, float top, float nearClip, float farClip)
void GPU_line_width(float width)
Definition gpu_state.cc:151
void orthographic_m4(float mat[4][4], float left, float right, float bottom, float top, float nearClip, float farClip)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
VecBase< int32_t, 2 > int2
void ED_view3d_mats_rv3d_restore(RegionView3D *rv3d, RV3DMatrixStore *rv3dmat)
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:135
int GPU_offscreen_height(const GPUOffScreen *offscreen)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
@ GPU_TEXTURE_USAGE_HOST_READ
void immAttr4fv(uint attr_id, const float data[4])
BMesh const char void * data
void ED_view3D_mats_rv3d_free(RV3DMatrixStore *rv3d_mat)
@ GPU_SHADER_3D_POLYLINE_FLAT_COLOR
@ GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR
bool GPU_depth_mask_get()
Definition gpu_state.cc:272
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:44
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:165
Image * BKE_image_add_from_imbuf(Main *bmain, ImBuf *ibuf, const char *name)
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
void GPU_matrix_projection_set(const float m[4][4])
gpu::UniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
void immAttr1f(uint attr_id, float x)
RV3DMatrixStore * ED_view3d_mats_rv3d_backup(RegionView3D *rv3d)
void immVertex3fv(uint attr_id, const float data[3])
void GPU_matrix_pop_projection()
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
void GPU_batch_draw_advanced(gpu::Batch *batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void immUniform2fv(const char *name, const float data[2])
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, gpu::TextureFormat format, eGPUTextureUsage usage, bool clear, char err_out[256])
void GPU_polygon_offset(float viewdist, float dist)
VecBase< float, 3 > float3
void GPU_matrix_pop()
void GPU_matrix_push_projection()
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
void GPU_matrix_set(const float m[4][4])
signed char int8_t
Definition BKE_text.h:76
void GPU_matrix_push()
void immBindUniformBuf(const char *name, gpu::UniformBuf *ubo)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
uint8_t * byte_data_for_write()
Definition allocimbuf.cc:60
const c_style_mat & ptr() const
RegionView3D * rv3d
Definition ED_view3d.hh:86
Depsgraph * depsgraph
Definition ED_view3d.hh:78