Blender V4.3
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
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 GLShader; /* For transform feedback. */
23 friend class GLStorageBuf; /* For sub copy. */
24
25 private:
27 GLuint vbo_id_ = 0;
29 ::GPUTexture *buffer_texture_ = nullptr;
32 bool is_wrapper_ = false;
34 size_t vbo_size_ = 0;
35
36 public:
37 void bind();
38
39 void update_sub(uint start, uint len, const void *data) override;
40
41 void read(void *data) const override;
42
43 void wrap_handle(uint64_t handle) override;
44
45 protected:
46 void acquire_data() override;
47 void resize_data() override;
48 void release_data() override;
49 void upload_data() override;
50 void duplicate_data(VertBuf *dst) override;
51 void bind_as_ssbo(uint binding) override;
52 void bind_as_texture(uint binding) override;
53
54 private:
55 bool is_active() const;
56
57 MEM_CXX_CLASS_ALLOC_FUNCS("GLVertBuf");
58};
59
60static inline GLenum to_gl(GPUUsageType type)
61{
62 switch (type) {
64 return GL_STREAM_DRAW;
66 return GL_DYNAMIC_DRAW;
69 return GL_STATIC_DRAW;
70 default:
71 BLI_assert(0);
72 return GL_STATIC_DRAW;
73 }
74}
75
76static inline GLenum to_gl(GPUVertCompType type)
77{
78 switch (type) {
79 case GPU_COMP_I8:
80 return GL_BYTE;
81 case GPU_COMP_U8:
82 return GL_UNSIGNED_BYTE;
83 case GPU_COMP_I16:
84 return GL_SHORT;
85 case GPU_COMP_U16:
86 return GL_UNSIGNED_SHORT;
87 case GPU_COMP_I32:
88 return GL_INT;
89 case GPU_COMP_U32:
90 return GL_UNSIGNED_INT;
91 case GPU_COMP_F32:
92 return GL_FLOAT;
93 case GPU_COMP_I10:
94 return GL_INT_2_10_10_10_REV;
95 default:
96 BLI_assert(0);
97 return GL_FLOAT;
98 }
99}
100
101} // namespace gpu
102} // namespace blender
#define BLI_assert(a)
Definition BLI_assert.h:50
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.
void bind_as_texture(uint binding) override
void read(void *data) const override
void bind_as_ssbo(uint binding) override
void wrap_handle(uint64_t handle) override
void duplicate_data(VertBuf *dst) override
void update_sub(uint start, uint len, const void *data) override
int len
static GLenum to_gl(const GPUAttachmentType type)
unsigned __int64 uint64_t
Definition stdint.h:90