Blender  V3.3
gpu_py_texture.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
12 #include <Python.h>
13 
14 #include "BLI_string.h"
15 
16 #include "DNA_image_types.h"
17 
18 #include "GPU_context.h"
19 #include "GPU_texture.h"
20 
21 #include "BKE_image.h"
22 
23 #include "../generic/py_capi_utils.h"
24 
25 #include "gpu_py.h"
26 #include "gpu_py_buffer.h"
27 
28 #include "gpu_py_texture.h" /* own include */
29 
30 /* -------------------------------------------------------------------- */
34 static const struct PyC_StringEnumItems pygpu_textureformat_items[] = {
35  {GPU_RGBA8UI, "RGBA8UI"},
36  {GPU_RGBA8I, "RGBA8I"},
37  {GPU_RGBA8, "RGBA8"},
38  {GPU_RGBA32UI, "RGBA32UI"},
39  {GPU_RGBA32I, "RGBA32I"},
40  {GPU_RGBA32F, "RGBA32F"},
41  {GPU_RGBA16UI, "RGBA16UI"},
42  {GPU_RGBA16I, "RGBA16I"},
43  {GPU_RGBA16F, "RGBA16F"},
44  {GPU_RGBA16, "RGBA16"},
45  {GPU_RG8UI, "RG8UI"},
46  {GPU_RG8I, "RG8I"},
47  {GPU_RG8, "RG8"},
48  {GPU_RG32UI, "RG32UI"},
49  {GPU_RG32I, "RG32I"},
50  {GPU_RG32F, "RG32F"},
51  {GPU_RG16UI, "RG16UI"},
52  {GPU_RG16I, "RG16I"},
53  {GPU_RG16F, "RG16F"},
54  {GPU_RG16, "RG16"},
55  {GPU_R8UI, "R8UI"},
56  {GPU_R8I, "R8I"},
57  {GPU_R8, "R8"},
58  {GPU_R32UI, "R32UI"},
59  {GPU_R32I, "R32I"},
60  {GPU_R32F, "R32F"},
61  {GPU_R16UI, "R16UI"},
62  {GPU_R16I, "R16I"},
63  {GPU_R16F, "R16F"},
64  {GPU_R16, "R16"},
65  {GPU_R11F_G11F_B10F, "R11F_G11F_B10F"},
66  {GPU_DEPTH32F_STENCIL8, "DEPTH32F_STENCIL8"},
67  {GPU_DEPTH24_STENCIL8, "DEPTH24_STENCIL8"},
68  {GPU_SRGB8_A8, "SRGB8_A8"},
69  {GPU_RGB16F, "RGB16F"},
70  {GPU_SRGB8_A8_DXT1, "SRGB8_A8_DXT1"},
71  {GPU_SRGB8_A8_DXT3, "SRGB8_A8_DXT3"},
72  {GPU_SRGB8_A8_DXT5, "SRGB8_A8_DXT5"},
73  {GPU_RGBA8_DXT1, "RGBA8_DXT1"},
74  {GPU_RGBA8_DXT3, "RGBA8_DXT3"},
75  {GPU_RGBA8_DXT5, "RGBA8_DXT5"},
76  {GPU_DEPTH_COMPONENT32F, "DEPTH_COMPONENT32F"},
77  {GPU_DEPTH_COMPONENT24, "DEPTH_COMPONENT24"},
78  {GPU_DEPTH_COMPONENT16, "DEPTH_COMPONENT16"},
79  {0, NULL},
80 };
81 
83 {
84  if (UNLIKELY(bpygpu_tex->tex == NULL)) {
85  PyErr_SetString(PyExc_ReferenceError,
87  "GPU texture was freed, no further access is valid"
88 #else
89  "GPU texture: internal error"
90 #endif
91  );
92 
93  return -1;
94  }
95  return 0;
96 }
97 
98 #define BPYGPU_TEXTURE_CHECK_OBJ(bpygpu) \
99  { \
100  if (UNLIKELY(pygpu_texture_valid_check(bpygpu) == -1)) { \
101  return NULL; \
102  } \
103  } \
104  ((void)0)
105 
108 /* -------------------------------------------------------------------- */
112 static PyObject *pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds)
113 {
115 
116  PyObject *py_size;
117  int size[3] = {1, 1, 1};
118  int layers = 0;
119  int is_cubemap = false;
120  struct PyC_StringEnum pygpu_textureformat = {pygpu_textureformat_items, GPU_RGBA8};
121  BPyGPUBuffer *pybuffer_obj = NULL;
122  char err_out[256] = "unknown error. See console";
123 
124  static const char *_keywords[] = {"size", "layers", "is_cubemap", "format", "data", NULL};
125  static _PyArg_Parser _parser = {
126  "O" /* `size` */
127  "|$" /* Optional keyword only arguments. */
128  "i" /* `layers` */
129  "p" /* `is_cubemap` */
130  "O&" /* `format` */
131  "O!" /* `data` */
132  ":GPUTexture.__new__",
133  _keywords,
134  0,
135  };
136  if (!_PyArg_ParseTupleAndKeywordsFast(args,
137  kwds,
138  &_parser,
139  &py_size,
140  &layers,
141  &is_cubemap,
143  &pygpu_textureformat,
145  &pybuffer_obj)) {
146  return NULL;
147  }
148 
149  int len = 1;
150  if (PySequence_Check(py_size)) {
151  len = PySequence_Size(py_size);
152  if ((len < 1) || (len > 3)) {
153  PyErr_Format(PyExc_ValueError,
154  "GPUTexture.__new__: \"size\" must be between 1 and 3 in length (got %d)",
155  len);
156  return NULL;
157  }
158  if (PyC_AsArray(size, sizeof(*size), py_size, len, &PyLong_Type, "GPUTexture.__new__") == -1) {
159  return NULL;
160  }
161  }
162  else if (PyLong_Check(py_size)) {
163  size[0] = PyLong_AsLong(py_size);
164  }
165  else {
166  PyErr_SetString(PyExc_ValueError, "GPUTexture.__new__: Expected an int or tuple as first arg");
167  return NULL;
168  }
169 
170  void *data = NULL;
171  if (pybuffer_obj) {
172  if (pybuffer_obj->format != GPU_DATA_FLOAT) {
173  PyErr_SetString(PyExc_ValueError,
174  "GPUTexture.__new__: Only Buffer of format `FLOAT` is currently supported");
175  return NULL;
176  }
177 
178  int component_len = GPU_texture_component_len(pygpu_textureformat.value_found);
179  int component_size_expected = sizeof(float);
180  size_t data_space_expected = (size_t)size[0] * size[1] * size[2] * max_ii(1, layers) *
181  component_len * component_size_expected;
182  if (is_cubemap) {
183  data_space_expected *= 6 * size[0];
184  }
185 
186  if (bpygpu_Buffer_size(pybuffer_obj) < data_space_expected) {
187  PyErr_SetString(PyExc_ValueError, "GPUTexture.__new__: Buffer size smaller than requested");
188  return NULL;
189  }
190  data = pybuffer_obj->buf.as_void;
191  }
192 
193  GPUTexture *tex = NULL;
194  if (is_cubemap && len != 1) {
195  STRNCPY(err_out,
196  "In cubemaps the same dimension represents height, width and depth. No tuple needed");
197  }
198  else if (size[0] < 1 || size[1] < 1 || size[2] < 1) {
199  STRNCPY(err_out, "Values less than 1 are not allowed in dimensions");
200  }
201  else if (layers && len == 3) {
202  STRNCPY(err_out, "3D textures have no layers");
203  }
204  else if (!GPU_context_active_get()) {
205  STRNCPY(err_out, "No active GPU context found");
206  }
207  else {
208  const char *name = "python_texture";
209  if (is_cubemap) {
210  if (layers) {
212  name, size[0], layers, 1, pygpu_textureformat.value_found, data);
213  }
214  else {
215  tex = GPU_texture_create_cube(name, size[0], 1, pygpu_textureformat.value_found, data);
216  }
217  }
218  else if (layers) {
219  if (len == 2) {
221  name, size[0], size[1], layers, 1, pygpu_textureformat.value_found, data);
222  }
223  else {
225  name, size[0], layers, 1, pygpu_textureformat.value_found, data);
226  }
227  }
228  else if (len == 3) {
229  tex = GPU_texture_create_3d(name,
230  size[0],
231  size[1],
232  size[2],
233  1,
234  pygpu_textureformat.value_found,
236  data);
237  }
238  else if (len == 2) {
240  name, size[0], size[1], 1, pygpu_textureformat.value_found, data);
241  }
242  else {
243  tex = GPU_texture_create_1d(name, size[0], 1, pygpu_textureformat.value_found, data);
244  }
245  }
246 
247  if (tex == NULL) {
248  PyErr_Format(PyExc_RuntimeError, "gpu.texture.new(...) failed with '%s'", err_out);
249  return NULL;
250  }
251 
252  return BPyGPUTexture_CreatePyObject(tex, false);
253 }
254 
255 PyDoc_STRVAR(pygpu_texture_width_doc, "Width of the texture.\n\n:type: `int`");
256 static PyObject *pygpu_texture_width_get(BPyGPUTexture *self, void *UNUSED(type))
257 {
259  return PyLong_FromLong(GPU_texture_width(self->tex));
260 }
261 
262 PyDoc_STRVAR(pygpu_texture_height_doc, "Height of the texture.\n\n:type: `int`");
263 static PyObject *pygpu_texture_height_get(BPyGPUTexture *self, void *UNUSED(type))
264 {
266  return PyLong_FromLong(GPU_texture_height(self->tex));
267 }
268 
269 PyDoc_STRVAR(pygpu_texture_format_doc, "Format of the texture.\n\n:type: `str`");
270 static PyObject *pygpu_texture_format_get(BPyGPUTexture *self, void *UNUSED(type))
271 {
274  return PyUnicode_FromString(PyC_StringEnum_FindIDFromValue(pygpu_textureformat_items, format));
275 }
276 
278  pygpu_texture_clear_doc,
279  ".. method:: clear(format='FLOAT', value=(0.0, 0.0, 0.0, 1.0))\n"
280  "\n"
281  " Fill texture with specific value.\n"
282  "\n"
283  " :param format: The format that describes the content of a single item.\n"
284  " Possible values are `FLOAT`, `INT`, `UINT`, `UBYTE`, `UINT_24_8` and `10_11_11_REV`.\n"
285  " :type type: str\n"
286  " :arg value: sequence each representing the value to fill.\n"
287  " :type value: sequence of 1, 2, 3 or 4 values\n");
288 static PyObject *pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObject *kwds)
289 {
291  struct PyC_StringEnum pygpu_dataformat = {bpygpu_dataformat_items};
292  union {
293  int i[4];
294  float f[4];
295  char c[4];
296  } values;
297 
298  PyObject *py_values;
299 
300  static const char *_keywords[] = {"format", "value", NULL};
301  static _PyArg_Parser _parser = {
302  "$" /* Keyword only arguments. */
303  "O&" /* `format` */
304  "O" /* `value` */
305  ":clear",
306  _keywords,
307  0,
308  };
309  if (!_PyArg_ParseTupleAndKeywordsFast(
310  args, kwds, &_parser, PyC_ParseStringEnum, &pygpu_dataformat, &py_values)) {
311  return NULL;
312  }
313 
314  int shape = PySequence_Size(py_values);
315  if (shape == -1) {
316  return NULL;
317  }
318 
319  if (shape > 4) {
320  PyErr_SetString(PyExc_AttributeError, "too many dimensions, max is 4");
321  return NULL;
322  }
323 
324  if (shape != 1 &&
326  PyErr_SetString(PyExc_AttributeError,
327  "`UINT_24_8` and `10_11_11_REV` only support single values");
328  return NULL;
329  }
330 
331  memset(&values, 0, sizeof(values));
332  if (PyC_AsArray(&values,
333  (pygpu_dataformat.value_found == GPU_DATA_FLOAT) ? sizeof(*values.f) :
334  sizeof(*values.i),
335  py_values,
336  shape,
337  (pygpu_dataformat.value_found == GPU_DATA_FLOAT) ? &PyFloat_Type : &PyLong_Type,
338  "clear") == -1) {
339  return NULL;
340  }
341 
342  if (pygpu_dataformat.value_found == GPU_DATA_UBYTE) {
343  /* Convert to byte. */
344  values.c[0] = values.i[0];
345  values.c[1] = values.i[1];
346  values.c[2] = values.i[2];
347  values.c[3] = values.i[3];
348  }
349 
350  GPU_texture_clear(self->tex, pygpu_dataformat.value_found, &values);
351  Py_RETURN_NONE;
352 }
353 
354 PyDoc_STRVAR(pygpu_texture_read_doc,
355  ".. method:: read()\n"
356  "\n"
357  " Creates a buffer with the value of all pixels.\n"
358  "\n");
359 static PyObject *pygpu_texture_read(BPyGPUTexture *self)
360 {
362  eGPUTextureFormat tex_format = GPU_texture_format(self->tex);
363 
364  /* #GPU_texture_read is restricted in combining 'data_format' with 'tex_format'.
365  * So choose data_format here. */
366  eGPUDataFormat best_data_format;
367  switch (tex_format) {
371  best_data_format = GPU_DATA_FLOAT;
372  break;
375  best_data_format = GPU_DATA_UINT_24_8;
376  break;
377  case GPU_R8UI:
378  case GPU_R16UI:
379  case GPU_RG16UI:
380  case GPU_R32UI:
381  best_data_format = GPU_DATA_UINT;
382  break;
383  case GPU_RG16I:
384  case GPU_R16I:
385  best_data_format = GPU_DATA_INT;
386  break;
387  case GPU_R8:
388  case GPU_RG8:
389  case GPU_RGBA8:
390  case GPU_RGBA8UI:
391  case GPU_SRGB8_A8:
392  best_data_format = GPU_DATA_UBYTE;
393  break;
394  case GPU_R11F_G11F_B10F:
395  best_data_format = GPU_DATA_10_11_11_REV;
396  break;
397  default:
398  best_data_format = GPU_DATA_FLOAT;
399  break;
400  }
401 
402  void *buf = GPU_texture_read(self->tex, best_data_format, 0);
403  const Py_ssize_t shape[3] = {GPU_texture_height(self->tex),
404  GPU_texture_width(self->tex),
405  GPU_texture_component_len(tex_format)};
406 
407  int shape_len = (shape[2] == 1) ? 2 : 3;
408  return (PyObject *)BPyGPU_Buffer_CreatePyObject(best_data_format, shape, shape_len, buf);
409 }
410 
411 #ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
412 PyDoc_STRVAR(pygpu_texture_free_doc,
413  ".. method:: free()\n"
414  "\n"
415  " Free the texture object.\n"
416  " The texture object will no longer be accessible.\n");
417 static PyObject *pygpu_texture_free(BPyGPUTexture *self)
418 {
420 
421  GPU_texture_free(self->tex);
422  self->tex = NULL;
423  Py_RETURN_NONE;
424 }
425 #endif
426 
428 {
429  if (self->tex) {
430 #ifndef GPU_NO_USE_PY_REFERENCES
432 #endif
433  GPU_texture_free(self->tex);
434  }
435  Py_TYPE(self)->tp_free((PyObject *)self);
436 }
437 
438 static PyGetSetDef pygpu_texture__tp_getseters[] = {
439  {"width", (getter)pygpu_texture_width_get, (setter)NULL, pygpu_texture_width_doc, NULL},
440  {"height", (getter)pygpu_texture_height_get, (setter)NULL, pygpu_texture_height_doc, NULL},
441  {"format", (getter)pygpu_texture_format_get, (setter)NULL, pygpu_texture_format_doc, NULL},
442  {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
443 };
444 
445 static struct PyMethodDef pygpu_texture__tp_methods[] = {
446  {"clear",
447  (PyCFunction)pygpu_texture_clear,
448  METH_VARARGS | METH_KEYWORDS,
449  pygpu_texture_clear_doc},
450  {"read", (PyCFunction)pygpu_texture_read, METH_NOARGS, pygpu_texture_read_doc},
451 #ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
452  {"free", (PyCFunction)pygpu_texture_free, METH_NOARGS, pygpu_texture_free_doc},
453 #endif
454  {NULL, NULL, 0, NULL},
455 };
456 
458  pygpu_texture__tp_doc,
459  ".. class:: GPUTexture(size, layers=0, is_cubemap=False, format='RGBA8', data=None)\n"
460  "\n"
461  " This object gives access to off GPU textures.\n"
462  "\n"
463  " :arg size: Dimensions of the texture 1D, 2D, 3D or cubemap.\n"
464  " :type size: tuple or int\n"
465  " :arg layers: Number of layers in texture array or number of cubemaps in cubemap array\n"
466  " :type layers: int\n"
467  " :arg is_cubemap: Indicates the creation of a cubemap texture.\n"
468  " :type is_cubemap: int\n"
469  " :arg format: Internal data format inside GPU memory. Possible values are:\n"
470  " `RGBA8UI`,\n"
471  " `RGBA8I`,\n"
472  " `RGBA8`,\n"
473  " `RGBA32UI`,\n"
474  " `RGBA32I`,\n"
475  " `RGBA32F`,\n"
476  " `RGBA16UI`,\n"
477  " `RGBA16I`,\n"
478  " `RGBA16F`,\n"
479  " `RGBA16`,\n"
480  " `RG8UI`,\n"
481  " `RG8I`,\n"
482  " `RG8`,\n"
483  " `RG32UI`,\n"
484  " `RG32I`,\n"
485  " `RG32F`,\n"
486  " `RG16UI`,\n"
487  " `RG16I`,\n"
488  " `RG16F`,\n"
489  " `RG16`,\n"
490  " `R8UI`,\n"
491  " `R8I`,\n"
492  " `R8`,\n"
493  " `R32UI`,\n"
494  " `R32I`,\n"
495  " `R32F`,\n"
496  " `R16UI`,\n"
497  " `R16I`,\n"
498  " `R16F`,\n"
499  " `R16`,\n"
500  " `R11F_G11F_B10F`,\n"
501  " `DEPTH32F_STENCIL8`,\n"
502  " `DEPTH24_STENCIL8`,\n"
503  " `SRGB8_A8`,\n"
504  " `RGB16F`,\n"
505  " `SRGB8_A8_DXT1`,\n"
506  " `SRGB8_A8_DXT3`,\n"
507  " `SRGB8_A8_DXT5`,\n"
508  " `RGBA8_DXT1`,\n"
509  " `RGBA8_DXT3`,\n"
510  " `RGBA8_DXT5`,\n"
511  " `DEPTH_COMPONENT32F`,\n"
512  " `DEPTH_COMPONENT24`,\n"
513  " `DEPTH_COMPONENT16`,\n"
514  " :type format: str\n"
515  " :arg data: Buffer object to fill the texture.\n"
516  " :type data: :class:`gpu.types.Buffer`\n");
517 PyTypeObject BPyGPUTexture_Type = {
518  PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUTexture",
519  .tp_basicsize = sizeof(BPyGPUTexture),
520  .tp_dealloc = (destructor)BPyGPUTexture__tp_dealloc,
521  .tp_flags = Py_TPFLAGS_DEFAULT,
522  .tp_doc = pygpu_texture__tp_doc,
523  .tp_methods = pygpu_texture__tp_methods,
524  .tp_getset = pygpu_texture__tp_getseters,
525  .tp_new = pygpu_texture__tp_new,
526 };
527 
530 /* -------------------------------------------------------------------- */
534 PyDoc_STRVAR(pygpu_texture_from_image_doc,
535  ".. function:: from_image(image)\n"
536  "\n"
537  " Get GPUTexture corresponding to an Image datablock. The GPUTexture memory is "
538  "shared with Blender.\n"
539  " Note: Colors read from the texture will be in scene linear color space and have "
540  "premultiplied or straight alpha matching the image alpha mode.\n"
541  "\n"
542  " :arg image: The Image datablock.\n"
543  " :type image: :class:`bpy.types.Image`\n"
544  " :return: The GPUTexture used by the image.\n"
545  " :rtype: :class:`gpu.types.GPUTexture`\n");
546 static PyObject *pygpu_texture_from_image(PyObject *UNUSED(self), PyObject *arg)
547 {
548  Image *ima = PyC_RNA_AsPointer(arg, "Image");
549  if (ima == NULL) {
550  return NULL;
551  }
552 
553  ImageUser iuser;
554  BKE_imageuser_default(&iuser);
555  GPUTexture *tex = BKE_image_get_gpu_texture(ima, &iuser, NULL);
556 
557  return BPyGPUTexture_CreatePyObject(tex, true);
558 }
559 
560 static struct PyMethodDef pygpu_texture__m_methods[] = {
561  {"from_image", (PyCFunction)pygpu_texture_from_image, METH_O, pygpu_texture_from_image_doc},
562  {NULL, NULL, 0, NULL},
563 };
564 
565 PyDoc_STRVAR(pygpu_texture__m_doc, "This module provides utils for textures.");
566 static PyModuleDef pygpu_texture_module_def = {
567  PyModuleDef_HEAD_INIT,
568  .m_name = "gpu.texture",
569  .m_doc = pygpu_texture__m_doc,
570  .m_methods = pygpu_texture__m_methods,
571 };
572 
575 /* -------------------------------------------------------------------- */
579 int bpygpu_ParseTexture(PyObject *o, void *p)
580 {
581  if (o == Py_None) {
582  *(GPUTexture **)p = NULL;
583  return 1;
584  }
585 
586  if (!BPyGPUTexture_Check(o)) {
587  PyErr_Format(
588  PyExc_ValueError, "expected a texture or None object, got %s", Py_TYPE(o)->tp_name);
589  return 0;
590  }
591 
593  return 0;
594  }
595 
596  *(GPUTexture **)p = ((BPyGPUTexture *)o)->tex;
597  return 1;
598 }
599 
600 PyObject *bpygpu_texture_init(void)
601 {
602  PyObject *submodule;
603  submodule = PyModule_Create(&pygpu_texture_module_def);
604 
605  return submodule;
606 }
607 
610 /* -------------------------------------------------------------------- */
614 PyObject *BPyGPUTexture_CreatePyObject(GPUTexture *tex, bool shared_reference)
615 {
616  BPyGPUTexture *self;
617 
618  if (shared_reference) {
619 #ifndef GPU_NO_USE_PY_REFERENCES
620  void **ref = GPU_texture_py_reference_get(tex);
621  if (ref) {
622  /* Retrieve BPyGPUTexture reference. */
623  self = (BPyGPUTexture *)POINTER_OFFSET(ref, -offsetof(BPyGPUTexture, tex));
624  BLI_assert(self->tex == tex);
625  Py_INCREF(self);
626  return (PyObject *)self;
627  }
628 #endif
629 
631  }
632 
633  self = PyObject_New(BPyGPUTexture, &BPyGPUTexture_Type);
634  self->tex = tex;
635 
636 #ifndef GPU_NO_USE_PY_REFERENCES
638  GPU_texture_py_reference_set(tex, (void **)&self->tex);
639 #endif
640 
641  return (PyObject *)self;
642 }
643 
646 #undef BPYGPU_TEXTURE_CHECK_OBJ
typedef float(TangentPoint)[2]
struct GPUTexture * BKE_image_get_gpu_texture(struct Image *image, struct ImageUser *iuser, struct ImBuf *ibuf)
Definition: image_gpu.cc:438
void BKE_imageuser_default(struct ImageUser *iuser)
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE int max_ii(int a, int b)
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
#define UNUSED(x)
#define UNLIKELY(x)
#define ELEM(...)
#define POINTER_OFFSET(v, ofs)
GPUContext * GPU_context_active_get(void)
Definition: gpu_context.cc:142
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
GPUTexture * GPU_texture_create_2d_array(const char *name, int w, int h, int d, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:297
GPUTexture * GPU_texture_create_1d_array(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:284
void GPU_texture_py_reference_set(GPUTexture *tex, void **py_ref)
Definition: gpu_texture.cc:675
void ** GPU_texture_py_reference_get(GPUTexture *tex)
Definition: gpu_texture.cc:670
int GPU_texture_height(const GPUTexture *tex)
Definition: gpu_texture.cc:607
GPUTexture * GPU_texture_create_1d(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:278
void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
Definition: gpu_texture.cc:438
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
int GPU_texture_width(const GPUTexture *tex)
Definition: gpu_texture.cc:602
void * GPU_texture_read(GPUTexture *tex, eGPUDataFormat data_format, int miplvl)
Definition: gpu_texture.cc:432
eGPUDataFormat
Definition: GPU_texture.h:170
@ GPU_DATA_UINT_24_8
Definition: GPU_texture.h:175
@ GPU_DATA_INT
Definition: GPU_texture.h:172
@ GPU_DATA_10_11_11_REV
Definition: GPU_texture.h:176
@ GPU_DATA_UBYTE
Definition: GPU_texture.h:174
@ GPU_DATA_UINT
Definition: GPU_texture.h:173
@ GPU_DATA_FLOAT
Definition: GPU_texture.h:171
void GPU_texture_ref(GPUTexture *tex)
Definition: gpu_texture.cc:578
void GPU_texture_free(GPUTexture *tex)
Definition: gpu_texture.cc:564
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:291
eGPUTextureFormat
Definition: GPU_texture.h:83
@ GPU_R16UI
Definition: GPU_texture.h:111
@ GPU_RG16F
Definition: GPU_texture.h:103
@ GPU_DEPTH32F_STENCIL8
Definition: GPU_texture.h:119
@ GPU_R16I
Definition: GPU_texture.h:112
@ GPU_SRGB8_A8
Definition: GPU_texture.h:121
@ GPU_DEPTH24_STENCIL8
Definition: GPU_texture.h:120
@ GPU_R32I
Definition: GPU_texture.h:109
@ GPU_RG8UI
Definition: GPU_texture.h:95
@ GPU_R16F
Definition: GPU_texture.h:113
@ GPU_SRGB8_A8_DXT5
Definition: GPU_texture.h:151
@ GPU_RG8I
Definition: GPU_texture.h:96
@ GPU_RG16I
Definition: GPU_texture.h:102
@ GPU_RG32UI
Definition: GPU_texture.h:98
@ GPU_RGBA32F
Definition: GPU_texture.h:90
@ GPU_RG8
Definition: GPU_texture.h:97
@ GPU_RG32I
Definition: GPU_texture.h:99
@ GPU_SRGB8_A8_DXT1
Definition: GPU_texture.h:149
@ GPU_RG16
Definition: GPU_texture.h:104
@ GPU_RGBA32UI
Definition: GPU_texture.h:88
@ GPU_R8I
Definition: GPU_texture.h:106
@ GPU_R16
Definition: GPU_texture.h:114
@ GPU_RG16UI
Definition: GPU_texture.h:101
@ GPU_RGBA8I
Definition: GPU_texture.h:86
@ GPU_RGBA8_DXT1
Definition: GPU_texture.h:152
@ GPU_RGBA8UI
Definition: GPU_texture.h:85
@ GPU_RGBA16UI
Definition: GPU_texture.h:91
@ GPU_RGBA16I
Definition: GPU_texture.h:92
@ GPU_R8UI
Definition: GPU_texture.h:105
@ GPU_RGBA16
Definition: GPU_texture.h:94
@ GPU_SRGB8_A8_DXT3
Definition: GPU_texture.h:150
@ GPU_RGBA8_DXT3
Definition: GPU_texture.h:153
@ GPU_RG32F
Definition: GPU_texture.h:100
@ GPU_R8
Definition: GPU_texture.h:107
@ GPU_DEPTH_COMPONENT24
Definition: GPU_texture.h:166
@ GPU_RGB16F
Definition: GPU_texture.h:127
@ GPU_R32UI
Definition: GPU_texture.h:108
@ GPU_RGBA32I
Definition: GPU_texture.h:89
@ GPU_RGBA8_DXT5
Definition: GPU_texture.h:154
@ GPU_DEPTH_COMPONENT32F
Definition: GPU_texture.h:165
@ GPU_DEPTH_COMPONENT16
Definition: GPU_texture.h:167
@ GPU_R11F_G11F_B10F
Definition: GPU_texture.h:118
@ GPU_RGBA8
Definition: GPU_texture.h:87
GPUTexture * GPU_texture_create_3d(const char *name, int w, int h, int d, int mip_len, eGPUTextureFormat texture_format, eGPUDataFormat data_format, const void *data)
Definition: gpu_texture.cc:309
eGPUTextureFormat GPU_texture_format(const GPUTexture *tex)
Definition: gpu_texture.cc:639
GPUTexture * GPU_texture_create_cube(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:322
size_t GPU_texture_component_len(eGPUTextureFormat format)
Definition: gpu_texture.cc:717
GPUTexture * GPU_texture_create_cube_array(const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:329
PyObject * self
Definition: bpy_driver.c:165
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
int len
Definition: draw_manager.c:108
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img GPU_RGBA16F
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx GPU_R32F
struct PyC_StringEnumItems bpygpu_dataformat_items[]
Definition: gpu_py.c:38
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
Definition: gpu_py.h:14
BPyGPUBuffer * BPyGPU_Buffer_CreatePyObject(const int format, const Py_ssize_t *shape, const int shape_len, void *buffer)
PyTypeObject BPyGPU_BufferType
size_t bpygpu_Buffer_size(BPyGPUBuffer *buffer)
#define BPYGPU_USE_GPUOBJ_FREE_METHOD
static PyObject * pygpu_texture_read(BPyGPUTexture *self)
static PyObject * pygpu_texture_format_get(BPyGPUTexture *self, void *UNUSED(type))
PyTypeObject BPyGPUTexture_Type
static PyObject * pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds)
static struct PyMethodDef pygpu_texture__m_methods[]
static struct PyMethodDef pygpu_texture__tp_methods[]
PyObject * bpygpu_texture_init(void)
static const struct PyC_StringEnumItems pygpu_textureformat_items[]
static void BPyGPUTexture__tp_dealloc(BPyGPUTexture *self)
static PyObject * pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObject *kwds)
PyObject * BPyGPUTexture_CreatePyObject(GPUTexture *tex, bool shared_reference)
static int pygpu_texture_valid_check(BPyGPUTexture *bpygpu_tex)
static PyGetSetDef pygpu_texture__tp_getseters[]
static PyObject * pygpu_texture_width_get(BPyGPUTexture *self, void *UNUSED(type))
PyDoc_STRVAR(pygpu_texture_width_doc, "Width of the texture.\n\n:type: `int`")
#define BPYGPU_TEXTURE_CHECK_OBJ(bpygpu)
int bpygpu_ParseTexture(PyObject *o, void *p)
static PyObject * pygpu_texture_from_image(PyObject *UNUSED(self), PyObject *arg)
static PyObject * pygpu_texture_height_get(BPyGPUTexture *self, void *UNUSED(type))
static PyModuleDef pygpu_texture_module_def
struct BPyGPUTexture BPyGPUTexture
#define BPyGPUTexture_Check(v)
format
Definition: logImageCore.h:38
static unsigned c
Definition: RandGen.cpp:83
int PyC_ParseStringEnum(PyObject *o, void *p)
void * PyC_RNA_AsPointer(PyObject *value, const char *type_name)
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 struct PyC_StringEnumItems *items, const int value)
void * as_void
Definition: gpu_py_buffer.h:32
union BPyGPUBuffer::@1155 buf
PyObject_HEAD struct GPUTexture * tex