Blender V4.3
gl_context.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
12
13#include "GPU_framebuffer.hh"
14
15#include "BLI_set.hh"
16#include "BLI_vector.hh"
17
18#include "gl_state.hh"
19
20#include <mutex>
21
22namespace blender {
23namespace gpu {
24
25class GLVaoCache;
26
28 public:
30 std::mutex lists_mutex;
34
35 public:
36 void orphans_clear();
37};
38
39class GLContext : public Context {
40 public:
43 static GLint max_cubemap_size;
44 static GLint max_ubo_size;
45 static GLint max_ubo_binds;
46 static GLint max_ssbo_binds;
47
57 static bool multi_bind_support;
64
70 static float derivative_signs[2];
71
74
78
79 private:
84 Set<GLVaoCache *> vao_caches_;
85 Set<GPUFrameBuffer *> framebuffers_;
87 std::mutex lists_mutex_;
89 Vector<GLuint> orphaned_vertarrays_;
90 Vector<GLuint> orphaned_framebuffers_;
92 GLSharedOrphanLists &shared_orphan_list_;
93
94 public:
95 GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list);
96 ~GLContext();
97
98 static void check_error(const char *info);
99
100 void activate() override;
101 void deactivate() override;
102 void begin_frame() override;
103 void end_frame() override;
104
105 void flush() override;
106 void finish() override;
107
108 void memory_statistics_get(int *r_total_mem, int *r_free_mem) override;
109
110 static GLContext *get()
111 {
112 return static_cast<GLContext *>(Context::get());
113 }
114
116 {
117 GLContext *ctx = GLContext::get();
118 return static_cast<GLStateManager *>(ctx->state_manager);
119 };
120
121 /* These need to be called with the context the id was created with. */
122 void vao_free(GLuint vao_id);
123 void fbo_free(GLuint fbo_id);
124 /* These can be called by any threads even without OpenGL ctx. Deletion will be delayed. */
125 static void buf_free(GLuint buf_id);
126 static void tex_free(GLuint tex_id);
127
128 void vao_cache_register(GLVaoCache *cache);
129 void vao_cache_unregister(GLVaoCache *cache);
130
131 void debug_group_begin(const char *name, int index) override;
132 void debug_group_end() override;
133 bool debug_capture_begin(const char *title) override;
134 void debug_capture_end() override;
135 void *debug_capture_scope_create(const char *name) override;
136 bool debug_capture_scope_begin(void *scope) override;
137 void debug_capture_scope_end(void *scope) override;
138
139 void debug_unbind_all_ubo() override;
140 void debug_unbind_all_ssbo() override;
141
142 private:
143 static void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id);
144 void orphans_clear();
145
146 MEM_CXX_CLASS_ALLOC_FUNCS("GLContext")
147};
148
149} // namespace gpu
150} // namespace blender
static Context * get()
void * debug_capture_scope_create(const char *name) override
Definition gl_debug.cc:438
static bool stencil_texturing_support
Definition gl_context.hh:61
static void buf_free(GLuint buf_id)
void debug_unbind_all_ubo() override
Definition gl_debug.cc:469
static bool layered_rendering_support
Definition gl_context.hh:55
void debug_capture_end() override
Definition gl_debug.cc:424
static bool debug_layer_support
Definition gl_context.hh:51
bool debug_capture_begin(const char *title) override
Definition gl_debug.cc:404
void debug_group_begin(const char *name, int index) override
Definition gl_debug.cc:384
static bool framebuffer_fetch_support
Definition gl_context.hh:54
void memory_statistics_get(int *r_total_mem, int *r_free_mem) override
static bool shader_draw_parameters_support
Definition gl_context.hh:60
static bool explicit_location_support
Definition gl_context.hh:53
void debug_capture_scope_end(void *scope) override
Definition gl_debug.cc:457
static GLint max_ssbo_binds
Definition gl_context.hh:46
static bool debug_layer_workaround
Definition gl_context.hh:67
static float derivative_signs[2]
Definition gl_context.hh:70
static GLStateManager * state_manager_active_get()
void begin_frame() override
void debug_group_end() override
Definition gl_debug.cc:395
void activate() override
void flush() override
static GLint max_ubo_binds
Definition gl_context.hh:45
static void check_error(const char *info)
GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list)
Definition gl_context.cc:36
void vao_cache_unregister(GLVaoCache *cache)
static GLint max_ubo_size
Definition gl_context.hh:44
static bool direct_state_access_support
Definition gl_context.hh:52
static GLContext * get()
void finish() override
static void tex_free(GLuint tex_id)
static bool texture_filter_anisotropic_support
Definition gl_context.hh:63
static bool clear_texture_support
Definition gl_context.hh:50
static bool unused_fb_slot_workaround
Definition gl_context.hh:68
void deactivate() override
bool debug_capture_scope_begin(void *scope) override
Definition gl_debug.cc:443
static bool multi_bind_support
Definition gl_context.hh:57
static GLint max_cubemap_size
Definition gl_context.hh:43
void vao_free(GLuint vao_id)
static bool texture_barrier_support
Definition gl_context.hh:62
static bool native_barycentric_support
Definition gl_context.hh:56
static bool multi_bind_image_support
Definition gl_context.hh:58
void end_frame() override
static bool generate_mipmap_workaround
Definition gl_context.hh:69
void debug_unbind_all_ssbo() override
Definition gl_debug.cc:474
void vao_cache_register(GLVaoCache *cache)
void fbo_free(GLuint fbo_id)
static bool multi_draw_indirect_support
Definition gl_context.hh:59
unsigned short uint16_t
Definition stdint.h:79