Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/GPU_vertex_buffer.h
| Show All 40 Lines | |||||
| } GPUVertBufStatus; | } GPUVertBufStatus; | ||||
| ENUM_OPERATORS(GPUVertBufStatus) | ENUM_OPERATORS(GPUVertBufStatus) | ||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
| extern "C" { | extern "C" { | ||||
| #endif | #endif | ||||
| #define VRAM_USAGE 1 | |||||
| /** | /** | ||||
| * How to create a #GPUVertBuf: | * How to create a #GPUVertBuf: | ||||
| * 1) verts = GPU_vertbuf_calloc() | * 1) verts = GPU_vertbuf_calloc() | ||||
| * 2) GPU_vertformat_attr_add(verts->format, ...) | * 2) GPU_vertformat_attr_add(verts->format, ...) | ||||
| * 3) GPU_vertbuf_data_alloc(verts, vertex_len) <-- finalizes/packs vertex format | * 3) GPU_vertbuf_data_alloc(verts, vertex_len) <-- finalizes/packs vertex format | ||||
| * 4) GPU_vertbuf_attr_fill(verts, pos, application_pos_buffer) | * 4) GPU_vertbuf_attr_fill(verts, pos, application_pos_buffer) | ||||
| */ | */ | ||||
| typedef enum { | typedef enum { | ||||
| /* can be extended to support more types */ | /* can be extended to support more types */ | ||||
| GPU_USAGE_STREAM, | GPU_USAGE_STREAM, | ||||
| GPU_USAGE_STATIC, /* do not keep data in memory */ | GPU_USAGE_STATIC, /* do not keep data in memory */ | ||||
| GPU_USAGE_DYNAMIC, | GPU_USAGE_DYNAMIC, | ||||
| } GPUUsageType; | } GPUUsageType; | ||||
| typedef struct GPUVertBuf GPUVertBuf; | typedef struct GPUVertBuf GPUVertBuf; | ||||
| #define GPU_vertbuf_calloc() GPU_vertbuf_create(GPU_USAGE_STATIC); | GPUVertBuf *GPU_vertbuf_calloc(void); | ||||
| GPUVertBuf *GPU_vertbuf_create(GPUUsageType); | |||||
| GPUVertBuf *GPU_vertbuf_create_with_format_ex(const GPUVertFormat *, GPUUsageType); | GPUVertBuf *GPU_vertbuf_create_with_format_ex(const GPUVertFormat *, GPUUsageType); | ||||
| #define GPU_vertbuf_create_with_format(format) \ | #define GPU_vertbuf_create_with_format(format) \ | ||||
| GPU_vertbuf_create_with_format_ex(format, GPU_USAGE_STATIC) | GPU_vertbuf_create_with_format_ex(format, GPU_USAGE_STATIC) | ||||
| void GPU_vertbuf_clear(GPUVertBuf *verts); | void GPU_vertbuf_clear(GPUVertBuf *verts); | ||||
| void GPU_vertbuf_discard(GPUVertBuf *); | void GPU_vertbuf_discard(GPUVertBuf *); | ||||
| /* Avoid GPUVertBuf datablock being free but not its data. */ | /* Avoid GPUVertBuf datablock being free but not its data. */ | ||||
| void GPU_vertbuf_handle_ref_add(GPUVertBuf *verts); | void GPU_vertbuf_handle_ref_add(GPUVertBuf *verts); | ||||
| void GPU_vertbuf_handle_ref_remove(GPUVertBuf *verts); | void GPU_vertbuf_handle_ref_remove(GPUVertBuf *verts); | ||||
| void GPU_vertbuf_init(GPUVertBuf *, GPUUsageType); | |||||
| void GPU_vertbuf_init_with_format_ex(GPUVertBuf *, const GPUVertFormat *, GPUUsageType); | void GPU_vertbuf_init_with_format_ex(GPUVertBuf *, const GPUVertFormat *, GPUUsageType); | ||||
| #define GPU_vertbuf_init_with_format(verts, format) \ | #define GPU_vertbuf_init_with_format(verts, format) \ | ||||
| GPU_vertbuf_init_with_format_ex(verts, format, GPU_USAGE_STATIC) | GPU_vertbuf_init_with_format_ex(verts, format, GPU_USAGE_STATIC) | ||||
| GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts); | GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts); | ||||
| uint GPU_vertbuf_size_get(const GPUVertBuf *); | |||||
| void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len); | void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len); | ||||
| void GPU_vertbuf_data_resize(GPUVertBuf *, uint v_len); | void GPU_vertbuf_data_resize(GPUVertBuf *, uint v_len); | ||||
| void GPU_vertbuf_data_len_set(GPUVertBuf *, uint v_len); | void GPU_vertbuf_data_len_set(GPUVertBuf *, uint v_len); | ||||
| /* The most important #set_attr variant is the untyped one. Get it right first. | /* The most important #set_attr variant is the untyped one. Get it right first. | ||||
| * It takes a void* so the app developer is responsible for matching their app data types | * It takes a void* so the app developer is responsible for matching their app data types | ||||
| * to the vertex attribute's type and component count. They're in control of both, so this | * to the vertex attribute's type and component count. They're in control of both, so this | ||||
| * should not be a problem. */ | * should not be a problem. */ | ||||
| void GPU_vertbuf_attr_set(GPUVertBuf *, uint a_idx, uint v_idx, const void *data); | void GPU_vertbuf_attr_set(GPUVertBuf *, uint a_idx, uint v_idx, const void *data); | ||||
| void GPU_vertbuf_vert_set(GPUVertBuf *verts, uint v_idx, const void *data); | void GPU_vertbuf_vert_set(GPUVertBuf *verts, uint v_idx, const void *data); | ||||
| /* Tightly packed, non interleaved input data. */ | /* Tightly packed, non interleaved input data. */ | ||||
| void GPU_vertbuf_attr_fill(GPUVertBuf *, uint a_idx, const void *data); | void GPU_vertbuf_attr_fill(GPUVertBuf *, uint a_idx, const void *data); | ||||
| void GPU_vertbuf_attr_fill_stride(GPUVertBuf *, uint a_idx, uint stride, const void *data); | void GPU_vertbuf_attr_fill_stride(GPUVertBuf *, uint a_idx, uint stride, const void *data); | ||||
| /* For low level access only */ | /* For low level access only */ | ||||
| typedef struct GPUVertBufRaw { | typedef struct GPUVertBufRaw { | ||||
| uint size; | uint size; | ||||
| uint stride; | uint stride; | ||||
| unsigned char *data; | unsigned char *data; | ||||
| unsigned char *data_init; | unsigned char *data_init; | ||||
| #if TRUST_NO_ONE | #ifdef DEBUG | ||||
| /* Only for overflow check */ | /* Only for overflow check */ | ||||
| unsigned char *_data_end; | unsigned char *_data_end; | ||||
| #endif | #endif | ||||
| } GPUVertBufRaw; | } GPUVertBufRaw; | ||||
| GPU_INLINE void *GPU_vertbuf_raw_step(GPUVertBufRaw *a) | GPU_INLINE void *GPU_vertbuf_raw_step(GPUVertBufRaw *a) | ||||
| { | { | ||||
| unsigned char *data = a->data; | unsigned char *data = a->data; | ||||
| a->data += a->stride; | a->data += a->stride; | ||||
| #if TRUST_NO_ONE | BLI_assert(data < a->_data_end); | ||||
| assert(data < a->_data_end); | |||||
| #endif | |||||
| return (void *)data; | return (void *)data; | ||||
| } | } | ||||
| GPU_INLINE uint GPU_vertbuf_raw_used(GPUVertBufRaw *a) | GPU_INLINE uint GPU_vertbuf_raw_used(GPUVertBufRaw *a) | ||||
| { | { | ||||
| return ((a->data - a->data_init) / a->stride); | return ((a->data - a->data_init) / a->stride); | ||||
| } | } | ||||
| Show All 27 Lines | |||||