Beispiel #1
0
static void wm_draw_region_buffer_create(ARegion *ar, bool stereo, bool use_viewport)
{
  if (ar->draw_buffer) {
    if (ar->draw_buffer->stereo != stereo) {
      /* Free draw buffer on stereo changes. */
      wm_draw_region_buffer_free(ar);
    }
    else {
      /* Free offscreen buffer on size changes. Viewport auto resizes. */
      GPUOffScreen *offscreen = ar->draw_buffer->offscreen[0];
      if (offscreen && (GPU_offscreen_width(offscreen) != ar->winx ||
                        GPU_offscreen_height(offscreen) != ar->winy)) {
        wm_draw_region_buffer_free(ar);
      }
    }
  }

  if (!ar->draw_buffer) {
    if (use_viewport) {
      /* Allocate viewport which includes an offscreen buffer with depth
       * multisample, etc. */
      ar->draw_buffer = MEM_callocN(sizeof(wmDrawBuffer), "wmDrawBuffer");
      ar->draw_buffer->viewport[0] = GPU_viewport_create();
      ar->draw_buffer->viewport[1] = (stereo) ? GPU_viewport_create() : NULL;
    }
    else {
      /* Allocate offscreen buffer if it does not exist. This one has no
       * depth or multisample buffers. 3D view creates own buffers with
       * the data it needs. */
      GPUOffScreen *offscreen = GPU_offscreen_create(ar->winx, ar->winy, 0, false, false, NULL);
      if (!offscreen) {
        return;
      }

      wm_draw_offscreen_texture_parameters(offscreen);

      GPUOffScreen *offscreen_right = NULL;
      if (stereo) {
        offscreen_right = GPU_offscreen_create(ar->winx, ar->winy, 0, false, false, NULL);

        if (!offscreen_right) {
          GPU_offscreen_free(offscreen);
          return;
        }

        wm_draw_offscreen_texture_parameters(offscreen_right);
      }

      ar->draw_buffer = MEM_callocN(sizeof(wmDrawBuffer), "wmDrawBuffer");
      ar->draw_buffer->offscreen[0] = offscreen;
      ar->draw_buffer->offscreen[1] = offscreen_right;
    }

    ar->draw_buffer->bound_view = -1;
    ar->draw_buffer->stereo = stereo;
  }
}
Beispiel #2
0
static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *args, PyObject *kwds)
{
    static const char *kwlist[] = {"scene", "view3d", "region", "projection_matrix", "modelview_matrix", NULL};

    MatrixObject *py_mat_modelview, *py_mat_projection;
    PyObject *py_scene, *py_region, *py_view3d;

    Scene *scene;
    View3D *v3d;
    ARegion *ar;
    GPUFX *fx;
    GPUFXSettings fx_settings;
    void *rv3d_mats;

    BPY_GPU_OFFSCREEN_CHECK_OBJ(self);

    if (!PyArg_ParseTupleAndKeywords(
                args, kwds, "OOOO&O&:draw_view3d", (char **)(kwlist),
                &py_scene, &py_view3d, &py_region,
                pygpu_offscreen_check_matrix, &py_mat_projection,
                pygpu_offscreen_check_matrix, &py_mat_modelview) ||
            (!(scene    = PyC_RNA_AsPointer(py_scene, "Scene")) ||
             !(v3d      = PyC_RNA_AsPointer(py_view3d, "SpaceView3D")) ||
             !(ar       = PyC_RNA_AsPointer(py_region, "Region"))))
    {
        return NULL;
    }

    fx = GPU_fx_compositor_create();

    fx_settings = v3d->fx_settings;  /* full copy */

    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(
        scene, v3d, ar, GPU_offscreen_width(self->ofs), GPU_offscreen_height(self->ofs),
        (float(*)[4])py_mat_modelview->matrix, (float(*)[4])py_mat_projection->matrix,
        false, true, true, "",
        fx, &fx_settings,
        self->ofs);

    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;
}
Beispiel #3
0
static PyObject *bpygpu_offscreen_draw_view3d(BPyGPUOffScreen *self,
                                              PyObject *args,
                                              PyObject *kwds)
{
  MatrixObject *py_mat_view, *py_mat_projection;
  PyObject *py_scene, *py_view_layer, *py_region, *py_view3d;

  struct Depsgraph *depsgraph;
  struct Scene *scene;
  struct ViewLayer *view_layer;
  View3D *v3d;
  ARegion *ar;
  struct RV3DMatrixStore *rv3d_mats;

  BPY_GPU_OFFSCREEN_CHECK_OBJ(self);

  static const char *_keywords[] = {
      "scene", "view_layer", "view3d", "region", "view_matrix", "projection_matrix", NULL};

  static _PyArg_Parser _parser = {"OOOOO&O&:draw_view3d", _keywords, 0};
  if (!_PyArg_ParseTupleAndKeywordsFast(args,
                                        kwds,
                                        &_parser,
                                        &py_scene,
                                        &py_view_layer,
                                        &py_view3d,
                                        &py_region,
                                        Matrix_Parse4x4,
                                        &py_mat_view,
                                        Matrix_Parse4x4,
                                        &py_mat_projection) ||
      (!(scene = PyC_RNA_AsPointer(py_scene, "Scene")) ||
       !(view_layer = PyC_RNA_AsPointer(py_view_layer, "ViewLayer")) ||
       !(v3d = PyC_RNA_AsPointer(py_view3d, "SpaceView3D")) ||
       !(ar = PyC_RNA_AsPointer(py_region, "Region")))) {
    return NULL;
  }

  BLI_assert(BKE_id_is_in_global_main(&scene->id));

  depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);

  rv3d_mats = ED_view3d_mats_rv3d_backup(ar->regiondata);

  GPU_offscreen_bind(self->ofs, true);

  ED_view3d_draw_offscreen(depsgraph,
                           scene,
                           v3d->shading.type,
                           v3d,
                           ar,
                           GPU_offscreen_width(self->ofs),
                           GPU_offscreen_height(self->ofs),
                           (float(*)[4])py_mat_view->matrix,
                           (float(*)[4])py_mat_projection->matrix,
                           false,
                           true,
                           "",
                           true,
                           self->ofs,
                           NULL);

  GPU_offscreen_unbind(self->ofs, true);

  ED_view3d_mats_rv3d_restore(ar->regiondata, rv3d_mats);
  MEM_freeN(rv3d_mats);

  Py_RETURN_NONE;
}
Beispiel #4
0
static PyObject *bpygpu_offscreen_width_get(BPyGPUOffScreen *self, void *UNUSED(type))
{
  BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
  return PyLong_FromLong(GPU_offscreen_width(self->ofs));
}