Blender  V3.3
gl_batch.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 
11 #pragma once
12 
13 #include "MEM_guardedalloc.h"
14 
15 #include "gpu_batch_private.hh"
16 
17 #include "gl_index_buffer.hh"
18 #include "gl_vertex_buffer.hh"
19 
20 #include "glew-mx.h"
21 
22 namespace blender {
23 namespace gpu {
24 
25 class GLContext;
26 class GLShaderInterface;
27 
28 #define GPU_VAO_STATIC_LEN 3
29 
35 class GLVaoCache {
36  private:
38  GLContext *context_ = nullptr;
40  GLShaderInterface *interface_ = nullptr;
42  GLuint vao_id_ = 0;
44  GLuint vao_base_instance_ = 0;
45  int base_instance_ = 0;
46 
47  bool is_dynamic_vao_count = false;
48  union {
50  struct {
55  struct {
58  GLuint *vao_ids;
60  };
61 
62  public:
63  GLVaoCache();
64  ~GLVaoCache();
65 
66  GLuint vao_get(GPUBatch *batch);
67  GLuint base_instance_vao_get(GPUBatch *batch, int i_first);
68 
72  GLuint lookup(const GLShaderInterface *interface);
76  void insert(const GLShaderInterface *interface, GLuint vao_id);
77  void remove(const GLShaderInterface *interface);
78  void clear();
79 
80  private:
81  void init();
86  void context_check();
87 };
88 
89 class GLBatch : public Batch {
90  public:
93 
94  public:
95  void draw(int v_first, int v_count, int i_first, int i_count) override;
96  void bind(int i_first);
97 
98  /* Convenience getters. */
99 
100  GLIndexBuf *elem_() const
101  {
102  return static_cast<GLIndexBuf *>(unwrap(elem));
103  }
104  GLVertBuf *verts_(const int index) const
105  {
106  return static_cast<GLVertBuf *>(unwrap(verts[index]));
107  }
108  GLVertBuf *inst_(const int index) const
109  {
110  return static_cast<GLVertBuf *>(unwrap(inst[index]));
111  }
112 
114 };
115 
116 } // namespace gpu
117 } // namespace blender
unsigned int uint
Definition: BLI_sys_types.h:67
GPUBatch
Definition: GPU_batch.h:78
Read Guarded memory(de)allocation.
GLVertBuf * verts_(const int index) const
Definition: gl_batch.hh:104
GLIndexBuf * elem_() const
Definition: gl_batch.hh:100
MEM_CXX_CLASS_ALLOC_FUNCS("GLBatch")
void bind(int i_first)
Definition: gl_batch.cc:263
void draw(int v_first, int v_count, int i_first, int i_count) override
Definition: gl_batch.cc:288
GLVertBuf * inst_(const int index) const
Definition: gl_batch.hh:108
GLVaoCache vao_cache_
Definition: gl_batch.hh:92
GLuint base_instance_vao_get(GPUBatch *batch, int i_first)
Definition: gl_batch.cc:204
struct blender::gpu::GLVaoCache::@687::@689 static_vaos
GLuint lookup(const GLShaderInterface *interface)
Definition: gl_batch.cc:174
const GLShaderInterface ** interfaces
Definition: gl_batch.hh:57
const GLShaderInterface * interfaces[GPU_VAO_STATIC_LEN]
Definition: gl_batch.hh:51
void insert(const GLShaderInterface *interface, GLuint vao_id)
Definition: gl_batch.cc:58
GLuint vao_get(GPUBatch *batch)
Definition: gl_batch.cc:236
GLuint vao_ids[GPU_VAO_STATIC_LEN]
Definition: gl_batch.hh:52
struct blender::gpu::GLVaoCache::@687::@690 dynamic_vaos
void remove(const GLShaderInterface *interface)
Definition: gl_batch.cc:116
static float verts[][3]
#define GPU_VAO_STATIC_LEN
Definition: gl_batch.hh:28
struct @653::@655 batch
static Context * unwrap(GPUContext *ctx)