Blender V5.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
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::gpu {
18
19class GLVertBuf : public VertBuf {
20 friend class GLTexture; /* For buffer texture. */
21 friend class GLStorageBuf; /* For sub copy. */
22
23 private:
25 GLuint vbo_id_ = 0;
27 gpu::Texture *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 void copy_sub(VertBuf &source_buf,
41 uint source_first_vertex,
42 uint dest_first_vertex,
43 uint vertex_len) override;
44
45 void read(void *data) const override;
46
47 void wrap_handle(uint64_t handle) override;
48
49 protected:
50 void acquire_data() override;
51 void resize_data() override;
52 void release_data() override;
53 void upload_data() override;
54 void bind_as_ssbo(uint binding) override;
55 void bind_as_texture(uint binding) override;
56
57 private:
58 bool is_active() const;
59
60 MEM_CXX_CLASS_ALLOC_FUNCS("GLVertBuf");
61};
62
63static inline GLenum to_gl(GPUUsageType type)
64{
65 switch (type) {
67 return GL_STREAM_DRAW;
69 return GL_DYNAMIC_DRAW;
72 return GL_STATIC_DRAW;
73 default:
74 BLI_assert(0);
75 return GL_STATIC_DRAW;
76 }
77}
78
79static inline GLenum to_gl(GPUVertCompType type)
80{
81 switch (type) {
82 case GPU_COMP_I8:
83 return GL_BYTE;
84 case GPU_COMP_U8:
85 return GL_UNSIGNED_BYTE;
86 case GPU_COMP_I16:
87 return GL_SHORT;
88 case GPU_COMP_U16:
89 return GL_UNSIGNED_SHORT;
90 case GPU_COMP_I32:
91 return GL_INT;
92 case GPU_COMP_U32:
93 return GL_UNSIGNED_INT;
94 case GPU_COMP_F32:
95 return GL_FLOAT;
96 case GPU_COMP_I10:
97 return GL_INT_2_10_10_10_REV;
98 default:
99 BLI_assert(0);
100 return GL_FLOAT;
101 }
102}
103
104} // namespace blender::gpu
Read Blender memory allocation and freeing.
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 update_sub(uint start, uint len, const void *data) override
void copy_sub(VertBuf &source_buf, uint source_first_vertex, uint dest_first_vertex, uint vertex_len) override
Copy from part of source vertex buffer into the vertex buffer.
MutableSpan< T > data()
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
GLenum to_gl(eGPUDataFormat format)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint
Definition BKE_text.h:55