Blender  V3.3
GPU_texture.h
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 #pragma once
9 
10 #include "BLI_utildefines.h"
11 
12 #include "GPU_state.h"
13 
14 struct GPUVertBuf;
15 
17 typedef struct GPUTexture GPUTexture;
18 
25 typedef enum eGPUSamplerState {
27  GPU_SAMPLER_FILTER = (1 << 0),
28  GPU_SAMPLER_MIPMAP = (1 << 1),
32  GPU_SAMPLER_CLAMP_BORDER = (1 << 5), /* Clamp to border color instead of border texel. */
33  GPU_SAMPLER_COMPARE = (1 << 6),
34  GPU_SAMPLER_ANISO = (1 << 7),
35  GPU_SAMPLER_ICON = (1 << 8),
36 
39 
40 #define GPU_TEXTURE_FREE_SAFE(texture) \
41  do { \
42  if (texture != NULL) { \
43  GPU_texture_free(texture); \
44  texture = NULL; \
45  } \
46  } while (0)
47 
52 static const int GPU_SAMPLER_MAX = (GPU_SAMPLER_ICON + 1);
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
62 void GPU_samplers_update(void);
63 
64 /* GPU Texture
65  * - always returns unsigned char RGBA textures
66  * - if texture with non square dimensions is created, depending on the
67  * graphics card capabilities the texture may actually be stored in a
68  * larger texture with power of two dimensions.
69  * - can use reference counting:
70  * - reference counter after GPU_texture_create is 1
71  * - GPU_texture_ref increases by one
72  * - GPU_texture_free decreases by one, and frees if 0
73  * - if created with from_blender, will not free the texture
74  */
75 
83 typedef enum eGPUTextureFormat {
84  /* Formats texture & render-buffer. */
114  GPU_R16, /* Max texture buffer format. */
115 
116  /* Special formats texture & render-buffer. */
122 #if 0
123  GPU_RGB10_A2UI,
124 #endif
125 
126  /* Texture only format */
128 #if 0
129  GPU_RGBA16_SNORM,
130  GPU_RGBA8_SNORM,
131  GPU_RGB32F,
132  GPU_RGB32I,
133  GPU_RGB32UI,
134  GPU_RGB16_SNORM,
135  GPU_RGB16I,
136  GPU_RGB16UI,
137  GPU_RGB16,
138  GPU_RGB8_SNORM,
139  GPU_RGB8,
140  GPU_RGB8I,
141  GPU_RGB8UI,
142  GPU_RG16_SNORM,
143  GPU_RG8_SNORM,
144  GPU_R16_SNORM,
145  GPU_R8_SNORM,
146 #endif
147 
148  /* Special formats texture only */
155 #if 0
156  GPU_SRGB8,
157  GPU_RGB9_E5,
158  GPU_COMPRESSED_RG_RGTC2,
159  GPU_COMPRESSED_SIGNED_RG_RGTC2,
160  GPU_COMPRESSED_RED_RGTC1,
161  GPU_COMPRESSED_SIGNED_RED_RGTC1,
162 #endif
163 
164  /* Depth Formats */
169 
170 typedef enum eGPUDataFormat {
180 
181 typedef enum eGPUTextureUsage {
187 
189 
190 unsigned int GPU_texture_memory_usage_get(void);
191 
199  const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data);
201  const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data);
203  const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data);
204 GPUTexture *GPU_texture_create_2d_array(const char *name,
205  int w,
206  int h,
207  int d,
208  int mip_len,
210  const float *data);
211 GPUTexture *GPU_texture_create_3d(const char *name,
212  int w,
213  int h,
214  int d,
215  int mip_len,
216  eGPUTextureFormat texture_format,
217  eGPUDataFormat data_format,
218  const void *data);
220  const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data);
222  const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data);
223 
224 /* Special textures. */
225 
226 GPUTexture *GPU_texture_create_from_vertbuf(const char *name, struct GPUVertBuf *vert);
234  const char *name, int w, int h, int miplen, eGPUTextureFormat format, const void *data);
238 GPUTexture *GPU_texture_create_error(int dimension, bool array);
246 GPUTexture *GPU_texture_create_view(const char *name,
247  const GPUTexture *src,
249  int mip_start,
250  int mip_len,
251  int layer_start,
252  int layer_len,
253  bool cube_as_array);
254 
256  int miplvl,
257  eGPUDataFormat gpu_data_format,
258  const void *pixels);
259 
263 void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data);
265  eGPUDataFormat data_format,
266  const void *pixels,
267  int offset_x,
268  int offset_y,
269  int offset_z,
270  int width,
271  int height,
272  int depth);
278 
279 void *GPU_texture_read(GPUTexture *tex, eGPUDataFormat data_format, int miplvl);
288 void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data);
289 
291 
293 void GPU_texture_bind(GPUTexture *tex, int unit);
294 void GPU_texture_bind_ex(GPUTexture *tex, eGPUSamplerState state, int unit, bool set_number);
296 void GPU_texture_unbind_all(void);
297 
298 void GPU_texture_image_bind(GPUTexture *tex, int unit);
301 
306 
308 void GPU_texture_anisotropic_filter(GPUTexture *tex, bool use_aniso);
309 void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare);
310 void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter);
311 void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter);
312 void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp);
313 void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4]);
318 void GPU_texture_stencil_texture_mode_set(GPUTexture *tex, bool use_stencil);
319 
325 
326 int GPU_texture_width(const GPUTexture *tex);
327 int GPU_texture_height(const GPUTexture *tex);
332 void GPU_texture_orig_size_set(GPUTexture *tex, int w, int h);
334 bool GPU_texture_array(const GPUTexture *tex);
335 bool GPU_texture_cube(const GPUTexture *tex);
336 bool GPU_texture_depth(const GPUTexture *tex);
337 bool GPU_texture_stencil(const GPUTexture *tex);
338 bool GPU_texture_integer(const GPUTexture *tex);
339 
340 #ifndef GPU_NO_USE_PY_REFERENCES
342 void GPU_texture_py_reference_set(GPUTexture *tex, void **py_ref);
343 #endif
344 
346 
347 void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *size);
348 
349 /* Utilities. */
350 
352 size_t GPU_texture_dataformat_size(eGPUDataFormat data_format);
353 
354 #ifdef __cplusplus
355 }
356 #endif
unsigned int uint
Definition: BLI_sys_types.h:67
#define ENUM_OPERATORS(_type, _max)
_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 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
void GPU_texture_unbind_all(void)
Definition: gpu_texture.cc:478
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
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
eGPUSamplerState
Definition: GPU_texture.h:25
@ GPU_SAMPLER_REPEAT_S
Definition: GPU_texture.h:29
@ 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_ICON
Definition: GPU_texture.h:35
@ GPU_SAMPLER_FILTER
Definition: GPU_texture.h:27
@ GPU_SAMPLER_COMPARE
Definition: GPU_texture.h:33
@ GPU_SAMPLER_REPEAT_T
Definition: GPU_texture.h:30
@ GPU_SAMPLER_CLAMP_BORDER
Definition: GPU_texture.h:32
@ GPU_SAMPLER_DEFAULT
Definition: GPU_texture.h:26
@ GPU_SAMPLER_REPEAT_R
Definition: GPU_texture.h:31
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_image_bind(GPUTexture *tex, int unit)
Definition: gpu_texture.cc:483
void GPU_texture_bind_ex(GPUTexture *tex, eGPUSamplerState state, int unit, bool set_number)
void GPU_texture_copy(GPUTexture *dst, GPUTexture *src)
Definition: gpu_texture.cc:503
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_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp)
Definition: gpu_texture.cc:546
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_update_mipmap(GPUTexture *tex, int miplvl, eGPUDataFormat gpu_data_format, const void *pixels)
Definition: gpu_texture.cc:406
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
GPUTexture * GPU_texture_create_from_vertbuf(const char *name, struct GPUVertBuf *vert)
Definition: gpu_texture.cc:361
void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter)
Definition: gpu_texture.cc:527
int GPU_texture_width(const GPUTexture *tex)
Definition: gpu_texture.cc:602
void GPU_texture_image_unbind_all(void)
Definition: gpu_texture.cc:493
void GPU_texture_image_unbind(GPUTexture *tex)
Definition: gpu_texture.cc:488
void * GPU_texture_read(GPUTexture *tex, eGPUDataFormat data_format, int miplvl)
Definition: gpu_texture.cc:432
eGPUDataFormat
Definition: GPU_texture.h:170
@ GPU_DATA_HALF_FLOAT
Definition: GPU_texture.h:178
@ 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_2_10_10_10_REV
Definition: GPU_texture.h:177
@ GPU_DATA_FLOAT
Definition: GPU_texture.h:171
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_get_mipmap_size(GPUTexture *tex, int lvl, int *size)
Definition: gpu_texture.cc:688
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
void GPU_texture_free(GPUTexture *tex)
Definition: gpu_texture.cc:564
unsigned int GPU_texture_memory_usage_get(void)
Definition: gpu_texture.cc:227
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
Definition: gpu_texture.cc:518
eGPUTextureUsage
Definition: GPU_texture.h:181
@ GPU_TEXTURE_USAGE_SHADER_READ
Definition: GPU_texture.h:182
@ GPU_TEXTURE_USAGE_SHADER_WRITE
Definition: GPU_texture.h:183
@ GPU_TEXTURE_USAGE_ATTACHMENT
Definition: GPU_texture.h:184
@ GPU_TEXTURE_USAGE_GENERAL
Definition: GPU_texture.h:185
void GPU_texture_unbind(GPUTexture *tex)
Definition: gpu_texture.cc:472
int GPU_texture_layer_count(const GPUTexture *tex)
Definition: gpu_texture.cc:612
static const int GPU_SAMPLER_MAX
Definition: GPU_texture.h:52
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_compare_mode(GPUTexture *tex, bool use_compare)
Definition: gpu_texture.cc:510
GPUTexture * GPU_texture_create_compressed_2d(const char *name, int w, int h, int miplen, eGPUTextureFormat format, const void *data)
Definition: gpu_texture.cc:336
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_R32F
Definition: GPU_texture.h:110
@ GPU_R16I
Definition: GPU_texture.h:112
@ GPU_SRGB8_A8
Definition: GPU_texture.h:121
@ GPU_DEPTH24_STENCIL8
Definition: GPU_texture.h:120
@ GPU_RGB10_A2
Definition: GPU_texture.h:117
@ 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_RGBA16F
Definition: GPU_texture.h:93
@ 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
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
void GPU_texture_orig_size_set(GPUTexture *tex, int w, int h)
Definition: gpu_texture.cc:632
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
void GPU_samplers_update(void)
Definition: gpu_texture.cc:702
int GPU_texture_dimensions(const GPUTexture *tex)
Definition: gpu_texture.cc:583
void GPU_texture_anisotropic_filter(GPUTexture *tex, bool use_aniso)
Definition: gpu_texture.cc:537
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_bind(GPUTexture *tex, int unit)
Definition: gpu_texture.cc:466
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
GPUTexture * GPU_texture_create_error(int dimension, bool array)
Definition: gpu_texture.cc:374
void GPU_texture_generate_mipmap(GPUTexture *tex)
Definition: gpu_texture.cc:498
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
SyclQueue void void * src
int len
Definition: draw_manager.c:108
const int state
format
Definition: logImageCore.h:38