Refactor: GPU: Remove unnecessary C wrappers for textures

This is the first step into merging `DRW_gpu_wrapper.hh` into
the GPU module.

This is very similar to #119825.

Pull Request: https://projects.blender.org/blender/blender/pulls/142732
This commit is contained in:
Clément Foucault
2025-07-22 09:48:10 +02:00
parent 748958f084
commit f0254c2dcf
145 changed files with 1114 additions and 1009 deletions

View File

@@ -32,7 +32,7 @@
#include "gpu_py_texture.hh" /* own include */
/* -------------------------------------------------------------------- */
/** \name GPUTexture Common Utilities
/** \name blender::gpu::Texture Common Utilities
* \{ */
const PyC_StringEnumItems pygpu_textureformat_items[] = {
@@ -110,7 +110,7 @@ static int pygpu_texture_valid_check(BPyGPUTexture *bpygpu_tex)
/** \} */
/* -------------------------------------------------------------------- */
/** \name GPUTexture Type
/** \name blender::gpu::Texture Type
* \{ */
static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args, PyObject *kwds)
@@ -134,7 +134,7 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
"p" /* `is_cubemap` */
"O&" /* `format` */
"O!" /* `data` */
":GPUTexture.__new__",
":blender::gpu::Texture.__new__",
_keywords,
nullptr,
};
@@ -168,12 +168,16 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
if (PySequence_Check(py_size)) {
len = PySequence_Size(py_size);
if ((len < 1) || (len > 3)) {
PyErr_Format(PyExc_ValueError,
"GPUTexture.__new__: \"size\" must be between 1 and 3 in length (got %d)",
len);
PyErr_Format(
PyExc_ValueError,
"blender::gpu::Texture.__new__: \"size\" must be between 1 and 3 in length (got %d)",
len);
return nullptr;
}
if (PyC_AsArray(size, sizeof(*size), py_size, len, &PyLong_Type, "GPUTexture.__new__") == -1) {
if (PyC_AsArray(
size, sizeof(*size), py_size, len, &PyLong_Type, "blender::gpu::Texture.__new__") ==
-1)
{
return nullptr;
}
}
@@ -181,15 +185,17 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
size[0] = PyLong_AsLong(py_size);
}
else {
PyErr_SetString(PyExc_ValueError, "GPUTexture.__new__: Expected an int or tuple as first arg");
PyErr_SetString(PyExc_ValueError,
"blender::gpu::Texture.__new__: Expected an int or tuple as first arg");
return nullptr;
}
void *data = nullptr;
if (pybuffer_obj) {
if (pybuffer_obj->format != GPU_DATA_FLOAT) {
PyErr_SetString(PyExc_ValueError,
"GPUTexture.__new__: Only Buffer of format `FLOAT` is currently supported");
PyErr_SetString(
PyExc_ValueError,
"blender::gpu::Texture.__new__: Only Buffer of format `FLOAT` is currently supported");
return nullptr;
}
@@ -203,13 +209,14 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
}
if (bpygpu_Buffer_size(pybuffer_obj) < data_space_expected) {
PyErr_SetString(PyExc_ValueError, "GPUTexture.__new__: Buffer size smaller than requested");
PyErr_SetString(PyExc_ValueError,
"blender::gpu::Texture.__new__: Buffer size smaller than requested");
return nullptr;
}
data = pybuffer_obj->buf.as_void;
}
GPUTexture *tex = nullptr;
blender::gpu::Texture *tex = nullptr;
if (is_cubemap && len != 1) {
STRNCPY(err_out,
"In cubemaps the same dimension represents height, width and depth. No tuple needed");
@@ -558,7 +565,8 @@ static PyMethodDef pygpu_texture__tp_methods[] = {
PyDoc_STRVAR(
/* Wrap. */
pygpu_texture__tp_doc,
".. class:: GPUTexture(size, layers=0, is_cubemap=False, format='RGBA8', data=None)\n"
".. class:: blender::gpu::Texture(size, layers=0, is_cubemap=False, format='RGBA8', "
"data=None)\n"
"\n"
" This object gives access to off GPU textures.\n"
"\n"
@@ -618,7 +626,7 @@ PyDoc_STRVAR(
" :type data: :class:`gpu.types.Buffer`\n");
PyTypeObject BPyGPUTexture_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUTexture",
/*tp_name*/ "blender::gpu::Texture",
/*tp_basicsize*/ sizeof(BPyGPUTexture),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)BPyGPUTexture__tp_dealloc,
@@ -679,15 +687,16 @@ PyDoc_STRVAR(
pygpu_texture_from_image_doc,
".. function:: from_image(image)\n"
"\n"
" Get GPUTexture corresponding to an Image datablock. The GPUTexture memory is "
" Get blender::gpu::Texture corresponding to an Image datablock. The blender::gpu::Texture "
"memory is "
"shared with Blender.\n"
" Note: Colors read from the texture will be in scene linear color space and have "
"premultiplied or straight alpha matching the image alpha mode.\n"
"\n"
" :arg image: The Image datablock.\n"
" :type image: :class:`bpy.types.Image`\n"
" :return: The GPUTexture used by the image.\n"
" :rtype: :class:`gpu.types.GPUTexture`\n");
" :return: The blender::gpu::Texture used by the image.\n"
" :rtype: :class:`gpu.types.blender::gpu::Texture`\n");
static PyObject *pygpu_texture_from_image(PyObject * /*self*/, PyObject *arg)
{
Image *ima = static_cast<Image *>(PyC_RNA_AsPointer(arg, "Image"));
@@ -697,7 +706,7 @@ static PyObject *pygpu_texture_from_image(PyObject * /*self*/, PyObject *arg)
ImageUser iuser;
BKE_imageuser_default(&iuser);
GPUTexture *tex = BKE_image_get_gpu_texture(ima, &iuser);
blender::gpu::Texture *tex = BKE_image_get_gpu_texture(ima, &iuser);
return BPyGPUTexture_CreatePyObject(tex, true);
}
@@ -732,7 +741,7 @@ static PyModuleDef pygpu_texture_module_def = {
int bpygpu_ParseTexture(PyObject *o, void *p)
{
if (o == Py_None) {
*(GPUTexture **)p = nullptr;
*(blender::gpu::Texture **)p = nullptr;
return 1;
}
@@ -746,7 +755,7 @@ int bpygpu_ParseTexture(PyObject *o, void *p)
return 0;
}
*(GPUTexture **)p = ((BPyGPUTexture *)o)->tex;
*(blender::gpu::Texture **)p = ((BPyGPUTexture *)o)->tex;
return 1;
}
@@ -764,7 +773,7 @@ PyObject *bpygpu_texture_init()
/** \name Public API
* \{ */
PyObject *BPyGPUTexture_CreatePyObject(GPUTexture *tex, bool shared_reference)
PyObject *BPyGPUTexture_CreatePyObject(blender::gpu::Texture *tex, bool shared_reference)
{
BPyGPUTexture *self;