Blender  V3.3
gpu_index_buffer_private.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 "BLI_assert.h"
11 
12 #include "GPU_index_buffer.h"
13 
14 #define GPU_TRACK_INDEX_RANGE 1
15 
16 namespace blender::gpu {
17 
18 typedef enum {
22 
23 static inline size_t to_bytesize(GPUIndexBufType type)
24 {
25  return (type == GPU_INDEX_U32) ? sizeof(uint32_t) : sizeof(uint16_t);
26 }
27 
34 class IndexBuf {
35  protected:
45  bool is_init_ = false;
47  bool is_subrange_ = false;
49  bool is_empty_ = false;
50 
51  union {
53  void *data_ = nullptr;
56  };
57 
58  public:
59  IndexBuf(){};
60  virtual ~IndexBuf();
61 
62  void init(uint indices_len, uint32_t *indices, uint min_index, uint max_index);
63  void init_subrange(IndexBuf *elem_src, uint start, uint length);
64  void init_build_on_device(uint index_len);
65 
66  /* Returns render index count (not precise). */
68  {
69  /* Return 0 to bypass drawing for index buffers full of restart indices.
70  * They can lead to graphical glitches on some systems. (See T96892) */
71  return is_empty_ ? 0 : index_len_;
72  }
73  /* Return size in byte of the drawable data buffer range. Actual buffer size might be bigger. */
74  size_t size_get() const
75  {
77  };
78 
79  bool is_init() const
80  {
81  return is_init_;
82  };
83 
84  virtual void upload_data() = 0;
85 
86  virtual void bind_as_ssbo(uint binding) = 0;
87 
88  virtual const uint32_t *read() const = 0;
89  uint32_t *unmap(const uint32_t *mapped_memory) const;
90 
91  virtual void update_sub(uint start, uint len, const void *data) = 0;
92 
93  private:
94  inline void squeeze_indices_short(uint min_idx, uint max_idx);
95  inline uint index_range(uint *r_min, uint *r_max);
96 };
97 
98 /* Syntactic sugar. */
99 static inline GPUIndexBuf *wrap(IndexBuf *indexbuf)
100 {
101  return reinterpret_cast<GPUIndexBuf *>(indexbuf);
102 }
103 static inline IndexBuf *unwrap(GPUIndexBuf *indexbuf)
104 {
105  return reinterpret_cast<IndexBuf *>(indexbuf);
106 }
107 static inline const IndexBuf *unwrap(const GPUIndexBuf *indexbuf)
108 {
109  return reinterpret_cast<const IndexBuf *>(indexbuf);
110 }
111 
112 static inline int indices_per_primitive(GPUPrimType prim_type)
113 {
114  switch (prim_type) {
115  case GPU_PRIM_POINTS:
116  return 1;
117  case GPU_PRIM_LINES:
118  return 2;
119  case GPU_PRIM_TRIS:
120  return 3;
121  case GPU_PRIM_LINES_ADJ:
122  return 4;
123  default:
124  return -1;
125  }
126 }
127 
128 } // namespace blender::gpu
unsigned int uint
Definition: BLI_sys_types.h:67
struct GPUIndexBuf GPUIndexBuf
_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
GPUPrimType
Definition: GPU_primitive.h:18
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:20
@ GPU_PRIM_POINTS
Definition: GPU_primitive.h:19
@ GPU_PRIM_LINES_ADJ
Definition: GPU_primitive.h:29
@ GPU_PRIM_TRIS
Definition: GPU_primitive.h:21
void init(uint indices_len, uint32_t *indices, uint min_index, uint max_index)
virtual void upload_data()=0
virtual const uint32_t * read() const =0
uint32_t * unmap(const uint32_t *mapped_memory) const
virtual void update_sub(uint start, uint len, const void *data)=0
void init_build_on_device(uint index_len)
void init_subrange(IndexBuf *elem_src, uint start, uint length)
virtual void bind_as_ssbo(uint binding)=0
int len
Definition: draw_manager.c:108
ccl_gpu_kernel_postfix int ccl_global int * indices
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
static int indices_per_primitive(GPUPrimType prim_type)
static size_t to_bytesize(GPUIndexBufType type)
T length(const vec_base< T, Size > &a)
unsigned short uint16_t
Definition: stdint.h:79
unsigned int uint32_t
Definition: stdint.h:80