Blender  V3.3
gpu_texture.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #include "BLI_string.h"
9 
10 #include "GPU_framebuffer.h"
11 #include "GPU_texture.h"
12 
13 #include "gpu_backend.hh"
14 #include "gpu_context_private.hh"
16 
17 #include "gpu_texture_private.hh"
18 
19 namespace blender::gpu {
20 
21 /* -------------------------------------------------------------------- */
25 Texture::Texture(const char *name)
26 {
27  if (name) {
28  BLI_strncpy(name_, name, sizeof(name_));
29  }
30  else {
31  name_[0] = '\0';
32  }
33 
34  for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
35  fb_[i] = nullptr;
36  }
37 }
38 
40 {
41  for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
42  if (fb_[i] != nullptr) {
44  }
45  }
46 
47 #ifndef GPU_NO_USE_PY_REFERENCES
48  if (this->py_ref) {
49  *this->py_ref = nullptr;
50  }
51 #endif
52 }
53 
54 bool Texture::init_1D(int w, int layers, int mip_len, eGPUTextureFormat format)
55 {
56  w_ = w;
57  h_ = layers;
58  d_ = 0;
59  int mip_len_max = 1 + floorf(log2f(w));
60  mipmaps_ = min_ii(mip_len, mip_len_max);
61  format_ = format;
63  type_ = (layers > 0) ? GPU_TEXTURE_1D_ARRAY : GPU_TEXTURE_1D;
66  }
67  return this->init_internal();
68 }
69 
70 bool Texture::init_2D(int w, int h, int layers, int mip_len, eGPUTextureFormat format)
71 {
72  w_ = w;
73  h_ = h;
74  d_ = layers;
75  int mip_len_max = 1 + floorf(log2f(max_ii(w, h)));
76  mipmaps_ = min_ii(mip_len, mip_len_max);
77  format_ = format;
79  type_ = (layers > 0) ? GPU_TEXTURE_2D_ARRAY : GPU_TEXTURE_2D;
82  }
83  return this->init_internal();
84 }
85 
86 bool Texture::init_3D(int w, int h, int d, int mip_len, eGPUTextureFormat format)
87 {
88  w_ = w;
89  h_ = h;
90  d_ = d;
91  int mip_len_max = 1 + floorf(log2f(max_iii(w, h, d)));
92  mipmaps_ = min_ii(mip_len, mip_len_max);
93  format_ = format;
98  }
99  return this->init_internal();
100 }
101 
102 bool Texture::init_cubemap(int w, int layers, int mip_len, eGPUTextureFormat format)
103 {
104  w_ = w;
105  h_ = w;
106  d_ = max_ii(1, layers) * 6;
107  int mip_len_max = 1 + floorf(log2f(w));
108  mipmaps_ = min_ii(mip_len, mip_len_max);
109  format_ = format;
111  type_ = (layers > 0) ? GPU_TEXTURE_CUBE_ARRAY : GPU_TEXTURE_CUBE;
114  }
115  return this->init_internal();
116 }
117 
119 {
120  /* See to_texture_format(). */
121  if (format == GPU_DEPTH_COMPONENT24) {
122  return false;
123  }
125  h_ = 0;
126  d_ = 0;
127  format_ = format;
130  return this->init_internal(vbo);
131 }
132 
135  int mip_start,
136  int mip_len,
137  int layer_start,
138  int layer_len,
139  bool cube_as_array)
140 {
141  const Texture *src = unwrap(src_);
142  w_ = src->w_;
143  h_ = src->h_;
144  d_ = src->d_;
145  layer_start = min_ii(layer_start, src->layer_count() - 1);
146  layer_len = min_ii(layer_len, (src->layer_count() - layer_start));
147  switch (src->type_) {
149  h_ = layer_len;
150  break;
152  BLI_assert(layer_len % 6 == 0);
155  d_ = layer_len;
156  break;
157  default:
158  BLI_assert(layer_len == 1 && layer_start == 0);
159  break;
160  }
161  mip_start = min_ii(mip_start, src->mipmaps_ - 1);
162  mip_len = min_ii(mip_len, (src->mipmaps_ - mip_start));
163  mipmaps_ = mip_len;
164  format_ = format;
166  /* For now always copy the target. Target aliasing could be exposed later. */
167  type_ = src->type_;
168  if (cube_as_array) {
171  }
172  sampler_state = src->sampler_state;
173  return this->init_internal(src_, mip_start, layer_start);
174 }
175 
178 /* -------------------------------------------------------------------- */
183 {
184  for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
185  if (fb_[i] == nullptr) {
186  fb_attachment_[i] = type;
187  fb_[i] = fb;
188  return;
189  }
190  }
191  BLI_assert_msg(0, "GPU: Error: Texture: Not enough attachment");
192 }
193 
195 {
196  for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
197  if (fb_[i] == fb) {
199  fb_[i] = nullptr;
200  return;
201  }
202  }
203  BLI_assert_msg(0, "GPU: Error: Texture: Framebuffer is not attached");
204 }
205 
207 {
208  int mip = 0;
209  int extent[3], offset[3] = {0, 0, 0};
210  this->mip_size_get(mip, extent);
211  this->update_sub(mip, offset, extent, format, data);
212 }
213 
216 } // namespace blender::gpu
217 
218 /* -------------------------------------------------------------------- */
222 using namespace blender;
223 using namespace blender::gpu;
224 
225 /* ------ Memory Management ------ */
226 
228 {
229  /* TODO(fclem): Do that inside the new Texture class. */
230  return 0;
231 }
232 
233 /* ------ Creation ------ */
234 
235 static inline GPUTexture *gpu_texture_create(const char *name,
236  const int w,
237  const int h,
238  const int d,
239  const eGPUTextureType type,
240  int mip_len,
241  eGPUTextureFormat tex_format,
242  eGPUDataFormat data_format,
243  const void *pixels)
244 {
245  BLI_assert(mip_len > 0);
247  bool success = false;
248  switch (type) {
249  case GPU_TEXTURE_1D:
251  success = tex->init_1D(w, h, mip_len, tex_format);
252  break;
253  case GPU_TEXTURE_2D:
255  success = tex->init_2D(w, h, d, mip_len, tex_format);
256  break;
257  case GPU_TEXTURE_3D:
258  success = tex->init_3D(w, h, d, mip_len, tex_format);
259  break;
260  case GPU_TEXTURE_CUBE:
262  success = tex->init_cubemap(w, d, mip_len, tex_format);
263  break;
264  default:
265  break;
266  }
267 
268  if (!success) {
269  delete tex;
270  return nullptr;
271  }
272  if (pixels) {
273  tex->update(data_format, pixels);
274  }
275  return reinterpret_cast<GPUTexture *>(tex);
276 }
277 
279  const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
280 {
281  return gpu_texture_create(name, w, 0, 0, GPU_TEXTURE_1D, mip_len, format, GPU_DATA_FLOAT, data);
282 }
283 
285  const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
286 {
287  return gpu_texture_create(
288  name, w, h, 0, GPU_TEXTURE_1D_ARRAY, mip_len, format, GPU_DATA_FLOAT, data);
289 }
290 
292  const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
293 {
294  return gpu_texture_create(name, w, h, 0, GPU_TEXTURE_2D, mip_len, format, GPU_DATA_FLOAT, data);
295 }
296 
298  int w,
299  int h,
300  int d,
301  int mip_len,
303  const float *data)
304 {
305  return gpu_texture_create(
306  name, w, h, d, GPU_TEXTURE_2D_ARRAY, mip_len, format, GPU_DATA_FLOAT, data);
307 }
308 
310  int w,
311  int h,
312  int d,
313  int mip_len,
314  eGPUTextureFormat texture_format,
315  eGPUDataFormat data_format,
316  const void *data)
317 {
318  return gpu_texture_create(
319  name, w, h, d, GPU_TEXTURE_3D, mip_len, texture_format, data_format, data);
320 }
321 
323  const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
324 {
325  return gpu_texture_create(
326  name, w, w, 0, GPU_TEXTURE_CUBE, mip_len, format, GPU_DATA_FLOAT, data);
327 }
328 
330  const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data)
331 {
332  return gpu_texture_create(
333  name, w, w, d, GPU_TEXTURE_CUBE_ARRAY, mip_len, format, GPU_DATA_FLOAT, data);
334 }
335 
337  const char *name, int w, int h, int miplen, eGPUTextureFormat tex_format, const void *data)
338 {
340  bool success = tex->init_2D(w, h, 0, miplen, tex_format);
341 
342  if (!success) {
343  delete tex;
344  return nullptr;
345  }
346  if (data) {
347  size_t ofs = 0;
348  for (int mip = 0; mip < miplen; mip++) {
349  int extent[3], offset[3] = {0, 0, 0};
350  tex->mip_size_get(mip, extent);
351 
352  size_t size = ((extent[0] + 3) / 4) * ((extent[1] + 3) / 4) * to_block_size(tex_format);
353  tex->update_sub(mip, offset, extent, to_data_format(tex_format), (uchar *)data + ofs);
354 
355  ofs += size;
356  }
357  }
358  return reinterpret_cast<GPUTexture *>(tex);
359 }
360 
362 {
365 
366  bool success = tex->init_buffer(vert, tex_format);
367  if (!success) {
368  delete tex;
369  return nullptr;
370  }
371  return reinterpret_cast<GPUTexture *>(tex);
372 }
373 
374 GPUTexture *GPU_texture_create_error(int dimension, bool is_array)
375 {
376  float pixel[4] = {1.0f, 0.0f, 1.0f, 1.0f};
377  int w = 1;
378  int h = (dimension < 2 && !is_array) ? 0 : 1;
379  int d = (dimension < 3 && !is_array) ? 0 : 1;
380 
382  type = (dimension == 2) ? (is_array ? GPU_TEXTURE_2D_ARRAY : GPU_TEXTURE_2D) : type;
383  type = (dimension == 1) ? (is_array ? GPU_TEXTURE_1D_ARRAY : GPU_TEXTURE_1D) : type;
384 
385  return gpu_texture_create("invalid_tex", w, h, d, type, 1, GPU_RGBA8, GPU_DATA_FLOAT, pixel);
386 }
387 
389  const GPUTexture *src,
391  int mip_start,
392  int mip_len,
393  int layer_start,
394  int layer_len,
395  bool cube_as_array)
396 {
397  BLI_assert(mip_len > 0);
398  BLI_assert(layer_len > 0);
400  view->init_view(src, format, mip_start, mip_len, layer_start, layer_len, cube_as_array);
401  return wrap(view);
402 }
403 
404 /* ------ Update ------ */
405 
407  int miplvl,
408  eGPUDataFormat data_format,
409  const void *pixels)
410 {
411  Texture *tex = reinterpret_cast<Texture *>(tex_);
412  int extent[3] = {1, 1, 1}, offset[3] = {0, 0, 0};
413  tex->mip_size_get(miplvl, extent);
414  reinterpret_cast<Texture *>(tex)->update_sub(miplvl, offset, extent, data_format, pixels);
415 }
416 
418  eGPUDataFormat data_format,
419  const void *pixels,
420  int offset_x,
421  int offset_y,
422  int offset_z,
423  int width,
424  int height,
425  int depth)
426 {
427  int offset[3] = {offset_x, offset_y, offset_z};
428  int extent[3] = {width, height, depth};
429  reinterpret_cast<Texture *>(tex)->update_sub(0, offset, extent, data_format, pixels);
430 }
431 
432 void *GPU_texture_read(GPUTexture *tex_, eGPUDataFormat data_format, int miplvl)
433 {
434  Texture *tex = reinterpret_cast<Texture *>(tex_);
435  return tex->read(miplvl, data_format);
436 }
437 
438 void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
439 {
440  BLI_assert(data != nullptr); /* Do not accept NULL as parameter. */
441  reinterpret_cast<Texture *>(tex)->clear(data_format, data);
442 }
443 
444 void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
445 {
446  reinterpret_cast<Texture *>(tex)->update(data_format, data);
447 }
448 
450 {
452 }
453 
454 /* ------ Binding ------ */
455 
458  int unit,
459  const bool UNUSED(set_number))
460 {
461  Texture *tex = reinterpret_cast<Texture *>(tex_);
462  state = (state >= GPU_SAMPLER_MAX) ? tex->sampler_state : state;
464 }
465 
466 void GPU_texture_bind(GPUTexture *tex_, int unit)
467 {
468  Texture *tex = reinterpret_cast<Texture *>(tex_);
469  Context::get()->state_manager->texture_bind(tex, tex->sampler_state, unit);
470 }
471 
473 {
474  Texture *tex = reinterpret_cast<Texture *>(tex_);
476 }
477 
479 {
481 }
482 
484 {
486 }
487 
489 {
491 }
492 
494 {
496 }
497 
499 {
500  reinterpret_cast<Texture *>(tex)->generate_mipmap();
501 }
502 
504 {
505  Texture *src = reinterpret_cast<Texture *>(src_);
506  Texture *dst = reinterpret_cast<Texture *>(dst_);
507  src->copy_to(dst);
508 }
509 
510 void GPU_texture_compare_mode(GPUTexture *tex_, bool use_compare)
511 {
512  Texture *tex = reinterpret_cast<Texture *>(tex_);
513  /* Only depth formats does support compare mode. */
514  BLI_assert(!(use_compare) || (tex->format_flag_get() & GPU_FORMAT_DEPTH));
515  SET_FLAG_FROM_TEST(tex->sampler_state, use_compare, GPU_SAMPLER_COMPARE);
516 }
517 
518 void GPU_texture_filter_mode(GPUTexture *tex_, bool use_filter)
519 {
520  Texture *tex = reinterpret_cast<Texture *>(tex_);
521  /* Stencil and integer format does not support filtering. */
522  BLI_assert(!(use_filter) ||
523  !(tex->format_flag_get() & (GPU_FORMAT_STENCIL | GPU_FORMAT_INTEGER)));
524  SET_FLAG_FROM_TEST(tex->sampler_state, use_filter, GPU_SAMPLER_FILTER);
525 }
526 
527 void GPU_texture_mipmap_mode(GPUTexture *tex_, bool use_mipmap, bool use_filter)
528 {
529  Texture *tex = reinterpret_cast<Texture *>(tex_);
530  /* Stencil and integer format does not support filtering. */
531  BLI_assert(!(use_filter || use_mipmap) ||
532  !(tex->format_flag_get() & (GPU_FORMAT_STENCIL | GPU_FORMAT_INTEGER)));
533  SET_FLAG_FROM_TEST(tex->sampler_state, use_mipmap, GPU_SAMPLER_MIPMAP);
534  SET_FLAG_FROM_TEST(tex->sampler_state, use_filter, GPU_SAMPLER_FILTER);
535 }
536 
537 void GPU_texture_anisotropic_filter(GPUTexture *tex_, bool use_aniso)
538 {
539  Texture *tex = reinterpret_cast<Texture *>(tex_);
540  /* Stencil and integer format does not support filtering. */
541  BLI_assert(!(use_aniso) ||
542  !(tex->format_flag_get() & (GPU_FORMAT_STENCIL | GPU_FORMAT_INTEGER)));
543  SET_FLAG_FROM_TEST(tex->sampler_state, use_aniso, GPU_SAMPLER_ANISO);
544 }
545 
546 void GPU_texture_wrap_mode(GPUTexture *tex_, bool use_repeat, bool use_clamp)
547 {
548  Texture *tex = reinterpret_cast<Texture *>(tex_);
549  SET_FLAG_FROM_TEST(tex->sampler_state, use_repeat, GPU_SAMPLER_REPEAT);
550  SET_FLAG_FROM_TEST(tex->sampler_state, !use_clamp, GPU_SAMPLER_CLAMP_BORDER);
551 }
552 
553 void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4])
554 {
555  reinterpret_cast<Texture *>(tex)->swizzle_set(swizzle);
556 }
557 
559 {
560  BLI_assert(GPU_texture_stencil(tex) || !use_stencil);
561  reinterpret_cast<Texture *>(tex)->stencil_texture_mode_set(use_stencil);
562 }
563 
565 {
566  Texture *tex = reinterpret_cast<Texture *>(tex_);
567  tex->refcount--;
568 
569  if (tex->refcount < 0) {
570  fprintf(stderr, "GPUTexture: negative refcount\n");
571  }
572 
573  if (tex->refcount == 0) {
574  delete tex;
575  }
576 }
577 
579 {
580  reinterpret_cast<Texture *>(tex)->refcount++;
581 }
582 
584 {
585  eGPUTextureType type = reinterpret_cast<const Texture *>(tex_)->type_get();
586  if (type & GPU_TEXTURE_1D) {
587  return 1;
588  }
589  if (type & GPU_TEXTURE_2D) {
590  return 2;
591  }
592  if (type & GPU_TEXTURE_3D) {
593  return 3;
594  }
595  if (type & GPU_TEXTURE_CUBE) {
596  return 2;
597  }
598  /* GPU_TEXTURE_BUFFER */
599  return 1;
600 }
601 
603 {
604  return reinterpret_cast<const Texture *>(tex)->width_get();
605 }
606 
608 {
609  return reinterpret_cast<const Texture *>(tex)->height_get();
610 }
611 
613 {
614  return reinterpret_cast<const Texture *>(tex)->layer_count();
615 }
616 
618 {
619  return reinterpret_cast<const Texture *>(tex)->mip_count();
620 }
621 
623 {
624  return reinterpret_cast<const Texture *>(tex)->src_w;
625 }
626 
628 {
629  return reinterpret_cast<const Texture *>(tex)->src_h;
630 }
631 
632 void GPU_texture_orig_size_set(GPUTexture *tex_, int w, int h)
633 {
634  Texture *tex = reinterpret_cast<Texture *>(tex_);
635  tex->src_w = w;
636  tex->src_h = h;
637 }
638 
640 {
641  return reinterpret_cast<const Texture *>(tex)->format_get();
642 }
643 
645 {
646  return (reinterpret_cast<const Texture *>(tex)->format_flag_get() & GPU_FORMAT_DEPTH) != 0;
647 }
648 
650 {
651  return (reinterpret_cast<const Texture *>(tex)->format_flag_get() & GPU_FORMAT_STENCIL) != 0;
652 }
653 
655 {
656  return (reinterpret_cast<const Texture *>(tex)->format_flag_get() & GPU_FORMAT_INTEGER) != 0;
657 }
658 
660 {
661  return (reinterpret_cast<const Texture *>(tex)->type_get() & GPU_TEXTURE_CUBE) != 0;
662 }
663 
665 {
666  return (reinterpret_cast<const Texture *>(tex)->type_get() & GPU_TEXTURE_ARRAY) != 0;
667 }
668 
669 #ifndef GPU_NO_USE_PY_REFERENCES
671 {
672  return unwrap(tex)->py_ref;
673 }
674 
676 {
677  BLI_assert(py_ref == nullptr || unwrap(tex)->py_ref == nullptr);
678  unwrap(tex)->py_ref = py_ref;
679 }
680 #endif
681 
682 /* TODO: remove. */
684 {
685  return reinterpret_cast<const Texture *>(tex)->gl_bindcode_get();
686 }
687 
688 void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *r_size)
689 {
690  return reinterpret_cast<Texture *>(tex)->mip_size_get(lvl, r_size);
691 }
692 
695 /* -------------------------------------------------------------------- */
703 {
704  /* Backend may not exist when we are updating preferences from background mode. */
705  GPUBackend *backend = GPUBackend::get();
706  if (backend) {
707  backend->samplers_update();
708  }
709 }
710 
713 /* -------------------------------------------------------------------- */
718 {
719  return to_component_len(tex_format);
720 }
721 
723 {
724  return to_bytesize(data_format);
725 }
726 
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
#define ATTR_FALLTHROUGH
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
MINLINE int max_iii(int a, int b, int c)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
unsigned char uchar
Definition: BLI_sys_types.h:70
unsigned int uint
Definition: BLI_sys_types.h:67
#define ARRAY_SIZE(arr)
#define UNUSED(x)
#define SET_FLAG_FROM_TEST(value, test, flag)
static AppView * view
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_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
_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 const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
eGPUSamplerState
Definition: GPU_texture.h:25
@ GPU_SAMPLER_ANISO
Definition: GPU_texture.h:34
@ GPU_SAMPLER_REPEAT
Definition: GPU_texture.h:37
@ GPU_SAMPLER_MIPMAP
Definition: GPU_texture.h:28
@ GPU_SAMPLER_FILTER
Definition: GPU_texture.h:27
@ GPU_SAMPLER_COMPARE
Definition: GPU_texture.h:33
@ GPU_SAMPLER_CLAMP_BORDER
Definition: GPU_texture.h:32
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
eGPUDataFormat
Definition: GPU_texture.h:170
@ GPU_DATA_FLOAT
Definition: GPU_texture.h:171
static const int GPU_SAMPLER_MAX
Definition: GPU_texture.h:52
eGPUTextureFormat
Definition: GPU_texture.h:83
@ GPU_DEPTH_COMPONENT24
Definition: GPU_texture.h:166
@ GPU_RGBA8
Definition: GPU_texture.h:87
const GPUVertFormat * GPU_vertbuf_get_format(const GPUVertBuf *verts)
uint GPU_vertbuf_get_vertex_len(const GPUVertBuf *verts)
struct GPUVertBuf GPUVertBuf
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
static Context * get()
Definition: gpu_context.cc:82
void attachment_remove(GPUAttachmentType type)
static GPUBackend * get()
Definition: gpu_context.cc:292
virtual Texture * texture_alloc(const char *name)=0
virtual void samplers_update()=0
virtual void texture_unbind_all()=0
virtual void texture_unbind(Texture *tex)=0
virtual void image_unbind_all()=0
virtual void image_unbind(Texture *tex)=0
virtual void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit)=0
virtual void image_bind(Texture *tex, int unit)=0
virtual void texture_unpack_row_length_set(uint len)=0
void attach_to(FrameBuffer *fb, GPUAttachmentType type)
Definition: gpu_texture.cc:182
eGPUTextureFormat format_
bool init_view(const GPUTexture *src, eGPUTextureFormat format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array)
Definition: gpu_texture.cc:133
eGPUTextureFormatFlag format_flag_
void update(eGPUDataFormat format, const void *data)
Definition: gpu_texture.cc:206
char name_[DEBUG_NAME_LEN]
FrameBuffer * fb_[GPU_TEX_MAX_FBO_ATTACHED]
bool init_buffer(GPUVertBuf *vbo, eGPUTextureFormat format)
Definition: gpu_texture.cc:118
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
bool init_1D(int w, int layers, int mip_len, eGPUTextureFormat format)
Definition: gpu_texture.cc:54
eGPUSamplerState sampler_state
virtual bool init_internal()=0
bool init_cubemap(int w, int layers, int mip_len, eGPUTextureFormat format)
Definition: gpu_texture.cc:102
virtual void update_sub(int mip, int offset[3], int extent[3], eGPUDataFormat format, const void *data)=0
void mip_size_get(int mip, int r_size[3]) const
bool init_3D(int w, int h, int d, int mip_len, eGPUTextureFormat format)
Definition: gpu_texture.cc:86
Texture(const char *name)
Definition: gpu_texture.cc:25
void detach_from(FrameBuffer *fb)
Definition: gpu_texture.cc:194
bool init_2D(int w, int h, int layers, int mip_len, eGPUTextureFormat format)
Definition: gpu_texture.cc:70
SyclQueue void void * src
int len
Definition: draw_manager.c:108
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
bool GPU_texture_cube(const GPUTexture *tex)
Definition: gpu_texture.cc:659
size_t GPU_texture_component_len(eGPUTextureFormat tex_format)
Definition: gpu_texture.cc:717
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_swizzle_set(GPUTexture *tex, const char swizzle[4])
Definition: gpu_texture.cc:553
void GPU_texture_compare_mode(GPUTexture *tex_, bool use_compare)
Definition: gpu_texture.cc:510
void GPU_texture_filter_mode(GPUTexture *tex_, bool use_filter)
Definition: gpu_texture.cc:518
void GPU_texture_image_bind(GPUTexture *tex, int unit)
Definition: gpu_texture.cc:483
void GPU_texture_bind_ex(GPUTexture *tex_, eGPUSamplerState state, int unit, const bool UNUSED(set_number))
Definition: gpu_texture.cc:456
void GPU_texture_update_sub(GPUTexture *tex, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
Definition: gpu_texture.cc:417
void ** GPU_texture_py_reference_get(GPUTexture *tex)
Definition: gpu_texture.cc:670
size_t GPU_texture_dataformat_size(eGPUDataFormat data_format)
Definition: gpu_texture.cc:722
void GPU_texture_image_unbind_all()
Definition: gpu_texture.cc:493
uint GPU_texture_memory_usage_get()
Definition: gpu_texture.cc:227
int GPU_texture_height(const GPUTexture *tex)
Definition: gpu_texture.cc:607
void GPU_texture_mipmap_mode(GPUTexture *tex_, bool use_mipmap, bool use_filter)
Definition: gpu_texture.cc:527
void GPU_texture_orig_size_set(GPUTexture *tex_, int w, int h)
Definition: gpu_texture.cc:632
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
GPUTexture * GPU_texture_create_error(int dimension, bool is_array)
Definition: gpu_texture.cc:374
void * GPU_texture_read(GPUTexture *tex_, eGPUDataFormat data_format, int miplvl)
Definition: gpu_texture.cc:432
void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *r_size)
Definition: gpu_texture.cc:688
int GPU_texture_dimensions(const GPUTexture *tex_)
Definition: gpu_texture.cc:583
static GPUTexture * gpu_texture_create(const char *name, const int w, const int h, const int d, const eGPUTextureType type, int mip_len, eGPUTextureFormat tex_format, eGPUDataFormat data_format, const void *pixels)
Definition: gpu_texture.cc:235
int GPU_texture_width(const GPUTexture *tex)
Definition: gpu_texture.cc:602
void GPU_texture_unbind(GPUTexture *tex_)
Definition: gpu_texture.cc:472
GPUTexture * GPU_texture_create_from_vertbuf(const char *name, GPUVertBuf *vert)
Definition: gpu_texture.cc:361
void GPU_texture_image_unbind(GPUTexture *tex)
Definition: gpu_texture.cc:488
int GPU_texture_mip_count(const GPUTexture *tex)
Definition: gpu_texture.cc:617
int GPU_texture_opengl_bindcode(const GPUTexture *tex)
Definition: gpu_texture.cc:683
bool GPU_texture_integer(const GPUTexture *tex)
Definition: gpu_texture.cc:654
bool GPU_texture_array(const GPUTexture *tex)
Definition: gpu_texture.cc:664
void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
Definition: gpu_texture.cc:444
GPUTexture * GPU_texture_create_view(const char *name, const GPUTexture *src, eGPUTextureFormat format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array)
Definition: gpu_texture.cc:388
void GPU_texture_ref(GPUTexture *tex)
Definition: gpu_texture.cc:578
int GPU_texture_layer_count(const GPUTexture *tex)
Definition: gpu_texture.cc:612
void GPU_texture_free(GPUTexture *tex_)
Definition: gpu_texture.cc:564
void GPU_texture_stencil_texture_mode_set(GPUTexture *tex, bool use_stencil)
Definition: gpu_texture.cc:558
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
void GPU_texture_bind(GPUTexture *tex_, int unit)
Definition: gpu_texture.cc:466
void GPU_texture_unbind_all()
Definition: gpu_texture.cc:478
bool GPU_texture_stencil(const GPUTexture *tex)
Definition: gpu_texture.cc:649
int GPU_texture_orig_width(const GPUTexture *tex)
Definition: gpu_texture.cc:622
GPUTexture * GPU_texture_create_compressed_2d(const char *name, int w, int h, int miplen, eGPUTextureFormat tex_format, const void *data)
Definition: gpu_texture.cc:336
void GPU_texture_anisotropic_filter(GPUTexture *tex_, bool use_aniso)
Definition: gpu_texture.cc:537
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
bool GPU_texture_depth(const GPUTexture *tex)
Definition: gpu_texture.cc:644
void GPU_unpack_row_length_set(uint len)
Definition: gpu_texture.cc:449
int GPU_texture_orig_height(const GPUTexture *tex)
Definition: gpu_texture.cc:627
GPUTexture * GPU_texture_create_cube(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:322
void GPU_texture_wrap_mode(GPUTexture *tex_, bool use_repeat, bool use_clamp)
Definition: gpu_texture.cc:546
void GPU_samplers_update()
Definition: gpu_texture.cc:702
void GPU_texture_update_mipmap(GPUTexture *tex_, int miplvl, eGPUDataFormat data_format, const void *pixels)
Definition: gpu_texture.cc:406
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
void GPU_texture_copy(GPUTexture *dst_, GPUTexture *src_)
Definition: gpu_texture.cc:503
void GPU_texture_generate_mipmap(GPUTexture *tex)
Definition: gpu_texture.cc:498
BLI_INLINE float fb(float length, float L)
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
const int state
format
Definition: logImageCore.h:38
#define floorf(x)
Definition: metal/compat.h:224
static void clear(Message *msg)
Definition: msgfmt.c:278
size_t to_block_size(eGPUTextureFormat data_type)
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
eGPUDataFormat to_data_format(eGPUTextureFormat tex_format)
static eGPUTextureFormat to_texture_format(const GPUVertFormat *format)
eGPUTextureFormatFlag to_format_flag(eGPUTextureFormat format)
static size_t to_bytesize(GPUIndexBufType type)
int to_component_len(eGPUTextureFormat format)
static void update(bNodeTree *ntree)