Blender  V2.93
gpu_index_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) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 #include "BLI_assert.h"
27 
28 #include "GPU_index_buffer.h"
29 
30 #define GPU_TRACK_INDEX_RANGE 1
31 
32 namespace blender::gpu {
33 
34 typedef enum {
38 
39 static inline size_t to_bytesize(GPUIndexBufType type)
40 {
41  return (type == GPU_INDEX_U32) ? sizeof(uint32_t) : sizeof(uint16_t);
42 }
43 
50 class IndexBuf {
51  protected:
61  bool is_init_ = false;
63  bool is_subrange_ = false;
64 
65  union {
67  void *data_ = nullptr;
70  };
71 
72  public:
73  IndexBuf(){};
74  virtual ~IndexBuf();
75 
76  void init(uint indices_len, uint32_t *indices);
77  void init_subrange(IndexBuf *elem_src, uint start, uint length);
78 
79  uint32_t index_len_get(void) const
80  {
81  return index_len_;
82  }
83  /* Return size in byte of the drawable data buffer range. Actual buffer size might be bigger. */
84  size_t size_get(void)
85  {
87  };
88 
89  bool is_init(void) const
90  {
91  return is_init_;
92  };
93 
94  private:
95  inline void squeeze_indices_short(uint min_idx, uint max_idx);
96  inline uint index_range(uint *r_min, uint *r_max);
97 };
98 
99 /* Syntactic sugar. */
100 static inline GPUIndexBuf *wrap(IndexBuf *indexbuf)
101 {
102  return reinterpret_cast<GPUIndexBuf *>(indexbuf);
103 }
104 static inline IndexBuf *unwrap(GPUIndexBuf *indexbuf)
105 {
106  return reinterpret_cast<IndexBuf *>(indexbuf);
107 }
108 
109 static inline int indices_per_primitive(GPUPrimType prim_type)
110 {
111  switch (prim_type) {
112  case GPU_PRIM_POINTS:
113  return 1;
114  case GPU_PRIM_LINES:
115  return 2;
116  case GPU_PRIM_TRIS:
117  return 3;
118  case GPU_PRIM_LINES_ADJ:
119  return 4;
120  default:
121  return -1;
122  }
123 }
124 
125 } // namespace blender::gpu
unsigned int uint
Definition: BLI_sys_types.h:83
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:34
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:36
@ GPU_PRIM_POINTS
Definition: GPU_primitive.h:35
@ GPU_PRIM_LINES_ADJ
Definition: GPU_primitive.h:43
@ GPU_PRIM_TRIS
Definition: GPU_primitive.h:37
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Definition: btQuaternion.h:895
void init(uint indices_len, uint32_t *indices)
uint32_t index_len_get(void) const
void init_subrange(IndexBuf *elem_src, uint start, uint length)
static ushort 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)
unsigned short uint16_t
Definition: stdint.h:82
unsigned int uint32_t
Definition: stdint.h:83