Blender  V2.93
GPU_framebuffer.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 
31 #pragma once
32 
33 #include "GPU_texture.h"
34 
35 typedef enum eGPUFrameBufferBits {
36  GPU_COLOR_BIT = (1 << 0),
37  GPU_DEPTH_BIT = (1 << 1),
38  GPU_STENCIL_BIT = (1 << 2),
40 
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 typedef struct GPUAttachment {
48  struct GPUTexture *tex;
49  int layer, mip;
51 
52 typedef enum eGPUBackBuffer {
56 
58 typedef struct GPUFrameBuffer GPUFrameBuffer;
59 
60 typedef struct GPUOffScreen GPUOffScreen;
61 
62 GPUFrameBuffer *GPU_framebuffer_create(const char *name);
66 void GPU_framebuffer_restore(void);
67 
69 bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256]);
70 
73 
74 #define GPU_FRAMEBUFFER_FREE_SAFE(fb) \
75  do { \
76  if (fb != NULL) { \
77  GPU_framebuffer_free(fb); \
78  fb = NULL; \
79  } \
80  } while (0)
81 
82 /* Frame-buffer setup: You need to call #GPU_framebuffer_bind for these
83  * to be effective. */
84 
85 void GPU_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb, GPUAttachment attachment, int slot);
87 
107 #define GPU_framebuffer_ensure_config(_fb, ...) \
108  do { \
109  if (*(_fb) == NULL) { \
110  *(_fb) = GPU_framebuffer_create(#_fb); \
111  } \
112  GPUAttachment config[] = __VA_ARGS__; \
113  GPU_framebuffer_config_array(*(_fb), config, (sizeof(config) / sizeof(GPUAttachment))); \
114  } while (0)
115 
116 void GPU_framebuffer_config_array(GPUFrameBuffer *fb, const GPUAttachment *config, int config_len);
117 
118 #define GPU_ATTACHMENT_NONE \
119  { \
120  NULL, -1, 0, \
121  }
122 #define GPU_ATTACHMENT_LEAVE \
123  { \
124  NULL, -1, -1, \
125  }
126 #define GPU_ATTACHMENT_TEXTURE(_tex) \
127  { \
128  _tex, -1, 0, \
129  }
130 #define GPU_ATTACHMENT_TEXTURE_MIP(_tex, _mip) \
131  { \
132  _tex, -1, _mip, \
133  }
134 #define GPU_ATTACHMENT_TEXTURE_LAYER(_tex, _layer) \
135  { \
136  _tex, _layer, 0, \
137  }
138 #define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_tex, _layer, _mip) \
139  { \
140  _tex, _layer, _mip, \
141  }
142 #define GPU_ATTACHMENT_TEXTURE_CUBEFACE(_tex, _face) \
143  { \
144  _tex, _face, 0, \
145  }
146 #define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_tex, _face, _mip) \
147  { \
148  _tex, _face, _mip, \
149  }
150 
153  GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip);
155  GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip);
156 
157 /* Frame-buffer operations. */
158 
159 void GPU_framebuffer_viewport_set(GPUFrameBuffer *fb, int x, int y, int w, int h);
160 void GPU_framebuffer_viewport_get(GPUFrameBuffer *fb, int r_viewport[4]);
162 
164  eGPUFrameBufferBits buffers,
165  const float clear_col[4],
166  float clear_depth,
167  unsigned int clear_stencil);
168 
169 #define GPU_framebuffer_clear_color(fb, col) \
170  GPU_framebuffer_clear(fb, GPU_COLOR_BIT, col, 0.0f, 0x00)
171 
172 #define GPU_framebuffer_clear_depth(fb, depth) \
173  GPU_framebuffer_clear(fb, GPU_DEPTH_BIT, NULL, depth, 0x00)
174 
175 #define GPU_framebuffer_clear_color_depth(fb, col, depth) \
176  GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT, col, depth, 0x00)
177 
178 #define GPU_framebuffer_clear_stencil(fb, stencil) \
179  GPU_framebuffer_clear(fb, GPU_STENCIL_BIT, NULL, 0.0f, stencil)
180 
181 #define GPU_framebuffer_clear_depth_stencil(fb, depth, stencil) \
182  GPU_framebuffer_clear(fb, GPU_DEPTH_BIT | GPU_STENCIL_BIT, NULL, depth, stencil)
183 
184 #define GPU_framebuffer_clear_color_depth_stencil(fb, col, depth, stencil) \
185  GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT | GPU_STENCIL_BIT, col, depth, stencil)
186 
187 void GPU_framebuffer_multi_clear(GPUFrameBuffer *fb, const float (*clear_cols)[4]);
188 
190  GPUFrameBuffer *fb, int x, int y, int w, int h, eGPUDataFormat format, void *data);
192  int x,
193  int y,
194  int w,
195  int h,
196  int channels,
197  int slot,
199  void *data);
200 
202  int read_slot,
203  GPUFrameBuffer *fb_write,
204  int write_slot,
205  eGPUFrameBufferBits blit_buffers);
206 
208  int max_lvl,
209  void (*callback)(void *userData, int level),
210  void *userData);
211 
215 
216 /* GPU OffScreen
217  * - wrapper around frame-buffer and texture for simple off-screen drawing
218  */
219 
221  int width, int height, bool depth, bool high_bitdepth, char err_out[256]);
223 void GPU_offscreen_bind(GPUOffScreen *ofs, bool save);
224 void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore);
226 void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y);
227 int GPU_offscreen_width(const GPUOffScreen *ofs);
228 int GPU_offscreen_height(const GPUOffScreen *ofs);
230 
232  GPUFrameBuffer **r_fb,
233  struct GPUTexture **r_color,
234  struct GPUTexture **r_depth);
235 
236 void GPU_clear_color(float red, float green, float blue, float alpha);
237 void GPU_clear_depth(float depth);
238 
240  int x, int y, int w, int h, int channels, eGPUDataFormat format, void *data);
241 
243 
244 #ifdef __cplusplus
245 }
246 #endif
unsigned int uint
Definition: BLI_sys_types.h:83
#define ENUM_OPERATORS(_type, _max)
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)
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 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
_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 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:33
eGPUDataFormat
Definition: GPU_texture.h:171
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
DEGForeachIDComponentCallback callback
static CCL_NAMESPACE_BEGIN const double alpha
void GPU_framebuffer_clear(GPUFrameBuffer *gpu_fb, eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil)
uint GPU_framebuffer_stack_level_get(void)
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)
GPUFrameBuffer * GPU_framebuffer_pop(void)
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_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip)
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, eGPUDataFormat format, void *pixels)
void GPU_framebuffer_viewport_get(GPUFrameBuffer *gpu_fb, int r_viewport[4])
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)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool depth, bool high_bitdepth, char err_out[256])
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)
BLI_INLINE float fb(float length, float L)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
format
Definition: logImageCore.h:47
int save(ostream &out, const Vec3r &v)
Definition: ViewMapIO.cpp:542
struct GPUTexture * tex
GPUTexture * depth