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
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu/intern/gpu_batch.c')
-rw-r--r--source/blender/gpu/intern/gpu_batch.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index 6bc3cd27130..5f77f13c135 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_attr_vbo = 0;
+
static void batch_update_program_bindings(GPUBatch *batch, uint i_first);
void GPU_batch_vao_cache_clear(GPUBatch *batch)
@@ -373,7 +375,7 @@ void GPU_batch_program_set_no_use(GPUBatch *batch,
const GPUShaderInterface *shaderface)
{
#if TRUST_NO_ONE
- assert(glIsProgram(shaderface->program));
+ assert(glIsProgram(program));
assert(batch->program_in_use == 0);
#endif
batch->interface = shaderface;
@@ -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 *attr_mask,
uint v_first,
const bool use_instancing)
{
@@ -446,6 +449,8 @@ static void create_bindings(GPUVertBuf *verts,
continue;
}
+ *attr_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)
{
- /* Reverse order so first vbos have more prevalence (in term of attrib override). */
+ uint16_t attr_mask = batch->interface->enabled_attr_mask;
+
+ /* Reverse order so first VBO'S have more prevalence (in term of attribute 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, &attr_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, &attr_mask, i_first, true);
+ }
+ }
+
+ if (attr_mask != 0 && GLEW_ARB_vertex_attrib_binding) {
+ for (uint16_t mask = 1, a = 0; a < 16; a++, mask <<= 1) {
+ if (attr_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_attr_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);
}
@@ -528,11 +551,11 @@ void GPU_batch_program_use_end(GPUBatch *batch)
#if TRUST_NO_ONE
# define GET_UNIFORM \
- const GPUShaderInput *uniform = GPU_shaderinterface_uniform_ensure(batch->interface, name); \
+ const GPUShaderInput *uniform = GPU_shaderinterface_uniform(batch->interface, name); \
assert(uniform);
#else
# define GET_UNIFORM \
- const GPUShaderInput *uniform = GPU_shaderinterface_uniform_ensure(batch->interface, name);
+ const GPUShaderInput *uniform = GPU_shaderinterface_uniform(batch->interface, name);
#endif
void GPU_batch_uniform_1ui(GPUBatch *batch, const char *name, uint value)
@@ -652,6 +675,7 @@ void GPU_batch_draw(GPUBatch *batch)
#endif
GPU_batch_program_use_begin(batch);
GPU_matrix_bind(batch->interface); // external call.
+ GPU_shader_set_srgb_uniform(batch->interface);
GPU_batch_bind(batch);
GPU_batch_draw_advanced(batch, 0, 0, 0, 0);
@@ -689,8 +713,8 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi
}
/* Verify there is enough data do draw. */
- /* TODO(fclem) Nice to have but this is invalid when using procedural drawcalls.
- * The right assert would be to check if there is an enabled attrib from each VBO
+ /* TODO(fclem) Nice to have but this is invalid when using procedural draw-calls.
+ * The right assert would be to check if there is an enabled attribute from each VBO
* and check their length. */
// BLI_assert(i_first + i_count <= (batch->inst ? batch->inst->vertex_len : INT_MAX));
// BLI_assert(v_first + v_count <=
@@ -1002,11 +1026,23 @@ void GPU_batch_program_set_imm_shader(GPUBatch *batch)
void gpu_batch_init(void)
{
+ if (g_default_attr_vbo == 0) {
+ g_default_attr_vbo = GPU_buf_alloc();
+
+ float default_attrib_data[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ glBindBuffer(GL_ARRAY_BUFFER, g_default_attr_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_attr_vbo);
+ g_default_attr_vbo = 0;
+
gpu_batch_presets_exit();
}