Blender  V3.3
GPU_framebuffer.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 
15 #pragma once
16 
17 #include "GPU_common_types.h"
18 #include "GPU_texture.h"
19 
20 typedef enum eGPUFrameBufferBits {
21  GPU_COLOR_BIT = (1 << 0),
22  GPU_DEPTH_BIT = (1 << 1),
23  GPU_STENCIL_BIT = (1 << 2),
25 
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef struct GPUAttachment {
33  struct GPUTexture *tex;
34  int layer, mip;
36 
37 typedef enum eGPUBackBuffer {
41 
43 typedef struct GPUFrameBuffer GPUFrameBuffer;
44 
45 typedef struct GPUOffScreen GPUOffScreen;
46 
47 GPUFrameBuffer *GPU_framebuffer_create(const char *name);
54 void GPU_framebuffer_restore(void);
55 
56 /* Advanced binding control. */
57 typedef struct GPULoadStore {
61 #define NULL_LOAD_STORE \
62  { \
63  GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_DONT_CARE \
64  }
65 
66 /* Load store config array (load_store_actions) matches attachment structure of
67  * GPU_framebuffer_config_array. This allows us to explicitly specify whether attachment data needs
68  * to be loaded and stored on a per-attachment basis. This enables a number of bandwidth
69  * optimizations:
70  * - No need to load contents if subsequent work is over-writing every pixel.
71  * - No need to store attachments whose contents are not used beyond this pass e.g. depth buffer.
72  * - State can be customized at bind-time rather than applying to the frame-buffer object as a
73  * whole.
74  *
75  * Example:
76  * \code{.c}
77  * GPU_framebuffer_bind_loadstore(&fb, {
78  * {GPU_LOADACTION_LOAD, GPU_STOREACTION_DONT_CARE} // must be depth buffer
79  * {GPU_LOADACTION_LOAD, GPU_STOREACTION_STORE}, // Color attachment 0
80  * {GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_STORE}, // Color attachment 1
81  * {GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_STORE} // Color attachment 2
82  * })
83  * \encode
84  */
86  const GPULoadStore *load_store_actions,
87  uint actions_len);
88 #define GPU_framebuffer_bind_ex(_fb, ...) \
89  { \
90  GPULoadStore actions[] = __VA_ARGS__; \
91  GPU_framebuffer_bind_loadstore(_fb, actions, (sizeof(actions) / sizeof(GPULoadStore))); \
92  }
93 
95 bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256]);
96 
102 
103 #define GPU_FRAMEBUFFER_FREE_SAFE(fb) \
104  do { \
105  if (fb != NULL) { \
106  GPU_framebuffer_free(fb); \
107  fb = NULL; \
108  } \
109  } while (0)
110 
111 /* Frame-buffer setup: You need to call #GPU_framebuffer_bind for these
112  * to be effective. */
113 
114 void GPU_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb, GPUAttachment attachment, int slot);
116 
136 #define GPU_framebuffer_ensure_config(_fb, ...) \
137  do { \
138  if (*(_fb) == NULL) { \
139  *(_fb) = GPU_framebuffer_create(#_fb); \
140  } \
141  GPUAttachment config[] = __VA_ARGS__; \
142  GPU_framebuffer_config_array(*(_fb), config, (sizeof(config) / sizeof(GPUAttachment))); \
143  } while (0)
144 
151 void GPU_framebuffer_config_array(GPUFrameBuffer *fb, const GPUAttachment *config, int config_len);
152 
153 #define GPU_ATTACHMENT_NONE \
154  { \
155  NULL, -1, 0, \
156  }
157 #define GPU_ATTACHMENT_LEAVE \
158  { \
159  NULL, -1, -1, \
160  }
161 #define GPU_ATTACHMENT_TEXTURE(_tex) \
162  { \
163  _tex, -1, 0, \
164  }
165 #define GPU_ATTACHMENT_TEXTURE_MIP(_tex, _mip) \
166  { \
167  _tex, -1, _mip, \
168  }
169 #define GPU_ATTACHMENT_TEXTURE_LAYER(_tex, _layer) \
170  { \
171  _tex, _layer, 0, \
172  }
173 #define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_tex, _layer, _mip) \
174  { \
175  _tex, _layer, _mip, \
176  }
177 #define GPU_ATTACHMENT_TEXTURE_CUBEFACE(_tex, _face) \
178  { \
179  _tex, _face, 0, \
180  }
181 #define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_tex, _face, _mip) \
182  { \
183  _tex, _face, _mip, \
184  }
185 
188  GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip);
190  GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip);
191 
192 /* Frame-buffer operations. */
193 
199 void GPU_framebuffer_viewport_set(GPUFrameBuffer *fb, int x, int y, int w, int h);
200 void GPU_framebuffer_viewport_get(GPUFrameBuffer *fb, int r_viewport[4]);
205 
207  eGPUFrameBufferBits buffers,
208  const float clear_col[4],
209  float clear_depth,
210  unsigned int clear_stencil);
211 
212 #define GPU_framebuffer_clear_color(fb, col) \
213  GPU_framebuffer_clear(fb, GPU_COLOR_BIT, col, 0.0f, 0x00)
214 
215 #define GPU_framebuffer_clear_depth(fb, depth) \
216  GPU_framebuffer_clear(fb, GPU_DEPTH_BIT, NULL, depth, 0x00)
217 
218 #define GPU_framebuffer_clear_color_depth(fb, col, depth) \
219  GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT, col, depth, 0x00)
220 
221 #define GPU_framebuffer_clear_stencil(fb, stencil) \
222  GPU_framebuffer_clear(fb, GPU_STENCIL_BIT, NULL, 0.0f, stencil)
223 
224 #define GPU_framebuffer_clear_depth_stencil(fb, depth, stencil) \
225  GPU_framebuffer_clear(fb, GPU_DEPTH_BIT | GPU_STENCIL_BIT, NULL, depth, stencil)
226 
227 #define GPU_framebuffer_clear_color_depth_stencil(fb, col, depth, stencil) \
228  GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT | GPU_STENCIL_BIT, col, depth, stencil)
229 
233 void GPU_framebuffer_multi_clear(GPUFrameBuffer *fb, const float (*clear_cols)[4]);
234 
236  GPUFrameBuffer *fb, int x, int y, int w, int h, eGPUDataFormat format, void *data);
238  int x,
239  int y,
240  int w,
241  int h,
242  int channels,
243  int slot,
245  void *data);
246 
251  int read_slot,
252  GPUFrameBuffer *fb_write,
253  int write_slot,
254  eGPUFrameBufferBits blit_buffers);
255 
257  int max_lvl,
258  void (*callback)(void *userData, int level),
259  void *userData);
260 
261 #ifndef GPU_NO_USE_PY_REFERENCES
263 void GPU_framebuffer_py_reference_set(GPUFrameBuffer *gpu_fb, void **py_ref);
264 #endif
265 
269 
270 /* GPU OffScreen
271  * - wrapper around frame-buffer and texture for simple off-screen drawing
272  */
273 
275  int width, int height, bool depth, eGPUTextureFormat format, char err_out[256]);
277 void GPU_offscreen_bind(GPUOffScreen *ofs, bool save);
278 void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore);
280 void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y);
281 int GPU_offscreen_width(const GPUOffScreen *ofs);
282 int GPU_offscreen_height(const GPUOffScreen *ofs);
284 
289  GPUFrameBuffer **r_fb,
290  struct GPUTexture **r_color,
291  struct GPUTexture **r_depth);
292 
293 void GPU_clear_color(float red, float green, float blue, float alpha);
294 void GPU_clear_depth(float depth);
295 
297  int x, int y, int w, int h, int channels, eGPUDataFormat format, void *data);
298 
300 
301 #ifdef __cplusplus
302 }
303 #endif
unsigned int uint
Definition: BLI_sys_types.h:67
#define ENUM_OPERATORS(_type, _max)
eGPULoadOp
eGPUStoreOp
GPUFrameBuffer * GPU_framebuffer_back_get(void)
struct GPUFrameBuffer GPUFrameBuffer
void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *fb)
void GPU_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb, GPUAttachment attachment, int slot)
bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256])
void GPU_framebuffer_restore(void)
eGPUFrameBufferBits
@ GPU_DEPTH_BIT
@ GPU_STENCIL_BIT
@ GPU_COLOR_BIT
GPUFrameBuffer * GPU_framebuffer_active_get(void)
void GPU_framebuffer_free(GPUFrameBuffer *fb)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
eGPUBackBuffer
@ GPU_BACKBUFFER_LEFT
@ GPU_BACKBUFFER_RIGHT
struct GPUAttachment GPUAttachment
void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, struct GPUTexture *tex)
void GPU_framebuffer_bind_loadstore(GPUFrameBuffer *fb, const GPULoadStore *load_store_actions, uint actions_len)
struct GPULoadStore GPULoadStore
bool GPU_framebuffer_bound(GPUFrameBuffer *fb)
GPUFrameBuffer * GPU_framebuffer_create(const char *name)
_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 y
_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 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 blue
_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 green
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
eGPUDataFormat
Definition: GPU_texture.h:170
eGPUTextureFormat
Definition: GPU_texture.h:83
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its red
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its and blue channels(Deprecated)") DefNode(ShaderNode
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
DEGForeachIDComponentCallback callback
void GPU_framebuffer_clear(GPUFrameBuffer *gpu_fb, eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil)
void GPU_framebuffer_texture_layer_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip)
void GPU_framebuffer_config_array(GPUFrameBuffer *gpu_fb, const GPUAttachment *config, int config_len)
void GPU_framebuffer_multi_clear(GPUFrameBuffer *gpu_fb, const float(*clear_cols)[4])
void GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip)
void GPU_offscreen_free(GPUOffScreen *ofs)
void GPU_framebuffer_read_color(GPUFrameBuffer *gpu_fb, int x, int y, int w, int h, int channels, int slot, eGPUDataFormat format, void *data)
void GPU_offscreen_unbind(GPUOffScreen *UNUSED(ofs), bool restore)
void GPU_framebuffer_py_reference_set(GPUFrameBuffer *gpu_fb, void **py_ref)
void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool depth, eGPUTextureFormat format, char err_out[256])
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, eGPUDataFormat format, void *pixels)
void ** GPU_framebuffer_py_reference_get(GPUFrameBuffer *gpu_fb)
void GPU_framebuffer_viewport_get(GPUFrameBuffer *gpu_fb, int r_viewport[4])
uint GPU_framebuffer_stack_level_get()
void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *gpu_fb, int max_lvl, void(*callback)(void *userData, int level), void *userData)
void GPU_backbuffer_bind(eGPUBackBuffer buffer)
void GPU_clear_color(float red, float green, float blue, float alpha)
void GPU_offscreen_viewport_data_get(GPUOffScreen *ofs, GPUFrameBuffer **r_fb, GPUTexture **r_color, GPUTexture **r_depth)
void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y)
void GPU_frontbuffer_read_pixels(int x, int y, int w, int h, int channels, eGPUDataFormat format, void *data)
void GPU_framebuffer_push(GPUFrameBuffer *fb)
int GPU_offscreen_width(const GPUOffScreen *ofs)
void GPU_framebuffer_viewport_reset(GPUFrameBuffer *gpu_fb)
void GPU_framebuffer_blit(GPUFrameBuffer *gpufb_read, int read_slot, GPUFrameBuffer *gpufb_write, int write_slot, eGPUFrameBufferBits blit_buffers)
void GPU_clear_depth(float depth)
void GPU_offscreen_bind(GPUOffScreen *ofs, bool save)
GPUTexture * GPU_offscreen_color_texture(const GPUOffScreen *ofs)
void GPU_framebuffer_viewport_set(GPUFrameBuffer *gpu_fb, int x, int y, int width, int height)
int GPU_offscreen_height(const GPUOffScreen *ofs)
void GPU_framebuffer_read_depth(GPUFrameBuffer *gpu_fb, int x, int y, int w, int h, eGPUDataFormat format, void *data)
GPUFrameBuffer * GPU_framebuffer_pop()
BLI_INLINE float fb(float length, float L)
ccl_global float * buffer
format
Definition: logImageCore.h:38
struct GPUTexture * tex
eGPULoadOp load_action
eGPUStoreOp store_action