[Bf-blender-cvs] [b7f6377e38b] master: gpu.types.GPUOffScreen: accept format argument for color texture
Germano Cavalcante
noreply at git.blender.org
Wed Dec 29 15:47:45 CET 2021
Commit: b7f6377e38ba7fae4f38ffcff9b8fd9e2aa57882
Author: Germano Cavalcante
Date: Wed Dec 29 11:45:27 2021 -0300
Branches: master
https://developer.blender.org/rBb7f6377e38ba7fae4f38ffcff9b8fd9e2aa57882
gpu.types.GPUOffScreen: accept format argument for color texture
Some projects need more than 8-bit RGBA off-screen, so add the ability to
accept color format and defaults to RGBA8 so existing code should not be
affected.
Currently supported formats:
- RGBA8 (default)
- RGBA16
- RGBA16F
- RGBA32F
Reviewed By: mano-wii
Differential Revision: https://developer.blender.org/D13650
===================================================================
M source/blender/python/gpu/gpu_py_offscreen.c
===================================================================
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),
More information about the Bf-blender-cvs
mailing list