GPU: Move gpu_vertex_buffer.c to C++

This commit is contained in:
Clément Foucault 2020-07-28 02:15:22 +02:00
parent 959529d4b8
commit f84342d7e1
3 changed files with 19 additions and 14 deletions

View File

@ -82,7 +82,7 @@ set(SRC
intern/gpu_texture_image.cc
intern/gpu_texture_smoke.cc
intern/gpu_uniformbuffer.c
intern/gpu_vertex_buffer.c
intern/gpu_vertex_buffer.cc
intern/gpu_vertex_format.cc
intern/gpu_viewport.c

View File

@ -59,10 +59,10 @@ typedef struct GPUVertBuf {
/** 0 indicates not yet allocated. */
uint32_t vbo_id;
/** Usage hint for GL optimisation. */
uint usage : 2;
GPUUsageType usage;
/** Data has been touched and need to be reuploaded to GPU. */
uint dirty : 1;
unsigned char *data; /* NULL indicates data in VRAM (unmapped) */
bool dirty;
uchar *data; /* NULL indicates data in VRAM (unmapped) */
} GPUVertBuf;
GPUVertBuf *GPU_vertbuf_create(GPUUsageType);

View File

@ -39,17 +39,22 @@ static uint vbo_memory_usage;
static GLenum convert_usage_type_to_gl(GPUUsageType type)
{
static const GLenum table[] = {
[GPU_USAGE_STREAM] = GL_STREAM_DRAW,
[GPU_USAGE_STATIC] = GL_STATIC_DRAW,
[GPU_USAGE_DYNAMIC] = GL_DYNAMIC_DRAW,
};
return table[type];
switch (type) {
case GPU_USAGE_STREAM:
return GL_STREAM_DRAW;
case GPU_USAGE_DYNAMIC:
return GL_DYNAMIC_DRAW;
case GPU_USAGE_STATIC:
return GL_STATIC_DRAW;
default:
BLI_assert(0);
return GL_STATIC_DRAW;
}
}
GPUVertBuf *GPU_vertbuf_create(GPUUsageType usage)
{
GPUVertBuf *verts = MEM_mallocN(sizeof(GPUVertBuf), "GPUVertBuf");
GPUVertBuf *verts = (GPUVertBuf *)MEM_mallocN(sizeof(GPUVertBuf), "GPUVertBuf");
GPU_vertbuf_init(verts, usage);
return verts;
}
@ -109,7 +114,7 @@ GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts)
}
if (verts->data) {
verts_dst->data = MEM_dupallocN(verts->data);
verts_dst->data = (uchar *)MEM_dupallocN(verts->data);
}
return verts_dst;
}
@ -161,7 +166,7 @@ void GPU_vertbuf_data_alloc(GPUVertBuf *verts, uint v_len)
#endif
verts->dirty = true;
verts->vertex_len = verts->vertex_alloc = v_len;
verts->data = MEM_mallocN(sizeof(GLubyte) * GPU_vertbuf_size_get(verts), "GPUVertBuf data");
verts->data = (uchar *)MEM_mallocN(sizeof(GLubyte) * GPU_vertbuf_size_get(verts), __func__);
}
/* resize buffer keeping existing data */
@ -178,7 +183,7 @@ void GPU_vertbuf_data_resize(GPUVertBuf *verts, uint v_len)
#endif
verts->dirty = true;
verts->vertex_len = verts->vertex_alloc = v_len;
verts->data = MEM_reallocN(verts->data, sizeof(GLubyte) * GPU_vertbuf_size_get(verts));
verts->data = (uchar *)MEM_reallocN(verts->data, sizeof(GLubyte) * GPU_vertbuf_size_get(verts));
}
/* Set vertex count but does not change allocation.