[Bf-blender-cvs] [fb095af] master: View3D: refactor ED_view3d_draw_offscreen and view3d_main_area_draw_objects
Campbell Barton
noreply at git.blender.org
Sat Apr 12 07:42:11 CEST 2014
Commit: fb095afe4d27c83a72cad0829fe0ab0546b9e8ea
Author: Campbell Barton
Date: Sat Apr 12 15:34:59 2014 +1000
https://developer.blender.org/rBfb095afe4d27c83a72cad0829fe0ab0546b9e8ea
View3D: refactor ED_view3d_draw_offscreen and view3d_main_area_draw_objects
de-duplicate object drawing code between offscreen buffer and regular view3d.
Also skip drawing grease pencil and setting pixelspace when drawing from lamps.
===================================================================
M source/blender/editors/space_view3d/view3d_draw.c
===================================================================
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 2552be9..d22dca4 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1062,7 +1062,7 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
rctf viewborder;
Camera *ca = NULL;
- RegionView3D *rv3d = (RegionView3D *)ar->regiondata;
+ RegionView3D *rv3d = ar->regiondata;
if (v3d->camera == NULL)
return;
@@ -1892,7 +1892,7 @@ static void view3d_draw_transp(Scene *scene, ARegion *ar, View3D *v3d)
}
/* clears zbuffer and draws it over */
-static void view3d_draw_xray(Scene *scene, ARegion *ar, View3D *v3d, int clear)
+static void view3d_draw_xray(Scene *scene, ARegion *ar, View3D *v3d, const bool clear)
{
View3DAfter *v3da, *next;
@@ -1911,7 +1911,7 @@ static void view3d_draw_xray(Scene *scene, ARegion *ar, View3D *v3d, int clear)
/* clears zbuffer and draws it over */
-static void view3d_draw_xraytransp(Scene *scene, ARegion *ar, View3D *v3d, int clear)
+static void view3d_draw_xraytransp(Scene *scene, ARegion *ar, View3D *v3d, const bool clear)
{
View3DAfter *v3da, *next;
@@ -2554,6 +2554,171 @@ void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float view
}
}
+
+
+/**
+ * Shared by #ED_view3d_draw_offscreen and #view3d_main_area_draw_objects
+ *
+ * \note \a C and \a grid_unit will be NULL when \a draw_offscreen is set.
+ * \note Drawing lamps and opengl render uses this, so dont do grease pencil or view widgets here.
+ */
+static void view3d_draw_objects(
+ const bContext *C,
+ Scene *scene, View3D *v3d, ARegion *ar,
+ const char **grid_unit,
+ const bool do_bgpic, const bool draw_offscreen)
+{
+ RegionView3D *rv3d = ar->regiondata;
+ Base *base;
+ const bool do_camera_frame = !draw_offscreen;
+
+ if (!draw_offscreen) {
+ ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
+ }
+
+ if (rv3d->rflag & RV3D_CLIPPING)
+ view3d_draw_clipping(rv3d);
+
+ /* set zbuffer after we draw clipping region */
+ if (v3d->drawtype > OB_WIRE) {
+ v3d->zbuf = true;
+ glEnable(GL_DEPTH_TEST);
+ }
+ else {
+ v3d->zbuf = false;
+ }
+
+ if (!draw_offscreen) {
+ /* needs to be done always, gridview is adjusted in drawgrid() now, but only for ortho views. */
+ rv3d->gridview = v3d->grid;
+ if (scene->unit.system) {
+ rv3d->gridview /= scene->unit.scale_length;
+ }
+
+ if ((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) {
+ if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
+ drawfloor(scene, v3d, grid_unit);
+ }
+ }
+ else {
+ if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
+ ED_region_pixelspace(ar);
+ drawgrid(&scene->unit, ar, v3d, grid_unit);
+ /* XXX make function? replaces persp(1) */
+ glMatrixMode(GL_PROJECTION);
+ glLoadMatrixf(rv3d->winmat);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadMatrixf(rv3d->viewmat);
+ }
+ }
+ }
+
+ /* important to do before clipping */
+ if (do_bgpic) {
+ view3d_draw_bgpic_test(scene, ar, v3d, false, do_camera_frame);
+ }
+
+ if (rv3d->rflag & RV3D_CLIPPING) {
+ ED_view3d_clipping_set(rv3d);
+ }
+
+ /* draw set first */
+ if (scene->set) {
+ Scene *sce_iter;
+ for (SETLOOPER(scene->set, sce_iter, base)) {
+ if (v3d->lay & base->lay) {
+ UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f);
+ draw_object(scene, ar, v3d, base, DRAW_CONSTCOLOR | DRAW_SCENESET);
+
+ if (base->object->transflag & OB_DUPLI) {
+ draw_dupli_objects_color(scene, ar, v3d, base, TH_WIRE);
+ }
+ }
+ }
+
+ /* Transp and X-ray afterdraw stuff for sets is done later */
+ }
+
+
+ if (draw_offscreen) {
+ for (base = scene->base.first; base; base = base->next) {
+ if (v3d->lay & base->lay) {
+ /* dupli drawing */
+ if (base->object->transflag & OB_DUPLI)
+ draw_dupli_objects(scene, ar, v3d, base);
+
+ draw_object(scene, ar, v3d, base, 0);
+ }
+ }
+ }
+ else {
+ unsigned int lay_used = 0;
+
+ /* then draw not selected and the duplis, but skip editmode object */
+ for (base = scene->base.first; base; base = base->next) {
+ lay_used |= base->lay & ((1 << 20) - 1);
+
+ if (v3d->lay & base->lay) {
+
+ /* dupli drawing */
+ if (base->object->transflag & OB_DUPLI) {
+ draw_dupli_objects(scene, ar, v3d, base);
+ }
+ if ((base->flag & SELECT) == 0) {
+ if (base->object != scene->obedit)
+ draw_object(scene, ar, v3d, base, 0);
+ }
+ }
+ }
+
+ v3d->lay_used = lay_used;
+
+ /* draw selected and editmode */
+ for (base = scene->base.first; base; base = base->next) {
+ if (v3d->lay & base->lay) {
+ if (base->object == scene->obedit || (base->flag & SELECT)) {
+ draw_object(scene, ar, v3d, base, 0);
+ }
+ }
+ }
+ }
+
+ /* must be before xray draw which clears the depth buffer */
+ if (v3d->flag2 & V3D_SHOW_GPENCIL) {
+ /* must be before xray draw which clears the depth buffer */
+ if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
+ draw_gpencil_view3d(scene, v3d, ar, true);
+ if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
+ }
+
+ /* transp and X-ray afterdraw stuff */
+ if (v3d->afterdraw_transp.first) view3d_draw_transp(scene, ar, v3d);
+ if (v3d->afterdraw_xray.first) view3d_draw_xray(scene, ar, v3d, true);
+ if (v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(scene, ar, v3d, true);
+
+ if (!draw_offscreen) {
+ ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
+ }
+
+ if (rv3d->rflag & RV3D_CLIPPING)
+ ED_view3d_clipping_disable();
+
+ /* important to do after clipping */
+ if (do_bgpic) {
+ view3d_draw_bgpic_test(scene, ar, v3d, true, do_camera_frame);
+ }
+
+ if (!draw_offscreen) {
+ BIF_draw_manipulator(C);
+ }
+
+ /* cleanup */
+ if (v3d->zbuf) {
+ v3d->zbuf = false;
+ glDisable(GL_DEPTH_TEST);
+ }
+}
+
static void view3d_main_area_setup_view(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4])
{
RegionView3D *rv3d = ar->regiondata;
@@ -2578,10 +2743,9 @@ void ED_view3d_draw_offscreen_init(Scene *scene, View3D *v3d)
* stuff like shadow buffers
*/
void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, int winy,
- float viewmat[4][4], float winmat[4][4], bool do_bgpic, bool do_sky)
+ float viewmat[4][4], float winmat[4][4],
+ bool do_bgpic, bool do_sky)
{
- RegionView3D *rv3d = ar->regiondata;
- Base *base;
int bwinx, bwiny;
rcti brect;
@@ -2591,7 +2755,7 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
bwinx = ar->winx;
bwiny = ar->winy;
brect = ar->winrct;
-
+
ar->winx = winx;
ar->winy = winy;
ar->winrct.xmin = 0;
@@ -2601,13 +2765,15 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
/* set theme */
UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
-
+
/* set flags */
G.f |= G_RENDER_OGL;
- /* free images which can have changed on frame-change
- * warning! can be slow so only free animated images - campbell */
- GPU_free_images_anim();
+ if ((v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
+ /* free images which can have changed on frame-change
+ * warning! can be slow so only free animated images - campbell */
+ GPU_free_images_anim();
+ }
/* clear opengl buffers */
if (do_sky) {
@@ -2622,91 +2788,28 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
/* setup view matrices */
view3d_main_area_setup_view(scene, v3d, ar, viewmat, winmat);
- if (rv3d->rflag & RV3D_CLIPPING)
- view3d_draw_clipping(rv3d);
- /* set zbuffer */
- if (v3d->drawtype > OB_WIRE) {
- v3d->zbuf = true;
- glEnable(GL_DEPTH_TEST);
- }
- else
- v3d->zbuf = false;
+ /* main drawing call */
+ view3d_draw_objects(NULL, scene, v3d, ar, NULL, do_bgpic, true);
- /* important to do before clipping */
- if (do_bgpic) {
- view3d_draw_bgpic_test(scene, ar, v3d, false, false);
- }
+ if ((v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
+ /* draw grease-pencil stuff */
+ ED_region_pixelspace(ar);
- if (rv3d->rflag & RV3D_CLIPPING)
- ED_view3d_clipping_set(rv3d);
- /* draw set first */
- if (scene->set) {
- Scene *sce_iter;
- for (SETLOOPER(scene->set, sce_iter, base)) {
- if (v3d->lay & base->lay) {
- UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f);
- draw_object(scene, ar, v3d, base, DRAW_CONSTCOLOR | DRAW_SCENESET);
-
- if (base->object->transflag & OB_DUPLI)
- draw_dupli_objects_color(scene, ar, v3d, base, TH_WIRE);
- }
- }
- }
-
- /* then draw not selected and the duplis, but skip editmode object */
- for (base = scene->base.first; base; base = base->next) {
- if (v3d->lay & base->lay) {
- /* dupli drawing */
- if (base->object->transflag & OB_DUPLI)
- draw_dupli_objects(scene, ar, v3d, base);
-
- draw_object(scene, ar, v3d, base, 0);
+ if (v3d->flag2 & V3D_SHOW_GPENCIL) {
+ /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */
+ draw_gpencil_view3d(scene, v3d, ar, false);
}
- }
-
- /* must be before xray draw which clears the depth buffer */
- if (v3d->flag2 & V3D_SHOW_GPENCIL) {
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
- draw_gpencil_view3d(scene, v3d, ar, true);
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- }
-
- /* transp and X-ray afterdraw stuff */
- if (v3d->afterdraw_transp.first) view3d_draw_transp(scene, ar, v3d);
- if (v3d->afterdraw_xray.first) view3d_draw_xray(scene, ar, v3d, 1); /* clears zbuffer if it is used! */
- if (v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(scene, ar, v3d, 1);
-
- if (rv3d->rflag & RV3D_CLIPPING)
- ED_view3d_clipping_disable();
-
- /* important to do after clipping */
- if (do_bgpic) {
- view3d_draw_bgpic_test(scene, ar, v3d, true, false);
- }
-
- /* cleanup */
- if (v3d->zbuf) {
- v3d->zbuf = false;
- glDisable(GL_DEPTH_TEST);
- }
-
- /* draw grease-pencil stuff */
- ED_region_pixelspace(ar);
-
- if (v3d->flag2 & V3D_SHOW_GPENCIL) {
- /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */
- draw_gpencil_view3d(scene, v3d, ar, false);
+ /* freeing the images
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list