diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_batch.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_batch.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c index 6bc3cd27130..fcfa4b7f0af 100644 --- a/source/blender/gpu/intern/gpu_batch.c +++ b/source/blender/gpu/intern/gpu_batch.c @@ -42,6 +42,8 @@ #include <stdlib.h> #include <string.h> +static GLuint g_default_attrib_vbo = 0; + static void batch_update_program_bindings(GPUBatch *batch, uint i_first); void GPU_batch_vao_cache_clear(GPUBatch *batch) @@ -414,6 +416,7 @@ void gpu_batch_remove_interface_ref(GPUBatch *batch, const GPUShaderInterface *i static void create_bindings(GPUVertBuf *verts, const GPUShaderInterface *interface, + uint16_t *attrib_mask, uint v_first, const bool use_instancing) { @@ -446,6 +449,8 @@ static void create_bindings(GPUVertBuf *verts, continue; } + *attrib_mask &= ~(1 << input->location); + if (a->comp_len == 16 || a->comp_len == 12 || a->comp_len == 8) { #if TRUST_NO_ONE assert(a->fetch_mode == GPU_FETCH_FLOAT); @@ -487,17 +492,35 @@ static void create_bindings(GPUVertBuf *verts, static void batch_update_program_bindings(GPUBatch *batch, uint i_first) { + uint16_t attrib_mask = batch->interface->enabled_attrib_mask; + /* Reverse order so first vbos have more prevalence (in term of attrib override). */ for (int v = GPU_BATCH_VBO_MAX_LEN - 1; v > -1; v--) { if (batch->verts[v] != NULL) { - create_bindings(batch->verts[v], batch->interface, 0, false); + create_bindings(batch->verts[v], batch->interface, &attrib_mask, 0, false); } } + for (int v = GPU_BATCH_INST_VBO_MAX_LEN - 1; v > -1; v--) { if (batch->inst[v]) { - create_bindings(batch->inst[v], batch->interface, i_first, true); + create_bindings(batch->inst[v], batch->interface, &attrib_mask, i_first, true); + } + } + + if (attrib_mask != 0 && GLEW_ARB_vertex_attrib_binding) { + for (uint16_t mask = 1, a = 0; a < 16; a++, mask <<= 1) { + if (attrib_mask & mask) { + /* This replaces glVertexAttrib4f(a, 0.0f, 0.0f, 0.0f, 1.0f); with a more modern style. + * Fix issues for some drivers (see T75069). */ + glBindVertexBuffer(a, g_default_attrib_vbo, (intptr_t)0, (intptr_t)0); + + glEnableVertexAttribArray(a); + glVertexAttribFormat(a, 4, GL_FLOAT, GL_FALSE, 0); + glVertexAttribBinding(a, a); + } } } + if (batch->elem) { GPU_indexbuf_use(batch->elem); } @@ -1002,11 +1025,23 @@ void GPU_batch_program_set_imm_shader(GPUBatch *batch) void gpu_batch_init(void) { + if (g_default_attrib_vbo == 0) { + g_default_attrib_vbo = GPU_buf_alloc(); + + float default_attrib_data[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + glBindBuffer(GL_ARRAY_BUFFER, g_default_attrib_vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4, default_attrib_data, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + gpu_batch_presets_init(); } void gpu_batch_exit(void) { + GPU_buf_free(g_default_attrib_vbo); + g_default_attrib_vbo = 0; + gpu_batch_presets_exit(); } |