Blender  V2.93
gpu_vertex_buffer_private.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2016 by Mike Erwin.
17  * All rights reserved.
18  */
19 
26 #pragma once
27 
28 #include "GPU_vertex_buffer.h"
29 
30 namespace blender::gpu {
31 
36 class VertBuf {
37  public:
38  static size_t memory_usage;
39 
49 
50  protected:
53 
54  private:
56  int handle_refcount_ = 1;
57 
58  public:
59  VertBuf();
60  virtual ~VertBuf();
61 
62  void init(const GPUVertFormat *format, GPUUsageType usage);
63  void clear(void);
64 
65  /* Data management. */
66  void allocate(uint vert_len);
67  void resize(uint vert_len);
68  void upload(void);
69 
70  VertBuf *duplicate(void);
71 
72  /* Size of the data allocated. */
73  size_t size_alloc_get(void) const
74  {
75  BLI_assert(format.packed);
76  return vertex_alloc * format.stride;
77  }
78  /* Size of the data uploaded to the GPU. */
79  size_t size_used_get(void) const
80  {
81  BLI_assert(format.packed);
82  return vertex_len * format.stride;
83  }
84 
85  void reference_add(void)
86  {
87  handle_refcount_++;
88  }
89  void reference_remove(void)
90  {
91  BLI_assert(handle_refcount_ > 0);
92  handle_refcount_--;
93  if (handle_refcount_ == 0) {
94  delete this;
95  }
96  }
97 
98  virtual void update_sub(uint start, uint len, void *data) = 0;
99 
100  protected:
101  virtual void acquire_data(void) = 0;
102  virtual void resize_data(void) = 0;
103  virtual void release_data(void) = 0;
104  virtual void upload_data(void) = 0;
105  virtual void duplicate_data(VertBuf *dst) = 0;
106 };
107 
108 /* Syntactic sugar. */
109 static inline GPUVertBuf *wrap(VertBuf *vert)
110 {
111  return reinterpret_cast<GPUVertBuf *>(vert);
112 }
113 static inline VertBuf *unwrap(GPUVertBuf *vert)
114 {
115  return reinterpret_cast<VertBuf *>(vert);
116 }
117 static inline const VertBuf *unwrap(const GPUVertBuf *vert)
118 {
119  return reinterpret_cast<const VertBuf *>(vert);
120 }
121 
122 } // namespace blender::gpu
#define BLI_assert(a)
Definition: BLI_assert.h:58
unsigned char uchar
Definition: BLI_sys_types.h:86
unsigned int uint
Definition: BLI_sys_types.h:83
struct GPUVertBuf GPUVertBuf
GPUVertBufStatus
@ GPU_VERTBUF_INVALID
GPUUsageType
@ GPU_USAGE_STATIC
virtual void release_data(void)=0
virtual void update_sub(uint start, uint len, void *data)=0
void resize(uint vert_len)
void init(const GPUVertFormat *format, GPUUsageType usage)
void allocate(uint vert_len)
virtual void upload_data(void)=0
virtual void duplicate_data(VertBuf *dst)=0
virtual void resize_data(void)=0
VertBuf * duplicate(void)
virtual void acquire_data(void)=0
format
Definition: logImageCore.h:47
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
uint len