| 
									
										
										
										
											2020-08-07 17:00:28 +02: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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright 2020, Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup gpu | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 03:01:45 +02:00
										 |  |  | #include "gpu_context_private.hh"
 | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-11 01:31:40 +02:00
										 |  |  | #include "GPU_framebuffer.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | #include "BLI_set.hh"
 | 
					
						
							| 
									
										
										
										
											2020-08-08 03:01:45 +02:00
										 |  |  | #include "BLI_vector.hh"
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | #include "gl_state.hh"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | #include "glew-mx.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <mutex>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | namespace blender { | 
					
						
							|  |  |  | namespace gpu { | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-21 12:30:55 +02:00
										 |  |  | class GLVaoCache; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | class GLSharedOrphanLists { | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   /** Mutex for the bellow structures. */ | 
					
						
							|  |  |  |   std::mutex lists_mutex; | 
					
						
							|  |  |  |   /** Buffers and textures are shared across context. Any context can free them. */ | 
					
						
							|  |  |  |   Vector<GLuint> textures; | 
					
						
							|  |  |  |   Vector<GLuint> buffers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   void orphans_clear(void); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-21 12:30:55 +02:00
										 |  |  | class GLContext : public GPUContext { | 
					
						
							| 
									
										
										
										
											2020-09-01 02:41:29 +02:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2020-09-07 18:52:30 +02:00
										 |  |  |   /** Capabilities. */ | 
					
						
							|  |  |  |   static GLint max_texture_3d_size; | 
					
						
							|  |  |  |   static GLint max_cubemap_size; | 
					
						
							|  |  |  |   static GLint max_ubo_size; | 
					
						
							|  |  |  |   static GLint max_ubo_binds; | 
					
						
							|  |  |  |   /** Extensions. */ | 
					
						
							|  |  |  |   static bool base_instance_support; | 
					
						
							|  |  |  |   static bool texture_cube_map_array_support; | 
					
						
							|  |  |  |   /** Workarounds. */ | 
					
						
							|  |  |  |   static bool texture_copy_workaround; | 
					
						
							|  |  |  |   static bool unused_fb_slot_workaround; | 
					
						
							|  |  |  |   static float derivative_signs[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-01 02:41:29 +02:00
										 |  |  |   /** Used for debugging purpose. Bitflags of all bound slots. */ | 
					
						
							|  |  |  |   uint16_t bound_ubo_slots; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   /* TODO(fclem) these needs to become private. */ | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   /** VBO for missing vertex attrib binding. Avoid undefined behavior on some implementation. */ | 
					
						
							|  |  |  |   GLuint default_attr_vbo_; | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * GPUBatch & GPUFramebuffer have references to the context they are from, in the case the | 
					
						
							|  |  |  |    * context is destroyed, we need to remove any reference to it. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2020-08-11 01:31:40 +02:00
										 |  |  |   Set<GLVaoCache *> vao_caches_; | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   Set<GPUFrameBuffer *> framebuffers_; | 
					
						
							|  |  |  |   /** Mutex for the bellow structures. */ | 
					
						
							|  |  |  |   std::mutex lists_mutex_; | 
					
						
							|  |  |  |   /** VertexArrays and framebuffers are not shared across context. */ | 
					
						
							|  |  |  |   Vector<GLuint> orphaned_vertarrays_; | 
					
						
							|  |  |  |   Vector<GLuint> orphaned_framebuffers_; | 
					
						
							|  |  |  |   /** GLBackend onws this data. */ | 
					
						
							|  |  |  |   GLSharedOrphanLists &shared_orphan_list_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list); | 
					
						
							|  |  |  |   ~GLContext(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 14:47:23 +02:00
										 |  |  |   static void check_error(const char *info); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   void activate(void) override; | 
					
						
							|  |  |  |   void deactivate(void) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   static inline GLStateManager *state_manager_active_get() | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     GLContext *ctx = static_cast<GLContext *>(GPU_context_active_get()); | 
					
						
							|  |  |  |     return static_cast<GLStateManager *>(ctx->state_manager); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   /* TODO(fclem) these needs to become private. */ | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id); | 
					
						
							|  |  |  |   void orphans_clear(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void vao_free(GLuint vao_id); | 
					
						
							|  |  |  |   void fbo_free(GLuint fbo_id); | 
					
						
							| 
									
										
										
										
											2020-08-11 01:31:40 +02:00
										 |  |  |   void vao_cache_register(GLVaoCache *cache); | 
					
						
							|  |  |  |   void vao_cache_unregister(GLVaoCache *cache); | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | }  // namespace gpu
 | 
					
						
							|  |  |  | }  // namespace blender
 |