View3D offscreen buffer was interferring with view navigation
authorDalai Felinto <dfelinto@gmail.com>
Tue, 27 Oct 2015 13:27:26 +0000 (11:27 -0200)
committerDalai Felinto <dfelinto@gmail.com>
Tue, 27 Oct 2015 13:29:21 +0000 (11:29 -0200)
the RegionView3D matrices need to be re-set after drawing.

Review and touch ups by Campbell Barton

source/blender/editors/include/ED_view3d.h
source/blender/editors/space_view3d/view3d_draw.c
source/blender/python/intern/gpu_offscreen.c

index 5cd73e4efb5d793a96e2ced4b2e4d69e5c57a63a..9da12211daa3c3a615e0c3e57a9faf32264f8798 100644 (file)
@@ -319,6 +319,9 @@ void ED_view3d_check_mats_rv3d(struct RegionView3D *rv3d);
 #endif
 int ED_view3d_scene_layer_set(int lay, const int *values, int *active);
 
+void *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d);
+void  ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, void *rv3dmat_pt);
+
 bool ED_view3d_context_activate(struct bContext *C);
 void ED_view3d_draw_offscreen_init(struct Scene *scene, struct View3D *v3d);
 void ED_view3d_draw_offscreen(
index 3e0ea5fac074b8ef4fe8b3a7549c4e061445a4fd..01398c8335beb6a04b329e4ee7b58801a4650fee 100644 (file)
@@ -2643,6 +2643,9 @@ CustomDataMask ED_view3d_screen_datamask(const bScreen *screen)
        return mask;
 }
 
+/**
+ * \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;
@@ -2916,6 +2919,47 @@ static void view3d_main_area_setup_view(Scene *scene, View3D *v3d, ARegion *ar,
        glLoadMatrixf(rv3d->viewmat);
 }
 
+/**
+ * Store values from #RegionView3D, set when drawing.
+ * This is needed when we draw with to a viewport using a different matrix (offscreen drawing for example).
+ *
+ * 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;
+};
+
+void *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d)
+{
+       struct RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__);
+       copy_m4_m4(rv3dmat->winmat, rv3d->winmat);
+       copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat);
+       copy_m4_m4(rv3dmat->persmat, rv3d->persmat);
+       copy_m4_m4(rv3dmat->persinv, rv3d->persinv);
+       copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv);
+       copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac);
+       rv3dmat->pixsize = rv3d->pixsize;
+       return (void *)rv3dmat;
+}
+
+void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, void *rv3dmat_pt)
+{
+       struct RV3DMatrixStore *rv3dmat = rv3dmat_pt;
+       copy_m4_m4(rv3d->winmat, rv3dmat->winmat);
+       copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat);
+       copy_m4_m4(rv3d->persmat, rv3dmat->persmat);
+       copy_m4_m4(rv3d->persinv, rv3dmat->persinv);
+       copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv);
+       copy_v4_v4(rv3d->viewcamtexcofac, rv3dmat->viewcamtexcofac);
+       rv3d->pixsize = rv3dmat->pixsize;
+}
+
 void ED_view3d_draw_offscreen_init(Scene *scene, View3D *v3d)
 {
        /* shadow buffers, before we setup matrices */
index f8285c6139f28a9f363bd18cb3d880e50f7471c7..ed31ac052c6d925a68b94d92e9c4fe1b66ba3e53 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <Python.h>
 
+#include "MEM_guardedalloc.h"
+
 #include "BLI_utildefines.h"
 
 #include "WM_types.h"
@@ -200,6 +202,7 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a
        ARegion *ar;
        GPUFX *fx;
        GPUFXSettings fx_settings;
+       void *rv3d_mats;
 
        BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
 
@@ -221,6 +224,8 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a
 
        ED_view3d_draw_offscreen_init(scene, v3d);
 
+       rv3d_mats = ED_view3d_mats_rv3d_backup(ar->regiondata);
+
        GPU_offscreen_bind(self->ofs, true); /* bind */
 
        ED_view3d_draw_offscreen(
@@ -233,6 +238,9 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a
        GPU_fx_compositor_destroy(fx);
        GPU_offscreen_unbind(self->ofs, true); /* unbind */
 
+       ED_view3d_mats_rv3d_restore(ar->regiondata, rv3d_mats);
+       MEM_freeN(rv3d_mats);
+
        Py_RETURN_NONE;
 }