Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/gpencil/gpencil_engine.c
| Show All 23 Lines | |||||
| */ | */ | ||||
| #include "DRW_engine.h" | #include "DRW_engine.h" | ||||
| #include "DRW_render.h" | #include "DRW_render.h" | ||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_shader_fx.h" | |||||
| #include "DNA_gpencil_types.h" | #include "DNA_gpencil_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "draw_mode_engines.h" | #include "draw_mode_engines.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| Show All 34 Lines | void DRW_gpencil_multisample_ensure(GPENCIL_Data *vedata, int rect_w, int rect_h) | ||||
| short samples = stl->storage->multisamples; | short samples = stl->storage->multisamples; | ||||
| if (samples > 0) { | if (samples > 0) { | ||||
| if (!fbl->multisample_fb) { | if (!fbl->multisample_fb) { | ||||
| fbl->multisample_fb = GPU_framebuffer_create(); | fbl->multisample_fb = GPU_framebuffer_create(); | ||||
| if (fbl->multisample_fb) { | if (fbl->multisample_fb) { | ||||
| if (txl->multisample_color == NULL) { | if (txl->multisample_color == NULL) { | ||||
| txl->multisample_color = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_RGBA32F, NULL, samples, NULL); | txl->multisample_color = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_RGBA16F, NULL, samples, NULL); | ||||
| } | } | ||||
| if (txl->multisample_depth == NULL) { | if (txl->multisample_depth == NULL) { | ||||
| txl->multisample_depth = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_DEPTH24_STENCIL8, NULL, samples, NULL); | txl->multisample_depth = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_DEPTH24_STENCIL8, NULL, samples, NULL); | ||||
| } | } | ||||
| GPU_framebuffer_ensure_config(&fbl->multisample_fb, { | GPU_framebuffer_ensure_config(&fbl->multisample_fb, { | ||||
| GPU_ATTACHMENT_TEXTURE(txl->multisample_depth), | GPU_ATTACHMENT_TEXTURE(txl->multisample_depth), | ||||
| GPU_ATTACHMENT_TEXTURE(txl->multisample_color) | GPU_ATTACHMENT_TEXTURE(txl->multisample_color) | ||||
| }); | }); | ||||
| Show All 27 Lines | e_data.temp_depth_tx_a = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH24_STENCIL8, | ||||
| &draw_engine_gpencil_type); | &draw_engine_gpencil_type); | ||||
| e_data.temp_color_tx_a = DRW_texture_pool_query_2D(size[0], size[1], fb_format, | e_data.temp_color_tx_a = DRW_texture_pool_query_2D(size[0], size[1], fb_format, | ||||
| &draw_engine_gpencil_type); | &draw_engine_gpencil_type); | ||||
| GPU_framebuffer_ensure_config(&fbl->temp_fb_a, { | GPU_framebuffer_ensure_config(&fbl->temp_fb_a, { | ||||
| GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_a), | GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_a), | ||||
| GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_a) | GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_a) | ||||
| }); | }); | ||||
| /* background framebuffer to speed up drawing process */ | e_data.temp_depth_tx_b = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH24_STENCIL8, | ||||
| &draw_engine_gpencil_type); | |||||
| e_data.temp_color_tx_b = DRW_texture_pool_query_2D(size[0], size[1], fb_format, | |||||
| &draw_engine_gpencil_type); | |||||
| GPU_framebuffer_ensure_config(&fbl->temp_fb_b, { | |||||
| GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_b), | |||||
| GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_b) | |||||
| }); | |||||
| /* background framebuffer to speed up drawing process (always 16 bits) */ | |||||
| e_data.background_depth_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH24_STENCIL8, | e_data.background_depth_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH24_STENCIL8, | ||||
| &draw_engine_gpencil_type); | &draw_engine_gpencil_type); | ||||
| e_data.background_color_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA32F, | e_data.background_color_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA32F, | ||||
| &draw_engine_gpencil_type); | &draw_engine_gpencil_type); | ||||
| GPU_framebuffer_ensure_config(&fbl->background_fb, { | GPU_framebuffer_ensure_config(&fbl->background_fb, { | ||||
| GPU_ATTACHMENT_TEXTURE(e_data.background_depth_tx), | GPU_ATTACHMENT_TEXTURE(e_data.background_depth_tx), | ||||
| GPU_ATTACHMENT_TEXTURE(e_data.background_color_tx) | GPU_ATTACHMENT_TEXTURE(e_data.background_color_tx) | ||||
| }); | }); | ||||
| ▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | void GPENCIL_engine_init(void *vedata) | ||||
| stl->storage->multisamples = U.gpencil_multisamples; | stl->storage->multisamples = U.gpencil_multisamples; | ||||
| /* create framebuffers */ | /* create framebuffers */ | ||||
| GPENCIL_create_framebuffers(vedata); | GPENCIL_create_framebuffers(vedata); | ||||
| /* create shaders */ | /* create shaders */ | ||||
| GPENCIL_create_shaders(); | GPENCIL_create_shaders(); | ||||
| GPENCIL_create_fx_shaders(&e_data); | |||||
| /* blank texture used if no texture defined for fill shader */ | /* blank texture used if no texture defined for fill shader */ | ||||
| if (!e_data.gpencil_blank_texture) { | if (!e_data.gpencil_blank_texture) { | ||||
| float rect[16][16][4] = {{{0.0f}}}; | float rect[16][16][4] = {{{0.0f}}}; | ||||
| e_data.gpencil_blank_texture = DRW_texture_create_2D(16, 16, GPU_RGBA8, DRW_TEX_FILTER, (float *)rect); | e_data.gpencil_blank_texture = DRW_texture_create_2D(16, 16, GPU_RGBA8, DRW_TEX_FILTER, (float *)rect); | ||||
| } | } | ||||
| } | } | ||||
| static void GPENCIL_engine_free(void) | static void GPENCIL_engine_free(void) | ||||
| { | { | ||||
| /* only free custom shaders, builtin shaders are freed in blender close */ | /* only free custom shaders, builtin shaders are freed in blender close */ | ||||
| DRW_SHADER_FREE_SAFE(e_data.gpencil_fill_sh); | DRW_SHADER_FREE_SAFE(e_data.gpencil_fill_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.gpencil_stroke_sh); | DRW_SHADER_FREE_SAFE(e_data.gpencil_stroke_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.gpencil_point_sh); | DRW_SHADER_FREE_SAFE(e_data.gpencil_point_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.gpencil_edit_point_sh); | DRW_SHADER_FREE_SAFE(e_data.gpencil_edit_point_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.gpencil_fullscreen_sh); | DRW_SHADER_FREE_SAFE(e_data.gpencil_fullscreen_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.gpencil_simple_fullscreen_sh); | DRW_SHADER_FREE_SAFE(e_data.gpencil_simple_fullscreen_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.gpencil_background_sh); | DRW_SHADER_FREE_SAFE(e_data.gpencil_background_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.gpencil_paper_sh); | DRW_SHADER_FREE_SAFE(e_data.gpencil_paper_sh); | ||||
| DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture); | DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture); | ||||
| /* effects */ | |||||
| GPENCIL_delete_fx_shaders(&e_data); | |||||
| } | } | ||||
| void GPENCIL_cache_init(void *vedata) | void GPENCIL_cache_init(void *vedata) | ||||
| { | { | ||||
| GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl; | GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl; | ||||
| GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl; | GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| Scene *scene = draw_ctx->scene; | Scene *scene = draw_ctx->scene; | ||||
| Show All 24 Lines | if (!stl->shgroups) { | ||||
| /* Alloc maximum size because count strokes is very slow and can be very complex due onion skinning. | /* Alloc maximum size because count strokes is very slow and can be very complex due onion skinning. | ||||
| I tried to allocate only one block and using realloc, increasing the size when read a new strokes | I tried to allocate only one block and using realloc, increasing the size when read a new strokes | ||||
| in cache_finish, but the realloc produce weird things on screen, so we keep as is while we found | in cache_finish, but the realloc produce weird things on screen, so we keep as is while we found | ||||
| a better solution | a better solution | ||||
| */ | */ | ||||
| stl->shgroups = MEM_mallocN(sizeof(GPENCIL_shgroup) * GPENCIL_MAX_SHGROUPS, "GPENCIL_shgroup"); | stl->shgroups = MEM_mallocN(sizeof(GPENCIL_shgroup) * GPENCIL_MAX_SHGROUPS, "GPENCIL_shgroup"); | ||||
| } | } | ||||
| /* prepare effects */ | |||||
| if (!stl->fx) { | |||||
| stl->fx = MEM_mallocN(sizeof(GPENCIL_fx) * GPENCIL_MAX_GP_OBJ, "GPENCIL_fx"); | |||||
| } | |||||
| /* init gp objects cache */ | /* init gp objects cache */ | ||||
| stl->g_data->gp_cache_used = 0; | stl->g_data->gp_cache_used = 0; | ||||
| stl->g_data->gp_cache_size = 0; | stl->g_data->gp_cache_size = 0; | ||||
| stl->g_data->gp_object_cache = NULL; | stl->g_data->gp_object_cache = NULL; | ||||
| { | { | ||||
| /* Stroke pass */ | /* Stroke pass */ | ||||
| psl->stroke_pass = DRW_pass_create("GPencil Stroke Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS | DRW_STATE_BLEND); | psl->stroke_pass = DRW_pass_create("GPencil Stroke Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS | DRW_STATE_BLEND); | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | stl->g_data->gp_object_cache = NULL; | ||||
| psl->mix_pass = DRW_pass_create("GPencil Mix Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); | psl->mix_pass = DRW_pass_create("GPencil Mix Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); | ||||
| DRWShadingGroup *mix_shgrp = DRW_shgroup_create(e_data.gpencil_fullscreen_sh, psl->mix_pass); | DRWShadingGroup *mix_shgrp = DRW_shgroup_create(e_data.gpencil_fullscreen_sh, psl->mix_pass); | ||||
| DRW_shgroup_call_add(mix_shgrp, quad, NULL); | DRW_shgroup_call_add(mix_shgrp, quad, NULL); | ||||
| DRW_shgroup_uniform_texture_ref(mix_shgrp, "strokeColor", &e_data.input_color_tx); | DRW_shgroup_uniform_texture_ref(mix_shgrp, "strokeColor", &e_data.input_color_tx); | ||||
| DRW_shgroup_uniform_texture_ref(mix_shgrp, "strokeDepth", &e_data.input_depth_tx); | DRW_shgroup_uniform_texture_ref(mix_shgrp, "strokeDepth", &e_data.input_depth_tx); | ||||
| DRW_shgroup_uniform_int(mix_shgrp, "tonemapping", &stl->storage->tonemapping, 1); | DRW_shgroup_uniform_int(mix_shgrp, "tonemapping", &stl->storage->tonemapping, 1); | ||||
| /* mix pass no blend used to copy between passes. A separated pass is required | /* mix pass no blend used to copy between passes. A separated pass is required | ||||
| * because if the mix pass is used, the acumulation of blend degrade the colors. | * because if mix_pass is used, the acumulation of blend degrade the colors. | ||||
| * | * | ||||
| * This pass is used too to take the snapshot used for background_pass. This image | * This pass is used too to take the snapshot used for background_pass. This image | ||||
| * will be used as the background while the user is drawing. | * will be used as the background while the user is drawing. | ||||
| */ | */ | ||||
| psl->mix_pass_noblend = DRW_pass_create("GPencil Mix Pass no blend", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); | psl->mix_pass_noblend = DRW_pass_create("GPencil Mix Pass no blend", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); | ||||
| DRWShadingGroup *mix_shgrp_noblend = DRW_shgroup_create(e_data.gpencil_fullscreen_sh, psl->mix_pass_noblend); | DRWShadingGroup *mix_shgrp_noblend = DRW_shgroup_create(e_data.gpencil_fullscreen_sh, psl->mix_pass_noblend); | ||||
| DRW_shgroup_call_add(mix_shgrp_noblend, quad, NULL); | DRW_shgroup_call_add(mix_shgrp_noblend, quad, NULL); | ||||
| DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeColor", &e_data.temp_color_tx_a); | DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeColor", &e_data.input_color_tx); | ||||
| DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeDepth", &e_data.temp_depth_tx_a); | DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeDepth", &e_data.input_depth_tx); | ||||
| DRW_shgroup_uniform_int(mix_shgrp_noblend, "tonemapping", &stl->storage->tonemapping, 1); | DRW_shgroup_uniform_int(mix_shgrp_noblend, "tonemapping", &stl->storage->tonemapping, 1); | ||||
| /* Painting session pass (used only to speedup while the user is drawing ) | /* Painting session pass (used only to speedup while the user is drawing ) | ||||
| * This pass is used to show the snapshot of the current grease pencil strokes captured | * This pass is used to show the snapshot of the current grease pencil strokes captured | ||||
| * when the user starts to draw. | * when the user starts to draw (see comments above). | ||||
| * In this way, the previous strokes don't need to be redraw and the drawing process | * In this way, the previous strokes don't need to be redraw and the drawing process | ||||
| * is far to agile. | * is far to agile. | ||||
| */ | */ | ||||
| psl->background_pass = DRW_pass_create("GPencil Background Painting Session Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); | psl->background_pass = DRW_pass_create("GPencil Background Painting Session Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); | ||||
| DRWShadingGroup *background_shgrp = DRW_shgroup_create(e_data.gpencil_background_sh, psl->background_pass); | DRWShadingGroup *background_shgrp = DRW_shgroup_create(e_data.gpencil_background_sh, psl->background_pass); | ||||
| DRW_shgroup_call_add(background_shgrp, quad, NULL); | DRW_shgroup_call_add(background_shgrp, quad, NULL); | ||||
| DRW_shgroup_uniform_texture_ref(background_shgrp, "strokeColor", &e_data.background_color_tx); | DRW_shgroup_uniform_texture_ref(background_shgrp, "strokeColor", &e_data.background_color_tx); | ||||
| DRW_shgroup_uniform_texture_ref(background_shgrp, "strokeDepth", &e_data.background_depth_tx); | DRW_shgroup_uniform_texture_ref(background_shgrp, "strokeDepth", &e_data.background_depth_tx); | ||||
| /* pass for drawing paper (only if viewport) | /* pass for drawing paper (only if viewport) | ||||
| * In render, the v3d is null | * In render, the v3d is null so the paper is disabled | ||||
| * The paper is way to isolate the drawing in complex scene and to have a cleaner | * The paper is way to isolate the drawing in complex scene and to have a cleaner | ||||
| * drawing area. | * drawing area. | ||||
| */ | */ | ||||
| if (v3d) { | if (v3d) { | ||||
| psl->paper_pass = DRW_pass_create("GPencil Paper Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND); | psl->paper_pass = DRW_pass_create("GPencil Paper Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND); | ||||
| DRWShadingGroup *paper_shgrp = DRW_shgroup_create(e_data.gpencil_paper_sh, psl->paper_pass); | DRWShadingGroup *paper_shgrp = DRW_shgroup_create(e_data.gpencil_paper_sh, psl->paper_pass); | ||||
| DRW_shgroup_call_add(paper_shgrp, quad, NULL); | DRW_shgroup_call_add(paper_shgrp, quad, NULL); | ||||
| DRW_shgroup_uniform_vec4(paper_shgrp, "color", v3d->gpencil_paper_color, 1); | DRW_shgroup_uniform_vec4(paper_shgrp, "color", v3d->gpencil_paper_color, 1); | ||||
| UI_GetThemeColor3fv(TH_GRID, stl->storage->gridcolor); | UI_GetThemeColor3fv(TH_GRID, stl->storage->gridcolor); | ||||
| DRW_shgroup_uniform_vec3(paper_shgrp, "gridcolor", &stl->storage->gridcolor[0], 1); | DRW_shgroup_uniform_vec3(paper_shgrp, "gridcolor", &stl->storage->gridcolor[0], 1); | ||||
| stl->storage->gridsize[0] = (float)v3d->gpencil_grid_size[0]; | stl->storage->gridsize[0] = (float)v3d->gpencil_grid_size[0]; | ||||
| stl->storage->gridsize[1] = (float)v3d->gpencil_grid_size[1]; | stl->storage->gridsize[1] = (float)v3d->gpencil_grid_size[1]; | ||||
| DRW_shgroup_uniform_vec2(paper_shgrp, "size", &stl->storage->gridsize[0], 1); | DRW_shgroup_uniform_vec2(paper_shgrp, "size", &stl->storage->gridsize[0], 1); | ||||
| if (v3d->flag3 & V3D_GP_SHOW_GRID) { | if (v3d->flag3 & V3D_GP_SHOW_GRID) { | ||||
| stl->storage->uselines = 1; | stl->storage->uselines = 1; | ||||
| } | } | ||||
| else { | else { | ||||
| stl->storage->uselines = 0; | stl->storage->uselines = 0; | ||||
| } | } | ||||
| DRW_shgroup_uniform_int(paper_shgrp, "uselines", &stl->storage->uselines, 1); | DRW_shgroup_uniform_int(paper_shgrp, "uselines", &stl->storage->uselines, 1); | ||||
| } | } | ||||
| /* create effects passes */ | |||||
| GPENCIL_create_fx_passes(psl); | |||||
| } | } | ||||
| } | } | ||||
| void GPENCIL_cache_populate(void *vedata, Object *ob) | void GPENCIL_cache_populate(void *vedata, Object *ob) | ||||
| { | { | ||||
| /* object must be visible */ | /* object must be visible */ | ||||
| if (!DRW_check_object_visible_within_active_context(ob)) { | if (!DRW_check_object_visible_within_active_context(ob)) { | ||||
| return; | return; | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | for (int i = 0; i < stl->g_data->gp_cache_used; i++) { | ||||
| } | } | ||||
| /* save end shading group */ | /* save end shading group */ | ||||
| stl->g_data->gp_object_cache[i].end_grp = stl->storage->shgroup_id - 1; | stl->g_data->gp_object_cache[i].end_grp = stl->storage->shgroup_id - 1; | ||||
| /* if render set to dirty to refresh viewport */ | /* if render set to dirty to refresh viewport */ | ||||
| if (stl->storage->is_render == true) { | if (stl->storage->is_render == true) { | ||||
| gpd->flag |= GP_DATA_CACHE_IS_DIRTY; | gpd->flag |= GP_DATA_CACHE_IS_DIRTY; | ||||
| } | } | ||||
| /* FX passses */ | |||||
| tGPencilObjectCache *cache = &stl->g_data->gp_object_cache[i]; | |||||
| if (!is_multiedit) { | |||||
| DRW_gpencil_fx_prepare(&e_data, vedata, cache); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* helper function to sort inverse gpencil objects using qsort */ | /* helper function to sort inverse gpencil objects using qsort */ | ||||
| static int gpencil_object_cache_compare_zdepth(const void *a1, const void *a2) | static int gpencil_object_cache_compare_zdepth(const void *a1, const void *a2) | ||||
| { | { | ||||
| const tGPencilObjectCache *ps1 = a1, *ps2 = a2; | const tGPencilObjectCache *ps1 = a1, *ps2 = a2; | ||||
| if (ps1->zdepth < ps2->zdepth) return 1; | if (ps1->zdepth < ps2->zdepth) return 1; | ||||
| else if (ps1->zdepth > ps2->zdepth) return -1; | else if (ps1->zdepth > ps2->zdepth) return -1; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* prepare a texture with full viewport for fast drawing */ | /* prepare a texture with full viewport screenshot for fast drawing */ | ||||
| static void gpencil_prepare_fast_drawing(GPENCIL_StorageList *stl, DefaultFramebufferList *dfbl, GPENCIL_FramebufferList *fbl, DRWPass *pass, float clearcol[4]) | static void gpencil_prepare_fast_drawing(GPENCIL_StorageList *stl, DefaultFramebufferList *dfbl, | ||||
| GPENCIL_FramebufferList *fbl, DRWPass *pass, | |||||
| const float clearcol[4]) | |||||
| { | { | ||||
| if (stl->g_data->session_flag & (GP_DRW_PAINT_IDLE | GP_DRW_PAINT_FILLING)) { | if (stl->g_data->session_flag & (GP_DRW_PAINT_IDLE | GP_DRW_PAINT_FILLING)) { | ||||
| GPU_framebuffer_bind(fbl->background_fb); | GPU_framebuffer_bind(fbl->background_fb); | ||||
| /* clean only in first loop cycle */ | /* clean only in first loop cycle */ | ||||
| if (stl->g_data->session_flag & GP_DRW_PAINT_IDLE) { | if (stl->g_data->session_flag & GP_DRW_PAINT_IDLE) { | ||||
| GPU_framebuffer_clear_color_depth(fbl->background_fb, clearcol, 1.0f); | GPU_framebuffer_clear_color_depth(fbl->background_fb, clearcol, 1.0f); | ||||
| stl->g_data->session_flag = GP_DRW_PAINT_FILLING; | stl->g_data->session_flag = GP_DRW_PAINT_FILLING; | ||||
| } | } | ||||
| Show All 31 Lines | void GPENCIL_draw_scene(void *ved) | ||||
| GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl; | GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl; | ||||
| GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl; | GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl; | ||||
| DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); | DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); | ||||
| GPENCIL_TextureList *txl = ((GPENCIL_Data *)vedata)->txl; | GPENCIL_TextureList *txl = ((GPENCIL_Data *)vedata)->txl; | ||||
| int init_grp, end_grp; | int init_grp, end_grp; | ||||
| tGPencilObjectCache *cache; | tGPencilObjectCache *cache; | ||||
| float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; | const float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| View3D *v3d = draw_ctx->v3d; | View3D *v3d = draw_ctx->v3d; | ||||
| Object *obact = draw_ctx->obact; | Object *obact = draw_ctx->obact; | ||||
| bool playing = (bool)stl->storage->playing; | bool playing = (bool)stl->storage->playing; | ||||
| bool is_render = stl->storage->is_render; | bool is_render = stl->storage->is_render; | ||||
| /* paper pass to display a confortable area to draw over complex scenes with geometry */ | /* paper pass to display a confortable area to draw over complex scenes with geometry */ | ||||
| Show All 19 Lines | if ((!is_render) && (stl->g_data->session_flag & GP_DRW_PAINT_PAINTING)) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (DRW_state_is_fbo()) { | if (DRW_state_is_fbo()) { | ||||
| /* attach temp textures */ | /* attach temp textures */ | ||||
| GPU_framebuffer_texture_attach(fbl->temp_fb_a, e_data.temp_depth_tx_a, 0, 0); | GPU_framebuffer_texture_attach(fbl->temp_fb_a, e_data.temp_depth_tx_a, 0, 0); | ||||
| GPU_framebuffer_texture_attach(fbl->temp_fb_a, e_data.temp_color_tx_a, 0, 0); | GPU_framebuffer_texture_attach(fbl->temp_fb_a, e_data.temp_color_tx_a, 0, 0); | ||||
| GPU_framebuffer_texture_attach(fbl->temp_fb_b, e_data.temp_depth_tx_b, 0, 0); | |||||
| GPU_framebuffer_texture_attach(fbl->temp_fb_b, e_data.temp_color_tx_b, 0, 0); | |||||
| GPU_framebuffer_texture_attach(fbl->background_fb, e_data.background_depth_tx, 0, 0); | GPU_framebuffer_texture_attach(fbl->background_fb, e_data.background_depth_tx, 0, 0); | ||||
| GPU_framebuffer_texture_attach(fbl->background_fb, e_data.background_color_tx, 0, 0); | GPU_framebuffer_texture_attach(fbl->background_fb, e_data.background_color_tx, 0, 0); | ||||
| /* Draw all pending objects */ | /* Draw all pending objects */ | ||||
| if (stl->g_data->gp_cache_used > 0) { | if (stl->g_data->gp_cache_used > 0) { | ||||
| /* sort by zdepth */ | /* sort by zdepth */ | ||||
| Show All 17 Lines | if (stl->g_data->gp_cache_used > 0) { | ||||
| MULTISAMPLE_GP_SYNC_ENABLE(stl->storage->multisamples, fbl); | MULTISAMPLE_GP_SYNC_ENABLE(stl->storage->multisamples, fbl); | ||||
| DRW_draw_pass_subset(psl->stroke_pass, | DRW_draw_pass_subset(psl->stroke_pass, | ||||
| stl->shgroups[init_grp].shgrps_fill != NULL ? stl->shgroups[init_grp].shgrps_fill : stl->shgroups[init_grp].shgrps_stroke, | stl->shgroups[init_grp].shgrps_fill != NULL ? stl->shgroups[init_grp].shgrps_fill : stl->shgroups[init_grp].shgrps_stroke, | ||||
| stl->shgroups[end_grp].shgrps_stroke); | stl->shgroups[end_grp].shgrps_stroke); | ||||
| MULTISAMPLE_GP_SYNC_DISABLE(stl->storage->multisamples, fbl, fbl->temp_fb_a, txl); | MULTISAMPLE_GP_SYNC_DISABLE(stl->storage->multisamples, fbl, fbl->temp_fb_a, txl); | ||||
| } | } | ||||
| /* Current buffer drawing */ | /* Current buffer drawing */ | ||||
| if ((!is_render) && (gpd->runtime.sbuffer_size > 0)) { | if ((!is_render) && (gpd->runtime.sbuffer_size > 0)) { | ||||
| DRW_draw_pass(psl->drawing_pass); | DRW_draw_pass(psl->drawing_pass); | ||||
| } | } | ||||
| /* fx passes */ | |||||
| if (BKE_shaderfx_has_gpencil(ob)) { | |||||
| stl->storage->tonemapping = 0; | |||||
| DRW_gpencil_fx_draw(&e_data, vedata, cache); | |||||
| } | |||||
| e_data.input_depth_tx = e_data.temp_depth_tx_a; | e_data.input_depth_tx = e_data.temp_depth_tx_a; | ||||
| e_data.input_color_tx = e_data.temp_color_tx_a; | e_data.input_color_tx = e_data.temp_color_tx_a; | ||||
| /* Combine with scene buffer */ | /* Combine with scene buffer */ | ||||
| if ((!is_render) || (fbl->main == NULL)) { | if ((!is_render) || (fbl->main == NULL)) { | ||||
| GPU_framebuffer_bind(dfbl->default_fb); | GPU_framebuffer_bind(dfbl->default_fb); | ||||
| } | } | ||||
| Show All 16 Lines | if (stl->g_data->gp_cache_used > 0) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* free memory */ | /* free memory */ | ||||
| gpencil_free_obj_list(stl); | gpencil_free_obj_list(stl); | ||||
| /* detach temp textures */ | /* detach temp textures */ | ||||
| if (DRW_state_is_fbo()) { | if (DRW_state_is_fbo()) { | ||||
| GPU_framebuffer_texture_detach(fbl->temp_fb_a, e_data.temp_depth_tx_a); | |||||
| GPU_framebuffer_texture_detach(fbl->temp_fb_a, e_data.temp_color_tx_a); | |||||
| GPU_framebuffer_texture_detach(fbl->temp_fb_b, e_data.temp_depth_tx_b); | |||||
| GPU_framebuffer_texture_detach(fbl->temp_fb_b, e_data.temp_color_tx_b); | |||||
| GPU_framebuffer_texture_detach(fbl->background_fb, e_data.background_depth_tx); | GPU_framebuffer_texture_detach(fbl->background_fb, e_data.background_depth_tx); | ||||
| GPU_framebuffer_texture_detach(fbl->background_fb, e_data.background_color_tx); | GPU_framebuffer_texture_detach(fbl->background_fb, e_data.background_color_tx); | ||||
| /* attach again default framebuffer after detach textures */ | /* attach again default framebuffer after detach textures */ | ||||
| if (!is_render) { | if (!is_render) { | ||||
| GPU_framebuffer_bind(dfbl->default_fb); | GPU_framebuffer_bind(dfbl->default_fb); | ||||
| } | } | ||||
| Show All 24 Lines | |||||