59 region.
winx = short(win_size.x);
60 region.
winy = short(win_size.y);
83 char err_out[256] =
"unknown";
86 if (offscreen ==
nullptr) {
139 const int2 &win_size,
144 float clip_start, clip_end;
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;
220 const float point_size,
244 const float line_width)
254 const int cyclic_add = (cyclic &&
indices.size() > 2) ? 1 : 0;
257 for (
const int point_i :
indices) {
262 if (cyclic &&
indices.size() > 2) {
263 const int point_i =
indices[0];
273 const int2 &win_size,
277 const bool is_fill_stroke)
284 data.keep_size =
false;
285 data.pixfactor = 1.0f;
288 data.caps_start = cap_start;
289 data.caps_end = cap_end;
290 data.fill_stroke = is_fill_stroke;
299 const int2 &win_size,
308 const bool fill_stroke,
309 const float radius_scale)
326 GPUUniformBuf *ubo =
create_shader_ubo(rv3d, win_size,
object, cap_start, cap_end, fill_stroke);
330 const int cyclic_add = (cyclic &&
indices.size() > 2) ? 1 : 0;
333 indices.size() + cyclic_add + 2);
335 auto draw_point = [&](
const int point_i) {
336 constexpr const float radius_to_pixel_factor =
338 const float thickness = radii[point_i] * radius_scale * radius_to_pixel_factor;
346 if (cyclic &&
indices.size() > 2) {
347 draw_point(
indices.last() - 1);
350 draw_point(
indices.first() + 1);
353 for (
const int point_i :
indices) {
357 if (cyclic &&
indices.size() > 2) {
359 draw_point(
indices.first() + 1);
363 draw_point(
indices.last() - 1);
371 const uint expand_prim_len = 12;
373 const uint final_vert_len = ((
batch->vertex_count_get() - 2) * expand_prim_len) * 3;
375 if (final_vert_len > 0) {
404 const float radius_scale)
421 for (
const int point_i :
indices) {
422 constexpr const float radius_to_pixel_factor =
424 const float thickness = radii[point_i] * radius_scale * radius_to_pixel_factor;
442 const float2 &viewport_size,
443 const float line_width,
450 constexpr const int segments_num = 32;
451 static const float2 coords[] = {
452 {1.0000f, 0.0000f}, {0.9808f, 0.1951f}, {0.9239f, 0.3827f}, {0.8315f, 0.5556f},
453 {0.7071f, 0.7071f}, {0.5556f, 0.8315f}, {0.3827f, 0.9239f}, {0.1951f, 0.9808f},
454 {0.0000f, 1.0000f}, {-0.1951f, 0.9808f}, {-0.3827f, 0.9239f}, {-0.5556f, 0.8315f},
455 {-0.7071f, 0.7071f}, {-0.8315f, 0.5556f}, {-0.9239f, 0.3827f}, {-0.9808f, 0.1951f},
456 {-1.0000f, 0.0000f}, {-0.9808f, -0.1951f}, {-0.9239f, -0.3827f}, {-0.8315f, -0.5556f},
457 {-0.7071f, -0.7071f}, {-0.5556f, -0.8315f}, {-0.3827f, -0.9239f}, {-0.1951f, -0.9808f},
458 {-0.0000f, -1.0000f}, {0.1951f, -0.9808f}, {0.3827f, -0.9239f}, {0.5556f, -0.8315f},
459 {0.7071f, -0.7071f}, {0.8315f, -0.5556f}, {0.9239f, -0.3827f}, {0.9808f, -0.1951f},
472 for (
const int point_i :
indices) {
473 const float radius = radii[point_i];
482 if (segments_num - 1 -
i >
i) {
485 center +
float3(radius * scale * coords[segments_num - 1 -
i], 0.0f));
500 for (
const int point_i :
indices) {
501 const float radius = radii[point_i];
537 for (
const int point_i :
indices) {
550 const int2 &win_size,
557 const float radius_scale)
589 const int material_index = materials[stroke_i];
607 points_by_curve[stroke_i],
620 draw_dots(
transform, points_by_curve[stroke_i], positions, radii, colors, radius_scale);
Camera data-block and utility functions.
Low-level operations for curves.
Low-level operations for grease pencil.
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
Image * BKE_image_add_from_imbuf(Main *bmain, ImBuf *ibuf, const char *name)
General operations, lookup, etc. for materials.
Material * BKE_object_material_get(Object *ob, short act)
void orthographic_m4(float mat[4][4], float left, float right, float bottom, float top, float nearClip, float farClip)
void perspective_m4(float mat[4][4], float left, float right, float bottom, float top, float nearClip, float farClip)
MINLINE void copy_v2_v2(float r[2], const float a[2])
eMaterialGPencilStyle_Mode
@ GP_MATERIAL_MODE_SQUARE
Object is a sort of wrapper for general info.
RV3DMatrixStore * ED_view3d_mats_rv3d_backup(RegionView3D *rv3d)
void ED_view3d_mats_rv3d_restore(RegionView3D *rv3d, RV3DMatrixStore *rv3dmat)
void ED_view3D_mats_rv3d_free(RV3DMatrixStore *rv3d_mat)
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 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)
blender::gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, blender::gpu::VertBuf *vertex_buf, blender::gpu::IndexBuf *index_buf, eGPUBatchFlag owns_flag)
void GPU_batch_discard(blender::gpu::Batch *batch)
void GPU_batch_draw_advanced(blender::gpu::Batch *batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
void GPU_batch_bind_as_resources(blender::gpu::Batch *batch, GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants=nullptr)
void GPU_batch_set_shader(blender::gpu::Batch *batch, GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_debug_capture_end()
void GPU_debug_capture_begin(const char *title)
int GPU_offscreen_width(const GPUOffScreen *offscreen)
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
int GPU_offscreen_height(const GPUOffScreen *offscreen)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, eGPUTextureFormat format, eGPUTextureUsage usage, bool clear, char err_out[256])
void GPU_clear_color(float red, float green, float blue, float alpha)
void GPU_offscreen_free(GPUOffScreen *offscreen)
void GPU_clear_depth(float depth)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
void GPU_matrix_identity_projection_set()
void GPU_matrix_identity_set()
#define GPU_matrix_set(x)
void GPU_matrix_push_projection()
void GPU_matrix_pop_projection()
#define GPU_matrix_projection_set(x)
void GPU_polygon_offset(float viewdist, float dist)
@ GPU_PRIM_LINE_STRIP_ADJ
@ GPU_SHADER_GPENCIL_STROKE
@ GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR
@ GPU_SHADER_3D_FLAT_COLOR
@ GPU_SHADER_3D_POLYLINE_FLAT_COLOR
void GPU_program_point_size(bool enable)
void GPU_line_width(float width)
void GPU_depth_mask(bool depth)
void GPU_depth_test(eGPUDepthTest test)
bool GPU_depth_mask_get()
@ GPU_TEXTURE_USAGE_HOST_READ
#define GPU_vertbuf_create_with_format(format)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
void IMB_byte_from_float(ImBuf *ibuf)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
BMesh const char void * data
GAttributeReader lookup_or_default(StringRef attribute_id, AttrDomain domain, eCustomDataType data_type, const void *default_value=nullptr) const
const bke::CurvesGeometry & strokes() const
VArray< float > radii() const
void foreach_index(Fn &&fn) const
struct @242053044010324116347033273112253060004051364061::@051143074301336237271216303350234260141112266062 batch
constexpr float LEGACY_RADIUS_CONVERSION_FACTOR
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 ®ion, const RegionViewData &data)
constexpr const float min_stroke_thickness
constexpr const bool enable_debug_gpu_capture
void set_view_matrix(const RegionView3D &rv3d)
void draw_lines(const float4x4 &transform, IndexRange indices, Span< float3 > start_positions, Span< float3 > end_positions, const VArray< ColorGeometry4f > &colors, float line_width)
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 ®ion, const int2 &win_size)
static GPUUniformBuf * 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)
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 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)
void clear_projection_matrix()
void set_projection_matrix(const RegionView3D &rv3d)
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)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
struct MaterialGPencilStyle * gp_style
const c_style_mat & ptr() const