Blender  V3.3
gl_backend.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_backend.hh"
11 
12 #include "BLI_vector.hh"
13 
14 #include "gl_batch.hh"
15 #include "gl_compute.hh"
16 #include "gl_context.hh"
17 #include "gl_drawlist.hh"
18 #include "gl_framebuffer.hh"
19 #include "gl_index_buffer.hh"
20 #include "gl_query.hh"
21 #include "gl_shader.hh"
22 #include "gl_storage_buffer.hh"
23 #include "gl_texture.hh"
24 #include "gl_uniform_buffer.hh"
25 #include "gl_vertex_buffer.hh"
26 
27 namespace blender {
28 namespace gpu {
29 
30 class GLBackend : public GPUBackend {
31  private:
32  GLSharedOrphanLists shared_orphan_list_;
33 
34  public:
36  {
37  /* platform_init needs to go first. */
38  GLBackend::platform_init();
39 
40  GLBackend::capabilities_init();
42  }
44  {
45  GLBackend::platform_exit();
46  }
47 
48  void delete_resources() override
49  {
50  /* Delete any resources with context active. */
52  }
53 
54  static GLBackend *get()
55  {
56  return static_cast<GLBackend *>(GPUBackend::get());
57  }
58 
59  void samplers_update() override
60  {
62  };
63 
64  Context *context_alloc(void *ghost_window) override
65  {
66  return new GLContext(ghost_window, shared_orphan_list_);
67  };
68 
69  Batch *batch_alloc() override
70  {
71  return new GLBatch();
72  };
73 
74  DrawList *drawlist_alloc(int list_length) override
75  {
76  return new GLDrawList(list_length);
77  };
78 
79  FrameBuffer *framebuffer_alloc(const char *name) override
80  {
81  return new GLFrameBuffer(name);
82  };
83 
85  {
86  return new GLIndexBuf();
87  };
88 
90  {
91  return new GLQueryPool();
92  };
93 
94  Shader *shader_alloc(const char *name) override
95  {
96  return new GLShader(name);
97  };
98 
99  Texture *texture_alloc(const char *name) override
100  {
101  return new GLTexture(name);
102  };
103 
104  UniformBuf *uniformbuf_alloc(int size, const char *name) override
105  {
106  return new GLUniformBuf(size, name);
107  };
108 
109  StorageBuf *storagebuf_alloc(int size, GPUUsageType usage, const char *name) override
110  {
111  return new GLStorageBuf(size, usage, name);
112  };
113 
114  VertBuf *vertbuf_alloc() override
115  {
116  return new GLVertBuf();
117  };
118 
120  {
121  return shared_orphan_list_;
122  };
123 
124  void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
125  {
127  GLCompute::dispatch(groups_x_len, groups_y_len, groups_z_len);
128  }
129 
130  void compute_dispatch_indirect(StorageBuf *indirect_buf) override
131  {
133 
134  dynamic_cast<GLStorageBuf *>(indirect_buf)->bind_as(GL_DISPATCH_INDIRECT_BUFFER);
135  /* This barrier needs to be here as it only work on the currently bound indirect buffer. */
136  glMemoryBarrier(GL_DRAW_INDIRECT_BUFFER);
137 
138  glDispatchComputeIndirect((GLintptr)0);
139  /* Unbind. */
140  glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
141  }
142 
143  /* Render Frame Coordination */
144  void render_begin(void) override{};
145  void render_end(void) override{};
146  void render_step(void) override{};
147 
148  private:
149  static void platform_init();
150  static void platform_exit();
151 
152  static void capabilities_init();
153 };
154 
155 } // namespace gpu
156 } // namespace blender
GPUUsageType
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
DrawList * drawlist_alloc(int list_length) override
Definition: gl_backend.hh:74
void render_end(void) override
Definition: gl_backend.hh:145
static GLBackend * get()
Definition: gl_backend.hh:54
Shader * shader_alloc(const char *name) override
Definition: gl_backend.hh:94
Batch * batch_alloc() override
Definition: gl_backend.hh:69
UniformBuf * uniformbuf_alloc(int size, const char *name) override
Definition: gl_backend.hh:104
void compute_dispatch_indirect(StorageBuf *indirect_buf) override
Definition: gl_backend.hh:130
GLSharedOrphanLists & shared_orphan_list_get()
Definition: gl_backend.hh:119
QueryPool * querypool_alloc() override
Definition: gl_backend.hh:89
void render_step(void) override
Definition: gl_backend.hh:146
IndexBuf * indexbuf_alloc() override
Definition: gl_backend.hh:84
VertBuf * vertbuf_alloc() override
Definition: gl_backend.hh:114
Texture * texture_alloc(const char *name) override
Definition: gl_backend.hh:99
void samplers_update() override
Definition: gl_backend.hh:59
Context * context_alloc(void *ghost_window) override
Definition: gl_backend.hh:64
void delete_resources() override
Definition: gl_backend.hh:48
StorageBuf * storagebuf_alloc(int size, GPUUsageType usage, const char *name) override
Definition: gl_backend.hh:109
void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
Definition: gl_backend.hh:124
FrameBuffer * framebuffer_alloc(const char *name) override
Definition: gl_backend.hh:79
void render_begin(void) override
Definition: gl_backend.hh:144
static void dispatch(int group_x_len, int group_y_len, int group_z_len)
Definition: gl_compute.cc:13
static GLContext * get()
Definition: gl_context.hh:117
static GLStateManager * state_manager_active_get()
Definition: gl_context.hh:122
void apply_state() override
Definition: gl_state.cc:57
static void samplers_free()
Definition: gl_texture.cc:586
static void samplers_update()
Definition: gl_texture.cc:567
static void samplers_init()
Definition: gl_texture.cc:511
static GPUBackend * get()
Definition: gpu_context.cc:292