diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2020-03-09 18:27:24 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2020-03-09 18:27:24 +0300 |
commit | 29f3af95272590d26f610ae828b2eeee89c82a00 (patch) | |
tree | a696a58a2561c48f7ec6166e369e22081e0a64d8 /source/blender/draw/engines/gpencil/gpencil_engine.h | |
parent | dcb93126876879d969a30a7865700abd072066f8 (diff) |
GPencil: Refactor of Draw Engine, Vertex Paint and all internal functions
This commit is a full refactor of the grease pencil modules including Draw Engine, Modifiers, VFX, depsgraph update, improvements in operators and conversion of Sculpt and Weight paint tools to real brushes.
Also, a huge code cleanup has been done at all levels.
Thanks to @fclem for his work and yo @pepeland and @mendio for the testing and help in the development.
Differential Revision: https://developer.blender.org/D6293
Diffstat (limited to 'source/blender/draw/engines/gpencil/gpencil_engine.h')
-rw-r--r-- | source/blender/draw/engines/gpencil/gpencil_engine.h | 792 |
1 files changed, 347 insertions, 445 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h index 44a30260343..4b6059f1474 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.h +++ b/source/blender/draw/engines/gpencil/gpencil_engine.h @@ -23,6 +23,10 @@ #ifndef __GPENCIL_ENGINE_H__ #define __GPENCIL_ENGINE_H__ +#include "DNA_gpencil_types.h" + +#include "BLI_bitmap.h" + #include "GPU_batch.h" extern DrawEngineType draw_engine_gpencil_type; @@ -34,204 +38,201 @@ struct Object; struct RenderEngine; struct RenderLayer; struct bGPDstroke; - +struct View3D; +struct GpencilBatchCache; struct GPUBatch; struct GPUVertBuf; struct GPUVertFormat; -#define GPENCIL_MAX_SHGROUPS 65536 -#define GPENCIL_GROUPS_BLOCK_SIZE 1024 +/* used to convert pixel scale. */ +#define GPENCIL_PIXEL_FACTOR 2000.0f /* used to expand VBOs. Size has a big impact in the speed */ #define GPENCIL_VBO_BLOCK_SIZE 128 -#define GPENCIL_COLOR_SOLID 0 -#define GPENCIL_COLOR_TEXTURE 1 -#define GPENCIL_COLOR_PATTERN 2 - -/* *********** OBJECTS CACHE *********** */ -typedef struct tGPencilObjectCache_shgrp { - /** type of blend (regular, add, mult, etc...) */ - int mode; - /** flag to enable the layer clamping */ - bool mask_layer; - /** factor to define the opacity of the layer */ - float blend_opacity; - DRWShadingGroup *init_shgrp; - DRWShadingGroup *end_shgrp; -} tGPencilObjectCache_shgrp; - -/* used to save gpencil object data for drawing */ -typedef struct tGPencilObjectCache { - struct Object *ob; - struct bGPdata *gpd; - int idx; /*original index, can change after sort */ - char *name; - - /* effects */ - bool has_fx; - ListBase shader_fx; - float pixfactor; - DRWShadingGroup *fx_wave_sh; - DRWShadingGroup *fx_blur_sh; - DRWShadingGroup *fx_colorize_sh; - DRWShadingGroup *fx_pixel_sh; - DRWShadingGroup *fx_rim_sh; - DRWShadingGroup *fx_shadow_sh; - DRWShadingGroup *fx_glow_sh; - DRWShadingGroup *fx_swirl_sh; - DRWShadingGroup *fx_flip_sh; - DRWShadingGroup *fx_light_sh; - - float loc[3]; - float obmat[4][4]; - float zdepth; /* z-depth value to sort gp object */ - bool is_dup_ob; /* flag to tag duplicate objects */ - float scale; - - /* shading type */ - int shading_type[2]; - - /* GPU data size */ - int tot_vertex; - int tot_triangles; - - /* Save shader groups by layer */ - int tot_layers; - tGPencilObjectCache_shgrp *shgrp_array; - -} tGPencilObjectCache; +#define GP_MAX_MASKBITS 256 + +/* UBO structure. Watch out for padding. Must match GLSL declaration. */ +typedef struct gpMaterial { + float stroke_color[4]; + float fill_color[4]; + float fill_mix_color[4]; + float fill_uv_transform[3][2], _pad0[2]; + float stroke_texture_mix; + float stroke_u_scale; + float fill_texture_mix; + int flag; +} gpMaterial; + +/* gpMaterial->flag */ +/* WATCH Keep in sync with GLSL declaration. */ +#define GP_STROKE_ALIGNMENT_STROKE 1 +#define GP_STROKE_ALIGNMENT_OBJECT 2 +#define GP_STROKE_ALIGNMENT_FIXED 3 +#define GP_STROKE_ALIGNMENT 0x3 +#define GP_STROKE_OVERLAP (1 << 2) +#define GP_STROKE_TEXTURE_USE (1 << 3) +#define GP_STROKE_TEXTURE_STENCIL (1 << 4) +#define GP_STROKE_TEXTURE_PREMUL (1 << 5) +#define GP_STROKE_DOTS (1 << 6) +#define GP_FILL_TEXTURE_USE (1 << 10) +#define GP_FILL_TEXTURE_PREMUL (1 << 11) +#define GP_FILL_TEXTURE_CLIP (1 << 12) +#define GP_FILL_GRADIENT_USE (1 << 13) +#define GP_FILL_GRADIENT_RADIAL (1 << 14) + +#define GPENCIL_LIGHT_BUFFER_LEN 128 + +/* UBO structure. Watch out for padding. Must match GLSL declaration. */ +typedef struct gpLight { + float color[3], type; + float right[3], spotsize; + float up[3], spotblend; + float forward[4]; + float position[4]; +} gpLight; + +/* gpLight->type */ +/* WATCH Keep in sync with GLSL declaration. */ +#define GP_LIGHT_TYPE_POINT 0.0 +#define GP_LIGHT_TYPE_SPOT 1.0 +#define GP_LIGHT_TYPE_SUN 2.0 +#define GP_LIGHT_TYPE_AMBIENT 3.0 + +BLI_STATIC_ASSERT_ALIGN(gpMaterial, 16) +BLI_STATIC_ASSERT_ALIGN(gpLight, 16) + +/* *********** Draw Datas *********** */ +typedef struct GPENCIL_MaterialPool { + /* Linklist. */ + struct GPENCIL_MaterialPool *next; + /* GPU representatin of materials. */ + gpMaterial mat_data[GP_MATERIAL_BUFFER_LEN]; + /* Matching ubo. */ + struct GPUUniformBuffer *ubo; + /* Texture per material. NULL means none. */ + struct GPUTexture *tex_fill[GP_MATERIAL_BUFFER_LEN]; + struct GPUTexture *tex_stroke[GP_MATERIAL_BUFFER_LEN]; + /* Number of material used in this pool. */ + int used_count; +} GPENCIL_MaterialPool; + +typedef struct GPENCIL_LightPool { + /* GPU representatin of materials. */ + gpLight light_data[GPENCIL_LIGHT_BUFFER_LEN]; + /* Matching ubo. */ + struct GPUUniformBuffer *ubo; + /* Number of light in the pool. */ + int light_used; +} GPENCIL_LightPool; + +typedef struct GPENCIL_ViewLayerData { + /* GPENCIL_tObject */ + struct BLI_memblock *gp_object_pool; + /* GPENCIL_tLayer */ + struct BLI_memblock *gp_layer_pool; + /* GPENCIL_tVfx */ + struct BLI_memblock *gp_vfx_pool; + /* GPENCIL_MaterialPool */ + struct BLI_memblock *gp_material_pool; + /* GPENCIL_LightPool */ + struct BLI_memblock *gp_light_pool; + /* BLI_bitmap */ + struct BLI_memblock *gp_maskbit_pool; +} GPENCIL_ViewLayerData; + +/* *********** GPencil *********** */ + +typedef struct GPENCIL_tVfx { + /** Linklist */ + struct GPENCIL_tVfx *next; + DRWPass *vfx_ps; + /* Framebuffer reference since it may not be allocated yet. */ + GPUFrameBuffer **target_fb; +} GPENCIL_tVfx; + +typedef struct GPENCIL_tLayer { + /** Linklist */ + struct GPENCIL_tLayer *next; + /** Geometry pass (draw all strokes). */ + DRWPass *geom_ps; + /** Blend pass to composite onto the target buffer (blends modes). NULL if not needed. */ + DRWPass *blend_ps; + /** First shading group created for this layer. Contains all uniforms. */ + DRWShadingGroup *base_shgrp; + /** Layer id of the mask. */ + BLI_bitmap *mask_bits; + BLI_bitmap *mask_invert_bits; + /** Index in the layer list. Used as id for masking. */ + int layer_id; +} GPENCIL_tLayer; + +typedef struct GPENCIL_tObject { + /** Linklist */ + struct GPENCIL_tObject *next; + + struct { + GPENCIL_tLayer *first, *last; + } layers; + + struct { + GPENCIL_tVfx *first, *last; + } vfx; + + /* Distance to camera. Used for sorting. */ + float camera_z; + /* Used for stroke thickness scaling. */ + float object_scale; + /* Normal used for shading. Based on view angle. */ + float plane_normal[3]; + /* Used for drawing depth merge pass. */ + float plane_mat[4][4]; + + bool is_drawmode3d; +} GPENCIL_tObject; /* *********** LISTS *********** */ -typedef struct GPENCIL_shgroup { - int s_clamp; - int stroke_style; - int color_type; - int mode; - int texture_mix; - int texture_flip; - int texture_clamp; - int fill_style; - int keep_size; - int caps_mode[2]; - float obj_scale; - int xray_mode; - int alignment_mode; - - float gradient_f; - float gradient_s[2]; - - float mix_stroke_factor; - - /* color of the wireframe */ - float wire_color[4]; - /* shading type and mode */ - int shading_type[2]; - int is_xray; -} GPENCIL_shgroup; - -typedef struct GPENCIL_Storage { - int shgroup_id; /* total elements */ - int stroke_style; - int color_type; - int mode; - int xray; - int keep_size; - float obj_scale; - float pixfactor; - bool is_playing; - bool is_render; - bool is_mat_preview; - bool is_main_overlay; - bool is_main_onion; - bool background_ready; - int is_xray; - bool is_ontop; - bool reset_cache; - const float *pixsize; - float render_pixsize; - int tonemapping; - int do_select_outline; - float select_color[4]; - short multisamples; - float grid_matrix[4][4]; - - short framebuffer_flag; /* flag what framebuffer need to create */ - - int blend_mode; - int mask_layer; - - /* simplify settings*/ - bool simplify_fill; - bool simplify_modif; - bool simplify_fx; - bool simplify_blend; - - float gradient_f; - float gradient_s[2]; - int alignment_mode; - - float mix_stroke_factor; - - /* Render Matrices and data */ - float view_vecs[2][4]; /* vec4[2] */ - - int shade_render[2]; - - Object *camera; /* camera pointer for render mode */ -} GPENCIL_Storage; - -typedef enum eGpencilFramebuffer_Flag { - GP_FRAMEBUFFER_MULTISAMPLE = (1 << 0), - GP_FRAMEBUFFER_BASIC = (1 << 1), - GP_FRAMEBUFFER_DRAW = (1 << 2), -} eGpencilFramebuffer_Flag; - typedef struct GPENCIL_StorageList { - struct GPENCIL_Storage *storage; - struct g_data *g_data; - struct GPENCIL_shgroup *shgroups; + struct GPENCIL_PrivateData *pd; } GPENCIL_StorageList; typedef struct GPENCIL_PassList { - struct DRWPass *stroke_pass_2d; - struct DRWPass *stroke_pass_3d; - struct DRWPass *edit_pass; - struct DRWPass *drawing_pass; - struct DRWPass *mix_pass; - struct DRWPass *mix_pass_noblend; - struct DRWPass *background_pass; - struct DRWPass *paper_pass; - struct DRWPass *grid_pass; - struct DRWPass *blend_pass; - - /* effects */ - struct DRWPass *fx_shader_pass; - struct DRWPass *fx_shader_pass_blend; - + /* Composite the main GPencil buffer onto the rendered image. */ + struct DRWPass *composite_ps; + /* Composite the object depth to the default depth buffer to occlude overlays. */ + struct DRWPass *merge_depth_ps; + /* Invert mask buffer content. */ + struct DRWPass *mask_invert_ps; + /* Anti-Aliasing. */ + struct DRWPass *smaa_edge_ps; + struct DRWPass *smaa_weight_ps; + struct DRWPass *smaa_resolve_ps; } GPENCIL_PassList; typedef struct GPENCIL_FramebufferList { - struct GPUFrameBuffer *main; - struct GPUFrameBuffer *temp_fb_a; - struct GPUFrameBuffer *temp_fb_b; - struct GPUFrameBuffer *temp_fb_fx; - struct GPUFrameBuffer *background_fb; - - struct GPUFrameBuffer *multisample_fb; + struct GPUFrameBuffer *render_fb; + struct GPUFrameBuffer *gpencil_fb; + struct GPUFrameBuffer *snapshot_fb; + struct GPUFrameBuffer *layer_fb; + struct GPUFrameBuffer *object_fb; + struct GPUFrameBuffer *mask_fb; + struct GPUFrameBuffer *smaa_edge_fb; + struct GPUFrameBuffer *smaa_weight_fb; } GPENCIL_FramebufferList; typedef struct GPENCIL_TextureList { - struct GPUTexture *texture; - - /* multisample textures */ - struct GPUTexture *multisample_color; - struct GPUTexture *multisample_depth; - - /* Background textures for speed-up drawing. */ - struct GPUTexture *background_depth_tx; - struct GPUTexture *background_color_tx; - + /* Dummy texture to avoid errors cause by empty sampler. */ + struct GPUTexture *dummy_texture; + /* Snapshot for smoother drawing. */ + struct GPUTexture *snapshot_depth_tx; + struct GPUTexture *snapshot_color_tx; + struct GPUTexture *snapshot_reveal_tx; + /* Textures used by Antialiasing. */ + struct GPUTexture *smaa_area_tx; + struct GPUTexture *smaa_search_tx; + /* Textures used during render. Containing underlying rendered scene. */ + struct GPUTexture *render_depth_tx; + struct GPUTexture *render_color_tx; } GPENCIL_TextureList; typedef struct GPENCIL_Data { @@ -240,248 +241,175 @@ typedef struct GPENCIL_Data { struct GPENCIL_TextureList *txl; struct GPENCIL_PassList *psl; struct GPENCIL_StorageList *stl; - - /* render textures */ - struct GPUTexture *render_depth_tx; - struct GPUTexture *render_color_tx; - } GPENCIL_Data; /* *********** STATIC *********** */ -typedef struct g_data { - struct DRWShadingGroup *shgrps_edit_point; - struct DRWShadingGroup *shgrps_edit_line; - struct DRWShadingGroup *shgrps_drawing_stroke; - struct DRWShadingGroup *shgrps_drawing_fill; - struct DRWShadingGroup *shgrps_grid; - - int gp_cache_used; /* total objects in cache */ - int gp_cache_size; /* size of the cache */ - struct tGPencilObjectCache *gp_object_cache; - - /* for buffer only one batch is nedeed because the drawing is only of one stroke */ - GPUBatch *batch_buffer_stroke; - GPUBatch *batch_buffer_fill; - GPUBatch *batch_buffer_ctrlpoint; - - /* grid geometry */ - GPUBatch *batch_grid; - - /* runtime pointers texture */ - struct GPUTexture *input_depth_tx; - struct GPUTexture *input_color_tx; - - /* working textures */ - struct GPUTexture *temp_color_tx_a; - struct GPUTexture *temp_depth_tx_a; - - struct GPUTexture *temp_color_tx_b; - struct GPUTexture *temp_depth_tx_b; - - struct GPUTexture *temp_color_tx_fx; - struct GPUTexture *temp_depth_tx_fx; - - int session_flag; - bool do_instances; - -} g_data; /* Transient data */ - -/* flags for fast drawing support */ -typedef enum eGPsession_Flag { - GP_DRW_PAINT_HOLD = (1 << 0), - GP_DRW_PAINT_IDLE = (1 << 1), - GP_DRW_PAINT_FILLING = (1 << 2), - GP_DRW_PAINT_READY = (1 << 3), - GP_DRW_PAINT_PAINTING = (1 << 4), -} eGPsession_Flag; - -typedef struct GPENCIL_e_data { - /* textures */ - struct GPUTexture *gpencil_blank_texture; - - /* general drawing shaders */ - struct GPUShader *gpencil_fill_sh; - struct GPUShader *gpencil_stroke_sh; - struct GPUShader *gpencil_point_sh; - struct GPUShader *gpencil_edit_point_sh; - struct GPUShader *gpencil_line_sh; - struct GPUShader *gpencil_drawing_fill_sh; - struct GPUShader *gpencil_fullscreen_sh; - struct GPUShader *gpencil_simple_fullscreen_sh; - struct GPUShader *gpencil_blend_fullscreen_sh; - struct GPUShader *gpencil_background_sh; - struct GPUShader *gpencil_paper_sh; - - /* effects */ - struct GPUShader *gpencil_fx_blur_sh; - struct GPUShader *gpencil_fx_colorize_sh; - struct GPUShader *gpencil_fx_flip_sh; - struct GPUShader *gpencil_fx_glow_prepare_sh; - struct GPUShader *gpencil_fx_glow_resolve_sh; - struct GPUShader *gpencil_fx_light_sh; - struct GPUShader *gpencil_fx_pixel_sh; - struct GPUShader *gpencil_fx_rim_prepare_sh; - struct GPUShader *gpencil_fx_rim_resolve_sh; - struct GPUShader *gpencil_fx_shadow_prepare_sh; - struct GPUShader *gpencil_fx_shadow_resolve_sh; - struct GPUShader *gpencil_fx_swirl_sh; - struct GPUShader *gpencil_fx_wave_sh; - -} GPENCIL_e_data; /* Engine data */ - -/* GPUBatch Cache Element */ -typedef struct GpencilBatchCacheElem { - GPUBatch *batch; - GPUVertBuf *vbo; - int vbo_len; - /* attr ids */ - GPUVertFormat *format; - uint pos_id; - uint color_id; - uint thickness_id; - uint uvdata_id; - uint prev_pos_id; - - /* size for VBO alloc */ - int tot_vertex; -} GpencilBatchCacheElem; - -/* Defines each batch group to define later the shgroup */ -typedef struct GpencilBatchGroup { - struct bGPDlayer *gpl; /* reference to original layer */ - struct bGPDframe *gpf; /* reference to original frame */ - struct bGPDstroke *gps; /* reference to original stroke */ - short type; /* type of element */ - bool onion; /* the group is part of onion skin */ - int vertex_idx; /* index of vertex data */ -} GpencilBatchGroup; - -typedef enum GpencilBatchGroup_Type { - eGpencilBatchGroupType_Stroke = 1, - eGpencilBatchGroupType_Point = 2, - eGpencilBatchGroupType_Fill = 3, - eGpencilBatchGroupType_Edit = 4, - eGpencilBatchGroupType_Edlin = 5, -} GpencilBatchGroup_Type; - -/* Runtime data for GPU and evaluated frames after applying modifiers */ -typedef struct GpencilBatchCache { - GpencilBatchCacheElem b_stroke; - GpencilBatchCacheElem b_point; - GpencilBatchCacheElem b_fill; - GpencilBatchCacheElem b_edit; - GpencilBatchCacheElem b_edlin; - - /** Cache is dirty */ - bool is_dirty; - /** Edit mode flag */ - bool is_editmode; - /** Last cache frame */ - int cache_frame; - - /** Total groups in arrays */ - int grp_used; - /** Max size of the array */ - int grp_size; - /** Array of cache elements */ - struct GpencilBatchGroup *grp_cache; -} GpencilBatchCache; - -/* general drawing functions */ -struct DRWShadingGroup *gpencil_shgroup_stroke_create(struct GPENCIL_e_data *e_data, - struct GPENCIL_Data *vedata, - struct DRWPass *pass, - struct GPUShader *shader, - struct Object *ob, - float (*obmat)[4], - struct bGPdata *gpd, - struct bGPDlayer *gpl, - struct bGPDstroke *gps, - struct MaterialGPencilStyle *gp_style, - int id, - bool onion, - const float scale, - const int shading_type[2]); -void gpencil_populate_datablock(struct GPENCIL_e_data *e_data, - void *vedata, - struct Object *ob, - struct tGPencilObjectCache *cache_ob); -void gpencil_populate_buffer_strokes(struct GPENCIL_e_data *e_data, - void *vedata, - struct ToolSettings *ts, - struct Object *ob); -void gpencil_populate_multiedit(struct GPENCIL_e_data *e_data, - void *vedata, - struct Object *ob, - struct tGPencilObjectCache *cache_ob); -void gpencil_populate_particles(struct GPENCIL_e_data *e_data, - struct GHash *gh_objects, - void *vedata); - -void gpencil_multisample_ensure(struct GPENCIL_Data *vedata, int rect_w, int rect_h); - -/* create geometry functions */ -void gpencil_get_point_geom(struct GpencilBatchCacheElem *be, - struct bGPDstroke *gps, - short thickness, - const float ink[4], - const int follow_mode); -void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be, - struct bGPDstroke *gps, - short thickness, - const float ink[4]); -void gpencil_get_fill_geom(struct GpencilBatchCacheElem *be, - struct Object *ob, - struct bGPDstroke *gps, - const float color[4]); -void gpencil_get_edit_geom(struct GpencilBatchCacheElem *be, - struct bGPDstroke *gps, - float alpha, - short dflag); -void gpencil_get_edlin_geom(struct GpencilBatchCacheElem *be, - struct bGPDstroke *gps, - float alpha, - const bool hide_select); - -struct GPUBatch *gpencil_get_buffer_stroke_geom(struct bGPdata *gpd, short thickness); -struct GPUBatch *gpencil_get_buffer_fill_geom(struct bGPdata *gpd); -struct GPUBatch *gpencil_get_buffer_point_geom(struct bGPdata *gpd, short thickness); -struct GPUBatch *gpencil_get_buffer_ctrlpoint_geom(struct bGPdata *gpd); -struct GPUBatch *gpencil_get_grid(Object *ob); - -/* object cache functions */ -struct tGPencilObjectCache *gpencil_object_cache_add(struct tGPencilObjectCache *cache_array, - struct Object *ob, - int *gp_cache_size, - int *gp_cache_used); - -bool gpencil_onion_active(struct bGPdata *gpd); - -/* shading groups cache functions */ -struct GpencilBatchGroup *gpencil_group_cache_add(struct GpencilBatchGroup *cache_array, - struct bGPDlayer *gpl, - struct bGPDframe *gpf, - struct bGPDstroke *gps, - const short type, - const bool onion, - const int vertex_idx, - int *grp_size, - int *grp_used); +typedef struct GPENCIL_PrivateData { + /* Pointers copied from GPENCIL_ViewLayerData. */ + struct BLI_memblock *gp_object_pool; + struct BLI_memblock *gp_layer_pool; + struct BLI_memblock *gp_vfx_pool; + struct BLI_memblock *gp_material_pool; + struct BLI_memblock *gp_light_pool; + struct BLI_memblock *gp_maskbit_pool; + /* Last used material pool. */ + GPENCIL_MaterialPool *last_material_pool; + /* Last used light pool. */ + GPENCIL_LightPool *last_light_pool; + /* Common lightpool containing all lights in the scene. */ + GPENCIL_LightPool *global_light_pool; + /* Common lightpool containing one ambient white light. */ + GPENCIL_LightPool *shadeless_light_pool; + /* Linked list of tObjects. */ + struct { + GPENCIL_tObject *first, *last; + } tobjects, tobjects_infront; + /* Temp Textures (shared with other engines). */ + GPUTexture *depth_tx; + GPUTexture *color_tx; + GPUTexture *color_layer_tx; + GPUTexture *color_object_tx; + /* Revealage is 1 - alpha */ + GPUTexture *reveal_tx; + GPUTexture *reveal_layer_tx; + GPUTexture *reveal_object_tx; + /* Mask texture */ + GPUTexture *mask_tx; + /* Anti-Aliasing. */ + GPUTexture *smaa_edge_tx; + GPUTexture *smaa_weight_tx; + /* Pointer to dtxl->depth */ + GPUTexture *scene_depth_tx; + GPUFrameBuffer *scene_fb; + /* Copy of txl->dummy_tx */ + GPUTexture *dummy_tx; + /* Copy of v3d->shading.single_color. */ + float v3d_single_color[3]; + /* Copy of v3d->shading.color_type or -1 to ignore. */ + int v3d_color_type; + /* Current frame */ + int cfra; + /* If we are rendering for final render (F12). */ + bool is_render; + /* If we are in viewport display (used for VFX). */ + bool is_viewport; + /* True in selection and auto_depth drawing */ + bool draw_depth_only; + /* Is shading set to wireframe. */ + bool draw_wireframe; + /* Used by the depth merge step. */ + int is_stroke_order_3d; + float object_bound_mat[4][4]; + /* Used for computing object distance to camera. */ + float camera_z_axis[3], camera_z_offset; + float camera_pos[3]; + /* Pseudo depth of field parameter. Used to scale blur radius. */ + float dof_params[2]; + /* Used for DoF Setup. */ + Object *camera; + /* Copy of draw_ctx->scene for convenience. */ + struct Scene *scene; + + /* Active object. */ + Object *obact; + /* Object being in draw mode. */ + struct bGPdata *sbuffer_gpd; + /* Layer to append the temp stroke to. */ + struct bGPDlayer *sbuffer_layer; + /* Temporary stroke currently being drawn. */ + struct bGPDstroke *sbuffer_stroke; + /* List of temp objects containing the stroke. */ + struct { + GPENCIL_tObject *first, *last; + } sbuffer_tobjects; + /* Batches containing the temp stroke. */ + GPUBatch *stroke_batch; + GPUBatch *fill_batch; + bool do_fast_drawing; + bool snapshot_buffer_dirty; + + /* Display onion skinning */ + bool do_onion; + /* simplify settings */ + bool simplify_fill; + bool simplify_fx; + bool simplify_antialias; + /* Use scene lighting or flat shading (global setting). */ + bool use_lighting; + /* Use physical lights or just ambient lighting. */ + bool use_lights; + /* Do we need additional framebuffers? */ + bool use_layer_fb; + bool use_object_fb; + bool use_mask_fb; + /* Some blend mode needs to add negative values. + * This is only supported if target texture is signed. */ + bool use_signed_fb; + /* Use only lines for multiedit and not active frame. */ + bool use_multiedit_lines_only; + /* Layer opacity for fading. */ + float fade_layer_opacity; + /* Opacity for fading gpencil objects. */ + float fade_gp_object_opacity; + /* Opacity for fading 3D objects. */ + float fade_3d_object_opacity; + /* Mask opacity uniform. */ + float mask_opacity; + /* Xray transparency in solid mode. */ + float xray_alpha; + /* Mask invert uniform. */ + int mask_invert; +} GPENCIL_PrivateData; /* geometry batch cache functions */ struct GpencilBatchCache *gpencil_batch_cache_get(struct Object *ob, int cfra); -/* effects */ -void GPENCIL_create_fx_shaders(struct GPENCIL_e_data *e_data); -void GPENCIL_delete_fx_shaders(struct GPENCIL_e_data *e_data); -void GPENCIL_create_fx_passes(struct GPENCIL_PassList *psl); +GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_PrivateData *pd, Object *ob); +void gpencil_object_cache_sort(GPENCIL_PrivateData *pd); -void gpencil_fx_prepare(struct GPENCIL_e_data *e_data, - struct GPENCIL_Data *vedata, - struct tGPencilObjectCache *cache_ob); -void gpencil_fx_draw(struct GPENCIL_e_data *e_data, - struct GPENCIL_Data *vedata, - struct tGPencilObjectCache *cache_ob); +GPENCIL_tLayer *gpencil_layer_cache_add(GPENCIL_PrivateData *pd, + const Object *ob, + const bGPDlayer *gpl, + const bGPDframe *gpf, + GPENCIL_tObject *tgp_ob); +GPENCIL_tLayer *gpencil_layer_cache_get(GPENCIL_tObject *tgp_ob, int number); + +GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Object *ob, int *ofs); +void gpencil_material_resources_get(GPENCIL_MaterialPool *first_pool, + int mat_id, + struct GPUTexture **r_tex_stroke, + struct GPUTexture **r_tex_fill, + struct GPUUniformBuffer **r_ubo_mat); + +void gpencil_light_ambient_add(GPENCIL_LightPool *lightpool, const float color[3]); +void gpencil_light_pool_populate(GPENCIL_LightPool *matpool, Object *ob); +GPENCIL_LightPool *gpencil_light_pool_add(GPENCIL_PrivateData *pd); +GPENCIL_LightPool *gpencil_light_pool_create(GPENCIL_PrivateData *pd, Object *ob); + +/* effects */ +void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObject *tgp_ob); + +/* Shaders */ +struct GPUShader *GPENCIL_shader_antialiasing(int stage); +struct GPUShader *GPENCIL_shader_geometry_get(void); +struct GPUShader *GPENCIL_shader_composite_get(void); +struct GPUShader *GPENCIL_shader_layer_blend_get(void); +struct GPUShader *GPENCIL_shader_mask_invert_get(void); +struct GPUShader *GPENCIL_shader_depth_merge_get(void); +struct GPUShader *GPENCIL_shader_fx_blur_get(void); +struct GPUShader *GPENCIL_shader_fx_colorize_get(void); +struct GPUShader *GPENCIL_shader_fx_composite_get(void); +struct GPUShader *GPENCIL_shader_fx_transform_get(void); +struct GPUShader *GPENCIL_shader_fx_glow_get(void); +struct GPUShader *GPENCIL_shader_fx_pixelize_get(void); +struct GPUShader *GPENCIL_shader_fx_rim_get(void); +struct GPUShader *GPENCIL_shader_fx_shadow_get(void); + +void GPENCIL_shader_free(void); + +/* Antialiasing */ +void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata); +void GPENCIL_antialiasing_draw(struct GPENCIL_Data *vedata); /* main functions */ void GPENCIL_engine_init(void *vedata); @@ -493,43 +421,17 @@ void GPENCIL_draw_scene(void *vedata); /* render */ void GPENCIL_render_init(struct GPENCIL_Data *ved, struct RenderEngine *engine, - struct Depsgraph *depsgraph); + struct RenderLayer *render_layer, + const struct Depsgraph *depsgraph, + const rcti *rect); void GPENCIL_render_to_image(void *vedata, struct RenderEngine *engine, struct RenderLayer *render_layer, const rcti *rect); -/* TODO: GPXX workaround function to call free memory from draw manager while draw manager support - * scene finish callback. */ -void DRW_gpencil_free_runtime_data(void *ved); - -/* Use of multisample framebuffers. */ -#define MULTISAMPLE_GP_SYNC_ENABLE(lvl, fbl) \ - { \ - if ((lvl > 0) && (fbl->multisample_fb != NULL) && (DRW_state_is_fbo())) { \ - DRW_stats_query_start("GP Multisample Blit"); \ - GPU_framebuffer_bind(fbl->multisample_fb); \ - GPU_framebuffer_clear_color_depth_stencil( \ - fbl->multisample_fb, (const float[4]){0.0f}, 1.0f, 0x0); \ - DRW_stats_query_end(); \ - } \ - } \ - ((void)0) - -#define MULTISAMPLE_GP_SYNC_DISABLE(lvl, fbl, fb, txl) \ - { \ - if ((lvl > 0) && (fbl->multisample_fb != NULL) && (DRW_state_is_fbo())) { \ - DRW_stats_query_start("GP Multisample Resolve"); \ - GPU_framebuffer_bind(fb); \ - DRW_stats_query_end(); \ - } \ - } \ - ((void)0) - -#define GPENCIL_3D_DRAWMODE(ob, gpd) \ - ((gpd) && (gpd->draw_mode == GP_DRAWMODE_3D) && ((ob->dtx & OB_DRAWXRAY) == 0)) - -#define GPENCIL_USE_SOLID(stl) \ - ((stl) && ((stl->storage->is_render) || (stl->storage->is_mat_preview))) +/* Draw Data. */ +void gpencil_light_pool_free(void *storage); +void gpencil_material_pool_free(void *storage); +GPENCIL_ViewLayerData *GPENCIL_view_layer_data_ensure(void); #endif /* __GPENCIL_ENGINE_H__ */ |