Blender  V3.3
GPU_vertex_buffer.h
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 "BLI_utildefines.h"
13 
14 #include "GPU_vertex_format.h"
15 
16 typedef enum {
20  GPU_VERTBUF_INIT = (1 << 0),
26 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
41 typedef enum {
42  /* can be extended to support more types */
44  GPU_USAGE_STATIC, /* do not keep data in memory */
46  GPU_USAGE_DEVICE_ONLY, /* Do not do host->device data transfers. */
47 } GPUUsageType;
48 
50 typedef struct GPUVertBuf GPUVertBuf;
51 
54 
55 #define GPU_vertbuf_create_with_format(format) \
56  GPU_vertbuf_create_with_format_ex(format, GPU_USAGE_STATIC)
57 
64 const void *GPU_vertbuf_read(GPUVertBuf *verts);
65 void *GPU_vertbuf_unmap(const GPUVertBuf *verts, const void *mapped_data);
69 
75 
77 
79 
80 #define GPU_vertbuf_init_with_format(verts, format) \
81  GPU_vertbuf_init_with_format_ex(verts, format, GPU_USAGE_STATIC)
82 
84 
99 
106 void GPU_vertbuf_attr_set(GPUVertBuf *, uint a_idx, uint v_idx, const void *data);
107 
109 void GPU_vertbuf_vert_set(GPUVertBuf *verts, uint v_idx, const void *data);
110 
114 void GPU_vertbuf_attr_fill(GPUVertBuf *, uint a_idx, const void *data);
115 
116 void GPU_vertbuf_attr_fill_stride(GPUVertBuf *, uint a_idx, uint stride, const void *data);
117 
121 typedef struct GPUVertBufRaw {
124  unsigned char *data;
125  unsigned char *data_init;
126 #ifdef DEBUG
127  /* Only for overflow check */
128  unsigned char *_data_end;
129 #endif
131 
133 {
134  unsigned char *data = a->data;
135  a->data += a->stride;
136  BLI_assert(data < a->_data_end);
137  return (void *)data;
138 }
139 
141 {
142  return ((a->data - a->data_init) / a->stride);
143 }
144 
146 
152 
162 
167 void GPU_vertbuf_bind_as_ssbo(struct GPUVertBuf *verts, int binding);
168 void GPU_vertbuf_bind_as_texture(struct GPUVertBuf *verts, int binding);
169 
171 
177 void GPU_vertbuf_update_sub(GPUVertBuf *verts, uint start, uint len, const void *data);
178 
179 /* Metrics */
181 
182 /* Macros */
183 #define GPU_VERTBUF_DISCARD_SAFE(verts) \
184  do { \
185  if (verts != NULL) { \
186  GPU_vertbuf_discard(verts); \
187  verts = NULL; \
188  } \
189  } while (0)
190 
191 #ifdef __cplusplus
192 }
193 #endif
#define BLI_assert(a)
Definition: BLI_assert.h:46
unsigned int uint
Definition: BLI_sys_types.h:67
#define ENUM_OPERATORS(_type, _max)
#define GPU_INLINE
Definition: GPU_common.h:32
_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 const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
uint GPU_vertbuf_get_vertex_alloc(const GPUVertBuf *verts)
void GPU_vertbuf_wrap_handle(GPUVertBuf *verts, uint64_t handle)
void * GPU_vertbuf_unmap(const GPUVertBuf *verts, const void *mapped_data)
const GPUVertFormat * GPU_vertbuf_get_format(const GPUVertBuf *verts)
uint GPU_vertbuf_get_vertex_len(const GPUVertBuf *verts)
void GPU_vertbuf_vert_set(GPUVertBuf *verts, uint v_idx, const void *data)
void GPU_vertbuf_discard(GPUVertBuf *)
void * GPU_vertbuf_steal_data(GPUVertBuf *verts)
struct GPUVertBuf GPUVertBuf
GPU_INLINE uint GPU_vertbuf_raw_used(GPUVertBufRaw *a)
void GPU_vertbuf_update_sub(GPUVertBuf *verts, uint start, uint len, const void *data)
GPUVertBuf * GPU_vertbuf_calloc(void)
void GPU_vertbuf_clear(GPUVertBuf *verts)
void GPU_vertbuf_handle_ref_remove(GPUVertBuf *verts)
void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len)
void GPU_vertbuf_init_with_format_ex(GPUVertBuf *, const GPUVertFormat *, GPUUsageType)
GPUVertBufStatus
@ GPU_VERTBUF_INIT
@ GPU_VERTBUF_INVALID
@ GPU_VERTBUF_DATA_DIRTY
@ GPU_VERTBUF_DATA_UPLOADED
void GPU_vertbuf_bind_as_ssbo(struct GPUVertBuf *verts, int binding)
GPUVertBufStatus GPU_vertbuf_get_status(const GPUVertBuf *verts)
void GPU_vertbuf_attr_fill_stride(GPUVertBuf *, uint a_idx, uint stride, const void *data)
void * GPU_vertbuf_get_data(const GPUVertBuf *verts)
GPUVertBuf * GPU_vertbuf_duplicate(GPUVertBuf *verts)
void GPU_vertbuf_init_build_on_device(GPUVertBuf *verts, GPUVertFormat *format, uint v_len)
void GPU_vertbuf_use(GPUVertBuf *)
const void * GPU_vertbuf_read(GPUVertBuf *verts)
GPUVertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat *, GPUUsageType)
void GPU_vertbuf_attr_fill(GPUVertBuf *, uint a_idx, const void *data)
GPU_INLINE void * GPU_vertbuf_raw_step(GPUVertBufRaw *a)
void GPU_vertbuf_data_len_set(GPUVertBuf *, uint v_len)
void GPU_vertbuf_attr_get_raw_data(GPUVertBuf *, uint a_idx, GPUVertBufRaw *access)
void GPU_vertbuf_bind_as_texture(struct GPUVertBuf *verts, int binding)
void GPU_vertbuf_handle_ref_add(GPUVertBuf *verts)
uint GPU_vertbuf_get_memory_usage(void)
struct GPUVertBufRaw GPUVertBufRaw
void GPU_vertbuf_tag_dirty(GPUVertBuf *verts)
void GPU_vertbuf_attr_set(GPUVertBuf *, uint a_idx, uint v_idx, const void *data)
GPUUsageType
@ GPU_USAGE_STATIC
@ GPU_USAGE_STREAM
@ GPU_USAGE_DYNAMIC
@ GPU_USAGE_DEVICE_ONLY
void GPU_vertbuf_data_resize(GPUVertBuf *, uint v_len)
int len
Definition: draw_manager.c:108
static float verts[][3]
format
Definition: logImageCore.h:38
static unsigned a[3]
Definition: RandGen.cpp:78
unsigned __int64 uint64_t
Definition: stdint.h:90
unsigned char * data_init
unsigned char * data