diff options
-rw-r--r-- | source/blender/python/gpu/gpu_py_offscreen.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c index 48fbe09f0ce..19013dc9ca3 100644 --- a/source/blender/python/gpu/gpu_py_offscreen.c +++ b/source/blender/python/gpu/gpu_py_offscreen.c @@ -65,6 +65,14 @@ /** \name GPUOffScreen Common Utilities * \{ */ +static const struct PyC_StringEnumItems pygpu_framebuffer_color_texture_formats[] = { + {GPU_RGBA8, "RGBA8"}, + {GPU_RGBA16, "RGBA16"}, + {GPU_RGBA16F, "RGBA16F"}, + {GPU_RGBA32F, "RGBA32F"}, + {0, NULL}, +}; + static int pygpu_offscreen_valid_check(BPyGPUOffScreen *py_ofs) { if (UNLIKELY(py_ofs->ofs == NULL)) { @@ -219,16 +227,18 @@ static PyObject *pygpu_offscreen__tp_new(PyTypeObject *UNUSED(self), GPUOffScreen *ofs = NULL; int width, height; + struct PyC_StringEnum pygpu_textureformat = {pygpu_framebuffer_color_texture_formats, GPU_RGBA8}; char err_out[256]; - static const char *_keywords[] = {"width", "height", NULL}; - static _PyArg_Parser _parser = {"ii:GPUOffScreen.__new__", _keywords, 0}; - if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &width, &height)) { + static const char *_keywords[] = {"width", "height", "format", NULL}; + static _PyArg_Parser _parser = {"ii|$O&:GPUOffScreen.__new__", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, &width, &height, PyC_ParseStringEnum, &pygpu_textureformat)) { return NULL; } if (GPU_context_active_get()) { - ofs = GPU_offscreen_create(width, height, true, GPU_RGBA8, err_out); + ofs = GPU_offscreen_create(width, height, true, pygpu_textureformat.value_found, err_out); } else { STRNCPY(err_out, "No active GPU context found"); @@ -456,14 +466,21 @@ static struct PyMethodDef pygpu_offscreen__tp_methods[] = { }; PyDoc_STRVAR(pygpu_offscreen__tp_doc, - ".. class:: GPUOffScreen(width, height)\n" + ".. class:: GPUOffScreen(width, height, *, format='RGBA8')\n" "\n" " This object gives access to off screen buffers.\n" "\n" " :arg width: Horizontal dimension of the buffer.\n" " :type width: int\n" " :arg height: Vertical dimension of the buffer.\n" - " :type height: int\n"); + " :type height: int\n" + " :arg format: Internal data format inside GPU memory for color attachment " + "texture. Possible values are:\n" + " `RGBA8`,\n" + " `RGBA16`,\n" + " `RGBA16F`,\n" + " `RGBA32F`,\n" + " :type format: str\n"); PyTypeObject BPyGPUOffScreen_Type = { PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUOffScreen", .tp_basicsize = sizeof(BPyGPUOffScreen), |