Blender  V2.93
GPU_vertex_buffer.h
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 "BLI_utildefines.h"
29 
30 #include "GPU_vertex_format.h"
31 
32 typedef enum {
36  GPU_VERTBUF_INIT = (1 << 0),
42 
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
57 typedef enum {
58  /* can be extended to support more types */
60  GPU_USAGE_STATIC, /* do not keep data in memory */
62 } GPUUsageType;
63 
65 typedef struct GPUVertBuf GPUVertBuf;
66 
69 
70 #define GPU_vertbuf_create_with_format(format) \
71  GPU_vertbuf_create_with_format_ex(format, GPU_USAGE_STATIC)
72 
75 
76 /* Avoid GPUVertBuf datablock being free but not its data. */
79 
81 
82 #define GPU_vertbuf_init_with_format(verts, format) \
83  GPU_vertbuf_init_with_format_ex(verts, format, GPU_USAGE_STATIC)
84 
86 
90 
91 /* The most important #set_attr variant is the untyped one. Get it right first.
92  * It takes a void* so the app developer is responsible for matching their app data types
93  * to the vertex attribute's type and component count. They're in control of both, so this
94  * should not be a problem. */
95 
96 void GPU_vertbuf_attr_set(GPUVertBuf *, uint a_idx, uint v_idx, const void *data);
97 
98 void GPU_vertbuf_vert_set(GPUVertBuf *verts, uint v_idx, const void *data);
99 
100 /* Tightly packed, non interleaved input data. */
101 void GPU_vertbuf_attr_fill(GPUVertBuf *, uint a_idx, const void *data);
102 
103 void GPU_vertbuf_attr_fill_stride(GPUVertBuf *, uint a_idx, uint stride, const void *data);
104 
105 /* For low level access only */
106 typedef struct GPUVertBufRaw {
109  unsigned char *data;
110  unsigned char *data_init;
111 #ifdef DEBUG
112  /* Only for overflow check */
113  unsigned char *_data_end;
114 #endif
116 
118 {
119  unsigned char *data = a->data;
120  a->data += a->stride;
121  BLI_assert(data < a->_data_end);
122  return (void *)data;
123 }
124 
126 {
127  return ((a->data - a->data_init) / a->stride);
128 }
129 
131 
133 
139 
141 
142 /* XXX do not use. */
143 void GPU_vertbuf_update_sub(GPUVertBuf *verts, uint start, uint len, void *data);
144 
145 /* Metrics */
147 
148 /* Macros */
149 #define GPU_VERTBUF_DISCARD_SAFE(verts) \
150  do { \
151  if (verts != NULL) { \
152  GPU_vertbuf_discard(verts); \
153  verts = NULL; \
154  } \
155  } while (0)
156 
157 #ifdef __cplusplus
158 }
159 #endif
#define BLI_assert(a)
Definition: BLI_assert.h:58
unsigned int uint
Definition: BLI_sys_types.h:83
#define ENUM_OPERATORS(_type, _max)
#define GPU_INLINE
Definition: GPU_common.h:47
_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)
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)
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
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_update_sub(GPUVertBuf *verts, uint start, uint len, void *data)
void GPU_vertbuf_use(GPUVertBuf *)
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_handle_ref_add(GPUVertBuf *verts)
uint GPU_vertbuf_get_memory_usage(void)
struct GPUVertBufRaw GPUVertBufRaw
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
void GPU_vertbuf_data_resize(GPUVertBuf *, uint v_len)
static float verts[][3]
static unsigned a[3]
Definition: RandGen.cpp:92
unsigned char * data_init
unsigned char * data
uint len