46void GLVaoCache::init()
50 is_dynamic_vao_count =
false;
52 static_vaos.interfaces[
i] =
nullptr;
53 static_vaos.vao_ids[
i] = 0;
55 vao_base_instance_ = 0;
63 if (!is_dynamic_vao_count) {
66 if (static_vaos.vao_ids[
i] == 0) {
73 static_vaos.vao_ids[
i] = vao;
78 if (static_vaos.interfaces[
i] !=
nullptr) {
80 context_->vao_free(static_vaos.vao_ids[
i]);
84 is_dynamic_vao_count =
true;
86 dynamic_vaos.count = GPU_BATCH_VAO_DYN_ALLOC_COUNT;
93 if (is_dynamic_vao_count) {
95 for (
i = 0;
i < dynamic_vaos.count;
i++) {
96 if (dynamic_vaos.vao_ids[
i] == 0) {
101 if (
i == dynamic_vaos.count) {
103 i = dynamic_vaos.count;
104 dynamic_vaos.count += GPU_BATCH_VAO_DYN_ALLOC_COUNT;
106 (
void *)dynamic_vaos.interfaces,
sizeof(
GLShaderInterface *) * dynamic_vaos.count);
107 dynamic_vaos.vao_ids = (GLuint *)
MEM_recallocN(dynamic_vaos.vao_ids,
108 sizeof(GLuint) * dynamic_vaos.count);
111 dynamic_vaos.vao_ids[
i] = vao;
120 GLuint *vaos = (is_dynamic_vao_count) ? dynamic_vaos.vao_ids : static_vaos.vao_ids;
121 const GLShaderInterface **interfaces = (is_dynamic_vao_count) ? dynamic_vaos.interfaces :
122 static_vaos.interfaces;
123 for (
int i = 0;
i < count;
i++) {
125 context_->vao_free(vaos[
i]);
127 interfaces[
i] =
nullptr;
133 interface_ =
nullptr;
142 GLuint *vaos = (is_dynamic_vao_count) ? dynamic_vaos.vao_ids : static_vaos.vao_ids;
143 const GLShaderInterface **interfaces = (is_dynamic_vao_count) ? dynamic_vaos.interfaces :
144 static_vaos.interfaces;
146 if (context_ ==
nullptr) {
150 if (context_ == ctx) {
151 glDeleteVertexArrays(count, vaos);
152 glDeleteVertexArrays(1, &vao_base_instance_);
156 for (
int i = 0;
i < count;
i++) {
157 context_->vao_free(vaos[
i]);
159 context_->vao_free(vao_base_instance_);
162 for (
int i = 0;
i < count;
i++) {
163 if (interfaces[
i] !=
nullptr) {
168 if (is_dynamic_vao_count) {
174 context_->vao_cache_unregister(
this);
183 const GLShaderInterface **interfaces = (is_dynamic_vao_count) ? dynamic_vaos.interfaces :
184 static_vaos.interfaces;
185 for (
int i = 0;
i < count;
i++) {
187 return (is_dynamic_vao_count) ? dynamic_vaos.vao_ids[
i] : static_vaos.vao_ids[
i];
193void GLVaoCache::context_check()
198 if (context_ != ctx) {
199 if (context_ !=
nullptr) {
212 this->context_check();
218 vao_id_ = this->
lookup(interface_);
222 glGenVertexArrays(1, &vao_id_);
223 this->
insert(interface_, vao_id_);
257 GLenum gl_type =
to_gl(prim_type);
265 glDrawElementsInstancedBaseVertexBaseInstance(
266 gl_type, v_count, index_type, v_first_ofs, i_count, base_index, i_first);
269 glDrawArraysInstancedBaseInstance(gl_type, v_first, v_count, i_count, i_first);
280 GLenum gl_type =
to_gl(prim_type);
284 glDrawElementsIndirect(gl_type, index_type, (GLvoid *)offset);
287 glDrawArraysIndirect(gl_type, (GLvoid *)offset);
290 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
303 GLenum gl_type =
to_gl(prim_type);
307 glMultiDrawElementsIndirect(gl_type, index_type, (GLvoid *)offset, count, stride);
310 glMultiDrawArraysIndirect(gl_type, (GLvoid *)offset, count, stride);
313 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
StateManager * state_manager
void multi_draw_indirect(GPUStorageBuf *indirect_buf, int count, intptr_t offset, intptr_t stride) override
GLIndexBuf * elem_() const
void draw(int v_first, int v_count, int i_first, int i_count) override
void draw_indirect(GPUStorageBuf *indirect_buf, intptr_t offset) override
void vao_cache_unregister(GLVaoCache *cache)
void vao_cache_register(GLVaoCache *cache)
void * offset_ptr(uint additional_vertex_offset) const
GLuint lookup(const GLShaderInterface *interface)
GLuint vao_get(Batch *batch)
void insert(const GLShaderInterface *interface, GLuint vao_id)
void remove(const GLShaderInterface *interface)
GPUIndexBufType index_type_
virtual void apply_state()=0
#define GL_CHECK_RESOURCES(info)
#define MEM_recallocN(vmemh, len)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_callocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
#define GPU_VAO_STATIC_LEN
void update_bindings(const GLuint vao, const Batch *batch, const ShaderInterface *interface, int base_instance)
VKBatch * unwrap(Batch *batch)
GLenum to_gl(eGPUDataFormat format)