Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-03-30 19:10:08 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-03-30 21:09:26 +0300
commit8568d38f1b0858a3138b72698babd6ba7b65d6b3 (patch)
tree9246f1e2aef68e459228447f8cae3e43489d636e /intern
parentcc69831796cbc7038351283d7de33668be5360d4 (diff)
GWN: Add GWN_vertbuf_vertex_count_set.
This allows us to specify a the number of vertices to upload to the gpu. This is to keep the same allocation on the System Memory but send the least amount of data to the GPU/Driver.
Diffstat (limited to 'intern')
-rw-r--r--intern/gawain/gawain/gwn_vertex_buffer.h4
-rw-r--r--intern/gawain/src/gwn_vertex_buffer.c38
2 files changed, 28 insertions, 14 deletions
diff --git a/intern/gawain/gawain/gwn_vertex_buffer.h b/intern/gawain/gawain/gwn_vertex_buffer.h
index ddb77368a02..e9a37519b36 100644
--- a/intern/gawain/gawain/gwn_vertex_buffer.h
+++ b/intern/gawain/gawain/gwn_vertex_buffer.h
@@ -31,7 +31,8 @@ typedef enum {
typedef struct Gwn_VertBuf {
Gwn_VertFormat format;
- unsigned vertex_ct;
+ unsigned vertex_ct; // number of verts we want to draw
+ unsigned vertex_alloc; // number of verts data
bool dirty;
GLubyte* data; // NULL indicates data in VRAM (unmapped)
GLuint vbo_id; // 0 indicates not yet allocated
@@ -55,6 +56,7 @@ void GWN_vertbuf_init_with_format_ex(Gwn_VertBuf*, const Gwn_VertFormat*, Gwn_Us
unsigned GWN_vertbuf_size_get(const Gwn_VertBuf*);
void GWN_vertbuf_data_alloc(Gwn_VertBuf*, unsigned v_ct);
void GWN_vertbuf_data_resize(Gwn_VertBuf*, unsigned v_ct);
+void GWN_vertbuf_vertex_count_set(Gwn_VertBuf*, unsigned v_ct);
// The most important set_attrib 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
diff --git a/intern/gawain/src/gwn_vertex_buffer.c b/intern/gawain/src/gwn_vertex_buffer.c
index 39fc1885b92..f621b4c01b9 100644
--- a/intern/gawain/src/gwn_vertex_buffer.c
+++ b/intern/gawain/src/gwn_vertex_buffer.c
@@ -93,7 +93,7 @@ void GWN_vertbuf_data_alloc(Gwn_VertBuf* verts, unsigned v_ct)
#if TRUST_NO_ONE
// catch any unnecessary use
- assert(verts->vertex_ct != v_ct || verts->data == NULL);
+ assert(verts->vertex_alloc != v_ct || verts->data == NULL);
#endif
// only create the buffer the 1st time
@@ -105,16 +105,13 @@ void GWN_vertbuf_data_alloc(Gwn_VertBuf* verts, unsigned v_ct)
free(verts->data);
#if VRAM_USAGE
- vbo_memory_usage -= GWN_vertbuf_size_get(verts);
+ unsigned new_size = vertex_buffer_size(&verts->format, v_ct);
+ vbo_memory_usage += new_size - GWN_vertbuf_size_get(verts);
#endif
verts->dirty = true;
- verts->vertex_ct = v_ct;
+ verts->vertex_ct = verts->vertex_alloc = v_ct;
verts->data = malloc(sizeof(GLubyte) * GWN_vertbuf_size_get(verts));
-
-#if VRAM_USAGE
- vbo_memory_usage += GWN_vertbuf_size_get(verts);
-#endif
}
// resize buffer keeping existing data
@@ -122,20 +119,35 @@ void GWN_vertbuf_data_resize(Gwn_VertBuf* verts, unsigned v_ct)
{
#if TRUST_NO_ONE
assert(verts->data != NULL);
- assert(verts->vertex_ct != v_ct);
+ assert(verts->vertex_alloc != v_ct);
#endif
#if VRAM_USAGE
- vbo_memory_usage -= GWN_vertbuf_size_get(verts);
+ unsigned new_size = vertex_buffer_size(&verts->format, v_ct);
+ vbo_memory_usage += new_size - GWN_vertbuf_size_get(verts);
#endif
verts->dirty = true;
- verts->vertex_ct = v_ct;
+ verts->vertex_ct = verts->vertex_alloc = v_ct;
verts->data = realloc(verts->data, sizeof(GLubyte) * GWN_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, unsigned v_ct)
+ {
+#if TRUST_NO_ONE
+ assert(verts->data != NULL); // only for dynamic data
+ assert(v_ct <= verts->vertex_alloc);
+#endif
#if VRAM_USAGE
- vbo_memory_usage += GWN_vertbuf_size_get(verts);
+ unsigned new_size = vertex_buffer_size(&verts->format, v_ct);
+ vbo_memory_usage += new_size - GWN_vertbuf_size_get(verts);
#endif
+
+ verts->vertex_ct = v_ct;
}
void GWN_vertbuf_attr_set(Gwn_VertBuf* verts, unsigned a_idx, unsigned v_idx, const void* data)
@@ -145,7 +157,7 @@ void GWN_vertbuf_attr_set(Gwn_VertBuf* verts, unsigned a_idx, unsigned v_idx, co
#if TRUST_NO_ONE
assert(a_idx < format->attrib_ct);
- assert(v_idx < verts->vertex_ct);
+ assert(v_idx < verts->vertex_alloc);
assert(verts->data != NULL);
#endif
@@ -210,7 +222,7 @@ void GWN_vertbuf_attr_get_raw_data(Gwn_VertBuf* verts, unsigned a_idx, Gwn_VertB
access->data = (GLubyte*)verts->data + a->offset;
access->data_init = access->data;
#if TRUST_NO_ONE
- access->_data_end = access->data_init + (size_t)(verts->vertex_ct * format->stride);
+ access->_data_end = access->data_init + (size_t)(verts->vertex_alloc * format->stride);
#endif
}