Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_draw.c
| Show First 20 Lines • Show All 1,671 Lines • ▼ Show 20 Lines | void ED_view3d_draw_offscreen(Depsgraph *depsgraph, | ||||
| int winy, | int winy, | ||||
| const float viewmat[4][4], | const float viewmat[4][4], | ||||
| const float winmat[4][4], | const float winmat[4][4], | ||||
| bool is_image_render, | bool is_image_render, | ||||
| bool draw_background, | bool draw_background, | ||||
| const char *viewname, | const char *viewname, | ||||
| const bool do_color_management, | const bool do_color_management, | ||||
| GPUOffScreen *ofs, | GPUOffScreen *ofs, | ||||
| GPUViewport *viewport) | GPUViewport *viewport, | ||||
| RV3DMatrixStore **r_rv3d_mats) | |||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = region->regiondata; | ||||
| RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype); | RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype); | ||||
| /* Store `orig` variables. */ | /* Store `orig` variables. */ | ||||
| struct { | struct { | ||||
| struct bThemeState theme_state; | struct bThemeState theme_state; | ||||
| /* #View3D */ | /* #View3D */ | ||||
| eDrawType v3d_shading_type; | eDrawType v3d_shading_type; | ||||
| /* #Region */ | /* #Region */ | ||||
| int region_winx, region_winy; | int region_winx, region_winy; | ||||
| rcti region_winrct; | rcti region_winrct; | ||||
| /* #RegionView3D */ | /* #RegionView3D */ | ||||
| /** | /** | ||||
| * Needed so the value won't be left overwritten, | * Needed so the value won't be left overwritten, | ||||
| * Without this the #wmPaintCursor can't use the pixel size & view matrices for drawing. | * Without this the #wmPaintCursor can't use the pixel size & view matrices for drawing. | ||||
| */ | */ | ||||
| struct RV3DMatrixStore *rv3d_mats; | RV3DMatrixStore *rv3d_mats; | ||||
| } orig = { | } orig = { | ||||
| .v3d_shading_type = v3d->shading.type, | .v3d_shading_type = v3d->shading.type, | ||||
| .region_winx = region->winx, | .region_winx = region->winx, | ||||
| .region_winy = region->winy, | .region_winy = region->winy, | ||||
| .region_winrct = region->winrct, | .region_winrct = region->winrct, | ||||
| .rv3d_mats = ED_view3d_mats_rv3d_backup(region->regiondata), | .rv3d_mats = ED_view3d_mats_rv3d_backup(region->regiondata), | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | void ED_view3d_draw_offscreen(Depsgraph *depsgraph, | ||||
| GPU_matrix_pop_projection(); | GPU_matrix_pop_projection(); | ||||
| GPU_matrix_pop(); | GPU_matrix_pop(); | ||||
| /* Restore all `orig` members. */ | /* Restore all `orig` members. */ | ||||
| region->winx = orig.region_winx; | region->winx = orig.region_winx; | ||||
| region->winy = orig.region_winy; | region->winy = orig.region_winy; | ||||
| region->winrct = orig.region_winrct; | region->winrct = orig.region_winrct; | ||||
| /* Store view matrices as used here for use in the caller (e.g. reprojection). */ | |||||
| if (r_rv3d_mats != NULL) { | |||||
| *r_rv3d_mats = ED_view3d_mats_rv3d_backup(region->regiondata); | |||||
| } | |||||
| ED_view3d_mats_rv3d_restore(region->regiondata, orig.rv3d_mats); | ED_view3d_mats_rv3d_restore(region->regiondata, orig.rv3d_mats); | ||||
| MEM_freeN(orig.rv3d_mats); | MEM_freeN(orig.rv3d_mats); | ||||
| UI_Theme_Restore(&orig.theme_state); | UI_Theme_Restore(&orig.theme_state); | ||||
| v3d->shading.type = orig.v3d_shading_type; | v3d->shading.type = orig.v3d_shading_type; | ||||
| G.f &= ~G_FLAG_RENDER_VIEWPORT; | G.f &= ~G_FLAG_RENDER_VIEWPORT; | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | ED_view3d_draw_offscreen(depsgraph, | ||||
| winy, | winy, | ||||
| viewmat, | viewmat, | ||||
| winmat, | winmat, | ||||
| is_image_render, | is_image_render, | ||||
| draw_background, | draw_background, | ||||
| viewname, | viewname, | ||||
| do_color_management, | do_color_management, | ||||
| ofs, | ofs, | ||||
| viewport); | viewport, | ||||
| NULL); | |||||
| } | } | ||||
| /** | /** | ||||
| * 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(Depsgraph *depsgraph, | ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, | ||||
| Scene *scene, | Scene *scene, | ||||
| eDrawType drawtype, | eDrawType drawtype, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| ARegion *region, | ARegion *region, | ||||
| int sizex, | int sizex, | ||||
| int sizey, | int sizey, | ||||
| eImBufFlags imbuf_flag, | eImBufFlags imbuf_flag, | ||||
| int alpha_mode, | int alpha_mode, | ||||
| const char *viewname, | const char *viewname, | ||||
| /* output vars */ | /* output vars */ | ||||
| GPUOffScreen *ofs, | GPUOffScreen *ofs, | ||||
| char err_out[256]) | char err_out[256], | ||||
| RV3DMatrixStore **r_rv3d_mats) | |||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = region->regiondata; | ||||
| const bool draw_sky = (alpha_mode == R_ADDSKY); | const bool draw_sky = (alpha_mode == R_ADDSKY); | ||||
| /* view state */ | /* view state */ | ||||
| bool is_ortho = false; | bool is_ortho = false; | ||||
| float winmat[4][4]; | float winmat[4][4]; | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | ED_view3d_draw_offscreen(depsgraph, | ||||
| sizey, | sizey, | ||||
| NULL, | NULL, | ||||
| winmat, | winmat, | ||||
| true, | true, | ||||
| draw_sky, | draw_sky, | ||||
| viewname, | viewname, | ||||
| do_color_management, | do_color_management, | ||||
| ofs, | ofs, | ||||
| NULL); | NULL, | ||||
| r_rv3d_mats); | |||||
| if (ibuf->rect_float) { | if (ibuf->rect_float) { | ||||
| GPU_offscreen_read_pixels(ofs, GPU_DATA_FLOAT, ibuf->rect_float); | GPU_offscreen_read_pixels(ofs, GPU_DATA_FLOAT, ibuf->rect_float); | ||||
| } | } | ||||
| else if (ibuf->rect) { | else if (ibuf->rect) { | ||||
| GPU_offscreen_read_pixels(ofs, GPU_DATA_UNSIGNED_BYTE, ibuf->rect); | GPU_offscreen_read_pixels(ofs, GPU_DATA_UNSIGNED_BYTE, ibuf->rect); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | return ED_view3d_draw_offscreen_imbuf(depsgraph, | ||||
| &v3d, | &v3d, | ||||
| ®ion, | ®ion, | ||||
| width, | width, | ||||
| height, | height, | ||||
| imbuf_flag, | imbuf_flag, | ||||
| alpha_mode, | alpha_mode, | ||||
| viewname, | viewname, | ||||
| ofs, | ofs, | ||||
| err_out); | err_out, | ||||
| NULL); | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Viewport Clipping | /** \name Viewport Clipping | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 302 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Store values from #RegionView3D, set when drawing. | * Store values from #RegionView3D, set when drawing. | ||||
| * This is needed when we draw with to a viewport using a different matrix | * This is needed when we draw with to a viewport using a different matrix | ||||
| * (offscreen drawing for example). | * (offscreen drawing for example). | ||||
| * | * | ||||
| * Values set by #ED_view3d_update_viewmat should be handled here. | * Values set by #ED_view3d_update_viewmat should be handled here. | ||||
| */ | */ | ||||
| struct RV3DMatrixStore { | |||||
| float winmat[4][4]; | |||||
| float viewmat[4][4]; | |||||
| float viewinv[4][4]; | |||||
| float persmat[4][4]; | |||||
| float persinv[4][4]; | |||||
| float viewcamtexcofac[4]; | |||||
| float pixsize; | |||||
| }; | |||||
| struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d) | RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d) | ||||
| { | { | ||||
| struct RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__); | RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__); | ||||
| copy_m4_m4(rv3dmat->winmat, rv3d->winmat); | copy_m4_m4(rv3dmat->winmat, rv3d->winmat); | ||||
| copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat); | copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat); | ||||
| copy_m4_m4(rv3dmat->persmat, rv3d->persmat); | copy_m4_m4(rv3dmat->persmat, rv3d->persmat); | ||||
| copy_m4_m4(rv3dmat->persinv, rv3d->persinv); | copy_m4_m4(rv3dmat->persinv, rv3d->persinv); | ||||
| copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv); | copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv); | ||||
| copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac); | copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac); | ||||
| rv3dmat->pixsize = rv3d->pixsize; | rv3dmat->pixsize = rv3d->pixsize; | ||||
| return rv3dmat; | return rv3dmat; | ||||
| } | } | ||||
| void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat_pt) | void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat_pt) | ||||
| { | { | ||||
| struct RV3DMatrixStore *rv3dmat = rv3dmat_pt; | RV3DMatrixStore *rv3dmat = rv3dmat_pt; | ||||
| copy_m4_m4(rv3d->winmat, rv3dmat->winmat); | copy_m4_m4(rv3d->winmat, rv3dmat->winmat); | ||||
| copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat); | copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat); | ||||
| copy_m4_m4(rv3d->persmat, rv3dmat->persmat); | copy_m4_m4(rv3d->persmat, rv3dmat->persmat); | ||||
| copy_m4_m4(rv3d->persinv, rv3dmat->persinv); | copy_m4_m4(rv3d->persinv, rv3dmat->persinv); | ||||
| copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv); | copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv); | ||||
| copy_v4_v4(rv3d->viewcamtexcofac, rv3dmat->viewcamtexcofac); | copy_v4_v4(rv3d->viewcamtexcofac, rv3dmat->viewcamtexcofac); | ||||
| rv3d->pixsize = rv3dmat->pixsize; | rv3d->pixsize = rv3dmat->pixsize; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines | |||||