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/source
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-10-01 15:52:02 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-10-01 16:14:46 +0300
commit3a9ee33328a48278290af429b8b0e18fd36de1c0 (patch)
treefdd0cf50bc3ecae45455507d623442b1e2db80a2 /source
parent781995a09c0b52ad2fd073510c2f7dc52383d461 (diff)
GPU: Fix partial draw of batches with index buffers
Diffstat (limited to 'source')
-rw-r--r--source/blender/gpu/intern/gpu_batch.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index 87ea112148c..2cbeeb26924 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -528,6 +528,18 @@ static void primitive_restart_disable(void)
glDisable(GL_PRIMITIVE_RESTART);
}
+static void *elem_offset(const GPUIndexBuf *el, int v_first)
+{
+#if GPU_TRACK_INDEX_RANGE
+ if (el->index_type == GPU_INDEX_U8)
+ return (GLubyte *)0 + v_first;
+ else if (el->index_type == GPU_INDEX_U16)
+ return (GLushort *)0 + v_first;
+ else
+#endif
+ return (GLuint *)0 + v_first;
+}
+
void GPU_batch_draw(GPUBatch *batch)
{
#if TRUST_NO_ONE
@@ -547,10 +559,11 @@ void GPU_batch_draw_range_ex(GPUBatch *batch, int v_first, int v_count, bool for
#if TRUST_NO_ONE
assert(!(force_instance && (batch->inst == NULL)) || v_count > 0); // we cannot infer length if force_instance
#endif
+
const bool do_instance = (force_instance || batch->inst);
// If using offset drawing, use the default VAO and redo bindings.
- if (v_first != 0 && (do_instance || batch->elem)) {
+ if (v_first != 0 && do_instance) {
glBindVertexArray(GPU_vao_default());
batch_update_program_bindings(batch, v_first);
}
@@ -601,6 +614,8 @@ void GPU_batch_draw_range_ex(GPUBatch *batch, int v_first, int v_count, bool for
primitive_restart_enable(el);
}
+ void *v_first_ofs = elem_offset(el, v_first);
+
#if GPU_TRACK_INDEX_RANGE
if (el->base_index) {
glDrawRangeElementsBaseVertex(
@@ -609,14 +624,14 @@ void GPU_batch_draw_range_ex(GPUBatch *batch, int v_first, int v_count, bool for
el->max_index,
v_count,
el->gl_index_type,
- 0,
+ v_first_ofs,
el->base_index);
}
else {
- glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, v_count, el->gl_index_type, 0);
+ glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, v_count, el->gl_index_type, v_first_ofs);
}
#else
- glDrawElements(batch->gl_prim_type, v_count, GL_UNSIGNED_INT, 0);
+ glDrawElements(batch->gl_prim_type, v_count, GL_UNSIGNED_INT, v_first_ofs);
#endif
if (el->use_prim_restart) {
primitive_restart_disable();