Blender V5.3
gl_batch.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
11
12#pragma once
13
14#include "MEM_guardedalloc.h"
15
16#include "GPU_batch.hh"
17
18#include "gl_index_buffer.hh"
19#include "gl_vertex_buffer.hh"
20
21namespace blender::gpu {
22
23class GLContext;
25
26#define GPU_VAO_STATIC_LEN 3
27
34 private:
36 GLContext *context_ = nullptr;
38 GLShaderInterface *interface_ = nullptr;
40 GLuint vao_id_ = 0;
42 GLuint vao_base_instance_ = 0;
43 int base_instance_ = 0;
44
45 bool is_dynamic_vao_count = false;
46 union {
48 struct {
49 const GLShaderInterface *interfaces[GPU_VAO_STATIC_LEN];
50 GLuint vao_ids[GPU_VAO_STATIC_LEN];
51 } static_vaos;
53 struct {
54 uint count;
55 const GLShaderInterface **interfaces;
56 GLuint *vao_ids;
57 } dynamic_vaos;
58 };
59
60 public:
61 GLVaoCache();
63
64 GLuint vao_get(Batch *batch);
65
69 GLuint lookup(const GLShaderInterface *interface);
73 void insert(const GLShaderInterface *interface, GLuint vao_id);
74 void remove(const GLShaderInterface *interface);
75 void clear();
76
77 private:
78 void init();
83 void context_check();
84};
85
86class GLBatch : public Batch {
87 public:
90
91 public:
92 void draw(int v_first, int v_count, int i_first, int i_count) override;
93 void draw_indirect(StorageBuf *indirect_buf, intptr_t offset) override;
94 void multi_draw_indirect(StorageBuf *indirect_buf,
95 int count,
96 intptr_t offset,
97 intptr_t stride) override;
98 void bind();
99
100 /* Convenience getters. */
101
103 {
104 return static_cast<GLIndexBuf *>(elem);
105 }
106 GLVertBuf *verts_(const int index) const
107 {
108 return static_cast<GLVertBuf *>(verts[index]);
109 }
110
112};
113
114} // namespace blender::gpu
Read Blender memory allocation and freeing.
MEM_CXX_CLASS_ALLOC_FUNCS("GLBatch")
GLIndexBuf * elem_() const
Definition gl_batch.hh:102
GLVertBuf * verts_(const int index) const
Definition gl_batch.hh:106
void multi_draw_indirect(StorageBuf *indirect_buf, int count, intptr_t offset, intptr_t stride) override
Definition gl_batch.cc:295
void draw_indirect(StorageBuf *indirect_buf, intptr_t offset) override
Definition gl_batch.cc:275
GLVaoCache vao_cache_
Definition gl_batch.hh:89
GLuint vao_get(Batch *batch)
Definition gl_batch.cc:212
void remove(const GLShaderInterface *interface)
Definition gl_batch.cc:119
void insert(const GLShaderInterface *interface, GLuint vao_id)
Definition gl_batch.cc:62
GLuint lookup(const GLShaderInterface *interface)
Definition gl_batch.cc:182
#define GPU_VAO_STATIC_LEN
Definition mtl_batch.hh:26
unsigned int uint
Definition BKE_text.h:55
_W64 int intptr_t
Definition BKE_text.h:119