Blender V5.0
gl_vertex_buffer.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
11#include "MEM_guardedalloc.h"
12
13#include "GPU_texture.hh"
14
15#include "GPU_vertex_buffer.hh"
16
17namespace blender {
18namespace gpu {
19
20class GLVertBuf : public VertBuf {
21 friend class GLTexture; /* For buffer texture. */
22 friend class GLStorageBuf; /* For sub copy. */
23
24 private:
26 GLuint vbo_id_ = 0;
28 gpu::Texture *buffer_texture_ = nullptr;
31 bool is_wrapper_ = false;
33 size_t vbo_size_ = 0;
34
35 public:
36 void bind();
37
38 void update_sub(uint start, uint len, const void *data) override;
39
40 void read(void *data) const override;
41
42 void wrap_handle(uint64_t handle) override;
43
44 protected:
45 void acquire_data() override;
46 void resize_data() override;
47 void release_data() override;
48 void upload_data() override;
49 void bind_as_ssbo(uint binding) override;
50 void bind_as_texture(uint binding) override;
51
52 private:
53 bool is_active() const;
54
55 MEM_CXX_CLASS_ALLOC_FUNCS("GLVertBuf");
56};
57
58static inline GLenum to_gl(GPUUsageType type)
59{
60 switch (type) {
62 return GL_STREAM_DRAW;
64 return GL_DYNAMIC_DRAW;
67 return GL_STATIC_DRAW;
68 default:
69 BLI_assert(0);
70 return GL_STATIC_DRAW;
71 }
72}
73
74static inline GLenum to_gl(GPUVertCompType type)
75{
76 switch (type) {
77 case GPU_COMP_I8:
78 return GL_BYTE;
79 case GPU_COMP_U8:
80 return GL_UNSIGNED_BYTE;
81 case GPU_COMP_I16:
82 return GL_SHORT;
83 case GPU_COMP_U16:
84 return GL_UNSIGNED_SHORT;
85 case GPU_COMP_I32:
86 return GL_INT;
87 case GPU_COMP_U32:
88 return GL_UNSIGNED_INT;
89 case GPU_COMP_F32:
90 return GL_FLOAT;
91 case GPU_COMP_I10:
92 return GL_INT_2_10_10_10_REV;
93 default:
94 BLI_assert(0);
95 return GL_FLOAT;
96 }
97}
98
99} // namespace gpu
100} // namespace blender
#define BLI_assert(a)
Definition BLI_assert.h:46
unsigned int uint
@ GPU_USAGE_STATIC
@ GPU_USAGE_STREAM
@ GPU_USAGE_DYNAMIC
@ GPU_USAGE_DEVICE_ONLY
GPUVertCompType
@ GPU_COMP_U16
@ GPU_COMP_I10
@ GPU_COMP_F32
@ GPU_COMP_I32
@ GPU_COMP_I8
@ GPU_COMP_U32
@ GPU_COMP_I16
@ GPU_COMP_U8
Read Guarded memory(de)allocation.
unsigned long long int uint64_t
void bind_as_texture(uint binding) override
void bind_as_ssbo(uint binding) override
void wrap_handle(uint64_t handle) override
void update_sub(uint start, uint len, const void *data) override
MutableSpan< T > data()
static GLenum to_gl(const GPUAttachmentType type)
uint len