39 {int(blender::gpu::TextureFormat::UINT_8_8_8_8),
"RGBA8UI"},
40 {int(blender::gpu::TextureFormat::SINT_8_8_8_8),
"RGBA8I"},
41 {int(blender::gpu::TextureFormat::UNORM_8_8_8_8),
"RGBA8"},
42 {int(blender::gpu::TextureFormat::UINT_32_32_32_32),
"RGBA32UI"},
43 {int(blender::gpu::TextureFormat::SINT_32_32_32_32),
"RGBA32I"},
44 {int(blender::gpu::TextureFormat::SFLOAT_32_32_32_32),
"RGBA32F"},
45 {int(blender::gpu::TextureFormat::UINT_16_16_16_16),
"RGBA16UI"},
46 {int(blender::gpu::TextureFormat::SINT_16_16_16_16),
"RGBA16I"},
47 {int(blender::gpu::TextureFormat::SFLOAT_16_16_16_16),
"RGBA16F"},
48 {int(blender::gpu::TextureFormat::UNORM_16_16_16_16),
"RGBA16"},
49 {int(blender::gpu::TextureFormat::UINT_8_8),
"RG8UI"},
50 {int(blender::gpu::TextureFormat::SINT_8_8),
"RG8I"},
51 {int(blender::gpu::TextureFormat::UNORM_8_8),
"RG8"},
52 {int(blender::gpu::TextureFormat::UINT_32_32),
"RG32UI"},
53 {int(blender::gpu::TextureFormat::SINT_32_32),
"RG32I"},
54 {int(blender::gpu::TextureFormat::SFLOAT_32_32),
"RG32F"},
55 {int(blender::gpu::TextureFormat::UINT_16_16),
"RG16UI"},
56 {int(blender::gpu::TextureFormat::SINT_16_16),
"RG16I"},
57 {int(blender::gpu::TextureFormat::SFLOAT_16_16),
"RG16F"},
58 {int(blender::gpu::TextureFormat::UNORM_16_16),
"RG16"},
59 {int(blender::gpu::TextureFormat::UINT_8),
"R8UI"},
60 {int(blender::gpu::TextureFormat::SINT_8),
"R8I"},
61 {int(blender::gpu::TextureFormat::UNORM_8),
"R8"},
62 {int(blender::gpu::TextureFormat::UINT_32),
"R32UI"},
63 {int(blender::gpu::TextureFormat::SINT_32),
"R32I"},
64 {int(blender::gpu::TextureFormat::SFLOAT_32),
"R32F"},
65 {int(blender::gpu::TextureFormat::UINT_16),
"R16UI"},
66 {int(blender::gpu::TextureFormat::SINT_16),
"R16I"},
67 {int(blender::gpu::TextureFormat::SFLOAT_16),
"R16F"},
68 {int(blender::gpu::TextureFormat::UNORM_16),
"R16"},
69 {int(blender::gpu::TextureFormat::UFLOAT_11_11_10),
"R11F_G11F_B10F"},
70 {int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8),
"DEPTH32F_STENCIL8"},
72 {int(blender::gpu::TextureFormat::SRGBA_8_8_8_8),
"SRGB8_A8"},
73 {int(blender::gpu::TextureFormat::SFLOAT_16_16_16),
"RGB16F"},
74 {int(blender::gpu::TextureFormat::SRGB_DXT1),
"SRGB8_A8_DXT1"},
75 {int(blender::gpu::TextureFormat::SRGB_DXT3),
"SRGB8_A8_DXT3"},
76 {int(blender::gpu::TextureFormat::SRGB_DXT5),
"SRGB8_A8_DXT5"},
77 {int(blender::gpu::TextureFormat::SNORM_DXT1),
"RGBA8_DXT1"},
78 {int(blender::gpu::TextureFormat::SNORM_DXT3),
"RGBA8_DXT3"},
79 {int(blender::gpu::TextureFormat::SNORM_DXT5),
"RGBA8_DXT5"},
80 {int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH),
"DEPTH_COMPONENT32F"},
82 {int(blender::gpu::TextureFormat::UNORM_16_DEPTH),
"DEPTH_COMPONENT16"},
89 PyErr_SetString(PyExc_ReferenceError,
91 "GPU texture was freed, no further access is valid"
93 "GPU texture: internal error"
102#define BPYGPU_TEXTURE_CHECK_OBJ(bpygpu) \
104 if (UNLIKELY(pygpu_texture_valid_check(bpygpu) == -1)) { \
121 int size[3] = {1, 1, 1};
123 int is_cubemap =
false;
125 int(blender::gpu::TextureFormat::UNORM_8_8_8_8)};
127 char err_out[256] =
"unknown error. See console";
129 static const char *_keywords[] = {
"size",
"layers",
"is_cubemap",
"format",
"data",
nullptr};
130 static _PyArg_Parser _parser = {
138 ":GPUTexture.__new__",
142 if (!_PyArg_ParseTupleAndKeywordsFast(args,
149 &pygpu_textureformat,
157 pygpu_textureformat.
value_found = int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8);
159 PyExc_DeprecationWarning,
"'DEPTH24_STENCIL8' is deprecated. Use 'DEPTH32F_STENCIL8'.", 1);
162 pygpu_textureformat.
value_found = int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH);
163 PyErr_WarnEx(PyExc_DeprecationWarning,
164 "'DEPTH_COMPONENT24' is deprecated. Use 'DEPTH_COMPONENT32F'.",
169 if (PySequence_Check(py_size)) {
170 len = PySequence_Size(py_size);
171 if ((
len < 1) || (
len > 3)) {
172 PyErr_Format(PyExc_ValueError,
173 "GPUTexture.__new__: \"size\" must be between 1 and 3 in length (got %d)",
181 else if (PyLong_Check(py_size)) {
182 size[0] = PyLong_AsLong(py_size);
185 PyErr_SetString(PyExc_ValueError,
"GPUTexture.__new__: Expected an int or tuple as first arg");
189 void *
data =
nullptr;
192 PyErr_SetString(PyExc_ValueError,
193 "GPUTexture.__new__: Only Buffer of format `FLOAT` is currently supported");
199 int component_size_expected =
sizeof(
float);
200 size_t data_space_expected = size_t(
size[0]) *
size[1] *
size[2] *
max_ii(1, layers) *
201 component_len * component_size_expected;
203 data_space_expected *= 6 *
size[0];
207 PyErr_SetString(PyExc_ValueError,
"GPUTexture.__new__: Buffer size smaller than requested");
214 if (is_cubemap &&
len != 1) {
217 "In cubemaps the same dimension represents height, width and depth. No tuple needed");
220 STRNCPY_UTF8(err_out,
"Values less than 1 are not allowed in dimensions");
222 else if (layers &&
len == 3) {
229 const char *
name =
"python_texture";
240 static_cast<const float *
>(
data));
248 static_cast<const float *
>(
data));
261 static_cast<const float *
>(
data));
271 static_cast<const float *
>(
data));
291 static_cast<const float *
>(
data));
299 static_cast<const float *
>(
data));
303 if (tex ==
nullptr) {
304 PyErr_Format(PyExc_RuntimeError,
"gpu.texture.new(...) failed with '%s'", err_out);
313 pygpu_texture_width_doc,
314 "Width of the texture.\n"
325 pygpu_texture_height_doc,
326 "Height of the texture.\n"
337 pygpu_texture_format_doc,
338 "Format of the texture.\n"
345 return PyUnicode_FromString(
351 pygpu_texture_clear_doc,
352 ".. method:: clear(format='FLOAT', value=(0.0, 0.0, 0.0, 1.0))\n"
354 " Fill texture with specific value.\n"
356 " :arg format: The format that describes the content of a single item.\n"
357 " Possible values are ``FLOAT``, ``INT``, ``UINT``, ``UBYTE``, ``UINT_24_8`` & "
358 "``10_11_11_REV``.\n"
359 " ``UINT_24_8`` is deprecated, use ``FLOAT`` instead.\n"
360 " :type format: str\n"
361 " :arg value: Sequence each representing the value to fill. Sizes 1..4 are supported.\n"
362 " :type value: Sequence[float]\n");
375 static const char *_keywords[] = {
"format",
"value",
nullptr};
376 static _PyArg_Parser _parser = {
385 if (!_PyArg_ParseTupleAndKeywordsFast(
391 PyErr_WarnEx(PyExc_DeprecationWarning,
"`UINT_24_8` is deprecated, use `FLOAT` instead", 1);
394 int shape = PySequence_Size(py_values);
400 PyErr_SetString(PyExc_AttributeError,
"too many dimensions, max is 4");
407 PyErr_SetString(PyExc_AttributeError,
408 "`UINT_24_8` and `10_11_11_REV` only support single values");
412 memset(&values, 0,
sizeof(values));
426 values.c[0] = values.i[0];
427 values.c[1] = values.i[1];
428 values.c[2] = values.i[2];
429 values.c[3] = values.i[3];
438 pygpu_texture_read_doc,
439 ".. method:: read()\n"
441 " Creates a buffer with the value of all pixels.\n"
451 switch (tex_format) {
452 case blender::gpu::TextureFormat::UNORM_16_DEPTH:
453 case blender::gpu::TextureFormat::SFLOAT_32_DEPTH:
454 case blender::gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8:
457 case blender::gpu::TextureFormat::UINT_8:
458 case blender::gpu::TextureFormat::UINT_16:
459 case blender::gpu::TextureFormat::UINT_16_16:
460 case blender::gpu::TextureFormat::UINT_32:
463 case blender::gpu::TextureFormat::SINT_16_16:
464 case blender::gpu::TextureFormat::SINT_16:
467 case blender::gpu::TextureFormat::UNORM_8:
468 case blender::gpu::TextureFormat::UNORM_8_8:
469 case blender::gpu::TextureFormat::UNORM_8_8_8_8:
470 case blender::gpu::TextureFormat::UINT_8_8_8_8:
471 case blender::gpu::TextureFormat::SRGBA_8_8_8_8:
474 case blender::gpu::TextureFormat::UFLOAT_11_11_10:
487 int shape_len = (shape[2] == 1) ? 2 : 3;
491#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
494 pygpu_texture_free_doc,
495 ".. method:: free()\n"
497 " Free the texture object.\n"
498 " The texture object will no longer be accessible.\n");
512#ifndef GPU_NO_USE_PY_REFERENCES
517 Py_TYPE(
self)->tp_free((PyObject *)
self);
525 pygpu_texture_height_doc,
530 pygpu_texture_format_doc,
532 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
537# pragma clang diagnostic push
538# pragma clang diagnostic ignored "-Wcast-function-type"
540# pragma GCC diagnostic push
541# pragma GCC diagnostic ignored "-Wcast-function-type"
548 METH_VARARGS | METH_KEYWORDS,
549 pygpu_texture_clear_doc},
551#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
552 {
"free", (PyCFunction)pygpu_texture_free, METH_NOARGS, pygpu_texture_free_doc},
554 {
nullptr,
nullptr, 0,
nullptr},
559# pragma clang diagnostic pop
561# pragma GCC diagnostic pop
567 pygpu_texture__tp_doc,
568 ".. class:: GPUTexture(size, *, layers=0, is_cubemap=False, format='RGBA8', "
571 " This object gives access to off GPU textures.\n"
573 " :arg size: Dimensions of the texture 1D, 2D, 3D or cubemap.\n"
574 " :type size: int | Sequence[int]\n"
575 " :arg layers: Number of layers in texture array or number of cubemaps in cubemap array\n"
576 " :type layers: int\n"
577 " :arg is_cubemap: Indicates the creation of a cubemap texture.\n"
578 " :type is_cubemap: int\n"
579 " :arg format: Internal data format inside GPU memory. Possible values are:\n"
610 " ``R11F_G11F_B10F``,\n"
611 " ``DEPTH32F_STENCIL8``,\n"
612 " ``DEPTH24_STENCIL8`` (deprecated, use ``DEPTH32F_STENCIL8``),\n"
615 " ``SRGB8_A8_DXT1``,\n"
616 " ``SRGB8_A8_DXT3``,\n"
617 " ``SRGB8_A8_DXT5``,\n"
621 " ``DEPTH_COMPONENT32F``,\n"
622 " ``DEPTH_COMPONENT24``, (deprecated, use ``DEPTH_COMPONENT32F``),\n"
623 " ``DEPTH_COMPONENT16``.\n"
624 " :type format: str\n"
625 " :arg data: Buffer object to fill the texture.\n"
626 " :type data: :class:`gpu.types.Buffer`\n");
628 PyVarObject_HEAD_INIT(
nullptr, 0)
648 pygpu_texture__tp_doc,
687 pygpu_texture_from_image_doc,
688 ".. function:: from_image(image)\n"
690 " Get GPUTexture corresponding to an Image data-block. The GPUTexture "
692 "shared with Blender.\n"
693 " Note: Colors read from the texture will be in scene linear color space and have "
694 "premultiplied or straight alpha matching the image alpha mode.\n"
696 " :arg image: The Image data-block.\n"
697 " :type image: :class:`bpy.types.Image`\n"
698 " :return: The GPUTexture used by the image.\n"
699 " :rtype: :class:`gpu.types.GPUTexture`\n");
703 if (ima ==
nullptr) {
716 {
nullptr,
nullptr, 0,
nullptr},
721 pygpu_texture__m_doc,
722 "This module provides utilities for textures.");
726 pygpu_texture__m_doc,
750 PyExc_ValueError,
"expected a texture or None object, got %s", Py_TYPE(o)->tp_name);
780 if (shared_reference) {
781#ifndef GPU_NO_USE_PY_REFERENCES
788 return (PyObject *)
self;
798#ifndef GPU_NO_USE_PY_REFERENCES
803 return (PyObject *)
self;
808#undef BPYGPU_TEXTURE_CHECK_OBJ
void BKE_imageuser_default(ImageUser *iuser)
blender::gpu::Texture * BKE_image_get_gpu_texture(Image *image, ImageUser *iuser)
MINLINE int max_ii(int a, int b)
#define STRNCPY_UTF8(dst, src)
#define POINTER_OFFSET(v, ofs)
GPUContext * GPU_context_active_get()
void GPU_texture_clear(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
blender::gpu::Texture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
size_t GPU_texture_component_len(blender::gpu::TextureFormat format)
void ** GPU_texture_py_reference_get(blender::gpu::Texture *texture)
int GPU_texture_height(const blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_cube(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
blender::gpu::Texture * GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
blender::gpu::TextureFormat GPU_texture_format(const blender::gpu::Texture *texture)
int GPU_texture_width(const blender::gpu::Texture *texture)
@ GPU_DATA_UINT_24_8_DEPRECATED
blender::gpu::Texture * GPU_texture_create_cube_array(const char *name, int width, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_ref(blender::gpu::Texture *texture)
@ GPU_TEXTURE_USAGE_GENERAL
void * GPU_texture_read(blender::gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
void GPU_texture_py_reference_set(blender::gpu::Texture *texture, void **py_ref)
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
blender::gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
PyC_StringEnumItems bpygpu_dataformat_items[]
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
PyTypeObject BPyGPU_BufferType
BPyGPUBuffer * BPyGPU_Buffer_CreatePyObject(const int format, const Py_ssize_t *shape, const int shape_len, void *buffer)
size_t bpygpu_Buffer_size(BPyGPUBuffer *buffer)
#define BPYGPU_USE_GPUOBJ_FREE_METHOD
PyTypeObject BPyGPUTexture_Type
static PyObject * pygpu_texture_width_get(BPyGPUTexture *self, void *)
static PyObject * pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObject *kwds)
PyObject * BPyGPUTexture_CreatePyObject(blender::gpu::Texture *tex, bool shared_reference)
PyObject * bpygpu_texture_init()
static void BPyGPUTexture__tp_dealloc(BPyGPUTexture *self)
static int pygpu_texture_valid_check(BPyGPUTexture *bpygpu_tex)
static PyGetSetDef pygpu_texture__tp_getseters[]
#define BPYGPU_TEXTURE_CHECK_OBJ(bpygpu)
static PyObject * pygpu_texture_from_image(PyObject *, PyObject *arg)
PyDoc_STRVAR(pygpu_texture_width_doc, "Width of the texture.\n" "\n" ":type: int\n")
static PyObject * pygpu_texture__tp_new(PyTypeObject *, PyObject *args, PyObject *kwds)
static PyObject * pygpu_texture_height_get(BPyGPUTexture *self, void *)
int bpygpu_ParseTexture(PyObject *o, void *p)
static PyObject * pygpu_texture_read(BPyGPUTexture *self)
const PyC_StringEnumItems pygpu_textureformat_items[]
static PyMethodDef pygpu_texture__m_methods[]
static PyMethodDef pygpu_texture__tp_methods[]
static PyModuleDef pygpu_texture_module_def
static PyObject * pygpu_texture_format_get(BPyGPUTexture *self, void *)
constexpr int GPU_DEPTH24_STENCIL8_DEPRECATED
#define BPyGPUTexture_Check(v)
constexpr int GPU_DEPTH_COMPONENT24_DEPRECATED
void * PyC_RNA_AsPointer(PyObject *value, const char *type_name)
int PyC_ParseStringEnum(PyObject *o, void *p)
int PyC_AsArray(void *array, const size_t array_item_size, PyObject *value, const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix)
const char * PyC_StringEnum_FindIDFromValue(const PyC_StringEnumItems *items, const int value)
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()
union BPyGPUBuffer::@121060215011127262115351146023070133300154361035 buf
PyObject_HEAD blender::gpu::Texture * tex