Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/gpencil/gpencil_engine.c
| Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | void GPENCIL_engine_init(void *ved) | ||||
| stl->pd->scene_fb = dfbl->default_fb; | stl->pd->scene_fb = dfbl->default_fb; | ||||
| stl->pd->is_render = txl->render_depth_tx || (v3d && v3d->shading.type == OB_RENDER); | stl->pd->is_render = txl->render_depth_tx || (v3d && v3d->shading.type == OB_RENDER); | ||||
| stl->pd->is_viewport = (v3d != NULL); | stl->pd->is_viewport = (v3d != NULL); | ||||
| stl->pd->global_light_pool = gpencil_light_pool_add(stl->pd); | stl->pd->global_light_pool = gpencil_light_pool_add(stl->pd); | ||||
| stl->pd->shadeless_light_pool = gpencil_light_pool_add(stl->pd); | stl->pd->shadeless_light_pool = gpencil_light_pool_add(stl->pd); | ||||
| /* Small HACK: we don't want the global pool to be reused, | /* Small HACK: we don't want the global pool to be reused, | ||||
| * so we set the last light pool to NULL. */ | * so we set the last light pool to NULL. */ | ||||
| stl->pd->last_light_pool = NULL; | stl->pd->last_light_pool = NULL; | ||||
| stl->pd->taa_sample_len = GPENCIL_antialiasing_sample_count_get(stl->pd); | |||||
| stl->pd->is_playback = DRW_state_is_playback(); | |||||
| stl->pd->is_navigating = DRW_state_is_navigating(); | |||||
| bool use_scene_lights = false; | bool use_scene_lights = false; | ||||
| bool use_scene_world = false; | bool use_scene_world = false; | ||||
| if (v3d) { | if (v3d) { | ||||
| use_scene_lights = ((v3d->shading.type == OB_MATERIAL) && | use_scene_lights = ((v3d->shading.type == OB_MATERIAL) && | ||||
| (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS)) || | (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS)) || | ||||
| ((v3d->shading.type == OB_RENDER) && | ((v3d->shading.type == OB_RENDER) && | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | void GPENCIL_engine_init(void *ved) | ||||
| stl->pd->camera_z_offset = dot_v3v3(viewmatinv[3], viewmatinv[2]); | stl->pd->camera_z_offset = dot_v3v3(viewmatinv[3], viewmatinv[2]); | ||||
| if (ctx && ctx->rv3d && v3d) { | if (ctx && ctx->rv3d && v3d) { | ||||
| stl->pd->camera = (ctx->rv3d->persp == RV3D_CAMOB) ? v3d->camera : NULL; | stl->pd->camera = (ctx->rv3d->persp == RV3D_CAMOB) ? v3d->camera : NULL; | ||||
| } | } | ||||
| else { | else { | ||||
| stl->pd->camera = NULL; | stl->pd->camera = NULL; | ||||
| } | } | ||||
| GPENCIL_antialiasing_engine_init(vedata); | |||||
| } | } | ||||
| void GPENCIL_cache_init(void *ved) | void GPENCIL_cache_init(void *ved) | ||||
| { | { | ||||
| GPENCIL_Data *vedata = (GPENCIL_Data *)ved; | GPENCIL_Data *vedata = (GPENCIL_Data *)ved; | ||||
| GPENCIL_PassList *psl = vedata->psl; | GPENCIL_PassList *psl = vedata->psl; | ||||
| GPENCIL_TextureList *txl = vedata->txl; | GPENCIL_TextureList *txl = vedata->txl; | ||||
| GPENCIL_FramebufferList *fbl = vedata->fbl; | GPENCIL_FramebufferList *fbl = vedata->fbl; | ||||
| ▲ Show 20 Lines • Show All 540 Lines • ▼ Show 20 Lines | if (pd->use_mask_fb) { | ||||
| GPU_framebuffer_ensure_config(&fbl->mask_fb, | GPU_framebuffer_ensure_config(&fbl->mask_fb, | ||||
| { | { | ||||
| GPU_ATTACHMENT_TEXTURE(depth_tx), | GPU_ATTACHMENT_TEXTURE(depth_tx), | ||||
| GPU_ATTACHMENT_TEXTURE(color_tx), | GPU_ATTACHMENT_TEXTURE(color_tx), | ||||
| GPU_ATTACHMENT_TEXTURE(pd->mask_tx), | GPU_ATTACHMENT_TEXTURE(pd->mask_tx), | ||||
| }); | }); | ||||
| } | } | ||||
| GPENCIL_antialiasing_init(vedata); | |||||
| } | } | ||||
| GPENCIL_antialiasing_cache_finish(vedata); | |||||
| } | } | ||||
| static void GPENCIL_draw_scene_depth_only(void *ved) | static void GPENCIL_draw_scene_depth_only(void *ved) | ||||
| { | { | ||||
| GPENCIL_Data *vedata = (GPENCIL_Data *)ved; | GPENCIL_Data *vedata = (GPENCIL_Data *)ved; | ||||
| GPENCIL_PrivateData *pd = vedata->stl->pd; | GPENCIL_PrivateData *pd = vedata->stl->pd; | ||||
| DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); | DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); | ||||
| ▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void GPENCIL_draw_scene(void *ved) | void GPENCIL_draw_scene(void *ved) | ||||
| { | { | ||||
| GPENCIL_Data *vedata = (GPENCIL_Data *)ved; | GPENCIL_Data *vedata = (GPENCIL_Data *)ved; | ||||
| GPENCIL_PrivateData *pd = vedata->stl->pd; | GPENCIL_PrivateData *pd = vedata->stl->pd; | ||||
| GPENCIL_FramebufferList *fbl = vedata->fbl; | GPENCIL_FramebufferList *fbl = vedata->fbl; | ||||
| float clear_cols[2][4] = {{0.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}; | float clear_cols[2][4] = {{0.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}; | ||||
| const bool do_render = GPENCIL_antialiasing_setup(vedata); | |||||
| if (do_render) { | |||||
| /* Fade 3D objects. */ | /* Fade 3D objects. */ | ||||
| if ((!pd->is_render) && (pd->fade_3d_object_opacity > -1.0f) && (pd->obact != NULL) && | if ((!pd->is_render) && (pd->fade_3d_object_opacity > -1.0f) && (pd->obact != NULL) && | ||||
| (pd->obact->type == OB_GPENCIL)) { | (pd->obact->type == OB_GPENCIL)) { | ||||
| float background_color[3]; | float background_color[3]; | ||||
| ED_view3d_background_color_get(pd->scene, pd->v3d, background_color); | ED_view3d_background_color_get(pd->scene, pd->v3d, background_color); | ||||
| /* Blend color. */ | /* Blend color. */ | ||||
| interp_v3_v3v3(clear_cols[0], background_color, clear_cols[0], pd->fade_3d_object_opacity); | interp_v3_v3v3(clear_cols[0], background_color, clear_cols[0], pd->fade_3d_object_opacity); | ||||
| mul_v4_fl(clear_cols[1], pd->fade_3d_object_opacity); | mul_v4_fl(clear_cols[1], pd->fade_3d_object_opacity); | ||||
| } | } | ||||
| if (pd->draw_depth_only) { | if (pd->draw_depth_only) { | ||||
| GPENCIL_draw_scene_depth_only(vedata); | GPENCIL_draw_scene_depth_only(vedata); | ||||
| return; | return; | ||||
| } | } | ||||
| if (pd->tobjects.first == NULL) { | if (pd->tobjects.first == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (pd->do_fast_drawing) { | if (pd->do_fast_drawing) { | ||||
| GPENCIL_fast_draw_start(vedata); | GPENCIL_fast_draw_start(vedata); | ||||
| } | } | ||||
| if (pd->tobjects.first) { | if (pd->tobjects.first) { | ||||
| GPU_framebuffer_bind(fbl->gpencil_fb); | GPU_framebuffer_bind(fbl->gpencil_fb); | ||||
| GPU_framebuffer_multi_clear(fbl->gpencil_fb, clear_cols); | GPU_framebuffer_multi_clear(fbl->gpencil_fb, clear_cols); | ||||
| } | } | ||||
| LISTBASE_FOREACH (GPENCIL_tObject *, ob, &pd->tobjects) { | LISTBASE_FOREACH (GPENCIL_tObject *, ob, &pd->tobjects) { | ||||
| GPENCIL_draw_object(vedata, ob); | GPENCIL_draw_object(vedata, ob); | ||||
| } | } | ||||
| if (pd->do_fast_drawing) { | if (pd->do_fast_drawing) { | ||||
| GPENCIL_fast_draw_end(vedata); | GPENCIL_fast_draw_end(vedata); | ||||
| } | } | ||||
| if (pd->scene_fb) { | |||||
| GPENCIL_antialiasing_draw(vedata); | |||||
| } | |||||
| pd->gp_object_pool = pd->gp_layer_pool = pd->gp_vfx_pool = pd->gp_maskbit_pool = NULL; | pd->gp_object_pool = pd->gp_layer_pool = pd->gp_vfx_pool = pd->gp_maskbit_pool = NULL; | ||||
| } | |||||
| /* Free temp stroke buffers. */ | /* Free temp stroke buffers. */ | ||||
| if (pd->sbuffer_gpd) { | if (pd->sbuffer_gpd) { | ||||
| DRW_cache_gpencil_sbuffer_clear(pd->obact); | DRW_cache_gpencil_sbuffer_clear(pd->obact); | ||||
| } | } | ||||
| if (pd->scene_fb) { | |||||
| GPENCIL_antialiasing_draw(vedata); | |||||
| } | |||||
| } | |||||
| static void GPENCIL_view_update(void *vedata) | |||||
| { | |||||
| GPENCIL_Data *data = vedata; | |||||
| GPENCIL_antialiasing_view_updated(data); | |||||
| } | } | ||||
| static void GPENCIL_engine_free(void) | static void GPENCIL_engine_free(void) | ||||
| { | { | ||||
| GPENCIL_shader_free(); | GPENCIL_shader_free(); | ||||
| } | } | ||||
| static const DrawEngineDataSize GPENCIL_data_size = DRW_VIEWPORT_DATA_SIZE(GPENCIL_Data); | static const DrawEngineDataSize GPENCIL_data_size = DRW_VIEWPORT_DATA_SIZE(GPENCIL_Data); | ||||
| DrawEngineType draw_engine_gpencil_type = { | DrawEngineType draw_engine_gpencil_type = { | ||||
| NULL, | NULL, | ||||
| NULL, | NULL, | ||||
| N_("GpencilMode"), | N_("GpencilMode"), | ||||
| &GPENCIL_data_size, | &GPENCIL_data_size, | ||||
| &GPENCIL_engine_init, | &GPENCIL_engine_init, | ||||
| &GPENCIL_engine_free, | &GPENCIL_engine_free, | ||||
| &GPENCIL_cache_init, | &GPENCIL_cache_init, | ||||
| &GPENCIL_cache_populate, | &GPENCIL_cache_populate, | ||||
| &GPENCIL_cache_finish, | &GPENCIL_cache_finish, | ||||
| &GPENCIL_draw_scene, | &GPENCIL_draw_scene, | ||||
| NULL, | &GPENCIL_view_update, | ||||
| NULL, | NULL, | ||||
| &GPENCIL_render_to_image, | &GPENCIL_render_to_image, | ||||
| NULL, | NULL, | ||||
| }; | }; | ||||