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; }
static PyObject *GPU_export_shader(PyObject *UNUSED(self), PyObject *args, PyObject *kwds) { PyObject *pyscene; PyObject *pymat; PyObject *result; PyObject *dict; PyObject *val; PyObject *seq; int i; Scene *scene; PointerRNA tptr; Material *material; GPUShaderExport *shader; GPUInputUniform *uniform; GPUInputAttribute *attribute; static const char *kwlist[] = {"scene", "material", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:export_shader", (char **)(kwlist), &pyscene, &pymat)) return NULL; scene = (Scene *)PyC_RNA_AsPointer(pyscene, "Scene"); if (scene == NULL) { return NULL; } material = (Material *)PyC_RNA_AsPointer(pymat, "Material"); if (material == NULL) { return NULL; } /* we can call our internal function at last: */ shader = GPU_shader_export(scene, material); if (!shader) { PyErr_SetString(PyExc_RuntimeError, "cannot export shader"); return NULL; } /* build a dictionary */ result = PyDict_New(); if (shader->fragment) { PY_DICT_ADD_STRING(result, shader, fragment); } if (shader->vertex) { PY_DICT_ADD_STRING(result, shader, vertex); } seq = PyList_New(BLI_countlist(&shader->uniforms)); for (i = 0, uniform = shader->uniforms.first; uniform; uniform = uniform->next, i++) { dict = PyDict_New(); PY_DICT_ADD_STRING(dict, uniform, varname); PY_DICT_ADD_LONG(dict, uniform, datatype); PY_DICT_ADD_LONG(dict, uniform, type); if (uniform->lamp) { PY_DICT_ADD_ID(dict, uniform, lamp); } if (uniform->image) { PY_DICT_ADD_ID(dict, uniform, image); } if (uniform->type == GPU_DYNAMIC_SAMPLER_2DBUFFER || uniform->type == GPU_DYNAMIC_SAMPLER_2DIMAGE || uniform->type == GPU_DYNAMIC_SAMPLER_2DSHADOW) { PY_DICT_ADD_LONG(dict, uniform, texnumber); } if (uniform->texpixels) { val = PyByteArray_FromStringAndSize((const char *)uniform->texpixels, uniform->texsize * 4); PyDict_SetItemString(dict, "texpixels", val); Py_DECREF(val); PY_DICT_ADD_LONG(dict, uniform, texsize); } PyList_SET_ITEM(seq, i, dict); } PyDict_SetItemString(result, "uniforms", seq); Py_DECREF(seq); seq = PyList_New(BLI_countlist(&shader->attributes)); for (i = 0, attribute = shader->attributes.first; attribute; attribute = attribute->next, i++) { dict = PyDict_New(); PY_DICT_ADD_STRING(dict, attribute, varname); PY_DICT_ADD_LONG(dict, attribute, datatype); PY_DICT_ADD_LONG(dict, attribute, type); PY_DICT_ADD_LONG(dict, attribute, number); if (attribute->name) { if (attribute->name[0] != 0) { PY_DICT_ADD_STRING(dict, attribute, name); } else { val = PyLong_FromLong(0); PyDict_SetItemString(dict, "name", val); Py_DECREF(val); } } PyList_SET_ITEM(seq, i, dict); } PyDict_SetItemString(result, "attributes", seq); Py_DECREF(seq); GPU_free_shader_export(shader); return result; }
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; }