Blender  V3.3
gpencil_engine.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2017 Blender Foundation. */
3 
8 #pragma once
9 
10 #include "DNA_gpencil_types.h"
11 
12 #include "DRW_render.h"
13 
14 #include "BLI_bitmap.h"
15 
16 #include "GPU_batch.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include "gpencil_defines.h"
23 #include "gpencil_shader_shared.h"
24 
26 
27 struct GPENCIL_Data;
28 struct GPENCIL_StorageList;
29 struct GPUBatch;
30 struct GpencilBatchCache;
31 struct Object;
32 struct RenderEngine;
33 struct RenderLayer;
34 struct View3D;
35 struct bGPDstroke;
36 
37 /* used to convert pixel scale. */
38 #define GPENCIL_PIXEL_FACTOR 2000.0f
39 
40 /* used to expand VBOs. Size has a big impact in the speed */
41 #define GPENCIL_VBO_BLOCK_SIZE 128
42 
43 #define GP_MAX_MASKBITS 256
44 
45 /* *********** Draw Data *********** */
46 typedef struct GPENCIL_MaterialPool {
47  /* Single linked-list. */
49  /* GPU representation of materials. */
51  /* Matching ubo. */
52  struct GPUUniformBuf *ubo;
53  /* Texture per material. NULL means none. */
56  /* Number of material used in this pool. */
59 
60 typedef struct GPENCIL_LightPool {
61  /* GPU representation of materials. */
63  /* Matching ubo. */
64  struct GPUUniformBuf *ubo;
65  /* Number of light in the pool. */
68 
69 typedef struct GPENCIL_ViewLayerData {
70  /* GPENCIL_tObject */
72  /* GPENCIL_tLayer */
74  /* GPENCIL_tVfx */
76  /* GPENCIL_MaterialPool */
78  /* GPENCIL_LightPool */
80  /* BLI_bitmap */
83 
84 /* *********** GPencil *********** */
85 
86 typedef struct GPENCIL_tVfx {
88  struct GPENCIL_tVfx *next;
90  /* Frame-buffer reference since it may not be allocated yet. */
93 
94 typedef struct GPENCIL_tLayer {
107  int layer_id;
109 
110 typedef struct GPENCIL_tObject {
113 
114  struct {
117 
118  struct {
120  } vfx;
121 
122  /* Distance to camera. Used for sorting. */
123  float camera_z;
124  /* Used for stroke thickness scaling. */
126  /* Normal used for shading. Based on view angle. */
127  float plane_normal[3];
128  /* Used for drawing depth merge pass. */
129  float plane_mat[4][4];
130 
132 
133  /* Use Material Holdout. */
135 
137 
138 /* *********** LISTS *********** */
139 typedef struct GPENCIL_StorageList {
142 
143 typedef struct GPENCIL_PassList {
144  /* Composite the main GPencil buffer onto the rendered image. */
146  /* Composite the object depth to the default depth buffer to occlude overlays. */
148  /* Invert mask buffer content. */
150  /* Anti-Aliasing. */
155 
156 typedef struct GPENCIL_FramebufferList {
166 
167 typedef struct GPENCIL_TextureList {
168  /* Dummy texture to avoid errors cause by empty sampler. */
170  /* Snapshot for smoother drawing. */
174  /* Textures used by Antialiasing. */
177  /* Textures used during render. Containing underlying rendered scene. */
181 
182 typedef struct GPENCIL_Data {
183  void *engine_type; /* Required */
189 
190 /* *********** STATIC *********** */
191 typedef struct GPENCIL_PrivateData {
192  /* Pointers copied from GPENCIL_ViewLayerData. */
199  /* Last used material pool. */
201  /* Last used light pool. */
203  /* Common lightpool containing all lights in the scene. */
205  /* Common lightpool containing one ambient white light. */
207  /* Linked list of tObjects. */
208  struct {
211  /* Temp Textures (shared with other engines). */
216  /* Revealage is 1 - alpha */
220  /* Mask texture */
222  /* Anti-Aliasing. */
225  /* Pointer to dtxl->depth */
228  /* Copy of txl->dummy_tx */
230  /* Copy of v3d->shading.single_color. */
232  /* Copy of v3d->shading.color_type or -1 to ignore. */
234  /* Current frame */
235  int cfra;
236  /* If we are rendering for final render (F12).
237  * NOTE: set to false for viewport and opengl rendering (including sequencer scene rendering),
238  * but set to true when rendering in #OB_RENDER shading mode (viewport or opengl rendering). */
239  bool is_render;
240  /* If we are in viewport display (used for VFX). */
242  /* True in selection and auto_depth drawing */
244  /* Is shading set to wire-frame. */
246  /* Used by the depth merge step. */
248  float object_bound_mat[4][4];
249  /* Used for computing object distance to camera. */
251  float camera_pos[3];
252  /* Pseudo depth of field parameter. Used to scale blur radius. */
253  float dof_params[2];
254  /* Used for DoF Setup. */
256  /* Copy of draw_ctx->view_layer for convenience. */
258  /* Copy of draw_ctx->scene for convenience. */
259  struct Scene *scene;
260  /* Copy of draw_ctx->vie3d for convenience. */
261  struct View3D *v3d;
262 
263  /* Active object. */
265  /* Object being in draw mode. */
267  /* Layer to append the temp stroke to. */
269  /* Temporary stroke currently being drawn. */
271  /* List of temp objects containing the stroke. */
272  struct {
275  /* Batches containing the temp stroke. */
280 
281  /* Display onion skinning */
282  bool do_onion;
283  /* Playing animation */
284  bool playing;
285  /* simplify settings */
289  /* Use scene lighting or flat shading (global setting). */
291  /* Use physical lights or just ambient lighting. */
293  /* Do we need additional frame-buffers? */
297  /* Some blend mode needs to add negative values.
298  * This is only supported if target texture is signed. */
300  /* Use only lines for multiedit and not active frame. */
302  /* Layer opacity for fading. */
304  /* Opacity for fading gpencil objects. */
306  /* Opacity for fading 3D objects. */
308  /* Mask opacity uniform. */
310  /* Xray transparency in solid mode. */
311  float xray_alpha;
312  /* Mask invert uniform. */
314  /* Vertex Paint opacity. */
317 
318 /* geometry batch cache functions */
319 struct GpencilBatchCache *gpencil_batch_cache_get(struct Object *ob, int cfra);
320 
323 
325  const Object *ob,
326  const bGPDlayer *gpl,
327  const bGPDframe *gpf,
328  GPENCIL_tObject *tgp_ob);
330 
338  int mat_id,
339  struct GPUTexture **r_tex_stroke,
340  struct GPUTexture **r_tex_fill,
341  struct GPUUniformBuf **r_ubo_mat);
342 
343 void gpencil_light_ambient_add(GPENCIL_LightPool *lightpool, const float color[3]);
350 
351 /* effects */
353 
354 /* Shaders */
368 
369 void GPENCIL_shader_free(void);
370 
371 /* Antialiasing */
372 void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata);
373 void GPENCIL_antialiasing_draw(struct GPENCIL_Data *vedata);
374 
375 /* main functions */
376 void GPENCIL_engine_init(void *vedata);
377 void GPENCIL_cache_init(void *vedata);
378 void GPENCIL_cache_populate(void *vedata, struct Object *ob);
379 void GPENCIL_cache_finish(void *vedata);
380 void GPENCIL_draw_scene(void *vedata);
381 
382 /* render */
383 
388  struct RenderEngine *engine,
389  struct RenderLayer *render_layer,
390  const struct Depsgraph *depsgraph,
391  const rcti *rect);
392 void GPENCIL_render_to_image(void *vedata,
393  struct RenderEngine *engine,
394  struct RenderLayer *render_layer,
395  const rcti *rect);
396 
397 /* Draw Data. */
398 void gpencil_light_pool_free(void *storage);
399 void gpencil_material_pool_free(void *storage);
401 #ifdef __cplusplus
402 }
403 #endif
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:16
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
GPUBatch
Definition: GPU_batch.h:78
struct GPUFrameBuffer GPUFrameBuffer
struct GPUShader GPUShader
Definition: GPU_shader.h:20
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
struct GPUUniformBuf GPUUniformBuf
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
EvaluationStage stage
Definition: deg_eval.cc:89
const Depsgraph * depsgraph
#define GPENCIL_MATERIAL_BUFFER_LEN
#define GPENCIL_LIGHT_BUFFER_LEN
struct GPENCIL_Data GPENCIL_Data
struct GPUShader * GPENCIL_shader_fx_colorize_get(void)
void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObject *tgp_ob)
void GPENCIL_antialiasing_draw(struct GPENCIL_Data *vedata)
struct GPUShader * GPENCIL_shader_layer_blend_get(void)
struct GPUShader * GPENCIL_shader_fx_composite_get(void)
GPENCIL_tLayer * gpencil_layer_cache_get(GPENCIL_tObject *tgp_ob, int number)
void gpencil_material_resources_get(GPENCIL_MaterialPool *first_pool, int mat_id, struct GPUTexture **r_tex_stroke, struct GPUTexture **r_tex_fill, struct GPUUniformBuf **r_ubo_mat)
struct GPENCIL_tVfx GPENCIL_tVfx
void gpencil_light_pool_populate(GPENCIL_LightPool *lightpool, Object *ob)
struct GPENCIL_tObject GPENCIL_tObject
void GPENCIL_engine_init(void *vedata)
struct GPENCIL_FramebufferList GPENCIL_FramebufferList
void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
struct GpencilBatchCache * gpencil_batch_cache_get(struct Object *ob, int cfra)
GPENCIL_ViewLayerData * GPENCIL_view_layer_data_ensure(void)
struct GPUShader * GPENCIL_shader_mask_invert_get(void)
void GPENCIL_cache_init(void *vedata)
void GPENCIL_cache_finish(void *vedata)
GPENCIL_LightPool * gpencil_light_pool_add(GPENCIL_PrivateData *pd)
struct GPENCIL_ViewLayerData GPENCIL_ViewLayerData
void GPENCIL_cache_populate(void *vedata, struct Object *ob)
GPENCIL_tLayer * gpencil_layer_cache_add(GPENCIL_PrivateData *pd, const Object *ob, const bGPDlayer *gpl, const bGPDframe *gpf, GPENCIL_tObject *tgp_ob)
struct GPENCIL_MaterialPool GPENCIL_MaterialPool
struct GPUShader * GPENCIL_shader_fx_shadow_get(void)
struct GPENCIL_PassList GPENCIL_PassList
struct GPENCIL_tLayer GPENCIL_tLayer
void gpencil_light_pool_free(void *storage)
struct GPUShader * GPENCIL_shader_fx_transform_get(void)
void GPENCIL_shader_free(void)
GPENCIL_LightPool * gpencil_light_pool_create(GPENCIL_PrivateData *pd, Object *ob)
void GPENCIL_render_init(struct GPENCIL_Data *ved, struct RenderEngine *engine, struct RenderLayer *render_layer, const struct Depsgraph *depsgraph, const rcti *rect)
struct GPENCIL_StorageList GPENCIL_StorageList
void gpencil_material_pool_free(void *storage)
struct GPUShader * GPENCIL_shader_fx_rim_get(void)
struct GPUShader * GPENCIL_shader_fx_pixelize_get(void)
struct GPUShader * GPENCIL_shader_fx_blur_get(void)
void gpencil_object_cache_sort(GPENCIL_PrivateData *pd)
struct GPENCIL_LightPool GPENCIL_LightPool
DrawEngineType draw_engine_gpencil_type
struct GPENCIL_TextureList GPENCIL_TextureList
GPENCIL_MaterialPool * gpencil_material_pool_create(GPENCIL_PrivateData *pd, Object *ob, int *ofs)
struct GPUShader * GPENCIL_shader_antialiasing(int stage)
void gpencil_light_ambient_add(GPENCIL_LightPool *lightpool, const float color[3])
struct GPUShader * GPENCIL_shader_geometry_get(void)
void GPENCIL_draw_scene(void *vedata)
void GPENCIL_render_to_image(void *vedata, struct RenderEngine *engine, struct RenderLayer *render_layer, const rcti *rect)
struct GPUShader * GPENCIL_shader_fx_glow_get(void)
struct GPUShader * GPENCIL_shader_depth_merge_get(void)
struct GPENCIL_PrivateData GPENCIL_PrivateData
GPENCIL_tObject * gpencil_object_cache_add(GPENCIL_PrivateData *pd, Object *ob)
void * engine_type
struct GPENCIL_TextureList * txl
struct GPENCIL_PassList * psl
struct GPENCIL_StorageList * stl
struct GPENCIL_FramebufferList * fbl
struct GPUFrameBuffer * smaa_weight_fb
struct GPUFrameBuffer * render_fb
struct GPUFrameBuffer * smaa_edge_fb
struct GPUFrameBuffer * snapshot_fb
struct GPUFrameBuffer * mask_fb
struct GPUFrameBuffer * gpencil_fb
struct GPUFrameBuffer * object_fb
struct GPUFrameBuffer * layer_fb
gpLight light_data[GPENCIL_LIGHT_BUFFER_LEN]
struct GPUUniformBuf * ubo
gpMaterial mat_data[GPENCIL_MATERIAL_BUFFER_LEN]
struct GPUTexture * tex_fill[GPENCIL_MATERIAL_BUFFER_LEN]
struct GPUUniformBuf * ubo
struct GPENCIL_MaterialPool * next
struct GPUTexture * tex_stroke[GPENCIL_MATERIAL_BUFFER_LEN]
struct DRWPass * mask_invert_ps
struct DRWPass * smaa_weight_ps
struct DRWPass * merge_depth_ps
struct DRWPass * composite_ps
struct DRWPass * smaa_resolve_ps
struct DRWPass * smaa_edge_ps
float object_bound_mat[4][4]
GPENCIL_LightPool * last_light_pool
struct BLI_memblock * gp_vfx_pool
GPUTexture * scene_depth_tx
struct bGPDstroke * sbuffer_stroke
struct BLI_memblock * gp_layer_pool
GPUTexture * color_object_tx
GPENCIL_LightPool * shadeless_light_pool
GPUTexture * smaa_weight_tx
struct bGPDlayer * sbuffer_layer
struct ViewLayer * view_layer
GPUTexture * reveal_tx
struct BLI_memblock * gp_maskbit_pool
struct BLI_memblock * gp_object_pool
struct GPENCIL_PrivateData::@219 tobjects_infront
GPUTexture * dummy_tx
GPENCIL_tObject * first
GPUTexture * color_tx
GPUTexture * mask_tx
struct GPENCIL_PrivateData::@220 sbuffer_tobjects
GPENCIL_LightPool * global_light_pool
GPUTexture * depth_tx
struct BLI_memblock * gp_material_pool
struct View3D * v3d
GPUFrameBuffer * scene_fb
struct Scene * scene
GPENCIL_tObject * last
struct GPENCIL_PrivateData::@219 tobjects
GPUTexture * smaa_edge_tx
GPUTexture * reveal_layer_tx
struct bGPdata * sbuffer_gpd
GPUTexture * color_layer_tx
struct BLI_memblock * gp_light_pool
GPENCIL_MaterialPool * last_material_pool
GPUTexture * reveal_object_tx
struct GPENCIL_PrivateData * pd
struct GPUTexture * snapshot_reveal_tx
struct GPUTexture * smaa_area_tx
struct GPUTexture * snapshot_depth_tx
struct GPUTexture * snapshot_color_tx
struct GPUTexture * smaa_search_tx
struct GPUTexture * render_depth_tx
struct GPUTexture * render_color_tx
struct GPUTexture * dummy_texture
struct BLI_memblock * gp_vfx_pool
struct BLI_memblock * gp_material_pool
struct BLI_memblock * gp_maskbit_pool
struct BLI_memblock * gp_light_pool
struct BLI_memblock * gp_layer_pool
struct BLI_memblock * gp_object_pool
DRWShadingGroup * base_shgrp
BLI_bitmap * mask_invert_bits
DRWPass * geom_ps
BLI_bitmap * mask_bits
DRWPass * blend_ps
struct GPENCIL_tLayer * next
float plane_mat[4][4]
struct GPENCIL_tObject::@218 vfx
struct GPENCIL_tObject::@217 layers
GPENCIL_tLayer * last
struct GPENCIL_tObject * next
float plane_normal[3]
GPENCIL_tVfx * first
GPENCIL_tLayer * first
GPUFrameBuffer ** target_fb
DRWPass * vfx_ps
struct GPENCIL_tVfx * next