Blender V5.0
gpu_py_texture.cc File Reference
#include <Python.h>
#include "BLI_math_base.h"
#include "BLI_string_utf8.h"
#include "DNA_image_types.h"
#include "GPU_context.hh"
#include "GPU_texture.hh"
#include "BKE_image.hh"
#include "../generic/py_capi_utils.hh"
#include "../generic/python_compat.hh"
#include "gpu_py.hh"
#include "gpu_py_buffer.hh"
#include "gpu_py_texture.hh"

Go to the source code of this file.

Functions

Local API
int bpygpu_ParseTexture (PyObject *o, void *p)
PyObject * bpygpu_texture_init ()
Public API
PyObject * BPyGPUTexture_CreatePyObject (blender::gpu::Texture *tex, bool shared_reference)

GPUTexture Common Utilities

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

GPUTexture Type

static PyGetSetDef pygpu_texture__tp_getseters []
static PyMethodDef pygpu_texture__tp_methods []
PyTypeObject BPyGPUTexture_Type
static PyObject * pygpu_texture__tp_new (PyTypeObject *, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (pygpu_texture_width_doc, "Width of the texture.\n" "\n" ":type: int\n")
static PyObject * pygpu_texture_width_get (BPyGPUTexture *self, void *)
 PyDoc_STRVAR (pygpu_texture_height_doc, "Height of the texture.\n" "\n" ":type: int\n")
static PyObject * pygpu_texture_height_get (BPyGPUTexture *self, void *)
 PyDoc_STRVAR (pygpu_texture_format_doc, "Format of the texture.\n" "\n" ":type: str\n")
static PyObject * pygpu_texture_format_get (BPyGPUTexture *self, void *)
 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" " :arg format: The format that describes the content of a single item.\n" " Possible values are ``FLOAT``, ``INT``, ``UINT``, ``UBYTE``, ``UINT_24_8`` & " "``10_11_11_REV``.\n" " ``UINT_24_8`` is deprecated, use ``FLOAT`` instead.\n" " :type format: str\n" " :arg value: Sequence each representing the value to fill. Sizes 1..4 are supported.\n" " :type value: Sequence[float]\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: int | Sequence[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`` (deprecated, use ``DEPTH32F_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``, (deprecated, use ``DEPTH_COMPONENT32F``),\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 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 data-block. 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 data-block.\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 *, PyObject *arg)
 PyDoc_STRVAR (pygpu_texture__m_doc, "This module provides utilities for textures.")

Detailed Description

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

  • Use bpygpu_ for local API.
  • Use BPyGPU for public API.

Definition in file gpu_py_texture.cc.

Macro Definition Documentation

◆ BPYGPU_TEXTURE_CHECK_OBJ

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

Definition at line 102 of file gpu_py_texture.cc.

Referenced by pygpu_texture_clear(), pygpu_texture_format_get(), pygpu_texture_height_get(), pygpu_texture_read(), and pygpu_texture_width_get().

Function Documentation

◆ bpygpu_ParseTexture()

int bpygpu_ParseTexture ( PyObject * o,
void * p )
nodiscard

◆ bpygpu_texture_init()

PyObject * bpygpu_texture_init ( )
nodiscard

Definition at line 762 of file gpu_py_texture.cc.

References pygpu_texture_module_def.

Referenced by BPyInit_gpu().

◆ BPyGPUTexture__tp_dealloc()

void BPyGPUTexture__tp_dealloc ( BPyGPUTexture * self)
static

Definition at line 509 of file gpu_py_texture.cc.

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

◆ BPyGPUTexture_CreatePyObject()

PyObject * BPyGPUTexture_CreatePyObject ( blender::gpu::Texture * tex,
bool shared_reference )
nodiscard

◆ PyDoc_STRVAR() [1/8]

PyDoc_STRVAR ( pygpu_texture__m_doc ,
"This module provides utilities 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:int|Sequence\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`` [int],
\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`` deprecated, use ``DEPTH32F_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`` ,
(deprecated, use ``DEPTH_COMPONENT32F``) ,
\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" " :arg format: The format that describes the content of a single item.\n" " Possible values are ``FLOAT`` ,
``INT`` ,
``UINT`` ,
``UBYTE`` ,
``UINT_24_8`` &" "``10_11_11_REV``.\n" " ``UINT_24_8`` is deprecated,
use ``FLOAT`` instead.\n" " :type format:str\n" " :arg value:Sequence each representing the value to fill. Sizes 1..4 are supported.\n" " :type value:Sequence\n" [float] )

◆ PyDoc_STRVAR() [4/8]

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

◆ PyDoc_STRVAR() [5/8]

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

◆ 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\n"  )

◆ pygpu_texture__tp_new()

◆ pygpu_texture_clear()

◆ pygpu_texture_format_get()

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

◆ pygpu_texture_from_image()

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

◆ pygpu_texture_height_get()

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

Definition at line 329 of file gpu_py_texture.cc.

References BPYGPU_TEXTURE_CHECK_OBJ, GPU_texture_height(), and self.

◆ pygpu_texture_read()

◆ pygpu_texture_valid_check()

int pygpu_texture_valid_check ( BPyGPUTexture * bpygpu_tex)
static

Definition at line 86 of file gpu_py_texture.cc.

References BPYGPU_USE_GPUOBJ_FREE_METHOD, BPyGPUTexture::tex, and UNLIKELY.

Referenced by bpygpu_ParseTexture().

◆ pygpu_texture_width_get()

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

Definition at line 317 of file gpu_py_texture.cc.

References BPYGPU_TEXTURE_CHECK_OBJ, GPU_texture_width(), and self.

Variable Documentation

◆ BPyGPUTexture_Type

PyTypeObject BPyGPUTexture_Type

◆ pygpu_texture__m_methods

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

Definition at line 714 of file gpu_py_texture.cc.

◆ pygpu_texture__tp_getseters

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

Definition at line 520 of file gpu_py_texture.cc.

◆ pygpu_texture__tp_methods

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},
{nullptr, nullptr, 0, nullptr},
}
static PyObject * pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_texture_read(BPyGPUTexture *self)

Definition at line 545 of file gpu_py_texture.cc.

◆ pygpu_texture_module_def

PyModuleDef pygpu_texture_module_def
static
Initial value:
= {
"gpu.texture",
pygpu_texture__m_doc,
0,
nullptr,
nullptr,
nullptr,
nullptr,
}
static PyMethodDef pygpu_texture__m_methods[]

Definition at line 723 of file gpu_py_texture.cc.

Referenced by bpygpu_texture_init().

◆ pygpu_textureformat_items

const PyC_StringEnumItems pygpu_textureformat_items[]