Refactor: Remove unnecessary C wrappers for vertex and index buffers

Now that all relevant code is C++, the indirection from the C struct
`GPUVertBuf` to the C++ `blender::gpu::VertBuf` class just adds
complexity and necessitates a wrapper API, making more cleanups like
use of RAII or other C++ types more difficult.

This commit replaces the C wrapper structs with direct use of the
vertex and index buffer base classes. In C++ we can choose which parts
of a class are private, so we don't risk exposing too many
implementation details here.

Pull Request: https://projects.blender.org/blender/blender/pulls/119825
This commit is contained in:
Hans Goudey
2024-03-24 16:38:30 +01:00
committed by Hans Goudey
parent 84c6ead74b
commit fe76d8c946
151 changed files with 1228 additions and 1226 deletions

View File

@@ -246,7 +246,7 @@ PyTypeObject BPyGPUIndexBuf_Type = {
/** \name Public API
* \{ */
PyObject *BPyGPUIndexBuf_CreatePyObject(GPUIndexBuf *elem)
PyObject *BPyGPUIndexBuf_CreatePyObject(blender::gpu::IndexBuf *elem)
{
BPyGPUIndexBuf *self;

View File

@@ -8,7 +8,9 @@
#pragma once
struct GPUIndexBuf;
namespace blender::gpu {
class IndexBuf;
}
extern PyTypeObject BPyGPUIndexBuf_Type;
@@ -16,7 +18,7 @@ extern PyTypeObject BPyGPUIndexBuf_Type;
struct BPyGPUIndexBuf {
PyObject_VAR_HEAD
GPUIndexBuf *elem;
blender::gpu::IndexBuf *elem;
};
PyObject *BPyGPUIndexBuf_CreatePyObject(GPUIndexBuf *elem);
PyObject *BPyGPUIndexBuf_CreatePyObject(blender::gpu::IndexBuf *elem);

View File

@@ -104,7 +104,7 @@ static void pygpu_fill_format_sequence(void *data_dst_void,
#undef WARN_TYPE_LIMIT_PUSH
#undef WARN_TYPE_LIMIT_POP
static bool pygpu_vertbuf_fill_impl(GPUVertBuf *vbo,
static bool pygpu_vertbuf_fill_impl(blender::gpu::VertBuf *vbo,
uint data_id,
PyObject *seq,
const char *error_prefix)
@@ -201,7 +201,7 @@ static bool pygpu_vertbuf_fill_impl(GPUVertBuf *vbo,
return ok;
}
static int pygpu_vertbuf_fill(GPUVertBuf *buf,
static int pygpu_vertbuf_fill(blender::gpu::VertBuf *buf,
int id,
PyObject *py_seq_data,
const char *error_prefix)
@@ -241,7 +241,7 @@ static PyObject *pygpu_vertbuf__tp_new(PyTypeObject * /*type*/, PyObject *args,
PY_ARG_PARSER_HEAD_COMPAT()
"O!" /* `format` */
"I" /* `len` */
":GPUVertBuf.__new__",
":blender::gpu::VertBuf.__new__",
_keywords,
nullptr,
};
@@ -252,7 +252,7 @@ static PyObject *pygpu_vertbuf__tp_new(PyTypeObject * /*type*/, PyObject *args,
}
const GPUVertFormat *fmt = &((BPyGPUVertFormat *)params.py_fmt)->fmt;
GPUVertBuf *vbo = GPU_vertbuf_create_with_format(fmt);
blender::gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(fmt);
GPU_vertbuf_data_alloc(vbo, params.len);
@@ -307,7 +307,7 @@ static PyObject *pygpu_vertbuf_attr_fill(BPyGPUVertBuf *self, PyObject *args, Py
return nullptr;
}
if (!pygpu_vertbuf_fill(self->buf, id, data, "GPUVertBuf.attr_fill")) {
if (!pygpu_vertbuf_fill(self->buf, id, data, "blender::gpu::VertBuf.attr_fill")) {
return nullptr;
}
@@ -340,7 +340,7 @@ static void pygpu_vertbuf__tp_dealloc(BPyGPUVertBuf *self)
PyDoc_STRVAR(
/* Wrap. */
pygpu_vertbuf__tp_doc,
".. class:: GPUVertBuf(format, len)\n"
".. class:: blender::gpu::VertBuf(format, len)\n"
"\n"
" Contains a VBO.\n"
"\n"
@@ -350,7 +350,7 @@ PyDoc_STRVAR(
" :type len: int\n");
PyTypeObject BPyGPUVertBuf_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUVertBuf",
/*tp_name*/ "blender::gpu::VertBuf",
/*tp_basicsize*/ sizeof(BPyGPUVertBuf),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)pygpu_vertbuf__tp_dealloc,
@@ -406,7 +406,7 @@ PyTypeObject BPyGPUVertBuf_Type = {
/** \name Public API
* \{ */
PyObject *BPyGPUVertBuf_CreatePyObject(GPUVertBuf *buf)
PyObject *BPyGPUVertBuf_CreatePyObject(blender::gpu::VertBuf *buf)
{
BPyGPUVertBuf *self;

View File

@@ -10,7 +10,9 @@
#include "BLI_compiler_attrs.h"
struct GPUVertBuf;
namespace blender::gpu {
class VertBuf;
}
extern PyTypeObject BPyGPUVertBuf_Type;
@@ -19,7 +21,7 @@ extern PyTypeObject BPyGPUVertBuf_Type;
struct BPyGPUVertBuf {
PyObject_VAR_HEAD
/* The buf is owned, we may support thin wrapped batches later. */
GPUVertBuf *buf;
blender::gpu::VertBuf *buf;
};
PyObject *BPyGPUVertBuf_CreatePyObject(GPUVertBuf *buf) ATTR_NONNULL(1);
PyObject *BPyGPUVertBuf_CreatePyObject(blender::gpu::VertBuf *buf) ATTR_NONNULL(1);