Blender V4.5
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
8
9#pragma once
10
12
13#include "GPU_framebuffer.hh"
14
15#include "BKE_global.hh"
16#include "BLI_set.hh"
17#include "BLI_vector.hh"
18
19#include "gl_state.hh"
20
21#include <mutex>
22
23namespace blender {
24namespace gpu {
25
26class GLVaoCache;
27
29 public:
31 std::mutex lists_mutex;
35
36 public:
37 void orphans_clear();
38};
39
40class GLContext : public Context {
41 public:
43
44 static GLint max_cubemap_size;
45 static GLint max_ubo_size;
46 static GLint max_ubo_binds;
47 static GLint max_ssbo_binds;
48
50
58 static bool multi_bind_support;
65
67
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 struct TimeQuery {
95 std::string name;
96 union {
97 GLuint handles[2];
98 struct {
99 GLuint handle_start, handle_end;
100 };
101 };
102 bool finished;
103 int64_t cpu_start;
104 int64_t cpu_end;
105 };
106 struct FrameQueries {
107 Vector<TimeQuery> queries;
108 };
109 Vector<FrameQueries> frame_timings;
110
111 void process_frame_timings();
112
113 public:
114 GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list);
115 ~GLContext();
116
117 static void check_error(const char *info);
118
119 void activate() override;
120 void deactivate() override;
121 void begin_frame() override;
122 void end_frame() override;
123
124 void flush() override;
125 void finish() override;
126
127 void memory_statistics_get(int *r_total_mem, int *r_free_mem) override;
128
129 static GLContext *get()
130 {
131 return static_cast<GLContext *>(Context::get());
132 }
133
135 {
136 GLContext *ctx = GLContext::get();
137 return static_cast<GLStateManager *>(ctx->state_manager);
138 };
139
140 /* These need to be called with the context the id was created with. */
141 void vao_free(GLuint vao_id);
142 void fbo_free(GLuint fbo_id);
143 /* These can be called by any threads even without OpenGL ctx. Deletion will be delayed. */
144 static void buf_free(GLuint buf_id);
145 static void tex_free(GLuint tex_id);
146
147 void vao_cache_register(GLVaoCache *cache);
148 void vao_cache_unregister(GLVaoCache *cache);
149
150 void debug_group_begin(const char *name, int index) override;
151 void debug_group_end() override;
152 bool debug_capture_begin(const char *title) override;
153 void debug_capture_end() override;
154 void *debug_capture_scope_create(const char *name) override;
155 bool debug_capture_scope_begin(void *scope) override;
156 void debug_capture_scope_end(void *scope) override;
157
158 void debug_unbind_all_ubo() override;
159 void debug_unbind_all_ssbo() override;
160
161 private:
162 static void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id);
163 void orphans_clear();
164
165 MEM_CXX_CLASS_ALLOC_FUNCS("GLContext")
166};
167
168} // namespace gpu
169} // namespace blender
long long int int64_t
static Context * get()
void * debug_capture_scope_create(const char *name) override
Definition gl_debug.cc:512
static bool stencil_texturing_support
Definition gl_context.hh:62
static void buf_free(GLuint buf_id)
void debug_unbind_all_ubo() override
Definition gl_debug.cc:543
static bool layered_rendering_support
Definition gl_context.hh:56
void debug_capture_end() override
Definition gl_debug.cc:498
static bool debug_layer_support
Definition gl_context.hh:52
bool debug_capture_begin(const char *title) override
Definition gl_debug.cc:478
void debug_group_begin(const char *name, int index) override
Definition gl_debug.cc:369
static bool framebuffer_fetch_support
Definition gl_context.hh:55
void memory_statistics_get(int *r_total_mem, int *r_free_mem) override
static bool shader_draw_parameters_support
Definition gl_context.hh:61
static bool explicit_location_support
Definition gl_context.hh:54
void debug_capture_scope_end(void *scope) override
Definition gl_debug.cc:531
static GLint max_ssbo_binds
Definition gl_context.hh:47
static bool debug_layer_workaround
Definition gl_context.hh:68
static GLStateManager * state_manager_active_get()
void begin_frame() override
void debug_group_end() override
Definition gl_debug.cc:398
void activate() override
void flush() override
static GLint max_ubo_binds
Definition gl_context.hh:46
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:45
static bool direct_state_access_support
Definition gl_context.hh:53
static GLContext * get()
void finish() override
static void tex_free(GLuint tex_id)
static bool texture_filter_anisotropic_support
Definition gl_context.hh:64
static bool unused_fb_slot_workaround
Definition gl_context.hh:69
void deactivate() override
bool debug_capture_scope_begin(void *scope) override
Definition gl_debug.cc:517
static bool multi_bind_support
Definition gl_context.hh:58
static bool clip_control_support
Definition gl_context.hh:51
static GLint max_cubemap_size
Definition gl_context.hh:44
void vao_free(GLuint vao_id)
static bool texture_barrier_support
Definition gl_context.hh:63
static bool native_barycentric_support
Definition gl_context.hh:57
static bool multi_bind_image_support
Definition gl_context.hh:59
void end_frame() override
static bool generate_mipmap_workaround
Definition gl_context.hh:70
void debug_unbind_all_ssbo() override
Definition gl_debug.cc:548
void vao_cache_register(GLVaoCache *cache)
void fbo_free(GLuint fbo_id)
static bool multi_draw_indirect_support
Definition gl_context.hh:60
ParamHandle ** handles