| 
									
										
										
										
											2016-10-13 04:22:28 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2006 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup gpu | 
					
						
							| 
									
										
										
										
											2016-10-13 04:22:28 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * System that manages viewport drawing. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | #include "BLI_listbase.h"
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | #include "BLI_math_vector.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:01:14 +02:00
										 |  |  | #include "BLI_memblock.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "BLI_rect.h"
 | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | #include "BKE_colortools.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "IMB_colormanagement.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-23 20:47:42 +02:00
										 |  |  | #include "DNA_userdef_types.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "DNA_vec_types.h"
 | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "GPU_framebuffer.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-21 20:50:00 +00:00
										 |  |  | #include "GPU_glew.h"
 | 
					
						
							|  |  |  | #include "GPU_immediate.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | #include "GPU_matrix.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-21 20:50:00 +00:00
										 |  |  | #include "GPU_texture.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-31 01:45:41 +02:00
										 |  |  | #include "GPU_uniformbuffer.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "GPU_viewport.h"
 | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "DRW_engine.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-13 04:22:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 19:49:19 +10:00
										 |  |  | static const int default_fbl_len = (sizeof(DefaultFramebufferList)) / sizeof(void *); | 
					
						
							|  |  |  | static const int default_txl_len = (sizeof(DefaultTextureList)) / sizeof(void *); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  | #define MAX_ENABLE_ENGINE 8
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | /* Maximum number of simultaneous engine enabled at the same time.
 | 
					
						
							|  |  |  |  * Setting it lower than the real number will do lead to | 
					
						
							|  |  |  |  * higher VRAM usage due to sub-efficient buffer reuse. */ | 
					
						
							|  |  |  | #define MAX_ENGINE_BUFFER_SHARING 5
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct ViewportTempTexture { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   struct ViewportTempTexture *next, *prev; | 
					
						
							|  |  |  |   void *user[MAX_ENGINE_BUFFER_SHARING]; | 
					
						
							|  |  |  |   GPUTexture *texture; | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | } ViewportTempTexture; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 04:22:28 +00:00
										 |  |  | struct GPUViewport { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   int size[2]; | 
					
						
							|  |  |  |   int flag; | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   /* Set the active view (for stereoscoptic viewport rendering). */ | 
					
						
							|  |  |  |   int active_view; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* If engine_handles mismatch we free all ViewportEngineData in this viewport. */ | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |   struct { | 
					
						
							|  |  |  |     void *handle; | 
					
						
							|  |  |  |     ViewportEngineData *data; | 
					
						
							|  |  |  |   } engine_data[MAX_ENABLE_ENGINE]; | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DefaultFramebufferList *fbl; | 
					
						
							|  |  |  |   DefaultTextureList *txl; | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ViewportMemoryPool vmempool;           /* Used for rendering data structure. */ | 
					
						
							|  |  |  |   struct DRWInstanceDataList *idatalist; /* Used for rendering data structure. */ | 
					
						
							| 
									
										
										
										
											2017-11-06 16:47:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   ListBase | 
					
						
							|  |  |  |       tex_pool; /* ViewportTempTexture list : Temporary textures shared across draw engines. */ | 
					
						
							| 
									
										
										
										
											2018-03-17 04:47:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   /* Profiling data. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   double cache_time; | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Color management. */ | 
					
						
							|  |  |  |   ColorManagedViewSettings view_settings; | 
					
						
							|  |  |  |   ColorManagedDisplaySettings display_settings; | 
					
						
							|  |  |  |   float dither; | 
					
						
							|  |  |  |   /* TODO(fclem) the uvimage display use the viewport but do not set any view transform for the
 | 
					
						
							|  |  |  |    * moment. The end goal would be to let the GPUViewport do the color management. */ | 
					
						
							|  |  |  |   bool do_color_management; | 
					
						
							| 
									
										
										
										
											2016-10-13 04:22:28 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 20:07:02 +02:00
										 |  |  | enum { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DO_UPDATE = (1 << 0), | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   GPU_VIEWPORT_STEREO = (1 << 1), | 
					
						
							| 
									
										
										
										
											2017-09-25 20:07:02 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | static void gpu_viewport_buffers_free( | 
					
						
							|  |  |  |     FramebufferList *fbl, int fbl_len, TextureList *txl, TextureList *txl_stereo, int txl_len); | 
					
						
							| 
									
										
										
										
											2017-04-12 20:23:30 +10:00
										 |  |  | static void gpu_viewport_storage_free(StorageList *stl, int stl_len); | 
					
						
							|  |  |  | static void gpu_viewport_passes_free(PassList *psl, int psl_len); | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | static void gpu_viewport_texture_pool_free(GPUViewport *viewport); | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 20:07:02 +02:00
										 |  |  | void GPU_viewport_tag_update(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   viewport->flag |= DO_UPDATE; | 
					
						
							| 
									
										
										
										
											2017-09-25 20:07:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GPU_viewport_do_update(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bool ret = (viewport->flag & DO_UPDATE); | 
					
						
							|  |  |  |   viewport->flag &= ~DO_UPDATE; | 
					
						
							|  |  |  |   return ret; | 
					
						
							| 
									
										
										
										
											2017-09-25 20:07:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 04:22:28 +00:00
										 |  |  | GPUViewport *GPU_viewport_create(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPUViewport *viewport = MEM_callocN(sizeof(GPUViewport), "GPUViewport"); | 
					
						
							|  |  |  |   viewport->fbl = MEM_callocN(sizeof(DefaultFramebufferList), "FramebufferList"); | 
					
						
							|  |  |  |   viewport->txl = MEM_callocN(sizeof(DefaultTextureList), "TextureList"); | 
					
						
							|  |  |  |   viewport->idatalist = DRW_instance_data_list_create(); | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   viewport->do_color_management = false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   viewport->size[0] = viewport->size[1] = -1; | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   viewport->active_view = -1; | 
					
						
							|  |  |  |   return viewport; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | GPUViewport *GPU_viewport_stereo_create(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GPUViewport *viewport = GPU_viewport_create(); | 
					
						
							|  |  |  |   viewport->flag = GPU_VIEWPORT_STEREO; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return viewport; | 
					
						
							| 
									
										
										
										
											2016-10-13 04:22:28 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | static void gpu_viewport_framebuffer_view_set(GPUViewport *viewport, int view) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* Early check if the view is the latest requested. */ | 
					
						
							|  |  |  |   if (viewport->active_view == view) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   DefaultFramebufferList *dfbl = viewport->fbl; | 
					
						
							|  |  |  |   DefaultTextureList *dtxl = viewport->txl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Only swap the texture when this is a Stereo Viewport. */ | 
					
						
							|  |  |  |   if (((viewport->flag & GPU_VIEWPORT_STEREO) != 0)) { | 
					
						
							|  |  |  |     SWAP(GPUTexture *, dtxl->color, dtxl->color_stereo); | 
					
						
							|  |  |  |     SWAP(GPUTexture *, dtxl->color_overlay, dtxl->color_overlay_stereo); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < MAX_ENABLE_ENGINE; i++) { | 
					
						
							|  |  |  |       if (viewport->engine_data[i].handle != NULL) { | 
					
						
							|  |  |  |         ViewportEngineData *data = viewport->engine_data[i].data; | 
					
						
							|  |  |  |         SWAP(StorageList *, data->stl, data->stl_stereo); | 
					
						
							|  |  |  |         SWAP(TextureList *, data->txl, data->txl_stereo); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_framebuffer_ensure_config(&dfbl->default_fb, | 
					
						
							|  |  |  |                                 { | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_TEXTURE(dtxl->depth), | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_TEXTURE(dtxl->color), | 
					
						
							|  |  |  |                                 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_framebuffer_ensure_config(&dfbl->overlay_fb, | 
					
						
							|  |  |  |                                 { | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_TEXTURE(dtxl->depth), | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_TEXTURE(dtxl->color_overlay), | 
					
						
							|  |  |  |                                 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_framebuffer_ensure_config(&dfbl->depth_only_fb, | 
					
						
							|  |  |  |                                 { | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_TEXTURE(dtxl->depth), | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_NONE, | 
					
						
							|  |  |  |                                 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_framebuffer_ensure_config(&dfbl->color_only_fb, | 
					
						
							|  |  |  |                                 { | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_NONE, | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_TEXTURE(dtxl->color), | 
					
						
							|  |  |  |                                 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_framebuffer_ensure_config(&dfbl->overlay_only_fb, | 
					
						
							|  |  |  |                                 { | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_NONE, | 
					
						
							|  |  |  |                                     GPU_ATTACHMENT_TEXTURE(dtxl->color_overlay), | 
					
						
							|  |  |  |                                 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (((viewport->flag & GPU_VIEWPORT_STEREO) != 0)) { | 
					
						
							|  |  |  |     GPU_framebuffer_ensure_config(&dfbl->stereo_comp_fb, | 
					
						
							|  |  |  |                                   { | 
					
						
							|  |  |  |                                       GPU_ATTACHMENT_NONE, | 
					
						
							|  |  |  |                                       GPU_ATTACHMENT_TEXTURE(dtxl->color), | 
					
						
							|  |  |  |                                       GPU_ATTACHMENT_TEXTURE(dtxl->color_overlay), | 
					
						
							|  |  |  |                                   }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     dfbl->stereo_comp_fb = NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   viewport->active_view = view; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-03 19:32:05 +02:00
										 |  |  | void *GPU_viewport_engine_data_create(GPUViewport *viewport, void *engine_type) | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ViewportEngineData *data = MEM_callocN(sizeof(ViewportEngineData), "ViewportEngineData"); | 
					
						
							|  |  |  |   int fbl_len, txl_len, psl_len, stl_len; | 
					
						
							| 
									
										
										
										
											2017-04-12 19:49:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DRW_engine_viewport_data_size_get(engine_type, &fbl_len, &txl_len, &psl_len, &stl_len); | 
					
						
							| 
									
										
										
										
											2017-04-12 19:49:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   data->engine_type = engine_type; | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   data->fbl = MEM_callocN((sizeof(void *) * fbl_len) + sizeof(FramebufferList), "FramebufferList"); | 
					
						
							|  |  |  |   data->txl = MEM_callocN((sizeof(void *) * txl_len) + sizeof(TextureList), "TextureList"); | 
					
						
							|  |  |  |   data->psl = MEM_callocN((sizeof(void *) * psl_len) + sizeof(PassList), "PassList"); | 
					
						
							|  |  |  |   data->stl = MEM_callocN((sizeof(void *) * stl_len) + sizeof(StorageList), "StorageList"); | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   if ((viewport->flag & GPU_VIEWPORT_STEREO) != 0) { | 
					
						
							|  |  |  |     data->txl_stereo = MEM_callocN((sizeof(void *) * txl_len) + sizeof(TextureList), | 
					
						
							|  |  |  |                                    "TextureList"); | 
					
						
							|  |  |  |     data->stl_stereo = MEM_callocN((sizeof(void *) * stl_len) + sizeof(StorageList), | 
					
						
							|  |  |  |                                    "StorageList"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |   for (int i = 0; i < MAX_ENABLE_ENGINE; i++) { | 
					
						
							|  |  |  |     if (viewport->engine_data[i].handle == NULL) { | 
					
						
							|  |  |  |       viewport->engine_data[i].handle = engine_type; | 
					
						
							|  |  |  |       viewport->engine_data[i].data = data; | 
					
						
							|  |  |  |       return data; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |   BLI_assert(!"Too many draw engines enabled at the same time"); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 20:23:30 +10:00
										 |  |  | static void gpu_viewport_engines_data_free(GPUViewport *viewport) | 
					
						
							| 
									
										
										
										
											2017-02-17 17:29:43 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   int fbl_len, txl_len, psl_len, stl_len; | 
					
						
							| 
									
										
										
										
											2017-04-12 19:49:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |   for (int i = 0; i < MAX_ENABLE_ENGINE && viewport->engine_data[i].handle; i++) { | 
					
						
							|  |  |  |     ViewportEngineData *data = viewport->engine_data[i].data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     DRW_engine_viewport_data_size_get(data->engine_type, &fbl_len, &txl_len, &psl_len, &stl_len); | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |     gpu_viewport_buffers_free(data->fbl, fbl_len, data->txl, data->txl_stereo, txl_len); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     gpu_viewport_passes_free(data->psl, psl_len); | 
					
						
							|  |  |  |     gpu_viewport_storage_free(data->stl, stl_len); | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     MEM_freeN(data->fbl); | 
					
						
							|  |  |  |     MEM_freeN(data->txl); | 
					
						
							|  |  |  |     MEM_freeN(data->psl); | 
					
						
							|  |  |  |     MEM_freeN(data->stl); | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |     if ((viewport->flag & GPU_VIEWPORT_STEREO) != 0) { | 
					
						
							|  |  |  |       gpu_viewport_storage_free(data->stl_stereo, stl_len); | 
					
						
							|  |  |  |       MEM_freeN(data->txl_stereo); | 
					
						
							|  |  |  |       MEM_freeN(data->stl_stereo); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     /* We could handle this in the DRW module */ | 
					
						
							|  |  |  |     if (data->text_draw_cache) { | 
					
						
							|  |  |  |       extern void DRW_text_cache_destroy(struct DRWTextStore * dt); | 
					
						
							|  |  |  |       DRW_text_cache_destroy(data->text_draw_cache); | 
					
						
							|  |  |  |       data->text_draw_cache = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-28 04:33:58 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     MEM_freeN(data); | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |     /* Mark as unused*/ | 
					
						
							|  |  |  |     viewport->engine_data[i].handle = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   gpu_viewport_texture_pool_free(viewport); | 
					
						
							| 
									
										
										
										
											2017-02-17 17:29:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  | void *GPU_viewport_engine_data_get(GPUViewport *viewport, void *engine_handle) | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |   BLI_assert(engine_handle != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (int i = 0; i < MAX_ENABLE_ENGINE; i++) { | 
					
						
							|  |  |  |     if (viewport->engine_data[i].handle == engine_handle) { | 
					
						
							|  |  |  |       return viewport->engine_data[i].data; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-17 17:29:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 16:47:23 +01:00
										 |  |  | ViewportMemoryPool *GPU_viewport_mempool_get(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return &viewport->vmempool; | 
					
						
							| 
									
										
										
										
											2017-11-06 16:47:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-09 14:09:14 +01:00
										 |  |  | struct DRWInstanceDataList *GPU_viewport_instance_data_list_get(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return viewport->idatalist; | 
					
						
							| 
									
										
										
										
											2018-01-09 14:09:14 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | /* Note this function is only allowed to be called from `DRW_notify_view_update`. The rest
 | 
					
						
							|  |  |  |  * should bind the correct viewport. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The reason is that DRW_notify_view_update can be called from a different thread, but needs | 
					
						
							|  |  |  |  * access to the engine data. */ | 
					
						
							|  |  |  | void GPU_viewport_active_view_set(GPUViewport *viewport, int view) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   gpu_viewport_framebuffer_view_set(viewport, view); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | void *GPU_viewport_framebuffer_list_get(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return viewport->fbl; | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void *GPU_viewport_texture_list_get(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return viewport->txl; | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-26 04:39:25 +10:00
										 |  |  | void GPU_viewport_size_get(const GPUViewport *viewport, int size[2]) | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   copy_v2_v2_int(size, viewport->size); | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-26 04:39:25 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Special case, this is needed for when we have a viewport without a frame-buffer output | 
					
						
							| 
									
										
										
										
											2019-04-22 01:45:43 +10:00
										 |  |  |  * (occlusion queries for eg) | 
					
						
							|  |  |  |  * but still need to set the size since it may be used for other calculations. | 
					
						
							| 
									
										
										
										
											2017-04-26 04:39:25 +10:00
										 |  |  |  */ | 
					
						
							|  |  |  | void GPU_viewport_size_set(GPUViewport *viewport, const int size[2]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   copy_v2_v2_int(viewport->size, size); | 
					
						
							| 
									
										
										
										
											2017-04-26 04:39:25 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-17 04:47:26 +01:00
										 |  |  | double *GPU_viewport_cache_time_get(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return &viewport->cache_time; | 
					
						
							| 
									
										
										
										
											2018-03-17 04:47:26 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2018-09-24 18:46:51 +02:00
										 |  |  |  * Try to find a texture corresponding to params into the texture pool. | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  |  * If no texture was found, create one and add it to the pool. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | GPUTexture *GPU_viewport_texture_pool_query( | 
					
						
							|  |  |  |     GPUViewport *viewport, void *engine, int width, int height, int format) | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPUTexture *tex; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |   LISTBASE_FOREACH (ViewportTempTexture *, tmp_tex, &viewport->tex_pool) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if ((GPU_texture_format(tmp_tex->texture) == format) && | 
					
						
							|  |  |  |         (GPU_texture_width(tmp_tex->texture) == width) && | 
					
						
							|  |  |  |         (GPU_texture_height(tmp_tex->texture) == height)) { | 
					
						
							|  |  |  |       /* Search if the engine is not already using this texture */ | 
					
						
							| 
									
										
										
										
											2019-09-08 00:12:26 +10:00
										 |  |  |       for (int i = 0; i < MAX_ENGINE_BUFFER_SHARING; i++) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         if (tmp_tex->user[i] == engine) { | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (tmp_tex->user[i] == NULL) { | 
					
						
							|  |  |  |           tmp_tex->user[i] = engine; | 
					
						
							|  |  |  |           return tmp_tex->texture; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   tex = GPU_texture_create_2d(width, height, format, NULL, NULL); | 
					
						
							|  |  |  |   GPU_texture_bind(tex, 0); | 
					
						
							|  |  |  |   /* Doing filtering for depth does not make sense when not doing shadow mapping,
 | 
					
						
							|  |  |  |    * and enabling texture filtering on integer texture make them unreadable. */ | 
					
						
							|  |  |  |   bool do_filter = !GPU_texture_depth(tex) && !GPU_texture_integer(tex); | 
					
						
							|  |  |  |   GPU_texture_filter_mode(tex, do_filter); | 
					
						
							|  |  |  |   GPU_texture_unbind(tex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ViewportTempTexture *tmp_tex = MEM_callocN(sizeof(ViewportTempTexture), "ViewportTempTexture"); | 
					
						
							|  |  |  |   tmp_tex->texture = tex; | 
					
						
							|  |  |  |   tmp_tex->user[0] = engine; | 
					
						
							|  |  |  |   BLI_addtail(&viewport->tex_pool, tmp_tex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return tex; | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-18 20:32:06 +02:00
										 |  |  | static void gpu_viewport_texture_pool_clear_users(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ViewportTempTexture *tmp_tex_next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (ViewportTempTexture *tmp_tex = viewport->tex_pool.first; tmp_tex; tmp_tex = tmp_tex_next) { | 
					
						
							|  |  |  |     tmp_tex_next = tmp_tex->next; | 
					
						
							|  |  |  |     bool no_user = true; | 
					
						
							| 
									
										
										
										
											2019-09-08 00:12:26 +10:00
										 |  |  |     for (int i = 0; i < MAX_ENGINE_BUFFER_SHARING; i++) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       if (tmp_tex->user[i] != NULL) { | 
					
						
							|  |  |  |         tmp_tex->user[i] = NULL; | 
					
						
							|  |  |  |         no_user = false; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (no_user) { | 
					
						
							|  |  |  |       GPU_texture_free(tmp_tex->texture); | 
					
						
							|  |  |  |       BLI_freelinkN(&viewport->tex_pool, tmp_tex); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-05-18 20:32:06 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | static void gpu_viewport_texture_pool_free(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |   LISTBASE_FOREACH (ViewportTempTexture *, tmp_tex, &viewport->tex_pool) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     GPU_texture_free(tmp_tex->texture); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   BLI_freelistN(&viewport->tex_pool); | 
					
						
							| 
									
										
										
										
											2017-05-16 02:59:25 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  | /* Takes an NULL terminated array of engine_handle. Returns true is data is still valid. */ | 
					
						
							|  |  |  | bool GPU_viewport_engines_data_validate(GPUViewport *viewport, void **engine_handle_array) | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |   for (int i = 0; i < MAX_ENABLE_ENGINE && engine_handle_array[i]; i++) { | 
					
						
							|  |  |  |     if (viewport->engine_data[i].handle != engine_handle_array[i]) { | 
					
						
							|  |  |  |       gpu_viewport_engines_data_free(viewport); | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |   return true; | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 16:47:23 +01:00
										 |  |  | void GPU_viewport_cache_release(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |   for (int i = 0; i < MAX_ENABLE_ENGINE && viewport->engine_data[i].handle; i++) { | 
					
						
							|  |  |  |     ViewportEngineData *data = viewport->engine_data[i].data; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     int psl_len; | 
					
						
							|  |  |  |     DRW_engine_viewport_data_size_get(data->engine_type, NULL, NULL, &psl_len, NULL); | 
					
						
							|  |  |  |     gpu_viewport_passes_free(data->psl, psl_len); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-11-06 16:47:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | static void gpu_viewport_default_fb_create(GPUViewport *viewport) | 
					
						
							| 
									
										
										
										
											2018-03-14 03:22:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DefaultFramebufferList *dfbl = viewport->fbl; | 
					
						
							|  |  |  |   DefaultTextureList *dtxl = viewport->txl; | 
					
						
							|  |  |  |   int *size = viewport->size; | 
					
						
							|  |  |  |   bool ok = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   dtxl->color = GPU_texture_create_2d(size[0], size[1], GPU_RGBA16F, NULL, NULL); | 
					
						
							|  |  |  |   dtxl->color_overlay = GPU_texture_create_2d(size[0], size[1], GPU_SRGB8_A8, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   if (((viewport->flag & GPU_VIEWPORT_STEREO) != 0)) { | 
					
						
							|  |  |  |     dtxl->color_stereo = GPU_texture_create_2d(size[0], size[1], GPU_RGBA16F, NULL, NULL); | 
					
						
							|  |  |  |     dtxl->color_overlay_stereo = GPU_texture_create_2d(size[0], size[1], GPU_SRGB8_A8, NULL, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   /* Can be shared with GPUOffscreen. */ | 
					
						
							|  |  |  |   if (dtxl->depth == NULL) { | 
					
						
							|  |  |  |     dtxl->depth = GPU_texture_create_2d(size[0], size[1], GPU_DEPTH24_STENCIL8, NULL, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!dtxl->depth || !dtxl->color) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     ok = false; | 
					
						
							|  |  |  |     goto cleanup; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   gpu_viewport_framebuffer_view_set(viewport, 0); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ok = ok && GPU_framebuffer_check_valid(dfbl->default_fb, NULL); | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   ok = ok && GPU_framebuffer_check_valid(dfbl->overlay_fb, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ok = ok && GPU_framebuffer_check_valid(dfbl->color_only_fb, NULL); | 
					
						
							|  |  |  |   ok = ok && GPU_framebuffer_check_valid(dfbl->depth_only_fb, NULL); | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   ok = ok && GPU_framebuffer_check_valid(dfbl->overlay_only_fb, NULL); | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   if (((viewport->flag & GPU_VIEWPORT_STEREO) != 0)) { | 
					
						
							|  |  |  |     ok = ok && GPU_framebuffer_check_valid(dfbl->stereo_comp_fb, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-14 03:22:35 +01:00
										 |  |  | cleanup: | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (!ok) { | 
					
						
							|  |  |  |     GPU_viewport_free(viewport); | 
					
						
							|  |  |  |     DRW_opengl_context_disable(); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-14 03:22:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPU_framebuffer_restore(); | 
					
						
							| 
									
										
										
										
											2018-03-14 03:22:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | void GPU_viewport_bind(GPUViewport *viewport, int view, const rcti *rect) | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DefaultFramebufferList *dfbl = viewport->fbl; | 
					
						
							|  |  |  |   int fbl_len, txl_len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   int rect_size[2]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* add one pixel because of scissor test */ | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   rect_size[0] = BLI_rcti_size_x(rect) + 1; | 
					
						
							|  |  |  |   rect_size[1] = BLI_rcti_size_y(rect) + 1; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   DRW_opengl_context_enable(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (dfbl->default_fb) { | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |     if (!equals_v2v2_int(viewport->size, rect_size)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       gpu_viewport_buffers_free((FramebufferList *)viewport->fbl, | 
					
						
							|  |  |  |                                 default_fbl_len, | 
					
						
							|  |  |  |                                 (TextureList *)viewport->txl, | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |                                 NULL, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                                 default_txl_len); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:42:28 +02:00
										 |  |  |       for (int i = 0; i < MAX_ENABLE_ENGINE && viewport->engine_data[i].handle; i++) { | 
					
						
							|  |  |  |         ViewportEngineData *data = viewport->engine_data[i].data; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         DRW_engine_viewport_data_size_get(data->engine_type, &fbl_len, &txl_len, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |         gpu_viewport_buffers_free(data->fbl, fbl_len, data->txl, data->txl_stereo, txl_len); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       gpu_viewport_texture_pool_free(viewport); | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |       viewport->active_view = -1; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   copy_v2_v2_int(viewport->size, rect_size); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   gpu_viewport_texture_pool_clear_users(viewport); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   if (!dfbl->default_fb) { | 
					
						
							|  |  |  |     gpu_viewport_default_fb_create(viewport); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   gpu_viewport_framebuffer_view_set(viewport, view); | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_viewport_bind_from_offscreen(GPUViewport *viewport, struct GPUOffScreen *ofs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   DefaultFramebufferList *dfbl = viewport->fbl; | 
					
						
							|  |  |  |   DefaultTextureList *dtxl = viewport->txl; | 
					
						
							|  |  |  |   GPUTexture *color, *depth; | 
					
						
							|  |  |  |   GPUFrameBuffer *fb; | 
					
						
							|  |  |  |   viewport->size[0] = GPU_offscreen_width(ofs); | 
					
						
							|  |  |  |   viewport->size[1] = GPU_offscreen_height(ofs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_offscreen_viewport_data_get(ofs, &fb, &color, &depth); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* This is the only texture we can share. */ | 
					
						
							|  |  |  |   dtxl->depth = depth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   gpu_viewport_texture_pool_clear_users(viewport); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!dfbl->default_fb) { | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |     gpu_viewport_default_fb_create(viewport); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_viewport_colorspace_set(GPUViewport *viewport, | 
					
						
							|  |  |  |                                  ColorManagedViewSettings *view_settings, | 
					
						
							|  |  |  |                                  ColorManagedDisplaySettings *display_settings, | 
					
						
							|  |  |  |                                  float dither) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   memcpy(&viewport->view_settings, view_settings, sizeof(*view_settings)); | 
					
						
							|  |  |  |   memcpy(&viewport->display_settings, display_settings, sizeof(*display_settings)); | 
					
						
							|  |  |  |   viewport->dither = dither; | 
					
						
							|  |  |  |   viewport->do_color_management = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | /* Merge the stereo textures. `color` and `overlay` texture will be modified. */ | 
					
						
							|  |  |  | void GPU_viewport_stereo_composite(GPUViewport *viewport, Stereo3dFormat *stereo_format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!ELEM(stereo_format->display_mode, S3D_DISPLAY_ANAGLYPH, S3D_DISPLAY_INTERLACE)) { | 
					
						
							|  |  |  |     /* Early Exit: the other display modes need access to the full screen and cannot be
 | 
					
						
							|  |  |  |      * done from a single viewport. See `wm_stereo.c` */ | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   gpu_viewport_framebuffer_view_set(viewport, 0); | 
					
						
							|  |  |  |   DefaultTextureList *dtxl = viewport->txl; | 
					
						
							|  |  |  |   DefaultFramebufferList *dfbl = viewport->fbl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPUVertFormat *vert_format = immVertexFormat(); | 
					
						
							|  |  |  |   uint pos = GPU_vertformat_attr_add(vert_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | 
					
						
							|  |  |  |   GPU_framebuffer_bind(dfbl->stereo_comp_fb); | 
					
						
							|  |  |  |   GPU_matrix_push(); | 
					
						
							|  |  |  |   GPU_matrix_push_projection(); | 
					
						
							|  |  |  |   GPU_matrix_identity_set(); | 
					
						
							|  |  |  |   GPU_matrix_identity_projection_set(); | 
					
						
							|  |  |  |   immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE); | 
					
						
							|  |  |  |   immUniform1i("imageTexture", 0); | 
					
						
							|  |  |  |   immUniform1i("overlayTexture", 1); | 
					
						
							|  |  |  |   int settings = stereo_format->display_mode; | 
					
						
							|  |  |  |   if (settings == S3D_DISPLAY_ANAGLYPH) { | 
					
						
							|  |  |  |     switch (stereo_format->anaglyph_type) { | 
					
						
							|  |  |  |       case S3D_ANAGLYPH_REDCYAN: | 
					
						
							|  |  |  |         glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case S3D_ANAGLYPH_GREENMAGENTA: | 
					
						
							|  |  |  |         glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case S3D_ANAGLYPH_YELLOWBLUE: | 
					
						
							|  |  |  |         glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (settings == S3D_DISPLAY_INTERLACE) { | 
					
						
							|  |  |  |     settings |= stereo_format->interlace_type << 3; | 
					
						
							|  |  |  |     SET_FLAG_FROM_TEST(settings, stereo_format->flag & S3D_INTERLACE_SWAP, 1 << 6); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   immUniform1i("stereoDisplaySettings", settings); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_texture_bind(dtxl->color_stereo, 0); | 
					
						
							|  |  |  |   GPU_texture_bind(dtxl->color_overlay_stereo, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   immBegin(GPU_PRIM_TRI_STRIP, 4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   immVertex2f(pos, -1.0f, -1.0f); | 
					
						
							|  |  |  |   immVertex2f(pos, 1.0f, -1.0f); | 
					
						
							|  |  |  |   immVertex2f(pos, -1.0f, 1.0f); | 
					
						
							|  |  |  |   immVertex2f(pos, 1.0f, 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   immEnd(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_texture_unbind(dtxl->color_stereo); | 
					
						
							|  |  |  |   GPU_texture_unbind(dtxl->color_overlay_stereo); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   immUnbindProgram(); | 
					
						
							|  |  |  |   GPU_matrix_pop_projection(); | 
					
						
							|  |  |  |   GPU_matrix_pop(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (settings == S3D_DISPLAY_ANAGLYPH) { | 
					
						
							|  |  |  |     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_framebuffer_restore(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | static void gpu_viewport_draw_colormanaged(GPUViewport *viewport, | 
					
						
							|  |  |  |                                            const rctf *rect_pos, | 
					
						
							|  |  |  |                                            const rctf *rect_uv, | 
					
						
							|  |  |  |                                            bool display_colorspace) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   DefaultTextureList *dtxl = viewport->txl; | 
					
						
							|  |  |  |   GPUTexture *color = dtxl->color; | 
					
						
							|  |  |  |   GPUTexture *color_overlay = dtxl->color_overlay; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-11 16:42:01 +02:00
										 |  |  |   GPUVertFormat *vert_format = immVertexFormat(); | 
					
						
							|  |  |  |   uint pos = GPU_vertformat_attr_add(vert_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | 
					
						
							|  |  |  |   uint texco = GPU_vertformat_attr_add(vert_format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   bool use_ocio = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (viewport->do_color_management && display_colorspace) { | 
					
						
							|  |  |  |     use_ocio = IMB_colormanagement_setup_glsl_draw_from_space(&viewport->view_settings, | 
					
						
							|  |  |  |                                                               &viewport->display_settings, | 
					
						
							|  |  |  |                                                               NULL, | 
					
						
							|  |  |  |                                                               viewport->dither, | 
					
						
							|  |  |  |                                                               false, | 
					
						
							|  |  |  |                                                               true); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-11 16:42:01 +02:00
										 |  |  |   if (!use_ocio) { | 
					
						
							|  |  |  |     immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE); | 
					
						
							|  |  |  |     immUniform1i("display_transform", display_colorspace); | 
					
						
							|  |  |  |     immUniform1i("image_texture", 0); | 
					
						
							|  |  |  |     immUniform1i("overlays_texture", 1); | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_texture_bind(color, 0); | 
					
						
							|  |  |  |   GPU_texture_bind(color_overlay, 1); | 
					
						
							| 
									
										
										
										
											2020-04-11 16:42:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   immBegin(GPU_PRIM_TRI_STRIP, 4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   immAttr2f(texco, rect_uv->xmin, rect_uv->ymin); | 
					
						
							|  |  |  |   immVertex2f(pos, rect_pos->xmin, rect_pos->ymin); | 
					
						
							|  |  |  |   immAttr2f(texco, rect_uv->xmax, rect_uv->ymin); | 
					
						
							|  |  |  |   immVertex2f(pos, rect_pos->xmax, rect_pos->ymin); | 
					
						
							|  |  |  |   immAttr2f(texco, rect_uv->xmin, rect_uv->ymax); | 
					
						
							|  |  |  |   immVertex2f(pos, rect_pos->xmin, rect_pos->ymax); | 
					
						
							|  |  |  |   immAttr2f(texco, rect_uv->xmax, rect_uv->ymax); | 
					
						
							|  |  |  |   immVertex2f(pos, rect_pos->xmax, rect_pos->ymax); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   immEnd(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   GPU_texture_unbind(color); | 
					
						
							|  |  |  |   GPU_texture_unbind(color_overlay); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (use_ocio) { | 
					
						
							|  |  |  |     IMB_colormanagement_finish_glsl_draw(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-04-11 16:42:01 +02:00
										 |  |  |   else { | 
					
						
							|  |  |  |     immUnbindProgram(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
  regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
  based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
  context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
  to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
  have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
  first bigger application to adopt OpenXR. Congratulations to them and
  ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
											
										 
											2020-03-17 20:20:55 +01:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Version of #GPU_viewport_draw_to_screen() that lets caller decide if display colorspace | 
					
						
							|  |  |  |  * transform should be performed. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void GPU_viewport_draw_to_screen_ex(GPUViewport *viewport, | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |                                     int view, | 
					
						
							| 
									
										
											  
											
												VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
  regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
  based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
  context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
  to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
  have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
  first bigger application to adopt OpenXR. Congratulations to them and
  ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
											
										 
											2020-03-17 20:20:55 +01:00
										 |  |  |                                     const rcti *rect, | 
					
						
							|  |  |  |                                     bool display_colorspace) | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   gpu_viewport_framebuffer_view_set(viewport, view); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DefaultFramebufferList *dfbl = viewport->fbl; | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   DefaultTextureList *dtxl = viewport->txl; | 
					
						
							|  |  |  |   GPUTexture *color = dtxl->color; | 
					
						
							| 
									
										
										
										
											2018-03-25 03:34:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |   if (dfbl->default_fb == NULL) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 03:34:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const float w = (float)GPU_texture_width(color); | 
					
						
							|  |  |  |   const float h = (float)GPU_texture_height(color); | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
  regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
  based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
  context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
  to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
  have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
  first bigger application to adopt OpenXR. Congratulations to them and
  ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
											
										 
											2020-03-17 20:20:55 +01:00
										 |  |  |   /* We allow rects with min/max swapped, but we also need coorectly assigned coordinates. */ | 
					
						
							|  |  |  |   rcti sanitized_rect = *rect; | 
					
						
							|  |  |  |   BLI_rcti_sanitize(&sanitized_rect); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BLI_assert(w == BLI_rcti_size_x(&sanitized_rect) + 1); | 
					
						
							|  |  |  |   BLI_assert(h == BLI_rcti_size_y(&sanitized_rect) + 1); | 
					
						
							| 
									
										
										
										
											2018-02-13 18:18:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* wmOrtho for the screen has this same offset */ | 
					
						
							|  |  |  |   const float halfx = GLA_PIXEL_OFS / w; | 
					
						
							|  |  |  |   const float halfy = GLA_PIXEL_OFS / h; | 
					
						
							| 
									
										
										
										
											2018-04-27 10:22:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   rctf pos_rect = { | 
					
						
							| 
									
										
											  
											
												VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
  regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
  based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
  context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
  to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
  have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
  first bigger application to adopt OpenXR. Congratulations to them and
  ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
											
										 
											2020-03-17 20:20:55 +01:00
										 |  |  |       .xmin = sanitized_rect.xmin, | 
					
						
							|  |  |  |       .ymin = sanitized_rect.ymin, | 
					
						
							|  |  |  |       .xmax = sanitized_rect.xmin + w, | 
					
						
							|  |  |  |       .ymax = sanitized_rect.ymin + h, | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rctf uv_rect = { | 
					
						
							|  |  |  |       .xmin = halfx, | 
					
						
							|  |  |  |       .ymin = halfy, | 
					
						
							|  |  |  |       .xmax = halfx + 1.0f, | 
					
						
							|  |  |  |       .ymax = halfy + 1.0f, | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
											  
											
												VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
  regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
  based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
  context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
  to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
  have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
  first bigger application to adopt OpenXR. Congratulations to them and
  ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
											
										 
											2020-03-17 20:20:55 +01:00
										 |  |  |   /* Mirror the UV rect in case axis-swapped drawing is requested (by passing a rect with min and
 | 
					
						
							|  |  |  |    * max values swapped). */ | 
					
						
							|  |  |  |   if (BLI_rcti_size_x(rect) < 0) { | 
					
						
							|  |  |  |     SWAP(float, uv_rect.xmin, uv_rect.xmax); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (BLI_rcti_size_y(rect) < 0) { | 
					
						
							|  |  |  |     SWAP(float, uv_rect.ymin, uv_rect.ymax); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
  regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
  based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
  context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
  to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
  have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
  first bigger application to adopt OpenXR. Congratulations to them and
  ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
											
										 
											2020-03-17 20:20:55 +01:00
										 |  |  |   gpu_viewport_draw_colormanaged(viewport, &pos_rect, &uv_rect, display_colorspace); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Merge and draw the buffers of \a viewport into the currently active framebuffer, performing | 
					
						
							|  |  |  |  * color transform to display space. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-04-11 16:42:01 +02:00
										 |  |  |  * \param rect: Coordinates to draw into. By swapping min and max values, drawing can be done with | 
					
						
							|  |  |  |  *              inversed axis coordinates (upside down or sideways). | 
					
						
							| 
									
										
											  
											
												VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
  regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
  based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
  context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
  to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
  have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
  first bigger application to adopt OpenXR. Congratulations to them and
  ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
											
										 
											2020-03-17 20:20:55 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | void GPU_viewport_draw_to_screen(GPUViewport *viewport, int view, const rcti *rect) | 
					
						
							| 
									
										
											  
											
												VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
  regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
  based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
  context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
  to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
  have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
  first bigger application to adopt OpenXR. Congratulations to them and
  ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
											
										 
											2020-03-17 20:20:55 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   GPU_viewport_draw_to_screen_ex(viewport, view, rect, true); | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Clear vars assigned from offscreen, so we don't free data owned by `GPUOffScreen`. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void GPU_viewport_unbind_from_offscreen(GPUViewport *viewport, | 
					
						
							|  |  |  |                                         struct GPUOffScreen *ofs, | 
					
						
							|  |  |  |                                         bool display_colorspace) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   DefaultFramebufferList *dfbl = viewport->fbl; | 
					
						
							|  |  |  |   DefaultTextureList *dtxl = viewport->txl; | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   if (dfbl->default_fb == NULL) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-08 20:00:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   GPU_depth_test(false); | 
					
						
							|  |  |  |   GPU_offscreen_bind(ofs, false); | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |   rctf pos_rect = { | 
					
						
							|  |  |  |       .xmin = -1.0f, | 
					
						
							|  |  |  |       .ymin = -1.0f, | 
					
						
							|  |  |  |       .xmax = 1.0f, | 
					
						
							|  |  |  |       .ymax = 1.0f, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rctf uv_rect = { | 
					
						
							|  |  |  |       .xmin = 0.0f, | 
					
						
							|  |  |  |       .ymin = 0.0f, | 
					
						
							|  |  |  |       .xmax = 1.0f, | 
					
						
							|  |  |  |       .ymax = 1.0f, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   gpu_viewport_draw_colormanaged(viewport, &pos_rect, &uv_rect, display_colorspace); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* This one is from the offscreen. Don't free it with the viewport. */ | 
					
						
							|  |  |  |   dtxl->depth = NULL; | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 03:34:06 +02:00
										 |  |  | void GPU_viewport_unbind(GPUViewport *UNUSED(viewport)) | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPU_framebuffer_restore(); | 
					
						
							|  |  |  |   DRW_opengl_context_disable(); | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | GPUTexture *GPU_viewport_color_texture(GPUViewport *viewport, int view) | 
					
						
							| 
									
										
										
										
											2018-04-27 10:22:37 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DefaultFramebufferList *dfbl = viewport->fbl; | 
					
						
							| 
									
										
										
										
											2018-04-27 10:22:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (dfbl->default_fb) { | 
					
						
							|  |  |  |     DefaultTextureList *dtxl = viewport->txl; | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |     if (viewport->active_view == view) { | 
					
						
							|  |  |  |       return dtxl->color; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       return dtxl->color_stereo; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-04-27 10:22:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2018-04-27 10:22:37 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  | static void gpu_viewport_buffers_free( | 
					
						
							|  |  |  |     FramebufferList *fbl, int fbl_len, TextureList *txl, TextureList *txl_stereo, int txl_len) | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (int i = 0; i < fbl_len; i++) { | 
					
						
							|  |  |  |     GPUFrameBuffer *fb = fbl->framebuffers[i]; | 
					
						
							|  |  |  |     if (fb) { | 
					
						
							|  |  |  |       GPU_framebuffer_free(fb); | 
					
						
							|  |  |  |       fbl->framebuffers[i] = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   for (int i = 0; i < txl_len; i++) { | 
					
						
							|  |  |  |     GPUTexture *tex = txl->textures[i]; | 
					
						
							|  |  |  |     if (tex) { | 
					
						
							|  |  |  |       GPU_texture_free(tex); | 
					
						
							|  |  |  |       txl->textures[i] = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |   if (txl_stereo != NULL) { | 
					
						
							|  |  |  |     for (int i = 0; i < txl_len; i++) { | 
					
						
							|  |  |  |       GPUTexture *tex = txl_stereo->textures[i]; | 
					
						
							|  |  |  |       if (tex) { | 
					
						
							|  |  |  |         GPU_texture_free(tex); | 
					
						
							|  |  |  |         txl_stereo->textures[i] = NULL; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 20:23:30 +10:00
										 |  |  | static void gpu_viewport_storage_free(StorageList *stl, int stl_len) | 
					
						
							| 
									
										
										
										
											2017-02-08 21:44:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (int i = 0; i < stl_len; i++) { | 
					
						
							|  |  |  |     void *storage = stl->storage[i]; | 
					
						
							|  |  |  |     if (storage) { | 
					
						
							|  |  |  |       MEM_freeN(storage); | 
					
						
							|  |  |  |       stl->storage[i] = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-08 21:44:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 20:23:30 +10:00
										 |  |  | static void gpu_viewport_passes_free(PassList *psl, int psl_len) | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-16 09:40:16 +11:00
										 |  |  |   memset(psl->passes, 0, sizeof(*psl->passes) * psl_len); | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-26 19:41:17 +01:00
										 |  |  | /* Must be executed inside Drawmanager Opengl Context. */ | 
					
						
							| 
									
										
										
										
											2016-10-13 04:22:28 +00:00
										 |  |  | void GPU_viewport_free(GPUViewport *viewport) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   gpu_viewport_engines_data_free(viewport); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   gpu_viewport_buffers_free((FramebufferList *)viewport->fbl, | 
					
						
							|  |  |  |                             default_fbl_len, | 
					
						
							|  |  |  |                             (TextureList *)viewport->txl, | 
					
						
							| 
									
										
										
										
											2020-03-19 08:06:49 +01:00
										 |  |  |                             NULL, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                             default_txl_len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   gpu_viewport_texture_pool_free(viewport); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   MEM_freeN(viewport->fbl); | 
					
						
							|  |  |  |   MEM_freeN(viewport->txl); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 01:45:41 +02:00
										 |  |  |   if (viewport->vmempool.commands != NULL) { | 
					
						
							|  |  |  |     BLI_memblock_destroy(viewport->vmempool.commands, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-05-31 01:45:41 +02:00
										 |  |  |   if (viewport->vmempool.commands_small != NULL) { | 
					
						
							|  |  |  |     BLI_memblock_destroy(viewport->vmempool.commands_small, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (viewport->vmempool.callbuffers != NULL) { | 
					
						
							|  |  |  |     BLI_memblock_destroy(viewport->vmempool.callbuffers, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (viewport->vmempool.obmats != NULL) { | 
					
						
							|  |  |  |     BLI_memblock_destroy(viewport->vmempool.obmats, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (viewport->vmempool.obinfos != NULL) { | 
					
						
							|  |  |  |     BLI_memblock_destroy(viewport->vmempool.obinfos, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-05-20 18:01:42 +02:00
										 |  |  |   if (viewport->vmempool.cullstates != NULL) { | 
					
						
							|  |  |  |     BLI_memblock_destroy(viewport->vmempool.cullstates, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (viewport->vmempool.shgroups != NULL) { | 
					
						
							| 
									
										
										
										
											2019-05-13 15:57:03 +02:00
										 |  |  |     BLI_memblock_destroy(viewport->vmempool.shgroups, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (viewport->vmempool.uniforms != NULL) { | 
					
						
							| 
									
										
										
										
											2019-05-13 15:57:03 +02:00
										 |  |  |     BLI_memblock_destroy(viewport->vmempool.uniforms, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-05-20 18:01:42 +02:00
										 |  |  |   if (viewport->vmempool.views != NULL) { | 
					
						
							|  |  |  |     BLI_memblock_destroy(viewport->vmempool.views, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (viewport->vmempool.passes != NULL) { | 
					
						
							| 
									
										
										
										
											2019-05-13 15:57:03 +02:00
										 |  |  |     BLI_memblock_destroy(viewport->vmempool.passes, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-23 20:34:26 +02:00
										 |  |  |   if (viewport->vmempool.images != NULL) { | 
					
						
							| 
									
										
										
										
											2019-05-07 18:01:14 +02:00
										 |  |  |     BLI_memblock_iter iter; | 
					
						
							| 
									
										
										
										
											2019-04-23 20:34:26 +02:00
										 |  |  |     GPUTexture **tex; | 
					
						
							| 
									
										
										
										
											2019-05-07 18:01:14 +02:00
										 |  |  |     BLI_memblock_iternew(viewport->vmempool.images, &iter); | 
					
						
							|  |  |  |     while ((tex = BLI_memblock_iterstep(&iter))) { | 
					
						
							| 
									
										
										
										
											2019-04-23 20:34:26 +02:00
										 |  |  |       GPU_texture_free(*tex); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-13 15:57:03 +02:00
										 |  |  |     BLI_memblock_destroy(viewport->vmempool.images, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-23 20:34:26 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 01:45:41 +02:00
										 |  |  |   for (int i = 0; i < viewport->vmempool.ubo_len; i++) { | 
					
						
							|  |  |  |     GPU_uniformbuffer_free(viewport->vmempool.matrices_ubo[i]); | 
					
						
							|  |  |  |     GPU_uniformbuffer_free(viewport->vmempool.obinfos_ubo[i]); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   MEM_SAFE_FREE(viewport->vmempool.matrices_ubo); | 
					
						
							|  |  |  |   MEM_SAFE_FREE(viewport->vmempool.obinfos_ubo); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DRW_instance_data_list_free(viewport->idatalist); | 
					
						
							|  |  |  |   MEM_freeN(viewport->idatalist); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   MEM_freeN(viewport); | 
					
						
							| 
									
										
										
										
											2016-10-13 04:22:28 +00:00
										 |  |  | } |