Blender  V3.3
gl_context.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
8 #pragma once
9 
10 #include "gpu_context_private.hh"
11 
12 #include "GPU_framebuffer.h"
13 
14 #include "BLI_set.hh"
15 #include "BLI_vector.hh"
16 
17 #include "gl_state.hh"
18 
19 #include "glew-mx.h"
20 
21 #include <mutex>
22 
23 namespace blender {
24 namespace gpu {
25 
26 class GLVaoCache;
27 
29  public:
35 
36  public:
37  void orphans_clear();
38 };
39 
40 class GLContext : public Context {
41  public:
44  static GLint max_cubemap_size;
45  static GLint max_texture_3d_size;
46  static GLint max_ubo_size;
47  static GLint max_ubo_binds;
48  static GLint max_ssbo_size;
49  static GLint max_ssbo_binds;
50 
53  static bool base_instance_support;
54  static bool clear_texture_support;
55  static bool copy_image_support;
56  static bool debug_layer_support;
63  static bool multi_bind_support;
72 
78  static float derivative_signs[2];
79 
82 
85 
86  private:
91  Set<GLVaoCache *> vao_caches_;
92  Set<GPUFrameBuffer *> framebuffers_;
94  std::mutex lists_mutex_;
96  Vector<GLuint> orphaned_vertarrays_;
97  Vector<GLuint> orphaned_framebuffers_;
99  GLSharedOrphanLists &shared_orphan_list_;
100 
101  public:
102  GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list);
103  ~GLContext();
104 
105  static void check_error(const char *info);
106 
107  void activate() override;
108  void deactivate() override;
109  void begin_frame() override;
110  void end_frame() override;
111 
112  void flush() override;
113  void finish() override;
114 
115  void memory_statistics_get(int *total_mem, int *free_mem) override;
116 
117  static GLContext *get()
118  {
119  return static_cast<GLContext *>(Context::get());
120  }
121 
123  {
124  GLContext *ctx = GLContext::get();
125  return static_cast<GLStateManager *>(ctx->state_manager);
126  };
127 
128  /* These need to be called with the context the id was created with. */
129  void vao_free(GLuint vao_id);
130  void fbo_free(GLuint fbo_id);
131  /* These can be called by any threads even without OpenGL ctx. Deletion will be delayed. */
132  static void buf_free(GLuint buf_id);
133  static void tex_free(GLuint tex_id);
134 
135  void vao_cache_register(GLVaoCache *cache);
136  void vao_cache_unregister(GLVaoCache *cache);
137 
138  void debug_group_begin(const char *name, int index) override;
139  void debug_group_end() override;
140 
141  private:
142  static void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id);
143  void orphans_clear();
144 
145  MEM_CXX_CLASS_ALLOC_FUNCS("GLContext")
146 };
147 
148 } // namespace gpu
149 } // namespace blender
ThreadMutex mutex
static Context * get()
Definition: gpu_context.cc:82
static bool stencil_texturing_support
Definition: gl_context.hh:66
static bool geometry_shader_invocations
Definition: gl_context.hh:59
static void buf_free(GLuint buf_id)
Definition: gl_context.cc:250
static bool layered_rendering_support
Definition: gl_context.hh:61
static bool debug_layer_support
Definition: gl_context.hh:56
void debug_group_begin(const char *name, int index) override
Definition: gl_debug.cc:366
static bool shader_draw_parameters_support
Definition: gl_context.hh:65
static bool explicit_location_support
Definition: gl_context.hh:58
static GLint max_ssbo_binds
Definition: gl_context.hh:49
static GLint max_texture_3d_size
Definition: gl_context.hh:45
static bool debug_layer_workaround
Definition: gl_context.hh:75
static float derivative_signs[2]
Definition: gl_context.hh:78
static bool base_instance_support
Definition: gl_context.hh:53
static bool vertex_attrib_binding_support
Definition: gl_context.hh:71
void begin_frame() override
Definition: gl_context.cc:152
void debug_group_end() override
Definition: gl_debug.cc:375
void activate() override
Definition: gl_context.cc:107
void flush() override
Definition: gl_context.cc:168
static bool texture_storage_support
Definition: gl_context.hh:70
static GLint max_ssbo_size
Definition: gl_context.hh:48
static GLint max_ubo_binds
Definition: gl_context.hh:47
void memory_statistics_get(int *total_mem, int *free_mem) override
Definition: gl_context.cc:304
static void check_error(const char *info)
GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list)
Definition: gl_context.cc:35
static bool fixed_restart_index_support
Definition: gl_context.hh:60
static bool copy_image_support
Definition: gl_context.hh:55
static bool texture_gather_support
Definition: gl_context.hh:69
void vao_cache_unregister(GLVaoCache *cache)
Definition: gl_context.cc:291
static GLint max_ubo_size
Definition: gl_context.hh:46
static bool direct_state_access_support
Definition: gl_context.hh:57
static GLContext * get()
Definition: gl_context.hh:117
void finish() override
Definition: gl_context.cc:173
static void tex_free(GLuint tex_id)
Definition: gl_context.cc:262
static bool texture_filter_anisotropic_support
Definition: gl_context.hh:68
static GLStateManager * state_manager_active_get()
Definition: gl_context.hh:122
static bool clear_texture_support
Definition: gl_context.hh:54
static bool unused_fb_slot_workaround
Definition: gl_context.hh:76
void deactivate() override
Definition: gl_context.cc:146
static bool multi_bind_support
Definition: gl_context.hh:63
static GLint max_cubemap_size
Definition: gl_context.hh:44
static bool texture_cube_map_array_support
Definition: gl_context.hh:67
void vao_free(GLuint vao_id)
Definition: gl_context.cc:230
static bool native_barycentric_support
Definition: gl_context.hh:62
void end_frame() override
Definition: gl_context.cc:157
static bool generate_mipmap_workaround
Definition: gl_context.hh:77
void vao_cache_register(GLVaoCache *cache)
Definition: gl_context.cc:284
void fbo_free(GLuint fbo_id)
Definition: gl_context.cc:240
static bool multi_draw_indirect_support
Definition: gl_context.hh:64
unsigned short uint16_t
Definition: stdint.h:79