Blender  V3.3
gl_vertex_buffer.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 
8 #pragma once
9 
10 #include "MEM_guardedalloc.h"
11 
12 #include "glew-mx.h"
13 
14 #include "GPU_texture.h"
15 
17 
18 namespace blender {
19 namespace gpu {
20 
21 class GLVertBuf : public VertBuf {
22  friend class GLTexture; /* For buffer texture. */
23  friend class GLShader; /* For transform feedback. */
24  friend class GLStorageBuf; /* For sub copy. */
25 
26  private:
28  GLuint vbo_id_ = 0;
30  struct ::GPUTexture *buffer_texture_ = nullptr;
33  bool is_wrapper_ = false;
35  size_t vbo_size_ = 0;
36 
37  public:
38  void bind();
39 
40  void update_sub(uint start, uint len, const void *data) override;
41 
42  const void *read() const override;
43  void *unmap(const void *mapped_data) const override;
44 
45  void wrap_handle(uint64_t handle) override;
46 
47  protected:
48  void acquire_data() override;
49  void resize_data() override;
50  void release_data() override;
51  void upload_data() override;
52  void duplicate_data(VertBuf *dst) override;
53  void bind_as_ssbo(uint binding) override;
54  void bind_as_texture(uint binding) override;
55 
56  private:
57  bool is_active() const;
58 
59  MEM_CXX_CLASS_ALLOC_FUNCS("GLVertBuf");
60 };
61 
62 static inline GLenum to_gl(GPUUsageType type)
63 {
64  switch (type) {
65  case GPU_USAGE_STREAM:
66  return GL_STREAM_DRAW;
67  case GPU_USAGE_DYNAMIC:
68  return GL_DYNAMIC_DRAW;
69  case GPU_USAGE_STATIC:
71  return GL_STATIC_DRAW;
72  default:
73  BLI_assert(0);
74  return GL_STATIC_DRAW;
75  }
76 }
77 
78 static inline GLenum to_gl(GPUVertCompType type)
79 {
80  switch (type) {
81  case GPU_COMP_I8:
82  return GL_BYTE;
83  case GPU_COMP_U8:
84  return GL_UNSIGNED_BYTE;
85  case GPU_COMP_I16:
86  return GL_SHORT;
87  case GPU_COMP_U16:
88  return GL_UNSIGNED_SHORT;
89  case GPU_COMP_I32:
90  return GL_INT;
91  case GPU_COMP_U32:
92  return GL_UNSIGNED_INT;
93  case GPU_COMP_F32:
94  return GL_FLOAT;
95  case GPU_COMP_I10:
96  return GL_INT_2_10_10_10_REV;
97  default:
98  BLI_assert(0);
99  return GL_FLOAT;
100  }
101 }
102 
103 } // namespace gpu
104 } // namespace blender
#define BLI_assert(a)
Definition: BLI_assert.h:46
unsigned int uint
Definition: BLI_sys_types.h:67
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
GPUUsageType
@ 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 upload_data() override
void * unmap(const void *mapped_data) const override
void bind_as_ssbo(uint binding) override
void wrap_handle(uint64_t handle) override
void duplicate_data(VertBuf *dst) override
void resize_data() override
void update_sub(uint start, uint len, const void *data) override
void acquire_data() override
const void * read() const override
void release_data() override
int len
Definition: draw_manager.c:108
static GLenum to_gl(const GPUAttachmentType type)
unsigned __int64 uint64_t
Definition: stdint.h:90