Blender  V3.3
gpu_py_texture.c File Reference
#include <Python.h>
#include "BLI_string.h"
#include "DNA_image_types.h"
#include "GPU_context.h"
#include "GPU_texture.h"
#include "BKE_image.h"
#include "../generic/py_capi_utils.h"
#include "gpu_py.h"
#include "gpu_py_buffer.h"
#include "gpu_py_texture.h"

Go to the source code of this file.

Functions

Local API
int bpygpu_ParseTexture (PyObject *o, void *p)
 
PyObject * bpygpu_texture_init (void)
 
Public API
PyObject * BPyGPUTexture_CreatePyObject (GPUTexture *tex, bool shared_reference)
 

GPUTexture Common Utilities

#define BPYGPU_TEXTURE_CHECK_OBJ(bpygpu)
 
static const struct PyC_StringEnumItems pygpu_textureformat_items []
 
static int pygpu_texture_valid_check (BPyGPUTexture *bpygpu_tex)
 

GPUTexture Type

static PyGetSetDef pygpu_texture__tp_getseters []
 
static struct PyMethodDef pygpu_texture__tp_methods []
 
PyTypeObject BPyGPUTexture_Type
 
static PyObject * pygpu_texture__tp_new (PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds)
 
 PyDoc_STRVAR (pygpu_texture_width_doc, "Width of the texture.\n\n:type: `int`")
 
static PyObject * pygpu_texture_width_get (BPyGPUTexture *self, void *UNUSED(type))
 
 PyDoc_STRVAR (pygpu_texture_height_doc, "Height of the texture.\n\n:type: `int`")
 
static PyObject * pygpu_texture_height_get (BPyGPUTexture *self, void *UNUSED(type))
 
 PyDoc_STRVAR (pygpu_texture_format_doc, "Format of the texture.\n\n:type: `str`")
 
static PyObject * pygpu_texture_format_get (BPyGPUTexture *self, void *UNUSED(type))
 
 PyDoc_STRVAR (pygpu_texture_clear_doc, ".. method:: clear(format='FLOAT', value=(0.0, 0.0, 0.0, 1.0))\n" "\n" " Fill texture with specific value.\n" "\n" " :param format: The format that describes the content of a single item.\n" " Possible values are `FLOAT`, `INT`, `UINT`, `UBYTE`, `UINT_24_8` and `10_11_11_REV`.\n" " :type type: str\n" " :arg value: sequence each representing the value to fill.\n" " :type value: sequence of 1, 2, 3 or 4 values\n")
 
static PyObject * pygpu_texture_clear (BPyGPUTexture *self, PyObject *args, PyObject *kwds)
 
 PyDoc_STRVAR (pygpu_texture_read_doc, ".. method:: read()\n" "\n" " Creates a buffer with the value of all pixels.\n" "\n")
 
static PyObject * pygpu_texture_read (BPyGPUTexture *self)
 
static void BPyGPUTexture__tp_dealloc (BPyGPUTexture *self)
 
 PyDoc_STRVAR (pygpu_texture__tp_doc, ".. class:: GPUTexture(size, layers=0, is_cubemap=False, format='RGBA8', data=None)\n" "\n" " This object gives access to off GPU textures.\n" "\n" " :arg size: Dimensions of the texture 1D, 2D, 3D or cubemap.\n" " :type size: tuple or int\n" " :arg layers: Number of layers in texture array or number of cubemaps in cubemap array\n" " :type layers: int\n" " :arg is_cubemap: Indicates the creation of a cubemap texture.\n" " :type is_cubemap: int\n" " :arg format: Internal data format inside GPU memory. Possible values are:\n" " `RGBA8UI`,\n" " `RGBA8I`,\n" " `RGBA8`,\n" " `RGBA32UI`,\n" " `RGBA32I`,\n" " `RGBA32F`,\n" " `RGBA16UI`,\n" " `RGBA16I`,\n" " `RGBA16F`,\n" " `RGBA16`,\n" " `RG8UI`,\n" " `RG8I`,\n" " `RG8`,\n" " `RG32UI`,\n" " `RG32I`,\n" " `RG32F`,\n" " `RG16UI`,\n" " `RG16I`,\n" " `RG16F`,\n" " `RG16`,\n" " `R8UI`,\n" " `R8I`,\n" " `R8`,\n" " `R32UI`,\n" " `R32I`,\n" " `R32F`,\n" " `R16UI`,\n" " `R16I`,\n" " `R16F`,\n" " `R16`,\n" " `R11F_G11F_B10F`,\n" " `DEPTH32F_STENCIL8`,\n" " `DEPTH24_STENCIL8`,\n" " `SRGB8_A8`,\n" " `RGB16F`,\n" " `SRGB8_A8_DXT1`,\n" " `SRGB8_A8_DXT3`,\n" " `SRGB8_A8_DXT5`,\n" " `RGBA8_DXT1`,\n" " `RGBA8_DXT3`,\n" " `RGBA8_DXT5`,\n" " `DEPTH_COMPONENT32F`,\n" " `DEPTH_COMPONENT24`,\n" " `DEPTH_COMPONENT16`,\n" " :type format: str\n" " :arg data: Buffer object to fill the texture.\n" " :type data: :class:`gpu.types.Buffer`\n")
 

GPU Texture module

static struct PyMethodDef pygpu_texture__m_methods []
 
static PyModuleDef pygpu_texture_module_def
 
 PyDoc_STRVAR (pygpu_texture_from_image_doc, ".. function:: from_image(image)\n" "\n" " Get GPUTexture corresponding to an Image datablock. The GPUTexture 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")
 
static PyObject * pygpu_texture_from_image (PyObject *UNUSED(self), PyObject *arg)
 
 PyDoc_STRVAR (pygpu_texture__m_doc, "This module provides utils for textures.")
 

Detailed Description

This file defines the texture functionalities of the 'gpu' module

Definition in file gpu_py_texture.c.

Macro Definition Documentation

◆ BPYGPU_TEXTURE_CHECK_OBJ

#define BPYGPU_TEXTURE_CHECK_OBJ (   bpygpu)
Value:
{ \
if (UNLIKELY(pygpu_texture_valid_check(bpygpu) == -1)) { \
return NULL; \
} \
} \
((void)0)
#define UNLIKELY(x)
SyclQueue void void size_t num_bytes void
static int pygpu_texture_valid_check(BPyGPUTexture *bpygpu_tex)

Definition at line 98 of file gpu_py_texture.c.

Function Documentation

◆ bpygpu_ParseTexture()

int bpygpu_ParseTexture ( PyObject *  o,
void p 
)

◆ bpygpu_texture_init()

PyObject* bpygpu_texture_init ( void  )

Definition at line 600 of file gpu_py_texture.c.

References pygpu_texture_module_def.

Referenced by BPyInit_gpu().

◆ BPyGPUTexture__tp_dealloc()

static void BPyGPUTexture__tp_dealloc ( BPyGPUTexture self)
static

Definition at line 427 of file gpu_py_texture.c.

References GPU_texture_free(), GPU_texture_py_reference_set(), NULL, and self.

◆ BPyGPUTexture_CreatePyObject()

PyObject* BPyGPUTexture_CreatePyObject ( GPUTexture tex,
bool  shared_reference 
)

◆ PyDoc_STRVAR() [1/8]

PyDoc_STRVAR ( pygpu_texture__m_doc  ,
"This module provides utils for textures."   
)

◆ PyDoc_STRVAR() [2/8]

PyDoc_STRVAR ( pygpu_texture__tp_doc  ,
".. class:: GPUTexture(size, layers=0, is_cubemap=False, format='RGBA8', data=None)\n" "\n" " This object gives access to off GPU textures.\n" "\n" " :arg size: Dimensions of the texture  1D,
2D  ,
3D or cubemap.\n" " :type size:tuple or int\n" " :arg layers:Number of layers in texture array or number of cubemaps in cubemap array\n" " :type layers:int\n" " :arg is_cubemap:Indicates the creation of a cubemap texture.\n" " :type is_cubemap:int\n" " :arg format:Internal data format inside GPU memory. Possible values are:\n" " `RGBA8UI`  ,
\n" " `RGBA8I`  ,
\n" " `RGBA8`  ,
\n" " `RGBA32UI`  ,
\n" " `RGBA32I`  ,
\n" " `RGBA32F`  ,
\n" " `RGBA16UI`  ,
\n" " `RGBA16I`  ,
\n" " `RGBA16F`  ,
\n" " `RGBA16`  ,
\n" " `RG8UI`  ,
\n" " `RG8I`  ,
\n" " `RG8`  ,
\n" " `RG32UI`  ,
\n" " `RG32I`  ,
\n" " `RG32F`  ,
\n" " `RG16UI`  ,
\n" " `RG16I`  ,
\n" " `RG16F`  ,
\n" " `RG16`  ,
\n" " `R8UI`  ,
\n" " `R8I`  ,
\n" " `R8`  ,
\n" " `R32UI`  ,
\n" " `R32I`  ,
\n" " `R32F`  ,
\n" " `R16UI`  ,
\n" " `R16I`  ,
\n" " `R16F`  ,
\n" " `R16`  ,
\n" " `R11F_G11F_B10F`  ,
\n" " `DEPTH32F_STENCIL8`  ,
\n" " `DEPTH24_STENCIL8`  ,
\n" " `SRGB8_A8`  ,
\n" " `RGB16F`  ,
\n" " `SRGB8_A8_DXT1`  ,
\n" " `SRGB8_A8_DXT3`  ,
\n" " `SRGB8_A8_DXT5`  ,
\n" " `RGBA8_DXT1`  ,
\n" " `RGBA8_DXT3`  ,
\n" " `RGBA8_DXT5`  ,
\n" " `DEPTH_COMPONENT32F`  ,
\n" " `DEPTH_COMPONENT24`  ,
\n" " `DEPTH_COMPONENT16`  ,
\n" " :type format:str\n" " :arg data:Buffer object to fill the texture.\n" " :type data::class:`gpu.types.Buffer`\n"   
)

◆ PyDoc_STRVAR() [3/8]

PyDoc_STRVAR ( pygpu_texture_clear_doc  ,
".. method:: clear(format='FLOAT', value=(0.0, 0.0, 0.0, 1.0))\n" "\n" " Fill texture with specific value.\n" "\n" " :param format: The format that describes the content of a single item.\n" " Possible values are `FLOAT ,
`INT`  ,
`UINT ,
`UBYTE`  ,
`UINT_24_8` and `10_11_11_REV`.\n" " :type type:str\n" " :arg value:sequence each representing the value to fill.\n" " :type value:sequence of  1,
,
3 or 4 values\n"   
)

◆ PyDoc_STRVAR() [4/8]

PyDoc_STRVAR ( pygpu_texture_format_doc  ,
"Format of the texture.\n\n:type: `str`"   
)

◆ PyDoc_STRVAR() [5/8]

PyDoc_STRVAR ( pygpu_texture_from_image_doc  ,
".. function:: from_image(image)\n" "\n" " Get GPUTexture corresponding to an Image datablock. The GPUTexture 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"   
)

◆ PyDoc_STRVAR() [6/8]

PyDoc_STRVAR ( pygpu_texture_height_doc  ,
"Height of the texture.\n\n:type: `int`"   
)

◆ PyDoc_STRVAR() [7/8]

PyDoc_STRVAR ( pygpu_texture_read_doc  ,
".. method:: read()\n" "\n" " Creates a buffer with the value of all pixels.\n" "\n"   
)

◆ PyDoc_STRVAR() [8/8]

PyDoc_STRVAR ( pygpu_texture_width_doc  ,
"Width of the texture.\n\n:type: `int`"   
)

◆ pygpu_texture__tp_new()

static PyObject* pygpu_texture__tp_new ( PyTypeObject *  UNUSEDself,
PyObject *  args,
PyObject *  kwds 
)
static

◆ pygpu_texture_clear()

static PyObject* pygpu_texture_clear ( BPyGPUTexture self,
PyObject *  args,
PyObject *  kwds 
)
static

◆ pygpu_texture_format_get()

static PyObject* pygpu_texture_format_get ( BPyGPUTexture self,
void UNUSEDtype 
)
static

◆ pygpu_texture_from_image()

static PyObject* pygpu_texture_from_image ( PyObject *  UNUSEDself,
PyObject *  arg 
)
static

Definition at line 546 of file gpu_py_texture.c.

◆ pygpu_texture_height_get()

static PyObject* pygpu_texture_height_get ( BPyGPUTexture self,
void UNUSEDtype 
)
static

Definition at line 263 of file gpu_py_texture.c.

References BPYGPU_TEXTURE_CHECK_OBJ, GPU_texture_height(), and self.

◆ pygpu_texture_read()

static PyObject* pygpu_texture_read ( BPyGPUTexture self)
static

◆ pygpu_texture_valid_check()

static int pygpu_texture_valid_check ( BPyGPUTexture bpygpu_tex)
static

Definition at line 82 of file gpu_py_texture.c.

References BPYGPU_USE_GPUOBJ_FREE_METHOD, NULL, BPyGPUTexture::tex, and UNLIKELY.

Referenced by bpygpu_ParseTexture().

◆ pygpu_texture_width_get()

static PyObject* pygpu_texture_width_get ( BPyGPUTexture self,
void UNUSEDtype 
)
static

Definition at line 256 of file gpu_py_texture.c.

References BPYGPU_TEXTURE_CHECK_OBJ, GPU_texture_width(), and self.

Variable Documentation

◆ BPyGPUTexture_Type

PyTypeObject BPyGPUTexture_Type
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUTexture",
.tp_basicsize = sizeof(BPyGPUTexture),
.tp_dealloc = (destructor)BPyGPUTexture__tp_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = pygpu_texture__tp_doc,
}
static PyObject * pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds)
static struct PyMethodDef pygpu_texture__tp_methods[]
static void BPyGPUTexture__tp_dealloc(BPyGPUTexture *self)
static PyGetSetDef pygpu_texture__tp_getseters[]
struct BPyGPUTexture BPyGPUTexture

Definition at line 517 of file gpu_py_texture.c.

Referenced by bpygpu_types_init(), BPyGPUTexture_CreatePyObject(), and pygpu_shader_uniform_sampler().

◆ pygpu_texture__m_methods

struct PyMethodDef pygpu_texture__m_methods[]
static
Initial value:
= {
{"from_image", (PyCFunction)pygpu_texture_from_image, METH_O, pygpu_texture_from_image_doc},
{NULL, NULL, 0, NULL},
}
static PyObject * pygpu_texture_from_image(PyObject *UNUSED(self), PyObject *arg)

Definition at line 546 of file gpu_py_texture.c.

◆ pygpu_texture__tp_getseters

PyGetSetDef pygpu_texture__tp_getseters[]
static
Initial value:
= {
{"width", (getter)pygpu_texture_width_get, (setter)NULL, pygpu_texture_width_doc, NULL},
{"height", (getter)pygpu_texture_height_get, (setter)NULL, pygpu_texture_height_doc, NULL},
{"format", (getter)pygpu_texture_format_get, (setter)NULL, pygpu_texture_format_doc, NULL},
}
static PyObject * pygpu_texture_format_get(BPyGPUTexture *self, void *UNUSED(type))
static PyObject * pygpu_texture_width_get(BPyGPUTexture *self, void *UNUSED(type))
static PyObject * pygpu_texture_height_get(BPyGPUTexture *self, void *UNUSED(type))

Definition at line 438 of file gpu_py_texture.c.

◆ pygpu_texture__tp_methods

struct PyMethodDef pygpu_texture__tp_methods[]
static
Initial value:
= {
{"clear",
(PyCFunction)pygpu_texture_clear,
METH_VARARGS | METH_KEYWORDS,
pygpu_texture_clear_doc},
{"read", (PyCFunction)pygpu_texture_read, METH_NOARGS, pygpu_texture_read_doc},
{NULL, NULL, 0, NULL},
}
static PyObject * pygpu_texture_read(BPyGPUTexture *self)
static PyObject * pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObject *kwds)

Definition at line 438 of file gpu_py_texture.c.

◆ pygpu_texture_module_def

PyModuleDef pygpu_texture_module_def
static
Initial value:
= {
PyModuleDef_HEAD_INIT,
.m_name = "gpu.texture",
.m_doc = pygpu_texture__m_doc,
}
static struct PyMethodDef pygpu_texture__m_methods[]

Definition at line 566 of file gpu_py_texture.c.

Referenced by bpygpu_texture_init().

◆ pygpu_textureformat_items

const struct PyC_StringEnumItems pygpu_textureformat_items[]
static

Definition at line 1 of file gpu_py_texture.c.

Referenced by pygpu_texture__tp_new(), and pygpu_texture_format_get().