Blender  V3.3
gpu_vertex_buffer_private.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2016 by Mike Erwin. All rights reserved. */
3 
10 #pragma once
11 
12 #include "GPU_vertex_buffer.h"
13 
14 namespace blender::gpu {
15 
20 class VertBuf {
21  public:
22  static size_t memory_usage;
23 
32  uchar *data = nullptr;
33 
34  protected:
37 
38  private:
40  int handle_refcount_ = 1;
41 
42  public:
43  VertBuf();
44  virtual ~VertBuf();
45 
46  void init(const GPUVertFormat *format, GPUUsageType usage);
47  void clear();
48 
49  /* Data management. */
50  void allocate(uint vert_len);
51  void resize(uint vert_len);
52  void upload();
53  virtual void bind_as_ssbo(uint binding) = 0;
54  virtual void bind_as_texture(uint binding) = 0;
55 
56  virtual void wrap_handle(uint64_t handle) = 0;
57 
58  VertBuf *duplicate();
59 
60  /* Size of the data allocated. */
61  size_t size_alloc_get() const
62  {
63  BLI_assert(format.packed);
64  return vertex_alloc * format.stride;
65  }
66  /* Size of the data uploaded to the GPU. */
67  size_t size_used_get() const
68  {
69  BLI_assert(format.packed);
70  return vertex_len * format.stride;
71  }
72 
74  {
75  handle_refcount_++;
76  }
78  {
79  BLI_assert(handle_refcount_ > 0);
80  handle_refcount_--;
81  if (handle_refcount_ == 0) {
82  delete this;
83  }
84  }
85 
86  virtual void update_sub(uint start, uint len, const void *data) = 0;
87  virtual const void *read() const = 0;
88  virtual void *unmap(const void *mapped_data) const = 0;
89 
90  protected:
91  virtual void acquire_data() = 0;
92  virtual void resize_data() = 0;
93  virtual void release_data() = 0;
94  virtual void upload_data() = 0;
95  virtual void duplicate_data(VertBuf *dst) = 0;
96 };
97 
98 /* Syntactic sugar. */
99 static inline GPUVertBuf *wrap(VertBuf *vert)
100 {
101  return reinterpret_cast<GPUVertBuf *>(vert);
102 }
103 static inline VertBuf *unwrap(GPUVertBuf *vert)
104 {
105  return reinterpret_cast<VertBuf *>(vert);
106 }
107 static inline const VertBuf *unwrap(const GPUVertBuf *vert)
108 {
109  return reinterpret_cast<const VertBuf *>(vert);
110 }
111 
112 } // namespace blender::gpu
#define BLI_assert(a)
Definition: BLI_assert.h:46
unsigned char uchar
Definition: BLI_sys_types.h:70
unsigned int uint
Definition: BLI_sys_types.h:67
struct GPUVertBuf GPUVertBuf
GPUVertBufStatus
@ GPU_VERTBUF_INVALID
GPUUsageType
@ GPU_USAGE_STATIC
virtual void wrap_handle(uint64_t handle)=0
virtual void bind_as_ssbo(uint binding)=0
void resize(uint vert_len)
virtual void upload_data()=0
virtual void * unmap(const void *mapped_data) const =0
void init(const GPUVertFormat *format, GPUUsageType usage)
virtual const void * read() const =0
void allocate(uint vert_len)
virtual void duplicate_data(VertBuf *dst)=0
virtual void resize_data()=0
virtual void bind_as_texture(uint binding)=0
virtual void release_data()=0
virtual void acquire_data()=0
virtual void update_sub(uint start, uint len, const void *data)=0
int len
Definition: draw_manager.c:108
format
Definition: logImageCore.h:38
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
unsigned __int64 uint64_t
Definition: stdint.h:90