Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_draw.c
| Show First 20 Lines • Show All 1,308 Lines • ▼ Show 20 Lines | float ED_scene_grid_scale(Scene *scene, const char **grid_unit) | ||||
| return 1.0f; | return 1.0f; | ||||
| } | } | ||||
| float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit) | float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit) | ||||
| { | { | ||||
| return v3d->grid * ED_scene_grid_scale(scene, grid_unit); | return v3d->grid * ED_scene_grid_scale(scene, grid_unit); | ||||
| } | } | ||||
| static bool is_cursor_visible(Scene *scene, SceneLayer *sl) | static bool is_cursor_visible(Scene *scene, ViewLayer *sl) | ||||
| { | { | ||||
| Object *ob = OBACT(sl); | Object *ob = OBACT(sl); | ||||
| /* don't draw cursor in paint modes, but with a few exceptions */ | /* don't draw cursor in paint modes, but with a few exceptions */ | ||||
| if (ob && ob->mode & OB_MODE_ALL_PAINT) { | if (ob && ob->mode & OB_MODE_ALL_PAINT) { | ||||
| /* exception: object is in weight paint and has deforming armature in pose mode */ | /* exception: object is in weight paint and has deforming armature in pose mode */ | ||||
| if (ob->mode & OB_MODE_WEIGHT_PAINT) { | if (ob->mode & OB_MODE_WEIGHT_PAINT) { | ||||
| if (BKE_object_pose_armature_get(ob) != NULL) { | if (BKE_object_pose_armature_get(ob) != NULL) { | ||||
| ▲ Show 20 Lines • Show All 515 Lines • ▼ Show 20 Lines | void view3d_draw_region_info(const bContext *C, ARegion *ar, const int offset) | ||||
| if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) { | if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) { | ||||
| ED_scene_draw_fps(scene, &rect); | ED_scene_draw_fps(scene, &rect); | ||||
| } | } | ||||
| else if (U.uiflag & USER_SHOW_VIEWPORTNAME) { | else if (U.uiflag & USER_SHOW_VIEWPORTNAME) { | ||||
| draw_viewport_name(ar, v3d, &rect); | draw_viewport_name(ar, v3d, &rect); | ||||
| } | } | ||||
| if (U.uiflag & USER_DRAWVIEWINFO) { | if (U.uiflag & USER_DRAWVIEWINFO) { | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| Object *ob = OBACT(sl); | Object *ob = OBACT(sl); | ||||
| draw_selected_name(scene, ob, &rect); | draw_selected_name(scene, ob, &rect); | ||||
| } | } | ||||
| #if 0 /* TODO */ | #if 0 /* TODO */ | ||||
| if (grid_unit) { /* draw below the viewport name */ | if (grid_unit) { /* draw below the viewport name */ | ||||
| char numstr[32] = ""; | char numstr[32] = ""; | ||||
| UI_FontThemeColor(BLF_default(), TH_TEXT_HI); | UI_FontThemeColor(BLF_default(), TH_TEXT_HI); | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | else { /* SCE_VIEWS_FORMAT_MULTIVIEW */ | ||||
| float viewmat[4][4]; | float viewmat[4][4]; | ||||
| Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname); | Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname); | ||||
| BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat); | BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat); | ||||
| view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, viewmat, winmat, NULL); | view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, viewmat, winmat, NULL); | ||||
| } | } | ||||
| } | } | ||||
| void ED_view3d_draw_offscreen_init(const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *sl, View3D *v3d) | void ED_view3d_draw_offscreen_init(const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *sl, View3D *v3d) | ||||
| { | { | ||||
| RenderEngineType *type = eval_ctx->engine; | RenderEngineType *type = eval_ctx->engine; | ||||
| if (type->flag & RE_USE_LEGACY_PIPELINE) { | if (type->flag & RE_USE_LEGACY_PIPELINE) { | ||||
| /* shadow buffers, before we setup matrices */ | /* shadow buffers, before we setup matrices */ | ||||
| if (draw_glsl_material(scene, sl, NULL, v3d, v3d->drawtype)) { | if (draw_glsl_material(scene, sl, NULL, v3d, v3d->drawtype)) { | ||||
| VP_deprecated_gpu_update_lamps_shadows_world(eval_ctx, scene, v3d); | VP_deprecated_gpu_update_lamps_shadows_world(eval_ctx, scene, v3d); | ||||
| } | } | ||||
| } | } | ||||
| Show All 13 Lines | else { | ||||
| VP_view3d_draw_background_none(); | VP_view3d_draw_background_none(); | ||||
| } | } | ||||
| } | } | ||||
| /* ED_view3d_draw_offscreen_init should be called before this to initialize | /* ED_view3d_draw_offscreen_init should be called before this to initialize | ||||
| * stuff like shadow buffers | * stuff like shadow buffers | ||||
| */ | */ | ||||
| void ED_view3d_draw_offscreen( | void ED_view3d_draw_offscreen( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *scene_layer, | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, | ||||
| View3D *v3d, ARegion *ar, int winx, int winy, | View3D *v3d, ARegion *ar, int winx, int winy, | ||||
| float viewmat[4][4], float winmat[4][4], | float viewmat[4][4], float winmat[4][4], | ||||
| bool do_bgpic, bool do_sky, bool is_persp, const char *viewname, | bool do_bgpic, bool do_sky, bool is_persp, const char *viewname, | ||||
| GPUFX *fx, GPUFXSettings *fx_settings, | GPUFX *fx, GPUFXSettings *fx_settings, | ||||
| GPUOffScreen *ofs) | GPUOffScreen *ofs) | ||||
| { | { | ||||
| bool do_compositing = false; | bool do_compositing = false; | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | if (type->flag & RE_USE_LEGACY_PIPELINE) { | ||||
| } | } | ||||
| if ((v3d->flag2 & V3D_RENDER_SHADOW) == 0) { | if ((v3d->flag2 & V3D_RENDER_SHADOW) == 0) { | ||||
| /* draw grease-pencil stuff */ | /* draw grease-pencil stuff */ | ||||
| ED_region_pixelspace(ar); | ED_region_pixelspace(ar); | ||||
| if (v3d->flag2 & V3D_SHOW_GPENCIL) { | if (v3d->flag2 & V3D_SHOW_GPENCIL) { | ||||
| /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */ | /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */ | ||||
| ED_gpencil_draw_view3d(NULL, scene, scene_layer, v3d, ar, false); | ED_gpencil_draw_view3d(NULL, scene, view_layer, v3d, ar, false); | ||||
| } | } | ||||
| /* freeing the images again here could be done after the operator runs, leaving for now */ | /* freeing the images again here could be done after the operator runs, leaving for now */ | ||||
| GPU_free_images_anim(); | GPU_free_images_anim(); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* XXX, should take depsgraph as arg */ | /* XXX, should take depsgraph as arg */ | ||||
| Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, scene_layer, false); | Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, false); | ||||
| BLI_assert(depsgraph != NULL); | BLI_assert(depsgraph != NULL); | ||||
| DRW_draw_render_loop_offscreen(depsgraph, eval_ctx->engine, ar, v3d, ofs); | DRW_draw_render_loop_offscreen(depsgraph, eval_ctx->engine, ar, v3d, ofs); | ||||
| } | } | ||||
| /* restore size */ | /* restore size */ | ||||
| ar->winx = bwinx; | ar->winx = bwinx; | ||||
| ar->winy = bwiny; | ar->winy = bwiny; | ||||
| ar->winrct = brect; | ar->winrct = brect; | ||||
| gpuPopProjectionMatrix(); | gpuPopProjectionMatrix(); | ||||
| gpuPopMatrix(); | gpuPopMatrix(); | ||||
| UI_Theme_Restore(&theme_state); | UI_Theme_Restore(&theme_state); | ||||
| G.f &= ~G_RENDER_OGL; | G.f &= ~G_RENDER_OGL; | ||||
| } | } | ||||
| /** | /** | ||||
| * Utility func for ED_view3d_draw_offscreen | * Utility func for ED_view3d_draw_offscreen | ||||
| * | * | ||||
| * \param ofs: Optional off-screen buffer, can be NULL. | * \param ofs: Optional off-screen buffer, can be NULL. | ||||
| * (avoids re-creating when doing multiple GL renders). | * (avoids re-creating when doing multiple GL renders). | ||||
| */ | */ | ||||
| ImBuf *ED_view3d_draw_offscreen_imbuf( | ImBuf *ED_view3d_draw_offscreen_imbuf( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *scene_layer, | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, | ||||
| View3D *v3d, ARegion *ar, int sizex, int sizey, | View3D *v3d, ARegion *ar, int sizex, int sizey, | ||||
| unsigned int flag, bool draw_background, | unsigned int flag, bool draw_background, | ||||
| int alpha_mode, int samples, bool full_samples, const char *viewname, | int alpha_mode, int samples, bool full_samples, const char *viewname, | ||||
| /* output vars */ | /* output vars */ | ||||
| GPUFX *fx, GPUOffScreen *ofs, char err_out[256]) | GPUFX *fx, GPUOffScreen *ofs, char err_out[256]) | ||||
| { | { | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| const bool draw_sky = (alpha_mode == R_ADDSKY); | const bool draw_sky = (alpha_mode == R_ADDSKY); | ||||
| Show All 13 Lines | ImBuf *ED_view3d_draw_offscreen_imbuf( | ||||
| if (own_ofs) { | if (own_ofs) { | ||||
| /* bind */ | /* bind */ | ||||
| ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out); | ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out); | ||||
| if (ofs == NULL) { | if (ofs == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| } | } | ||||
| ED_view3d_draw_offscreen_init(eval_ctx, scene, scene_layer, v3d); | ED_view3d_draw_offscreen_init(eval_ctx, scene, view_layer, v3d); | ||||
| GPU_offscreen_bind(ofs, true); | GPU_offscreen_bind(ofs, true); | ||||
| /* read in pixels & stamp */ | /* read in pixels & stamp */ | ||||
| ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, flag); | ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, flag); | ||||
| /* render 3d view */ | /* render 3d view */ | ||||
| if (rv3d->persp == RV3D_CAMOB && v3d->camera) { | if (rv3d->persp == RV3D_CAMOB && v3d->camera) { | ||||
| Show All 25 Lines | else { | ||||
| else { | else { | ||||
| perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend); | perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend); | ||||
| } | } | ||||
| } | } | ||||
| if ((samples && full_samples) == 0) { | if ((samples && full_samples) == 0) { | ||||
| /* Single-pass render, common case */ | /* Single-pass render, common case */ | ||||
| ED_view3d_draw_offscreen( | ED_view3d_draw_offscreen( | ||||
| eval_ctx, scene, scene_layer, v3d, ar, sizex, sizey, NULL, winmat, | eval_ctx, scene, view_layer, v3d, ar, sizex, sizey, NULL, winmat, | ||||
| draw_background, draw_sky, !is_ortho, viewname, | draw_background, draw_sky, !is_ortho, viewname, | ||||
| fx, &fx_settings, ofs); | fx, &fx_settings, ofs); | ||||
| if (ibuf->rect_float) { | if (ibuf->rect_float) { | ||||
| GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float); | GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float); | ||||
| } | } | ||||
| else if (ibuf->rect) { | else if (ibuf->rect) { | ||||
| GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, ibuf->rect); | GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, ibuf->rect); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Multi-pass render, use accumulation buffer & jitter for 'full' oversampling. | /* Multi-pass render, use accumulation buffer & jitter for 'full' oversampling. | ||||
| * Use because OpenGL may use a lower quality MSAA, and only over-sample edges. */ | * Use because OpenGL may use a lower quality MSAA, and only over-sample edges. */ | ||||
| static float jit_ofs[32][2]; | static float jit_ofs[32][2]; | ||||
| float winmat_jitter[4][4]; | float winmat_jitter[4][4]; | ||||
| /* use imbuf as temp storage, before writing into it from accumulation buffer */ | /* use imbuf as temp storage, before writing into it from accumulation buffer */ | ||||
| unsigned char *rect_temp = ibuf->rect ? (void *)ibuf->rect : (void *)ibuf->rect_float; | unsigned char *rect_temp = ibuf->rect ? (void *)ibuf->rect : (void *)ibuf->rect_float; | ||||
| unsigned int *accum_buffer = MEM_mallocN(sizex * sizey * sizeof(int[4]), "accum1"); | unsigned int *accum_buffer = MEM_mallocN(sizex * sizey * sizeof(int[4]), "accum1"); | ||||
| BLI_jitter_init(jit_ofs, samples); | BLI_jitter_init(jit_ofs, samples); | ||||
| /* first sample buffer, also initializes 'rv3d->persmat' */ | /* first sample buffer, also initializes 'rv3d->persmat' */ | ||||
| ED_view3d_draw_offscreen( | ED_view3d_draw_offscreen( | ||||
| eval_ctx, scene, scene_layer, v3d, ar, sizex, sizey, NULL, winmat, | eval_ctx, scene, view_layer, v3d, ar, sizex, sizey, NULL, winmat, | ||||
| draw_background, draw_sky, !is_ortho, viewname, | draw_background, draw_sky, !is_ortho, viewname, | ||||
| fx, &fx_settings, ofs); | fx, &fx_settings, ofs); | ||||
| GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp); | GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp); | ||||
| unsigned i = sizex * sizey * 4; | unsigned i = sizex * sizey * 4; | ||||
| while (i--) { | while (i--) { | ||||
| accum_buffer[i] = rect_temp[i]; | accum_buffer[i] = rect_temp[i]; | ||||
| } | } | ||||
| /* skip the first sample */ | /* skip the first sample */ | ||||
| for (int j = 1; j < samples; j++) { | for (int j = 1; j < samples; j++) { | ||||
| copy_m4_m4(winmat_jitter, winmat); | copy_m4_m4(winmat_jitter, winmat); | ||||
| window_translate_m4( | window_translate_m4( | ||||
| winmat_jitter, rv3d->persmat, | winmat_jitter, rv3d->persmat, | ||||
| (jit_ofs[j][0] * 2.0f) / sizex, | (jit_ofs[j][0] * 2.0f) / sizex, | ||||
| (jit_ofs[j][1] * 2.0f) / sizey); | (jit_ofs[j][1] * 2.0f) / sizey); | ||||
| ED_view3d_draw_offscreen( | ED_view3d_draw_offscreen( | ||||
| eval_ctx, scene, scene_layer, v3d, ar, sizex, sizey, NULL, winmat_jitter, | eval_ctx, scene, view_layer, v3d, ar, sizex, sizey, NULL, winmat_jitter, | ||||
| draw_background, draw_sky, !is_ortho, viewname, | draw_background, draw_sky, !is_ortho, viewname, | ||||
| fx, &fx_settings, ofs); | fx, &fx_settings, ofs); | ||||
| GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp); | GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp); | ||||
| i = sizex * sizey * 4; | i = sizex * sizey * 4; | ||||
| while (i--) { | while (i--) { | ||||
| accum_buffer[i] += rect_temp[i]; | accum_buffer[i] += rect_temp[i]; | ||||
| } | } | ||||
| Show All 34 Lines | |||||
| * Creates own fake 3d views (wrapping #ED_view3d_draw_offscreen_imbuf) | * Creates own fake 3d views (wrapping #ED_view3d_draw_offscreen_imbuf) | ||||
| * | * | ||||
| * \param ofs: Optional off-screen buffer can be NULL. | * \param ofs: Optional off-screen buffer can be NULL. | ||||
| * (avoids re-creating when doing multiple GL renders). | * (avoids re-creating when doing multiple GL renders). | ||||
| * | * | ||||
| * \note used by the sequencer | * \note used by the sequencer | ||||
| */ | */ | ||||
| ImBuf *ED_view3d_draw_offscreen_imbuf_simple( | ImBuf *ED_view3d_draw_offscreen_imbuf_simple( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *scene_layer, | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, | ||||
| Object *camera, int width, int height, | Object *camera, int width, int height, | ||||
| unsigned int flag, int drawtype, bool use_solid_tex, bool use_gpencil, bool draw_background, | unsigned int flag, int drawtype, bool use_solid_tex, bool use_gpencil, bool draw_background, | ||||
| int alpha_mode, int samples, bool full_samples, const char *viewname, | int alpha_mode, int samples, bool full_samples, const char *viewname, | ||||
| GPUFX *fx, GPUOffScreen *ofs, char err_out[256]) | GPUFX *fx, GPUOffScreen *ofs, char err_out[256]) | ||||
| { | { | ||||
| View3D v3d = {NULL}; | View3D v3d = {NULL}; | ||||
| ARegion ar = {NULL}; | ARegion ar = {NULL}; | ||||
| RegionView3D rv3d = {{{0}}}; | RegionView3D rv3d = {{{0}}}; | ||||
| Show All 38 Lines | invert_m4_m4(rv3d.viewmat, rv3d.viewinv); | ||||
| v3d.far = params.clipend; | v3d.far = params.clipend; | ||||
| v3d.lens = params.lens; | v3d.lens = params.lens; | ||||
| } | } | ||||
| mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat); | mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat); | ||||
| invert_m4_m4(rv3d.persinv, rv3d.viewinv); | invert_m4_m4(rv3d.persinv, rv3d.viewinv); | ||||
| return ED_view3d_draw_offscreen_imbuf( | return ED_view3d_draw_offscreen_imbuf( | ||||
| eval_ctx, scene, scene_layer, &v3d, &ar, width, height, flag, | eval_ctx, scene, view_layer, &v3d, &ar, width, height, flag, | ||||
| draw_background, alpha_mode, samples, full_samples, viewname, | draw_background, alpha_mode, samples, full_samples, viewname, | ||||
| fx, ofs, err_out); | fx, ofs, err_out); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Legacy Interface | /** \name Legacy Interface | ||||
| * | * | ||||
| * This will be removed once the viewport gets replaced | * This will be removed once the viewport gets replaced | ||||
| * meanwhile it should keep the old viewport working. | * meanwhile it should keep the old viewport working. | ||||
| * | * | ||||
| * \{ */ | * \{ */ | ||||
| void VP_legacy_drawcursor(Scene *scene, SceneLayer *sl, ARegion *ar, View3D *v3d) | void VP_legacy_drawcursor(Scene *scene, ViewLayer *sl, ARegion *ar, View3D *v3d) | ||||
| { | { | ||||
| if (is_cursor_visible(scene, sl)) { | if (is_cursor_visible(scene, sl)) { | ||||
| drawcursor(scene, ar, v3d); | drawcursor(scene, ar, v3d); | ||||
| } | } | ||||
| } | } | ||||
| void VP_legacy_draw_view_axis(RegionView3D *rv3d, rcti *rect) | void VP_legacy_draw_view_axis(RegionView3D *rv3d, rcti *rect) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines | |||||