Blender  V2.93
gl_context.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2020, Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 #include "gpu_context_private.hh"
27 
28 #include "GPU_framebuffer.h"
29 
30 #include "BLI_set.hh"
31 #include "BLI_vector.hh"
32 
33 #include "gl_state.hh"
34 
35 #include "glew-mx.h"
36 
37 #include <mutex>
38 
39 namespace blender {
40 namespace gpu {
41 
42 class GLVaoCache;
43 
45  public:
51 
52  public:
53  void orphans_clear(void);
54 };
55 
56 class GLContext : public Context {
57  public:
59  static GLint max_cubemap_size;
60  static GLint max_texture_3d_size;
61  static GLint max_ubo_size;
62  static GLint max_ubo_binds;
64  static bool base_instance_support;
65  static bool clear_texture_support;
66  static bool copy_image_support;
67  static bool debug_layer_support;
70  static bool multi_bind_support;
81  static float derivative_signs[2];
82 
85 
88 
89  private:
94  Set<GLVaoCache *> vao_caches_;
95  Set<GPUFrameBuffer *> framebuffers_;
97  std::mutex lists_mutex_;
99  Vector<GLuint> orphaned_vertarrays_;
100  Vector<GLuint> orphaned_framebuffers_;
102  GLSharedOrphanLists &shared_orphan_list_;
103 
104  public:
105  GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list);
106  ~GLContext();
107 
108  static void check_error(const char *info);
109 
110  void activate(void) override;
111  void deactivate(void) override;
112 
113  void flush(void) override;
114  void finish(void) override;
115 
116  void memory_statistics_get(int *total_mem, int *free_mem) override;
117 
118  static GLContext *get()
119  {
120  return static_cast<GLContext *>(Context::get());
121  }
122 
124  {
125  GLContext *ctx = GLContext::get();
126  return static_cast<GLStateManager *>(ctx->state_manager);
127  };
128 
129  /* These need to be called with the context the id was created with. */
130  void vao_free(GLuint vao_id);
131  void fbo_free(GLuint fbo_id);
132  /* These can be called by any threads even without OpenGL ctx. Deletion will be delayed. */
133  static void buf_free(GLuint buf_id);
134  static void tex_free(GLuint tex_id);
135 
136  void vao_cache_register(GLVaoCache *cache);
137  void vao_cache_unregister(GLVaoCache *cache);
138 
139  void debug_group_begin(const char *name, int index) override;
140  void debug_group_end(void) override;
141 
142  private:
143  static void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id);
144  void orphans_clear(void);
145 
146  MEM_CXX_CLASS_ALLOC_FUNCS("GLContext")
147 };
148 
149 } // namespace gpu
150 } // namespace blender
ThreadMutex mutex
static Context * get(void)
Definition: gpu_context.cc:88
static void buf_free(GLuint buf_id)
Definition: gl_context.cc:257
static bool debug_layer_support
Definition: gl_context.hh:67
void finish(void) override
Definition: gl_context.cc:180
void debug_group_begin(const char *name, int index) override
Definition: gl_debug.cc:363
static bool shader_draw_parameters_support
Definition: gl_context.hh:72
static GLint max_texture_3d_size
Definition: gl_context.hh:60
static bool debug_layer_workaround
Definition: gl_context.hh:78
static float derivative_signs[2]
Definition: gl_context.hh:81
static bool base_instance_support
Definition: gl_context.hh:64
static bool vertex_attrib_binding_support
Definition: gl_context.hh:76
void flush(void) override
Definition: gl_context.cc:175
static GLint max_ubo_binds
Definition: gl_context.hh:62
void memory_statistics_get(int *total_mem, int *free_mem) override
Definition: gl_context.cc:311
static void check_error(const char *info)
void deactivate(void) override
Definition: gl_context.cc:163
void activate(void) override
Definition: gl_context.cc:124
GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list)
Definition: gl_context.cc:52
static bool fixed_restart_index_support
Definition: gl_context.hh:69
static bool copy_image_support
Definition: gl_context.hh:66
static bool texture_gather_support
Definition: gl_context.hh:75
void vao_cache_unregister(GLVaoCache *cache)
Definition: gl_context.cc:298
static GLint max_ubo_size
Definition: gl_context.hh:61
static bool direct_state_access_support
Definition: gl_context.hh:68
static GLContext * get()
Definition: gl_context.hh:118
static void tex_free(GLuint tex_id)
Definition: gl_context.cc:269
static bool texture_filter_anisotropic_support
Definition: gl_context.hh:74
static GLStateManager * state_manager_active_get()
Definition: gl_context.hh:123
static bool clear_texture_support
Definition: gl_context.hh:65
static bool unused_fb_slot_workaround
Definition: gl_context.hh:79
static bool multi_bind_support
Definition: gl_context.hh:70
static GLint max_cubemap_size
Definition: gl_context.hh:59
static bool texture_cube_map_array_support
Definition: gl_context.hh:73
void vao_free(GLuint vao_id)
Definition: gl_context.cc:237
void debug_group_end(void) override
Definition: gl_debug.cc:372
static bool generate_mipmap_workaround
Definition: gl_context.hh:80
void vao_cache_register(GLVaoCache *cache)
Definition: gl_context.cc:291
void fbo_free(GLuint fbo_id)
Definition: gl_context.cc:247
static bool multi_draw_indirect_support
Definition: gl_context.hh:71
unsigned short uint16_t
Definition: stdint.h:82