| 
									
										
										
										
											2022-02-11 09:07:11 +11:00
										 |  |  | /* SPDX-License-Identifier: GPL-2.0-or-later
 | 
					
						
							|  |  |  |  * Copyright 2005 Blender Foundation. All rights reserved. */ | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup gpu | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |  * GPU Frame-buffer | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |  * - this is a wrapper for an OpenGL framebuffer object (FBO). in practice | 
					
						
							|  |  |  |  *   multiple FBO's may be created. | 
					
						
							|  |  |  |  * - actual FBO creation & config is deferred until GPU_framebuffer_bind or | 
					
						
							|  |  |  |  *   GPU_framebuffer_check_valid to allow creation & config while another | 
					
						
							|  |  |  |  *   opengl context is bound (since FBOs are not shared between ogl contexts). | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-27 11:41:04 +02:00
										 |  |  | #include "GPU_common_types.h"
 | 
					
						
							| 
									
										
										
										
											2020-07-28 16:32:30 +02:00
										 |  |  | #include "GPU_texture.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 21:52:30 +02:00
										 |  |  | typedef enum eGPUFrameBufferBits { | 
					
						
							|  |  |  |   GPU_COLOR_BIT = (1 << 0), | 
					
						
							|  |  |  |   GPU_DEPTH_BIT = (1 << 1), | 
					
						
							|  |  |  |   GPU_STENCIL_BIT = (1 << 2), | 
					
						
							|  |  |  | } eGPUFrameBufferBits; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-01 23:51:01 +05:30
										 |  |  | ENUM_OPERATORS(eGPUFrameBufferBits, GPU_STENCIL_BIT) | 
					
						
							| 
									
										
										
										
											2020-09-03 21:52:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | typedef struct GPUAttachment { | 
					
						
							|  |  |  |   struct GPUTexture *tex; | 
					
						
							| 
									
										
										
										
											2020-07-25 18:40:19 +02:00
										 |  |  |   int layer, mip; | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | } GPUAttachment; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 21:22:39 +02:00
										 |  |  | typedef enum eGPUBackBuffer { | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |   GPU_BACKBUFFER_LEFT = 0, | 
					
						
							| 
									
										
										
										
											2020-07-17 21:22:39 +02:00
										 |  |  |   GPU_BACKBUFFER_RIGHT, | 
					
						
							|  |  |  | } eGPUBackBuffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  | /** Opaque type hiding blender::gpu::FrameBuffer. */ | 
					
						
							|  |  |  | typedef struct GPUFrameBuffer GPUFrameBuffer; | 
					
						
							| 
									
										
										
										
											2020-08-25 23:27:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | typedef struct GPUOffScreen GPUOffScreen; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-29 01:28:26 +02:00
										 |  |  | GPUFrameBuffer *GPU_framebuffer_create(const char *name); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | void GPU_framebuffer_free(GPUFrameBuffer *fb); | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | void GPU_framebuffer_bind(GPUFrameBuffer *fb); | 
					
						
							| 
									
										
										
										
											2022-10-30 14:56:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const char *GPU_framebuffer_get_name(GPUFrameBuffer *fb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Workaround for binding a SRGB frame-buffer without doing the SRGB transform. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-18 14:43:18 +02:00
										 |  |  | void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *fb); | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | void GPU_framebuffer_restore(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-27 11:41:04 +02:00
										 |  |  | /* Advanced binding control. */ | 
					
						
							|  |  |  | typedef struct GPULoadStore { | 
					
						
							|  |  |  |   eGPULoadOp load_action; | 
					
						
							|  |  |  |   eGPUStoreOp store_action; | 
					
						
							|  |  |  | } GPULoadStore; | 
					
						
							|  |  |  | #define NULL_LOAD_STORE \
 | 
					
						
							|  |  |  |   { \ | 
					
						
							|  |  |  |     GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_DONT_CARE \ | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Load store config array (load_store_actions) matches attachment structure of
 | 
					
						
							|  |  |  |  * GPU_framebuffer_config_array. This allows us to explicitly specify whether attachment data needs | 
					
						
							|  |  |  |  * to be loaded and stored on a per-attachment basis. This enables a number of bandwidth | 
					
						
							| 
									
										
										
										
											2022-06-29 09:40:16 +10:00
										 |  |  |  * optimizations: | 
					
						
							| 
									
										
										
										
											2022-06-27 11:41:04 +02:00
										 |  |  |  *  - No need to load contents if subsequent work is over-writing every pixel. | 
					
						
							|  |  |  |  *  - No need to store attachments whose contents are not used beyond this pass e.g. depth buffer. | 
					
						
							| 
									
										
										
										
											2022-06-29 09:40:16 +10:00
										 |  |  |  *  - State can be customized at bind-time rather than applying to the frame-buffer object as a | 
					
						
							| 
									
										
										
										
											2022-06-27 11:41:04 +02:00
										 |  |  |  * whole. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Example: | 
					
						
							|  |  |  |  * \code{.c} | 
					
						
							|  |  |  |  * GPU_framebuffer_bind_loadstore(&fb, { | 
					
						
							|  |  |  |  *         {GPU_LOADACTION_LOAD, GPU_STOREACTION_DONT_CARE} // must be depth buffer
 | 
					
						
							| 
									
										
										
										
											2022-06-29 09:40:16 +10:00
										 |  |  |  *         {GPU_LOADACTION_LOAD, GPU_STOREACTION_STORE}, // Color attachment 0
 | 
					
						
							|  |  |  |  *         {GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_STORE}, // Color attachment 1
 | 
					
						
							|  |  |  |  *         {GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_STORE} // Color attachment 2
 | 
					
						
							| 
									
										
										
										
											2022-06-27 11:41:04 +02:00
										 |  |  |  * }) | 
					
						
							|  |  |  |  * \encode | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void GPU_framebuffer_bind_loadstore(GPUFrameBuffer *fb, | 
					
						
							|  |  |  |                                     const GPULoadStore *load_store_actions, | 
					
						
							|  |  |  |                                     uint actions_len); | 
					
						
							|  |  |  | #define GPU_framebuffer_bind_ex(_fb, ...) \
 | 
					
						
							|  |  |  |   { \ | 
					
						
							|  |  |  |     GPULoadStore actions[] = __VA_ARGS__; \ | 
					
						
							|  |  |  |     GPU_framebuffer_bind_loadstore(_fb, actions, (sizeof(actions) / sizeof(GPULoadStore))); \ | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | bool GPU_framebuffer_bound(GPUFrameBuffer *fb); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-31 18:16:08 +02:00
										 |  |  | GPUFrameBuffer *GPU_framebuffer_active_get(void); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the default frame-buffer. Will always exists even if it's just a dummy. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | GPUFrameBuffer *GPU_framebuffer_back_get(void); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | #define GPU_FRAMEBUFFER_FREE_SAFE(fb) \
 | 
					
						
							|  |  |  |   do { \ | 
					
						
							|  |  |  |     if (fb != NULL) { \ | 
					
						
							|  |  |  |       GPU_framebuffer_free(fb); \ | 
					
						
							|  |  |  |       fb = NULL; \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  | /* Frame-buffer setup: You need to call #GPU_framebuffer_bind for these
 | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  |  * to be effective. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 10:04:50 +10:00
										 |  |  | void GPU_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb, GPUAttachment attachment, int slot); | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, struct GPUTexture *tex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2019-03-19 15:17:46 +11:00
										 |  |  |  * How to use #GPU_framebuffer_ensure_config(). | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-03-19 15:17:46 +11:00
										 |  |  |  * Example: | 
					
						
							|  |  |  |  * \code{.c} | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  |  * GPU_framebuffer_ensure_config(&fb, { | 
					
						
							|  |  |  |  *         GPU_ATTACHMENT_TEXTURE(depth), // must be depth buffer
 | 
					
						
							|  |  |  |  *         GPU_ATTACHMENT_TEXTURE(tex1), | 
					
						
							|  |  |  |  *         GPU_ATTACHMENT_TEXTURE_CUBEFACE(tex2, 0), | 
					
						
							|  |  |  |  *         GPU_ATTACHMENT_TEXTURE_LAYER_MIP(tex2, 0, 0) | 
					
						
							|  |  |  |  * }) | 
					
						
							| 
									
										
										
										
											2019-03-19 15:17:46 +11:00
										 |  |  |  * \encode | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-10 08:40:49 +02:00
										 |  |  |  * \note Unspecified attachments (i.e: those beyond the last | 
					
						
							| 
									
										
										
										
											2019-03-19 15:17:46 +11:00
										 |  |  |  * GPU_ATTACHMENT_* in GPU_framebuffer_ensure_config list) are left unchanged. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note Make sure that the dimensions of your textures matches | 
					
						
							|  |  |  |  * otherwise you will have an invalid framebuffer error. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | #define GPU_framebuffer_ensure_config(_fb, ...) \
 | 
					
						
							|  |  |  |   do { \ | 
					
						
							|  |  |  |     if (*(_fb) == NULL) { \ | 
					
						
							| 
									
										
										
										
											2020-08-29 01:28:26 +02:00
										 |  |  |       *(_fb) = GPU_framebuffer_create(#_fb); \ | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  |     } \ | 
					
						
							|  |  |  |     GPUAttachment config[] = __VA_ARGS__; \ | 
					
						
							|  |  |  |     GPU_framebuffer_config_array(*(_fb), config, (sizeof(config) / sizeof(GPUAttachment))); \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * First #GPUAttachment in *config is always the depth/depth_stencil buffer. | 
					
						
							|  |  |  |  * Following #GPUAttachments are color buffers. | 
					
						
							|  |  |  |  * Setting #GPUAttachment.mip to -1 will leave the texture in this slot. | 
					
						
							|  |  |  |  * Setting #GPUAttachment.tex to NULL will detach the texture in this slot. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-07-08 13:14:49 +02:00
										 |  |  | void GPU_framebuffer_config_array(GPUFrameBuffer *fb, const GPUAttachment *config, int config_len); | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define GPU_ATTACHMENT_NONE \
 | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   { \ | 
					
						
							| 
									
										
										
										
											2020-07-27 00:08:48 +02:00
										 |  |  |     NULL, -1, 0, \ | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | #define GPU_ATTACHMENT_LEAVE \
 | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   { \ | 
					
						
							| 
									
										
										
										
											2020-07-27 00:08:48 +02:00
										 |  |  |     NULL, -1, -1, \ | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | #define GPU_ATTACHMENT_TEXTURE(_tex) \
 | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   { \ | 
					
						
							| 
									
										
										
										
											2020-07-27 00:08:48 +02:00
										 |  |  |     _tex, -1, 0, \ | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | #define GPU_ATTACHMENT_TEXTURE_MIP(_tex, _mip) \
 | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   { \ | 
					
						
							| 
									
										
										
										
											2020-07-27 00:08:48 +02:00
										 |  |  |     _tex, -1, _mip, \ | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | #define GPU_ATTACHMENT_TEXTURE_LAYER(_tex, _layer) \
 | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   { \ | 
					
						
							| 
									
										
										
										
											2020-07-27 00:08:48 +02:00
										 |  |  |     _tex, _layer, 0, \ | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | #define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_tex, _layer, _mip) \
 | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   { \ | 
					
						
							| 
									
										
										
										
											2020-07-27 00:08:48 +02:00
										 |  |  |     _tex, _layer, _mip, \ | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | #define GPU_ATTACHMENT_TEXTURE_CUBEFACE(_tex, _face) \
 | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   { \ | 
					
						
							| 
									
										
										
										
											2020-07-27 00:08:48 +02:00
										 |  |  |     _tex, _face, 0, \ | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | #define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_tex, _face, _mip) \
 | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   { \ | 
					
						
							| 
									
										
										
										
											2020-07-27 00:08:48 +02:00
										 |  |  |     _tex, _face, _mip, \ | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-30 19:07:49 +02:00
										 |  |  | void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip); | 
					
						
							|  |  |  | void GPU_framebuffer_texture_layer_attach( | 
					
						
							|  |  |  |     GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip); | 
					
						
							|  |  |  | void GPU_framebuffer_texture_cubeface_attach( | 
					
						
							|  |  |  |     GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip); | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-17 10:17:38 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Default size is used if the framebuffer contains no attachments. | 
					
						
							|  |  |  |  * It needs to be re-specified each time an attachment is added. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void GPU_framebuffer_default_size(GPUFrameBuffer *gpu_fb, int width, int height); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  | /* Frame-buffer operations. */ | 
					
						
							| 
									
										
										
										
											2018-03-25 14:18:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Viewport and scissor size is stored per frame-buffer. | 
					
						
							|  |  |  |  * It is only reset to its original dimensions explicitly OR when binding the frame-buffer after | 
					
						
							|  |  |  |  * modifying its attachments. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-03-25 14:18:39 +02:00
										 |  |  | void GPU_framebuffer_viewport_set(GPUFrameBuffer *fb, int x, int y, int w, int h); | 
					
						
							| 
									
										
										
										
											2020-08-29 15:17:13 +02:00
										 |  |  | void GPU_framebuffer_viewport_get(GPUFrameBuffer *fb, int r_viewport[4]); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Reset to its attachment(s) size. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-29 15:17:13 +02:00
										 |  |  | void GPU_framebuffer_viewport_reset(GPUFrameBuffer *fb); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 14:18:39 +02:00
										 |  |  | void GPU_framebuffer_clear(GPUFrameBuffer *fb, | 
					
						
							| 
									
										
										
										
											2019-01-23 14:15:43 +11:00
										 |  |  |                            eGPUFrameBufferBits buffers, | 
					
						
							| 
									
										
										
										
											2018-03-25 14:18:39 +02:00
										 |  |  |                            const float clear_col[4], | 
					
						
							|  |  |  |                            float clear_depth, | 
					
						
							|  |  |  |                            unsigned int clear_stencil); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GPU_framebuffer_clear_color(fb, col) \
 | 
					
						
							|  |  |  |   GPU_framebuffer_clear(fb, GPU_COLOR_BIT, col, 0.0f, 0x00) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GPU_framebuffer_clear_depth(fb, depth) \
 | 
					
						
							|  |  |  |   GPU_framebuffer_clear(fb, GPU_DEPTH_BIT, NULL, depth, 0x00) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GPU_framebuffer_clear_color_depth(fb, col, depth) \
 | 
					
						
							|  |  |  |   GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT, col, depth, 0x00) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GPU_framebuffer_clear_stencil(fb, stencil) \
 | 
					
						
							|  |  |  |   GPU_framebuffer_clear(fb, GPU_STENCIL_BIT, NULL, 0.0f, stencil) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GPU_framebuffer_clear_depth_stencil(fb, depth, stencil) \
 | 
					
						
							|  |  |  |   GPU_framebuffer_clear(fb, GPU_DEPTH_BIT | GPU_STENCIL_BIT, NULL, depth, stencil) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GPU_framebuffer_clear_color_depth_stencil(fb, col, depth, stencil) \
 | 
					
						
							|  |  |  |   GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT | GPU_STENCIL_BIT, col, depth, stencil) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Clear all textures attached to this frame-buffer with a different color. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-03-09 16:27:24 +01:00
										 |  |  | void GPU_framebuffer_multi_clear(GPUFrameBuffer *fb, const float (*clear_cols)[4]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 21:08:31 +02:00
										 |  |  | void GPU_framebuffer_read_depth( | 
					
						
							|  |  |  |     GPUFrameBuffer *fb, int x, int y, int w, int h, eGPUDataFormat format, void *data); | 
					
						
							| 
									
										
										
										
											2020-07-16 02:50:55 +02:00
										 |  |  | void GPU_framebuffer_read_color(GPUFrameBuffer *fb, | 
					
						
							|  |  |  |                                 int x, | 
					
						
							|  |  |  |                                 int y, | 
					
						
							|  |  |  |                                 int w, | 
					
						
							|  |  |  |                                 int h, | 
					
						
							|  |  |  |                                 int channels, | 
					
						
							|  |  |  |                                 int slot, | 
					
						
							|  |  |  |                                 eGPUDataFormat format, | 
					
						
							|  |  |  |                                 void *data); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Read_slot and write_slot are only used for color buffers. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-02-15 15:15:42 +01:00
										 |  |  | void GPU_framebuffer_blit(GPUFrameBuffer *fb_read, | 
					
						
							|  |  |  |                           int read_slot, | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  |                           GPUFrameBuffer *fb_write, | 
					
						
							|  |  |  |                           int write_slot, | 
					
						
							| 
									
										
										
										
											2019-01-23 14:15:43 +11:00
										 |  |  |                           eGPUFrameBufferBits blit_buffers); | 
					
						
							| 
									
										
										
										
											2017-02-15 15:15:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-22 02:01:58 +02:00
										 |  |  | void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *fb, | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  |                                           int max_lvl, | 
					
						
							| 
									
										
										
										
											2017-06-22 02:01:58 +02:00
										 |  |  |                                           void (*callback)(void *userData, int level), | 
					
						
							|  |  |  |                                           void *userData); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-30 11:20:39 -03:00
										 |  |  | #ifndef GPU_NO_USE_PY_REFERENCES
 | 
					
						
							| 
									
										
										
										
											2021-04-29 14:48:59 -03:00
										 |  |  | void **GPU_framebuffer_py_reference_get(GPUFrameBuffer *gpu_fb); | 
					
						
							|  |  |  | void GPU_framebuffer_py_reference_set(GPUFrameBuffer *gpu_fb, void **py_ref); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  | void GPU_framebuffer_push(GPUFrameBuffer *fb); | 
					
						
							|  |  |  | GPUFrameBuffer *GPU_framebuffer_pop(void); | 
					
						
							|  |  |  | uint GPU_framebuffer_stack_level_get(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | /* GPU OffScreen
 | 
					
						
							| 
									
										
										
										
											2020-09-02 09:58:26 +10:00
										 |  |  |  * - wrapper around frame-buffer and texture for simple off-screen drawing | 
					
						
							| 
									
										
										
										
											2018-03-25 17:46:48 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | GPUOffScreen *GPU_offscreen_create( | 
					
						
							| 
									
										
										
										
											2021-08-16 11:46:09 +09:00
										 |  |  |     int width, int height, bool depth, eGPUTextureFormat format, char err_out[256]); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | void GPU_offscreen_free(GPUOffScreen *ofs); | 
					
						
							|  |  |  | void GPU_offscreen_bind(GPUOffScreen *ofs, bool save); | 
					
						
							|  |  |  | void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore); | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  | void GPU_offscreen_read_pixels(GPUOffScreen *ofs, eGPUDataFormat format, void *pixels); | 
					
						
							| 
									
										
										
										
											2018-04-27 10:22:37 +02:00
										 |  |  | void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | int GPU_offscreen_width(const GPUOffScreen *ofs); | 
					
						
							|  |  |  | int GPU_offscreen_height(const GPUOffScreen *ofs); | 
					
						
							| 
									
										
										
										
											2018-02-13 18:18:04 +01:00
										 |  |  | struct GPUTexture *GPU_offscreen_color_texture(const GPUOffScreen *ofs); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * \note only to be used by viewport code! | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-05-03 02:50:29 +10:00
										 |  |  | void GPU_offscreen_viewport_data_get(GPUOffScreen *ofs, | 
					
						
							|  |  |  |                                      GPUFrameBuffer **r_fb, | 
					
						
							|  |  |  |                                      struct GPUTexture **r_color, | 
					
						
							|  |  |  |                                      struct GPUTexture **r_depth); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 15:17:31 -06:00
										 |  |  | void GPU_clear_color(float red, float green, float blue, float alpha); | 
					
						
							| 
									
										
										
										
											2019-06-17 20:28:27 +02:00
										 |  |  | void GPU_clear_depth(float depth); | 
					
						
							| 
									
										
										
										
											2018-06-26 15:17:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-16 02:50:55 +02:00
										 |  |  | void GPU_frontbuffer_read_pixels( | 
					
						
							|  |  |  |     int x, int y, int w, int h, int channels, eGPUDataFormat format, void *data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 21:22:39 +02:00
										 |  |  | void GPU_backbuffer_bind(eGPUBackBuffer buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |