Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <mano-wii>2021-12-29 17:45:27 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2021-12-29 17:46:53 +0300
commitb7f6377e38ba7fae4f38ffcff9b8fd9e2aa57882 (patch)
treee31e752cfbaa9bb614eb86731881d36eedb797cc
parentbdcc25830506aa8359351424707cc6d735df7f34 (diff)
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
-rw-r--r--source/blender/python/gpu/gpu_py_offscreen.c29
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),