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
This commit is contained in:
Germano Cavalcante 2021-12-29 11:45:27 -03:00 committed by Germano Cavalcante
parent bdcc258305
commit b7f6377e38
1 changed files with 23 additions and 6 deletions

View File

@ -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),