diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-02-09 19:26:13 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-02-11 22:36:20 +0300 |
commit | fc0797142d0c94342832bbead9db40e3e6ca9186 (patch) | |
tree | c4f608e0f6739b9e1227093caed8bc3dba00db37 /source/blender/gpu | |
parent | c5f2380be715916c17d86c7b34e49c5ac0cad792 (diff) |
Clay Engine: Refactoring of the dynamic batches
Support more attribs for interesting instancing
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/gawain/batch.c | 38 | ||||
-rw-r--r-- | source/blender/gpu/gawain/batch.h | 5 |
2 files changed, 21 insertions, 22 deletions
diff --git a/source/blender/gpu/gawain/batch.c b/source/blender/gpu/gawain/batch.c index ecc653e5e7b..6beddaca6c2 100644 --- a/source/blender/gpu/gawain/batch.c +++ b/source/blender/gpu/gawain/batch.c @@ -291,7 +291,8 @@ void Batch_draw_stupid(Batch* batch) } // clement : temp stuff -void Batch_draw_stupid_instanced(Batch* batch, unsigned int instance_vbo, int instance_count) +void Batch_draw_stupid_instanced(Batch* batch, unsigned int instance_vbo, int instance_count, + int attrib_nbr, int attrib_stride, int attrib_size[16], int attrib_loc[16]) { if (batch->vao_id) glBindVertexArray(batch->vao_id); @@ -301,28 +302,25 @@ void Batch_draw_stupid_instanced(Batch* batch, unsigned int instance_vbo, int in if (batch->program_dirty) Batch_update_program_bindings(batch); - const GLint loc = glGetAttribLocation(batch->program, "InstanceModelMatrix"); - -#if TRUST_NO_ONE - assert(loc != -1); -#endif - glBindBuffer(GL_ARRAY_BUFFER, instance_vbo); - glEnableVertexAttribArray(loc); - glVertexAttribPointer(loc + 0, 4, GL_FLOAT, GL_FALSE, sizeof(float)*4*4, (GLvoid*)0); - glEnableVertexAttribArray(loc + 1); - glVertexAttribPointer(loc + 1, 4, GL_FLOAT, GL_FALSE, sizeof(float)*4*4, (GLvoid*)(sizeof(float)*4)); - glEnableVertexAttribArray(loc + 2); - glVertexAttribPointer(loc + 2, 4, GL_FLOAT, GL_FALSE, sizeof(float)*4*4, (GLvoid*)(2 * sizeof(float)*4)); - glEnableVertexAttribArray(loc + 3); - glVertexAttribPointer(loc + 3, 4, GL_FLOAT, GL_FALSE, sizeof(float)*4*4, (GLvoid*)(3 * sizeof(float)*4)); + int ptr_ofs = 0; + for (int i = 0; i < attrib_nbr; ++i) { + int size = attrib_size[i]; + int loc = attrib_loc[i]; + int atr_ofs = 0; + + while (size > 0) { + glEnableVertexAttribArray(loc + atr_ofs); + glVertexAttribPointer(loc + atr_ofs, (size > 4) ? 4 : size, GL_FLOAT, GL_FALSE, + sizeof(float) * attrib_stride, (GLvoid*)(sizeof(float) * ptr_ofs)); + glVertexAttribDivisor(loc + atr_ofs, 1); + size -= 4; + atr_ofs++; + ptr_ofs += (size > 4) ? 4 : size; + } + } glBindBuffer(GL_ARRAY_BUFFER, 0); - glVertexAttribDivisor(loc + 0, 1); - glVertexAttribDivisor(loc + 1, 1); - glVertexAttribDivisor(loc + 2, 1); - glVertexAttribDivisor(loc + 3, 1); - // Batch_use_program(batch); //gpuBindMatrices(batch->program); diff --git a/source/blender/gpu/gawain/batch.h b/source/blender/gpu/gawain/batch.h index 763c4c1c495..660ed9eb762 100644 --- a/source/blender/gpu/gawain/batch.h +++ b/source/blender/gpu/gawain/batch.h @@ -61,8 +61,9 @@ void Batch_draw(Batch*); // clement : temp stuff -void Batch_draw_stupid(Batch* batch); -void Batch_draw_stupid_instanced(Batch* batch, unsigned int instance_vbo, int instance_count); +void Batch_draw_stupid(Batch*); +void Batch_draw_stupid_instanced(Batch*, unsigned int instance_vbo, int instance_count, + int attrib_nbr, int attrib_stride, int attrib_loc[16], int attrib_size[16]); |