diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_vertex_buffer.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_vertex_buffer.c | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.c b/source/blender/gpu/intern/gpu_vertex_buffer.c index 32f3d494015..5b29913800d 100644 --- a/source/blender/gpu/intern/gpu_vertex_buffer.c +++ b/source/blender/gpu/intern/gpu_vertex_buffer.c @@ -23,10 +23,10 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/gpu/intern/gwn_vertex_buffer.c +/** \file blender/gpu/intern/gpu_vertex_buffer.c * \ingroup gpu * - * Gawain vertex buffer + * GPU vertex buffer */ #include "GPU_vertex_buffer.h" @@ -39,27 +39,27 @@ static uint vbo_memory_usage; -static GLenum convert_usage_type_to_gl(Gwn_UsageType type) +static GLenum convert_usage_type_to_gl(GPUUsageType type) { static const GLenum table[] = { - [GWN_USAGE_STREAM] = GL_STREAM_DRAW, - [GWN_USAGE_STATIC] = GL_STATIC_DRAW, - [GWN_USAGE_DYNAMIC] = GL_DYNAMIC_DRAW + [GPU_USAGE_STREAM] = GL_STREAM_DRAW, + [GPU_USAGE_STATIC] = GL_STATIC_DRAW, + [GPU_USAGE_DYNAMIC] = GL_DYNAMIC_DRAW }; return table[type]; } -Gwn_VertBuf* GWN_vertbuf_create(Gwn_UsageType usage) +GPUVertBuf* GPU_vertbuf_create(GPUUsageType usage) { - Gwn_VertBuf* verts = malloc(sizeof(Gwn_VertBuf)); - GWN_vertbuf_init(verts, usage); + GPUVertBuf* verts = malloc(sizeof(GPUVertBuf)); + GPU_vertbuf_init(verts, usage); return verts; } -Gwn_VertBuf* GWN_vertbuf_create_with_format_ex(const Gwn_VertFormat* format, Gwn_UsageType usage) +GPUVertBuf* GPU_vertbuf_create_with_format_ex(const GPUVertFormat* format, GPUUsageType usage) { - Gwn_VertBuf* verts = GWN_vertbuf_create(usage); - GWN_vertformat_copy(&verts->format, format); + GPUVertBuf* verts = GPU_vertbuf_create(usage); + GPU_vertformat_copy(&verts->format, format); if (!format->packed) { VertexFormat_pack(&verts->format); } @@ -69,28 +69,28 @@ Gwn_VertBuf* GWN_vertbuf_create_with_format_ex(const Gwn_VertFormat* format, Gwn /* TODO: implement those memory savings */ } -void GWN_vertbuf_init(Gwn_VertBuf* verts, Gwn_UsageType usage) +void GPU_vertbuf_init(GPUVertBuf* verts, GPUUsageType usage) { - memset(verts, 0, sizeof(Gwn_VertBuf)); + memset(verts, 0, sizeof(GPUVertBuf)); verts->usage = usage; verts->dirty = true; } -void GWN_vertbuf_init_with_format_ex(Gwn_VertBuf* verts, const Gwn_VertFormat* format, Gwn_UsageType usage) +void GPU_vertbuf_init_with_format_ex(GPUVertBuf* verts, const GPUVertFormat* format, GPUUsageType usage) { - GWN_vertbuf_init(verts, usage); - GWN_vertformat_copy(&verts->format, format); + GPU_vertbuf_init(verts, usage); + GPU_vertformat_copy(&verts->format, format); if (!format->packed) { VertexFormat_pack(&verts->format); } } -void GWN_vertbuf_discard(Gwn_VertBuf* verts) +void GPU_vertbuf_discard(GPUVertBuf* verts) { if (verts->vbo_id) { - GWN_buf_id_free(verts->vbo_id); + GPU_buf_id_free(verts->vbo_id); #if VRAM_USAGE - vbo_memory_usage -= GWN_vertbuf_size_get(verts); + vbo_memory_usage -= GPU_vertbuf_size_get(verts); #endif } if (verts->data) { @@ -99,15 +99,15 @@ void GWN_vertbuf_discard(Gwn_VertBuf* verts) free(verts); } -uint GWN_vertbuf_size_get(const Gwn_VertBuf* verts) +uint GPU_vertbuf_size_get(const GPUVertBuf* verts) { return vertex_buffer_size(&verts->format, verts->vertex_len); } /* create a new allocation, discarding any existing data */ -void GWN_vertbuf_data_alloc(Gwn_VertBuf* verts, uint v_len) +void GPU_vertbuf_data_alloc(GPUVertBuf* verts, uint v_len) { - Gwn_VertFormat* format = &verts->format; + GPUVertFormat* format = &verts->format; if (!format->packed) { VertexFormat_pack(format); } @@ -117,7 +117,7 @@ void GWN_vertbuf_data_alloc(Gwn_VertBuf* verts, uint v_len) #endif /* only create the buffer the 1st time */ if (verts->vbo_id == 0) { - verts->vbo_id = GWN_buf_id_alloc(); + verts->vbo_id = GPU_buf_id_alloc(); } /* discard previous data if any */ if (verts->data) { @@ -125,15 +125,15 @@ void GWN_vertbuf_data_alloc(Gwn_VertBuf* verts, uint v_len) } #if VRAM_USAGE uint new_size = vertex_buffer_size(&verts->format, v_len); - vbo_memory_usage += new_size - GWN_vertbuf_size_get(verts); + vbo_memory_usage += new_size - GPU_vertbuf_size_get(verts); #endif verts->dirty = true; verts->vertex_len = verts->vertex_alloc = v_len; - verts->data = malloc(sizeof(GLubyte) * GWN_vertbuf_size_get(verts)); + verts->data = malloc(sizeof(GLubyte) * GPU_vertbuf_size_get(verts)); } /* resize buffer keeping existing data */ -void GWN_vertbuf_data_resize(Gwn_VertBuf* verts, uint v_len) +void GPU_vertbuf_data_resize(GPUVertBuf* verts, uint v_len) { #if TRUST_NO_ONE assert(verts->data != NULL); @@ -142,17 +142,17 @@ void GWN_vertbuf_data_resize(Gwn_VertBuf* verts, uint v_len) #if VRAM_USAGE uint new_size = vertex_buffer_size(&verts->format, v_len); - vbo_memory_usage += new_size - GWN_vertbuf_size_get(verts); + vbo_memory_usage += new_size - GPU_vertbuf_size_get(verts); #endif verts->dirty = true; verts->vertex_len = verts->vertex_alloc = v_len; - verts->data = realloc(verts->data, sizeof(GLubyte) * GWN_vertbuf_size_get(verts)); + verts->data = realloc(verts->data, sizeof(GLubyte) * GPU_vertbuf_size_get(verts)); } /* Set vertex count but does not change allocation. * Only this many verts will be uploaded to the GPU and rendered. * This is usefull for streaming data. */ -void GWN_vertbuf_vertex_count_set(Gwn_VertBuf* verts, uint v_len) +void GPU_vertbuf_vertex_count_set(GPUVertBuf* verts, uint v_len) { #if TRUST_NO_ONE assert(verts->data != NULL); /* only for dynamic data */ @@ -161,15 +161,15 @@ void GWN_vertbuf_vertex_count_set(Gwn_VertBuf* verts, uint v_len) #if VRAM_USAGE uint new_size = vertex_buffer_size(&verts->format, v_len); - vbo_memory_usage += new_size - GWN_vertbuf_size_get(verts); + vbo_memory_usage += new_size - GPU_vertbuf_size_get(verts); #endif verts->vertex_len = v_len; } -void GWN_vertbuf_attr_set(Gwn_VertBuf* verts, uint a_idx, uint v_idx, const void* data) +void GPU_vertbuf_attr_set(GPUVertBuf* verts, uint a_idx, uint v_idx, const void* data) { - const Gwn_VertFormat* format = &verts->format; - const Gwn_VertAttr* a = format->attribs + a_idx; + const GPUVertFormat* format = &verts->format; + const GPUVertAttr* a = format->attribs + a_idx; #if TRUST_NO_ONE assert(a_idx < format->attr_len); @@ -180,23 +180,23 @@ void GWN_vertbuf_attr_set(Gwn_VertBuf* verts, uint a_idx, uint v_idx, const void memcpy((GLubyte*)verts->data + a->offset + v_idx * format->stride, data, a->sz); } -void GWN_vertbuf_attr_fill(Gwn_VertBuf* verts, uint a_idx, const void* data) +void GPU_vertbuf_attr_fill(GPUVertBuf* verts, uint a_idx, const void* data) { - const Gwn_VertFormat* format = &verts->format; - const Gwn_VertAttr* a = format->attribs + a_idx; + const GPUVertFormat* format = &verts->format; + const GPUVertAttr* a = format->attribs + a_idx; #if TRUST_NO_ONE assert(a_idx < format->attr_len); #endif const uint stride = a->sz; /* tightly packed input data */ - GWN_vertbuf_attr_fill_stride(verts, a_idx, stride, data); + GPU_vertbuf_attr_fill_stride(verts, a_idx, stride, data); } -void GWN_vertbuf_attr_fill_stride(Gwn_VertBuf* verts, uint a_idx, uint stride, const void* data) +void GPU_vertbuf_attr_fill_stride(GPUVertBuf* verts, uint a_idx, uint stride, const void* data) { - const Gwn_VertFormat* format = &verts->format; - const Gwn_VertAttr* a = format->attribs + a_idx; + const GPUVertFormat* format = &verts->format; + const GPUVertAttr* a = format->attribs + a_idx; #if TRUST_NO_ONE assert(a_idx < format->attr_len); @@ -217,10 +217,10 @@ void GWN_vertbuf_attr_fill_stride(Gwn_VertBuf* verts, uint a_idx, uint stride, c } } -void GWN_vertbuf_attr_get_raw_data(Gwn_VertBuf* verts, uint a_idx, Gwn_VertBufRaw *access) +void GPU_vertbuf_attr_get_raw_data(GPUVertBuf* verts, uint a_idx, GPUVertBufRaw *access) { - const Gwn_VertFormat* format = &verts->format; - const Gwn_VertAttr* a = format->attribs + a_idx; + const GPUVertFormat* format = &verts->format; + const GPUVertAttr* a = format->attribs + a_idx; #if TRUST_NO_ONE assert(a_idx < format->attr_len); @@ -238,23 +238,23 @@ void GWN_vertbuf_attr_get_raw_data(Gwn_VertBuf* verts, uint a_idx, Gwn_VertBufRa #endif } -static void VertBuffer_upload_data(Gwn_VertBuf* verts) +static void VertBuffer_upload_data(GPUVertBuf* verts) { - uint buffer_sz = GWN_vertbuf_size_get(verts); + uint buffer_sz = GPU_vertbuf_size_get(verts); /* orphan the vbo to avoid sync */ glBufferData(GL_ARRAY_BUFFER, buffer_sz, NULL, convert_usage_type_to_gl(verts->usage)); /* upload data */ glBufferSubData(GL_ARRAY_BUFFER, 0, buffer_sz, verts->data); - if (verts->usage == GWN_USAGE_STATIC) { + if (verts->usage == GPU_USAGE_STATIC) { free(verts->data); verts->data = NULL; } verts->dirty = false; } -void GWN_vertbuf_use(Gwn_VertBuf* verts) +void GPU_vertbuf_use(GPUVertBuf* verts) { glBindBuffer(GL_ARRAY_BUFFER, verts->vbo_id); if (verts->dirty) { @@ -262,7 +262,7 @@ void GWN_vertbuf_use(Gwn_VertBuf* verts) } } -uint GWN_vertbuf_get_memory_usage(void) +uint GPU_vertbuf_get_memory_usage(void) { return vbo_memory_usage; } |