Changeset View
Changeset View
Standalone View
Standalone View
source/blender/viewport/intern/blender_viewport/blender_viewport.c
- This file was copied from source/blender/editors/space_view3d/view3d_draw.c.
| /* | /* | ||||
| * ***** BEGIN GPL LICENSE BLOCK ***** | * ***** BEGIN GPL LICENSE BLOCK ***** | ||||
| * | * | ||||
| * This program is free software; you can redistribute it and/or | * This program is free software; you can redistribute it and/or | ||||
| * modify it under the terms of the GNU General Public License | * modify it under the terms of the GNU General Public License | ||||
| * as published by the Free Software Foundation; either version 2 | * as published by the Free Software Foundation; either version 2 | ||||
| * of the License, or (at your option) any later version. | * of the License, or (at your option) any later version. | ||||
| * | * | ||||
| * This program is distributed in the hope that it will be useful, | * This program is distributed in the hope that it will be useful, | ||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| * GNU General Public License for more details. | * GNU General Public License for more details. | ||||
| * | * | ||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| * | * | ||||
| * The Original Code is Copyright (C) 2008 Blender Foundation. | |||||
| * All rights reserved. | |||||
| * | |||||
| * | |||||
| * Contributor(s): Blender Foundation | |||||
| * | |||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| /** \file blender/editors/space_view3d/view3d_draw.c | /** \file blender/viewport/intern/blender_viewport/blender_viewport.c | ||||
| * \ingroup spview3d | * \ingroup viewport | ||||
| * | |||||
| * \brief Blender Internal Viewport Engine | |||||
| */ | */ | ||||
| #include <math.h> | #include <stddef.h> | ||||
| #include <string.h> | |||||
| #include "BIF_gl.h" | #include "BIF_gl.h" | ||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_unit.h" | #include "BKE_unit.h" | ||||
| #include "BLI_listbase.h" | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_rect.h" | #include "BLI_rect.h" | ||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "BLT_translation.h" | |||||
| #include "DNA_camera_types.h" | #include "DNA_camera_types.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "DNA_windowmanager_types.h" | #include "DNA_windowmanager_types.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_view3d.h" | |||||
| #include "GPU_immediate.h" | #include "GPU_immediate.h" | ||||
| #include "UI_resources.h" | #include "MEM_guardedalloc.h" | ||||
| #include "RE_engine.h" | #include "RE_engine.h" | ||||
| #include "UI_resources.h" | |||||
| #include "viewport_intern.h" | |||||
| #include "VP_engine_API.h" | |||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "view3d_intern.h" /* own include */ | static void blender_viewport_engine_init(ViewportEngineType *engine_type); | ||||
| static void blender_viewport_engine_setup_render(ViewportEngine *engine, const bContext *C); | |||||
| /* prototypes */ | ViewportEngineType vp_blender_viewport = { | ||||
| static void draw_all_objects(const bContext *C, ARegion *ar, const bool only_depth, const bool use_depth); | NULL, NULL, | ||||
| "BLENDER_VIEWPORT", N_("Modern Viewport"), /* TODO temp name */ | |||||
| blender_viewport_engine_init, | |||||
| blender_viewport_engine_setup_render, | |||||
| }; | |||||
| /* TODO this could become the RenderData equivalent for viewports (but less messy ;) ) */ | |||||
| typedef struct DrawData { | typedef struct DrawData { | ||||
| rcti border_rect; | rcti border_rect; | ||||
| bool render_border; | bool render_border; | ||||
| bool clip_border; | bool clip_border; | ||||
| bool is_render; | bool is_render; | ||||
| } DrawData; | } DrawData; | ||||
| static void view3d_draw_data_init(const bContext *C, ARegion *ar, DrawData *draw_data) | static void viewport_draw_data_init(const bContext *C, ARegion *ar, DrawData *draw_data) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| draw_data->is_render = (v3d->drawtype == OB_RENDER); | draw_data->is_render = (v3d->drawtype == OB_RENDER); | ||||
| draw_data->render_border = ED_view3d_calc_render_border(scene, v3d, ar, &draw_data->border_rect); | draw_data->render_border = ED_view3d_calc_render_border(scene, v3d, ar, &draw_data->border_rect); | ||||
| draw_data->clip_border = (draw_data->render_border && !BLI_rcti_compare(&ar->drawrct, &draw_data->border_rect)); | draw_data->clip_border = (draw_data->render_border && !BLI_rcti_compare(&ar->drawrct, &draw_data->border_rect)); | ||||
| } | } | ||||
| /* ******************** general functions ***************** */ | /* ******************** general functions ***************** */ | ||||
| #if 0 | |||||
| static bool use_depth_doit(Scene *scene, View3D *v3d) | static bool use_depth_doit(Scene *scene, View3D *v3d) | ||||
| { | { | ||||
| if (v3d->drawtype > OB_WIRE) | if (v3d->drawtype > OB_WIRE) | ||||
| return true; | return true; | ||||
| /* special case (depth for wire color) */ | /* special case (depth for wire color) */ | ||||
| if (v3d->drawtype <= OB_WIRE) { | if (v3d->drawtype <= OB_WIRE) { | ||||
| if (scene->obedit && scene->obedit->type == OB_MESH) { | if (scene->obedit && scene->obedit->type == OB_MESH) { | ||||
| Mesh *me = scene->obedit->data; | Mesh *me = scene->obedit->data; | ||||
| if (me->drawflag & ME_DRAWEIGHT) { | if (me->drawflag & ME_DRAWEIGHT) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static bool use_depth(const bContext *C) | static bool use_depth(const bContext *C) | ||||
| { | { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| return use_depth_doit(scene, v3d); | return use_depth_doit(scene, v3d); | ||||
| } | } | ||||
| #endif | |||||
| /** | |||||
| * \note keep this synced with #ED_view3d_mats_rv3d_backup/#ED_view3d_mats_rv3d_restore | |||||
| */ | |||||
| void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4]) | |||||
| { | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| rctf cameraborder; | |||||
| /* setup window matrices */ | |||||
| if (winmat) | |||||
| copy_m4_m4(rv3d->winmat, winmat); | |||||
| else | |||||
| view3d_winmatrix_set(ar, v3d, NULL); | |||||
| /* setup view matrix */ | |||||
| if (viewmat) | |||||
| copy_m4_m4(rv3d->viewmat, viewmat); | |||||
| else | |||||
| view3d_viewmatrix_set(scene, v3d, rv3d); /* note: calls BKE_object_where_is_calc for camera... */ | |||||
| /* update utilitity matrices */ | |||||
| mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat); | |||||
| invert_m4_m4(rv3d->persinv, rv3d->persmat); | |||||
| invert_m4_m4(rv3d->viewinv, rv3d->viewmat); | |||||
| /* calculate GLSL view dependent values */ | |||||
| /* store window coordinates scaling/offset */ | |||||
| if (rv3d->persp == RV3D_CAMOB && v3d->camera) { | |||||
| ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &cameraborder, false); | |||||
| rv3d->viewcamtexcofac[0] = (float)ar->winx / BLI_rctf_size_x(&cameraborder); | |||||
| rv3d->viewcamtexcofac[1] = (float)ar->winy / BLI_rctf_size_y(&cameraborder); | |||||
| rv3d->viewcamtexcofac[2] = -rv3d->viewcamtexcofac[0] * cameraborder.xmin / (float)ar->winx; | |||||
| rv3d->viewcamtexcofac[3] = -rv3d->viewcamtexcofac[1] * cameraborder.ymin / (float)ar->winy; | |||||
| } | |||||
| else { | |||||
| rv3d->viewcamtexcofac[0] = rv3d->viewcamtexcofac[1] = 1.0f; | |||||
| rv3d->viewcamtexcofac[2] = rv3d->viewcamtexcofac[3] = 0.0f; | |||||
| } | |||||
| /* calculate pixelsize factor once, is used for lamps and obcenters */ | |||||
| { | |||||
| /* note: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])' | |||||
| * because of float point precision problems at large values [#23908] */ | |||||
| float v1[3], v2[3]; | |||||
| float len_px, len_sc; | |||||
| v1[0] = rv3d->persmat[0][0]; | |||||
| v1[1] = rv3d->persmat[1][0]; | |||||
| v1[2] = rv3d->persmat[2][0]; | |||||
| v2[0] = rv3d->persmat[0][1]; | |||||
| v2[1] = rv3d->persmat[1][1]; | |||||
| v2[2] = rv3d->persmat[2][1]; | |||||
| len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2))); | |||||
| len_sc = (float)MAX2(ar->winx, ar->winy); | |||||
| rv3d->pixsize = len_px / len_sc; | |||||
| } | |||||
| } | |||||
| static void view3d_main_region_setup_view(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4]) | static void view3d_main_region_setup_view(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4]) | ||||
| { | { | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| ED_view3d_update_viewmat(scene, v3d, ar, viewmat, winmat); | ED_view3d_update_viewmat(scene, v3d, ar, viewmat, winmat); | ||||
| /* set for opengl */ | /* set for opengl */ | ||||
| ▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | |||||
| */ | */ | ||||
| static void view3d_draw_background(const bContext *C) | static void view3d_draw_background(const bContext *C) | ||||
| { | { | ||||
| /* TODO viewport */ | /* TODO viewport */ | ||||
| UI_ThemeClearColor(TH_HIGH_GRAD); | UI_ThemeClearColor(TH_HIGH_GRAD); | ||||
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||||
| } | } | ||||
| #if 0 | |||||
| /** | /** | ||||
| * | * | ||||
| */ | */ | ||||
| static void view3d_draw_render_solid_surfaces(const bContext *C, ARegion *ar, const bool run_screen_shaders) | static void view3d_draw_render_solid_surfaces(const bContext *C, ARegion *ar, const bool run_screen_shaders) | ||||
| { | { | ||||
| /* TODO viewport */ | /* TODO viewport */ | ||||
| draw_all_objects(C, ar, false, use_depth(C)); | draw_all_objects(C, ar, false, use_depth(C)); | ||||
| } | } | ||||
| #endif | |||||
| /** | /** | ||||
| * | * | ||||
| */ | */ | ||||
| static void view3d_draw_render_transparent_surfaces(const bContext *C) | static void view3d_draw_render_transparent_surfaces(const bContext *C) | ||||
| { | { | ||||
| /* TODO viewport */ | /* TODO viewport */ | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 480 Lines • ▼ Show 20 Lines | if (show_axis_x || show_axis_y || show_axis_z) { | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| if (!write_depth) | if (!write_depth) | ||||
| glDepthMask(GL_TRUE); | glDepthMask(GL_TRUE); | ||||
| } | } | ||||
| } | } | ||||
| /** could move this elsewhere, but tied into #ED_view3d_grid_scale */ | |||||
| float ED_scene_grid_scale(Scene *scene, const char **grid_unit) | |||||
| { | |||||
| /* apply units */ | |||||
| if (scene->unit.system) { | |||||
| const void *usys; | |||||
| int len; | |||||
| bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len); | |||||
| if (usys) { | |||||
| int i = bUnit_GetBaseUnit(usys); | |||||
| if (grid_unit) | |||||
| *grid_unit = bUnit_GetNameDisplay(usys, i); | |||||
| return (float)bUnit_GetScaler(usys, i) / scene->unit.scale_length; | |||||
| } | |||||
| } | |||||
| return 1.0f; | |||||
| } | |||||
| float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit) | |||||
| { | |||||
| return v3d->grid * ED_scene_grid_scale(scene, grid_unit); | |||||
| } | |||||
| /** | /** | ||||
| * | * | ||||
| */ | */ | ||||
| static void view3d_draw_grid(const bContext *C, ARegion *ar) | static void view3d_draw_grid(const bContext *C, ARegion *ar) | ||||
| { | { | ||||
| /* TODO viewport | /* TODO viewport | ||||
| * Missing is the flags to check whether to draw it | * Missing is the flags to check whether to draw it | ||||
| * for now now we are using the flags in v3d itself. | * for now now we are using the flags in v3d itself. | ||||
| * | * | ||||
| * Also for now always assume depth is there, so we | * Also for now always assume depth is there, so we | ||||
| * draw on top of it. | * draw on top of it. | ||||
| */ | */ | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| const bool draw_floor = (rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO); | const bool draw_floor = (rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO); | ||||
| const char *grid_unit = NULL; | const char *grid_unit = NULL; | ||||
| /* ortho grid goes first, does not write to depth buffer and doesn't need depth test so it will override | /* ortho grid goes first, does not write to depth buffer and doesn't need depth test so it will override | ||||
| * objects if done last */ | * objects if done last */ | ||||
| /* needs to be done always, gridview is adjusted in drawgrid() now, but only for ortho views. */ | /* needs to be done always, gridview is adjusted in drawgrid() now, but only for ortho views. */ | ||||
| rv3d->gridview = ED_view3d_grid_scale(scene, v3d, grid_unit); | rv3d->gridview = ED_view3d_grid_scale(scene, v3d, &grid_unit); | ||||
| glEnable(GL_DEPTH_TEST); | glEnable(GL_DEPTH_TEST); | ||||
| if (!draw_floor) { | if (!draw_floor) { | ||||
| ED_region_pixelspace(ar); | ED_region_pixelspace(ar); | ||||
| *(&grid_unit) = NULL; /* drawgrid need this to detect/affect smallest valid unit... */ | *(&grid_unit) = NULL; /* drawgrid need this to detect/affect smallest valid unit... */ | ||||
| drawgrid(&scene->unit, ar, v3d, &grid_unit); | drawgrid(&scene->unit, ar, v3d, &grid_unit); | ||||
| glMatrixMode(GL_PROJECTION); | glMatrixMode(GL_PROJECTION); | ||||
| glLoadMatrixf(rv3d->winmat); | glLoadMatrixf(rv3d->winmat); | ||||
| glMatrixMode(GL_MODELVIEW); | glMatrixMode(GL_MODELVIEW); | ||||
| glLoadMatrixf(rv3d->viewmat); | glLoadMatrixf(rv3d->viewmat); | ||||
| } | } | ||||
| else { | else { | ||||
| drawfloor(scene, v3d, &grid_unit, false); | drawfloor(scene, v3d, &grid_unit, false); | ||||
| } | } | ||||
| glDisable(GL_DEPTH_TEST); | glDisable(GL_DEPTH_TEST); | ||||
| } | } | ||||
| /* ******************** view loop ***************** */ | /* ******************** view loop ***************** */ | ||||
| /** | #if 0 | ||||
| * Set the correct matrices | |||||
| */ | |||||
| static void view3d_draw_setup_view(const bContext *C, ARegion *ar) | |||||
| { | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| View3D *v3d = CTX_wm_view3d(C); | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| /* setup the view matrix */ | |||||
| if (view3d_stereo3d_active(C, scene, v3d, rv3d)) | |||||
| view3d_stereo3d_setup(scene, v3d, ar); | |||||
| else | |||||
| view3d_main_region_setup_view(scene, v3d, ar, NULL, NULL); | |||||
| } | |||||
| static void draw_all_objects(const bContext *C, ARegion *ar, const bool only_depth, const bool use_depth) | static void draw_all_objects(const bContext *C, ARegion *ar, const bool only_depth, const bool use_depth) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Base *base; | Base *base; | ||||
| if (only_depth) | if (only_depth) | ||||
| glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); | ||||
| Show All 21 Lines | |||||
| /** | /** | ||||
| * Draw only the scene depth buffer | * Draw only the scene depth buffer | ||||
| */ | */ | ||||
| static void draw_depth_buffer(const bContext *C, ARegion *ar) | static void draw_depth_buffer(const bContext *C, ARegion *ar) | ||||
| { | { | ||||
| draw_all_objects(C, ar, true, true); | draw_all_objects(C, ar, true, true); | ||||
| } | } | ||||
| #endif | |||||
| /** | /** | ||||
| * Required if the shaders need it or external engines | * Required if the shaders need it or external engines | ||||
| * (e.g., Cycles requires depth buffer handled separately). | * (e.g., Cycles requires depth buffer handled separately). | ||||
| */ | */ | ||||
| static void view3d_draw_prerender_buffers(const bContext *C, ARegion *ar, DrawData *draw_data) | static void viewport_draw_prerender_buffers(const ViewportEngine *engine, const bContext *UNUSED(C)) | ||||
| { | { | ||||
| const DrawData *draw_data = engine->render_data; | |||||
| /* TODO viewport */ | /* TODO viewport */ | ||||
| if (draw_data->is_render && (!draw_data->clip_border)) { | if (draw_data->is_render && (!draw_data->clip_border)) { | ||||
| draw_depth_buffer(C, ar); | // draw_depth_buffer(C, ar); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Draw all the plates that will fill the RGBD buffer | * Draw all the plates that will fill the RGBD buffer | ||||
| */ | */ | ||||
| static void view3d_draw_solid_plates(const bContext *C, ARegion *ar, DrawData *draw_data) | static void viewport_draw_solid_plates(const ViewportEngine *engine, const bContext *C) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| const DrawData *draw_data = engine->render_data; | |||||
| /* realtime plates */ | /* realtime plates */ | ||||
| if ((!draw_data->is_render) || draw_data->clip_border) { | if ((!draw_data->is_render) || draw_data->clip_border) { | ||||
| view3d_draw_background(C); | view3d_draw_background(C); | ||||
| view3d_draw_render_solid_surfaces(C, ar, true); | // view3d_draw_render_solid_surfaces(C, ar, true); | ||||
| view3d_draw_render_transparent_surfaces(C); | view3d_draw_render_transparent_surfaces(C); | ||||
| view3d_draw_post_draw(C); | view3d_draw_post_draw(C); | ||||
| } | } | ||||
| /* offline plates*/ | /* offline plates*/ | ||||
| if (draw_data->is_render) { | if (draw_data->is_render) { | ||||
| ARegion *ar = CTX_wm_region(C); | |||||
| view3d_draw_render_draw(C, scene, ar, v3d, draw_data->clip_border, &draw_data->border_rect); | view3d_draw_render_draw(C, scene, ar, v3d, draw_data->clip_border, &draw_data->border_rect); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Wires, outline, ... | * Wires, outline, ... | ||||
| */ | */ | ||||
| static void view3d_draw_geometry_overlay(const bContext *C) | static void viewport_draw_geometry_overlay(const ViewportEngine *UNUSED(engine), const bContext *C) | ||||
| { | { | ||||
| view3d_draw_wire_plates(C); | view3d_draw_wire_plates(C); | ||||
| view3d_draw_outline_plates(C); | view3d_draw_outline_plates(C); | ||||
| } | } | ||||
| /** | /** | ||||
| * Empties, lamps, parent lines, grid, ... | * Empties, lamps, parent lines, grid, ... | ||||
| */ | */ | ||||
| static void view3d_draw_other_elements(const bContext *C, ARegion *ar) | static void viewport_draw_other_elements(const ViewportEngine *UNUSED(engine), const bContext *C) | ||||
| { | { | ||||
| /* TODO viewport */ | /* TODO viewport */ | ||||
| view3d_draw_grid(C, ar); | view3d_draw_grid(C, CTX_wm_region(C)); | ||||
| } | } | ||||
| /** | /** | ||||
| * Paint brushes, armatures, ... | * Paint brushes, armatures, ... | ||||
| */ | */ | ||||
| static void view3d_draw_tool_ui(const bContext *C) | static void viewport_draw_tool_ui(const ViewportEngine *UNUSED(engine), const bContext *UNUSED(C)) | ||||
| { | { | ||||
| /* TODO viewport */ | /* TODO viewport */ | ||||
| } | } | ||||
| /** | /** | ||||
| * Blueprint images | * Blueprint images | ||||
| */ | */ | ||||
| static void view3d_draw_reference_images(const bContext *C) | static void viewport_draw_reference_images(const ViewportEngine *UNUSED(engine), const bContext *UNUSED(C)) | ||||
| { | { | ||||
| /* TODO viewport */ | /* TODO viewport */ | ||||
| } | } | ||||
| /** | /** | ||||
| * Grease Pencil | * Grease Pencil | ||||
| */ | */ | ||||
| static void view3d_draw_grease_pencil(const bContext *C) | static void viewport_draw_grease_pencil(const ViewportEngine *UNUSED(engine), const bContext *UNUSED(C)) | ||||
| { | { | ||||
| /* TODO viewport */ | /* TODO viewport */ | ||||
| } | } | ||||
| /** | static ViewportDrawPlate default_plates[] = { | ||||
| * This could run once per view, or even in parallel | {NULL, NULL, "PRERENDER_BUFFERS", viewport_draw_prerender_buffers}, | ||||
| * for each of them. What is a "view"? | {NULL, NULL, "SOLID_PLATES", viewport_draw_solid_plates}, | ||||
| * - a viewport with the camera elsewhere | {NULL, NULL, "GEOMETRY_OVERLAY", viewport_draw_geometry_overlay}, | ||||
| * - left/right stereo | {NULL, NULL, "OTHER_ELEMENTS", viewport_draw_other_elements}, | ||||
| * - panorama / fisheye individual cubemap faces | {NULL, NULL, "TOOL_UI", viewport_draw_tool_ui}, | ||||
| */ | {NULL, NULL, "REFERENCE_IMAGES", viewport_draw_reference_images}, | ||||
| static void view3d_draw_view(const bContext *C, ARegion *ar, DrawData *draw_data) | {NULL, NULL, "GREASE_PENCIL", viewport_draw_grease_pencil}, | ||||
| { | {NULL} | ||||
| /* TODO - Technically this should be drawn to a few FBO, so we can handle | }; | ||||
| * compositing better, but for now this will get the ball rolling (dfelinto) */ | |||||
| view3d_draw_setup_view(C, ar); | |||||
| view3d_draw_prerender_buffers(C, ar, draw_data); | |||||
| view3d_draw_solid_plates(C, ar, draw_data); | |||||
| view3d_draw_geometry_overlay(C); | |||||
| view3d_draw_other_elements(C, ar); | |||||
| view3d_draw_tool_ui(C); | |||||
| view3d_draw_reference_images(C); | |||||
| view3d_draw_grease_pencil(C); | |||||
| } | |||||
| void view3d_main_region_draw(const bContext *C, ARegion *ar) | static void draw_mode_add_default_plates(ViewportDrawMode *mode) | ||||
| { | { | ||||
| View3D *v3d = CTX_wm_view3d(C); | for (ViewportDrawPlate *plate = &default_plates[0]; plate->idname; plate++) { | ||||
| BLI_addtail(&mode->drawplates, plate); | |||||
| if (IS_VIEWPORT_LEGACY(v3d)) { | |||||
| view3d_main_region_draw_legacy(C, ar); | |||||
| return; | |||||
| } | } | ||||
| /* TODO viewport - there is so much to be done, in fact a lot will need to happen in the space_view3d.c | |||||
| * before we even call the drawing routine, but let's move on for now (dfelinto) | |||||
| * but this is a provisory way to start seeing things in the viewport */ | |||||
| DrawData draw_data; | |||||
| view3d_draw_data_init(C, ar, &draw_data); | |||||
| view3d_draw_view(C, ar, &draw_data); | |||||
| v3d->flag |= V3D_INVALID_BACKBUF; | |||||
| } | } | ||||
| /* ******************** legacy interface ***************** */ | static void blender_viewport_engine_init(ViewportEngineType *engine_type) | ||||
| /** | |||||
| * This will be removed once the viewport gets replaced | |||||
| * meanwhile it should keep the old viewport working. | |||||
| */ | |||||
| void VP_legacy_drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **grid_unit) | |||||
| { | { | ||||
| drawgrid(unit, ar, v3d, grid_unit); | ViewportDrawMode *defaultmode = MEM_callocN(sizeof(*defaultmode), "Blender viewport default plates"); | ||||
| draw_mode_add_default_plates(defaultmode); | |||||
| BLI_addtail(&engine_type->drawmodes, defaultmode); | |||||
| } | } | ||||
| void VP_legacy_drawfloor(Scene *scene, View3D *v3d, const char **grid_unit, bool write_depth) | /** | ||||
| * Set the correct matrices | |||||
| */ | |||||
| static void blender_viewport_engine_setup_render(ViewportEngine *engine, const bContext *C) | |||||
| { | { | ||||
| drawfloor(scene, v3d, grid_unit, write_depth); | /* TODO viewport - there is so much to be done, in fact a lot will need to happen in the space_view3d.c | ||||
| } | * before we even call the drawing routine, but let's move on for now (dfelinto) | ||||
| * but this is a provisory way to start seeing things in the viewport */ | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| ARegion *ar = CTX_wm_region(C); | |||||
| View3D *v3d = CTX_wm_view3d(C); | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| DrawData *draw_data = engine->render_data; | |||||
| void VP_legacy_view3d_main_region_setup_view(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4]) | /* setup the view matrix */ | ||||
| { | if (view3d_stereo3d_active(C, scene, v3d, rv3d)) | ||||
| view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat); | view3d_stereo3d_setup(scene, v3d, ar); | ||||
| } | else | ||||
| view3d_main_region_setup_view(scene, v3d, ar, NULL, NULL); | |||||
| bool VP_legacy_view3d_stereo3d_active(const bContext *C, Scene *scene, View3D *v3d, RegionView3D *rv3d) | if (!draw_data) { | ||||
| { | draw_data = MEM_callocN(sizeof(*draw_data), __func__); | ||||
| return view3d_stereo3d_active(C, scene, v3d, rv3d); | engine->render_data = draw_data; | ||||
| } | } | ||||
| viewport_draw_data_init(C, ar, draw_data); | |||||
| void VP_legacy_view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar) | |||||
| { | |||||
| view3d_stereo3d_setup(scene, v3d, ar); | |||||
| } | } | ||||
| bool VP_legacy_use_depth(Scene *scene, View3D *v3d) | |||||
| { | |||||
| return use_depth_doit(scene, v3d); | |||||
| } | |||||
| No newline at end of file | |||||