Blender  V2.93
GPU_texture.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 #include "BLI_utildefines.h"
27 
28 #include "GPU_state.h"
29 
30 struct GPUVertBuf;
31 
33 typedef struct GPUTexture GPUTexture;
34 
35 /* GPU Samplers state
36  * - Specify the sampler state to bind a texture with.
37  * - Internally used by textures.
38  * - All states are created at startup to avoid runtime costs.
39  */
40 typedef enum eGPUSamplerState {
42  GPU_SAMPLER_FILTER = (1 << 0),
43  GPU_SAMPLER_MIPMAP = (1 << 1),
47  GPU_SAMPLER_CLAMP_BORDER = (1 << 5), /* Clamp to border color instead of border texel. */
48  GPU_SAMPLER_COMPARE = (1 << 6),
49  GPU_SAMPLER_ANISO = (1 << 7),
50  GPU_SAMPLER_ICON = (1 << 8),
51 
54 
55 /* `GPU_SAMPLER_MAX` is not a valid enum value, but only a limit.
56  * It also creates a bad mask for the `NOT` operator in `ENUM_OPERATORS`.
57  */
58 static const int GPU_SAMPLER_MAX = (GPU_SAMPLER_ICON + 1);
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 void GPU_samplers_update(void);
66 
67 /* GPU Texture
68  * - always returns unsigned char RGBA textures
69  * - if texture with non square dimensions is created, depending on the
70  * graphics card capabilities the texture may actually be stored in a
71  * larger texture with power of two dimensions.
72  * - can use reference counting:
73  * - reference counter after GPU_texture_create is 1
74  * - GPU_texture_ref increases by one
75  * - GPU_texture_free decreases by one, and frees if 0
76  * - if created with from_blender, will not free the texture
77  */
78 
79 /* Wrapper to supported OpenGL/Vulkan texture internal storage
80  * If you need a type just un-comment it. Be aware that some formats
81  * are not supported by render-buffers. All of the following formats
82  * are part of the OpenGL 3.3 core
83  * specification. */
84 typedef enum eGPUTextureFormat {
85  /* Formats texture & render-buffer. */
115  GPU_R16, /* Max texture buffer format. */
116 
117  /* Special formats texture & renderbuffer */
123 #if 0
124  GPU_RGB10_A2UI,
125 #endif
126 
127  /* Texture only format */
129 #if 0
130  GPU_RGBA16_SNORM,
131  GPU_RGBA8_SNORM,
132  GPU_RGB32F,
133  GPU_RGB32I,
134  GPU_RGB32UI,
135  GPU_RGB16_SNORM,
136  GPU_RGB16I,
137  GPU_RGB16UI,
138  GPU_RGB16,
139  GPU_RGB8_SNORM,
140  GPU_RGB8,
141  GPU_RGB8I,
142  GPU_RGB8UI,
143  GPU_RG16_SNORM,
144  GPU_RG8_SNORM,
145  GPU_R16_SNORM,
146  GPU_R8_SNORM,
147 #endif
148 
149  /* Special formats texture only */
156 #if 0
157  GPU_SRGB8,
158  GPU_RGB9_E5,
159  GPU_COMPRESSED_RG_RGTC2,
160  GPU_COMPRESSED_SIGNED_RG_RGTC2,
161  GPU_COMPRESSED_RED_RGTC1,
162  GPU_COMPRESSED_SIGNED_RED_RGTC1,
163 #endif
164 
165  /* Depth Formats */
170 
171 typedef enum eGPUDataFormat {
180 
181 unsigned int GPU_texture_memory_usage_get(void);
182 
190  const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data);
192  const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data);
194  const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data);
196  const char *name, int w, int h, int d, int mip_len, eGPUTextureFormat format, const float *data);
197 GPUTexture *GPU_texture_create_3d(const char *name,
198  int w,
199  int h,
200  int d,
201  int mip_len,
202  eGPUTextureFormat texture_format,
203  eGPUDataFormat data_format,
204  const void *data);
206  const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data);
208  const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data);
209 
210 /* Special textures. */
211 GPUTexture *GPU_texture_create_from_vertbuf(const char *name, struct GPUVertBuf *vert);
216  const char *name, int w, int h, int miplen, eGPUTextureFormat format, const void *data);
217 GPUTexture *GPU_texture_create_error(int dimension, bool array);
218 
220  int miplvl,
221  eGPUDataFormat gpu_data_format,
222  const void *pixels);
223 
224 void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data);
226  eGPUDataFormat data_format,
227  const void *pixels,
228  int offset_x,
229  int offset_y,
230  int offset_z,
231  int width,
232  int height,
233  int depth);
235 
236 void *GPU_texture_read(GPUTexture *tex, eGPUDataFormat data_format, int miplvl);
237 void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data);
238 
240 
242 void GPU_texture_bind(GPUTexture *tex, int unit);
243 void GPU_texture_bind_ex(GPUTexture *tex, eGPUSamplerState state, int unit, const bool set_number);
245 void GPU_texture_unbind_all(void);
246 
247 void GPU_texture_image_bind(GPUTexture *tex, int unit);
250 
251 void GPU_texture_copy(GPUTexture *dst, GPUTexture *src);
252 
254 void GPU_texture_anisotropic_filter(GPUTexture *tex, bool use_aniso);
255 void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare);
256 void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter);
257 void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter);
258 void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp);
259 void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4]);
260 
261 int GPU_texture_width(const GPUTexture *tex);
262 int GPU_texture_height(const GPUTexture *tex);
265 void GPU_texture_orig_size_set(GPUTexture *tex, int w, int h);
267 bool GPU_texture_array(const GPUTexture *tex);
268 bool GPU_texture_cube(const GPUTexture *tex);
269 bool GPU_texture_depth(const GPUTexture *tex);
270 bool GPU_texture_stencil(const GPUTexture *tex);
271 bool GPU_texture_integer(const GPUTexture *tex);
273 
274 void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *size);
275 
276 /* utilities */
278 size_t GPU_texture_dataformat_size(eGPUDataFormat data_format);
279 
280 #ifdef __cplusplus
281 }
282 #endif
unsigned int uint
Definition: BLI_sys_types.h:83
#define ENUM_OPERATORS(_type, _max)
_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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
void GPU_texture_unbind_all(void)
Definition: gpu_texture.cc:427
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:256
bool GPU_texture_cube(const GPUTexture *tex)
Definition: gpu_texture.cc:574
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:243
eGPUSamplerState
Definition: GPU_texture.h:40
@ GPU_SAMPLER_REPEAT_S
Definition: GPU_texture.h:44
@ GPU_SAMPLER_ANISO
Definition: GPU_texture.h:49
@ GPU_SAMPLER_REPEAT
Definition: GPU_texture.h:52
@ GPU_SAMPLER_MIPMAP
Definition: GPU_texture.h:43
@ GPU_SAMPLER_ICON
Definition: GPU_texture.h:50
@ GPU_SAMPLER_FILTER
Definition: GPU_texture.h:42
@ GPU_SAMPLER_COMPARE
Definition: GPU_texture.h:48
@ GPU_SAMPLER_REPEAT_T
Definition: GPU_texture.h:45
@ GPU_SAMPLER_CLAMP_BORDER
Definition: GPU_texture.h:47
@ GPU_SAMPLER_DEFAULT
Definition: GPU_texture.h:41
@ GPU_SAMPLER_REPEAT_R
Definition: GPU_texture.h:46
void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4])
Definition: gpu_texture.cc:503
void GPU_texture_image_bind(GPUTexture *tex, int unit)
Definition: gpu_texture.cc:432
void GPU_texture_copy(GPUTexture *dst, GPUTexture *src)
Definition: gpu_texture.cc:453
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:356
void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp)
Definition: gpu_texture.cc:496
size_t GPU_texture_dataformat_size(eGPUDataFormat data_format)
Definition: gpu_texture.cc:621
void GPU_texture_update_mipmap(GPUTexture *tex, int miplvl, eGPUDataFormat gpu_data_format, const void *pixels)
Definition: gpu_texture.cc:345
int GPU_texture_height(const GPUTexture *tex)
Definition: gpu_texture.cc:532
GPUTexture * GPU_texture_create_1d(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:237
void GPU_texture_bind_ex(GPUTexture *tex, eGPUSamplerState state, int unit, const bool set_number)
void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
Definition: gpu_texture.cc:384
struct GPUTexture GPUTexture
Definition: GPU_texture.h:33
GPUTexture * GPU_texture_create_from_vertbuf(const char *name, struct GPUVertBuf *vert)
Definition: gpu_texture.cc:315
void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter)
Definition: gpu_texture.cc:477
int GPU_texture_width(const GPUTexture *tex)
Definition: gpu_texture.cc:527
void GPU_texture_image_unbind_all(void)
Definition: gpu_texture.cc:442
void GPU_texture_image_unbind(GPUTexture *tex)
Definition: gpu_texture.cc:437
void * GPU_texture_read(GPUTexture *tex, eGPUDataFormat data_format, int miplvl)
Definition: gpu_texture.cc:371
eGPUDataFormat
Definition: GPU_texture.h:171
@ GPU_DATA_UINT_24_8
Definition: GPU_texture.h:176
@ GPU_DATA_INT
Definition: GPU_texture.h:173
@ GPU_DATA_10_11_11_REV
Definition: GPU_texture.h:177
@ GPU_DATA_UBYTE
Definition: GPU_texture.h:175
@ GPU_DATA_UINT
Definition: GPU_texture.h:174
@ GPU_DATA_2_10_10_10_REV
Definition: GPU_texture.h:178
@ GPU_DATA_FLOAT
Definition: GPU_texture.h:172
int GPU_texture_opengl_bindcode(const GPUTexture *tex)
Definition: gpu_texture.cc:585
bool GPU_texture_integer(const GPUTexture *tex)
Definition: gpu_texture.cc:569
bool GPU_texture_array(const GPUTexture *tex)
Definition: gpu_texture.cc:579
void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *size)
Definition: gpu_texture.cc:590
void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
Definition: gpu_texture.cc:391
void GPU_texture_ref(GPUTexture *tex)
Definition: gpu_texture.cc:522
void GPU_texture_free(GPUTexture *tex)
Definition: gpu_texture.cc:508
unsigned int GPU_texture_memory_usage_get(void)
Definition: gpu_texture.cc:187
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
Definition: gpu_texture.cc:468
void GPU_texture_unbind(GPUTexture *tex)
Definition: gpu_texture.cc:421
static const int GPU_SAMPLER_MAX
Definition: GPU_texture.h:58
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:250
void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare)
Definition: gpu_texture.cc:460
GPUTexture * GPU_texture_create_compressed_2d(const char *name, int w, int h, int miplen, eGPUTextureFormat format, const void *data)
Definition: gpu_texture.cc:290
eGPUTextureFormat
Definition: GPU_texture.h:84
@ GPU_R16UI
Definition: GPU_texture.h:112
@ GPU_RG16F
Definition: GPU_texture.h:104
@ GPU_DEPTH32F_STENCIL8
Definition: GPU_texture.h:120
@ GPU_R32F
Definition: GPU_texture.h:111
@ GPU_R16I
Definition: GPU_texture.h:113
@ GPU_SRGB8_A8
Definition: GPU_texture.h:122
@ GPU_DEPTH24_STENCIL8
Definition: GPU_texture.h:121
@ GPU_RGB10_A2
Definition: GPU_texture.h:118
@ GPU_R32I
Definition: GPU_texture.h:110
@ GPU_RG8UI
Definition: GPU_texture.h:96
@ GPU_R16F
Definition: GPU_texture.h:114
@ GPU_SRGB8_A8_DXT5
Definition: GPU_texture.h:152
@ GPU_RG8I
Definition: GPU_texture.h:97
@ GPU_RG16I
Definition: GPU_texture.h:103
@ GPU_RG32UI
Definition: GPU_texture.h:99
@ GPU_RGBA32F
Definition: GPU_texture.h:91
@ GPU_RGBA16F
Definition: GPU_texture.h:94
@ GPU_RG8
Definition: GPU_texture.h:98
@ GPU_RG32I
Definition: GPU_texture.h:100
@ GPU_SRGB8_A8_DXT1
Definition: GPU_texture.h:150
@ GPU_RG16
Definition: GPU_texture.h:105
@ GPU_RGBA32UI
Definition: GPU_texture.h:89
@ GPU_R8I
Definition: GPU_texture.h:107
@ GPU_R16
Definition: GPU_texture.h:115
@ GPU_RG16UI
Definition: GPU_texture.h:102
@ GPU_RGBA8I
Definition: GPU_texture.h:87
@ GPU_RGBA8_DXT1
Definition: GPU_texture.h:153
@ GPU_RGBA8UI
Definition: GPU_texture.h:86
@ GPU_RGBA16UI
Definition: GPU_texture.h:92
@ GPU_RGBA16I
Definition: GPU_texture.h:93
@ GPU_R8UI
Definition: GPU_texture.h:106
@ GPU_RGBA16
Definition: GPU_texture.h:95
@ GPU_SRGB8_A8_DXT3
Definition: GPU_texture.h:151
@ GPU_RGBA8_DXT3
Definition: GPU_texture.h:154
@ GPU_RG32F
Definition: GPU_texture.h:101
@ GPU_R8
Definition: GPU_texture.h:108
@ GPU_DEPTH_COMPONENT24
Definition: GPU_texture.h:167
@ GPU_RGB16F
Definition: GPU_texture.h:128
@ GPU_R32UI
Definition: GPU_texture.h:109
@ GPU_RGBA32I
Definition: GPU_texture.h:90
@ GPU_RGBA8_DXT5
Definition: GPU_texture.h:155
@ GPU_DEPTH_COMPONENT32F
Definition: GPU_texture.h:166
@ GPU_DEPTH_COMPONENT16
Definition: GPU_texture.h:168
@ GPU_R11F_G11F_B10F
Definition: GPU_texture.h:119
@ GPU_RGBA8
Definition: GPU_texture.h:88
bool GPU_texture_stencil(const GPUTexture *tex)
Definition: gpu_texture.cc:564
int GPU_texture_orig_width(const GPUTexture *tex)
Definition: gpu_texture.cc:537
void GPU_texture_orig_size_set(GPUTexture *tex, int w, int h)
Definition: gpu_texture.cc:547
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:263
eGPUTextureFormat GPU_texture_format(const GPUTexture *tex)
Definition: gpu_texture.cc:554
bool GPU_texture_depth(const GPUTexture *tex)
Definition: gpu_texture.cc:559
void GPU_unpack_row_length_set(uint len)
Definition: gpu_texture.cc:398
void GPU_samplers_update(void)
Definition: gpu_texture.cc:605
void GPU_texture_anisotropic_filter(GPUTexture *tex, bool use_aniso)
Definition: gpu_texture.cc:487
int GPU_texture_orig_height(const GPUTexture *tex)
Definition: gpu_texture.cc:542
GPUTexture * GPU_texture_create_cube(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:276
void GPU_texture_bind(GPUTexture *tex, int unit)
Definition: gpu_texture.cc:415
size_t GPU_texture_component_len(eGPUTextureFormat format)
Definition: gpu_texture.cc:616
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:282
GPUTexture * GPU_texture_create_error(int dimension, bool array)
Definition: gpu_texture.cc:329
void GPU_texture_generate_mipmap(GPUTexture *tex)
Definition: gpu_texture.cc:447
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
format
Definition: logImageCore.h:47
static ulong state[N]
uint len