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:
@@ -797,8 +797,8 @@ static PyMethodDef pygpu_framebuffer__tp_methods[] = {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Ideally type aliases would de-duplicate: `GPUTexture | dict[str, int | GPUTexture]`
|
||||
* in this doc-string. */
|
||||
/* Ideally type aliases would de-duplicate: `blender::gpu::Texture | dict[str, int |
|
||||
* blender::gpu::Texture]` in this doc-string. */
|
||||
PyDoc_STRVAR(
|
||||
/* Wrap. */
|
||||
pygpu_framebuffer__tp_doc,
|
||||
@@ -809,14 +809,15 @@ PyDoc_STRVAR(
|
||||
"texture is attached to the frame-buffer.\n"
|
||||
" For cube map textures, layer is translated into a cube map face.\n"
|
||||
"\n"
|
||||
" :arg depth_slot: GPUTexture to attach or a `dict` containing keywords: "
|
||||
" :arg depth_slot: blender::gpu::Texture to attach or a `dict` containing keywords: "
|
||||
"'texture', 'layer' and 'mip'.\n"
|
||||
" :type depth_slot: :class:`gpu.types.GPUTexture` | dict[] | None\n"
|
||||
" :arg color_slots: Tuple where each item can be a GPUTexture or a `dict` "
|
||||
" :type depth_slot: :class:`gpu.types.blender::gpu::Texture` | dict[] | None\n"
|
||||
" :arg color_slots: Tuple where each item can be a blender::gpu::Texture or a `dict` "
|
||||
"containing keywords: 'texture', 'layer' and 'mip'.\n"
|
||||
" :type color_slots: :class:`gpu.types.GPUTexture` | "
|
||||
"dict[str, int | :class:`gpu.types.GPUTexture`] | "
|
||||
"Sequence[:class:`gpu.types.GPUTexture` | dict[str, int | :class:`gpu.types.GPUTexture`]] | "
|
||||
" :type color_slots: :class:`gpu.types.blender::gpu::Texture` | "
|
||||
"dict[str, int | :class:`gpu.types.blender::gpu::Texture`] | "
|
||||
"Sequence[:class:`gpu.types.blender::gpu::Texture` | dict[str, int | "
|
||||
":class:`gpu.types.blender::gpu::Texture`]] | "
|
||||
"None\n");
|
||||
PyTypeObject BPyGPUFrameBuffer_Type = {
|
||||
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
|
||||
|
||||
@@ -356,11 +356,11 @@ PyDoc_STRVAR(
|
||||
pygpu_offscreen_texture_color_doc,
|
||||
"The color texture attached.\n"
|
||||
"\n"
|
||||
":type: :class:`gpu.types.GPUTexture`");
|
||||
":type: :class:`gpu.types.blender::gpu::Texture`");
|
||||
static PyObject *pygpu_offscreen_texture_color_get(BPyGPUOffScreen *self, void * /*type*/)
|
||||
{
|
||||
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
|
||||
GPUTexture *texture = GPU_offscreen_color_texture(self->ofs);
|
||||
blender::gpu::Texture *texture = GPU_offscreen_color_texture(self->ofs);
|
||||
return BPyGPUTexture_CreatePyObject(texture, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -505,7 +505,7 @@ PyDoc_STRVAR(
|
||||
" :arg name: name of the uniform variable whose texture is to be specified.\n"
|
||||
" :type name: str\n"
|
||||
" :arg texture: Texture to attach.\n"
|
||||
" :type texture: :class:`gpu.types.GPUTexture`\n");
|
||||
" :type texture: :class:`gpu.types.blender::gpu::Texture`\n");
|
||||
static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args)
|
||||
{
|
||||
const char *name;
|
||||
@@ -534,7 +534,7 @@ PyDoc_STRVAR(
|
||||
" :arg name: Name of the image variable to which the texture is to be bound.\n"
|
||||
" :type name: str\n"
|
||||
" :arg texture: Texture to attach.\n"
|
||||
" :type texture: :class:`gpu.types.GPUTexture`\n");
|
||||
" :type texture: :class:`gpu.types.blender::gpu::Texture`\n");
|
||||
static PyObject *pygpu_shader_image(BPyGPUShader *self, PyObject *args)
|
||||
{
|
||||
const char *name;
|
||||
|
||||
@@ -730,7 +730,8 @@ PyDoc_STRVAR(
|
||||
"\n"
|
||||
" :arg slot: The image resource index.\n"
|
||||
" :type slot: int\n"
|
||||
" :arg format: The GPUTexture format that is passed to the shader. Possible values are:\n"
|
||||
" :arg format: The blender::gpu::Texture format that is passed to the shader. Possible "
|
||||
"values are:\n"
|
||||
"\n" PYDOC_TEX_FORMAT_ITEMS
|
||||
" :type format: str\n"
|
||||
" :arg type: The data type describing how the image is to be read in the shader. "
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
|
||||
#include "BLI_compiler_attrs.h"
|
||||
|
||||
struct GPUTexture;
|
||||
namespace blender::gpu {
|
||||
class Texture;
|
||||
}
|
||||
|
||||
extern PyTypeObject BPyGPUTexture_Type;
|
||||
|
||||
@@ -28,11 +30,11 @@ extern const struct PyC_StringEnumItems pygpu_textureformat_items[];
|
||||
|
||||
struct BPyGPUTexture {
|
||||
PyObject_HEAD
|
||||
GPUTexture *tex;
|
||||
blender::gpu::Texture *tex;
|
||||
};
|
||||
|
||||
[[nodiscard]] int bpygpu_ParseTexture(PyObject *o, void *p);
|
||||
[[nodiscard]] PyObject *bpygpu_texture_init();
|
||||
|
||||
[[nodiscard]] PyObject *BPyGPUTexture_CreatePyObject(GPUTexture *tex, bool shared_reference)
|
||||
ATTR_NONNULL(1);
|
||||
[[nodiscard]] PyObject *BPyGPUTexture_CreatePyObject(blender::gpu::Texture *tex,
|
||||
bool shared_reference) ATTR_NONNULL(1);
|
||||
|
||||
Reference in New Issue
Block a user