diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-05-29 17:28:54 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-05-29 17:28:54 +0300 |
commit | ec90780767721d03322d42f4c5796b7b2d03d8e3 (patch) | |
tree | 19ab9788a658281165c0822cc5223712616bad46 /intern | |
parent | 97e89027fc155bed061cd5ec81c5a3e6c12502cb (diff) |
Gawain: Add support for rendering using an instance batch (for particles)
Diffstat (limited to 'intern')
-rw-r--r-- | intern/gawain/gawain/batch.h | 2 | ||||
-rw-r--r-- | intern/gawain/src/batch.c | 66 |
2 files changed, 67 insertions, 1 deletions
diff --git a/intern/gawain/gawain/batch.h b/intern/gawain/gawain/batch.h index 9915b0b57f4..33a1c1b653c 100644 --- a/intern/gawain/gawain/batch.h +++ b/intern/gawain/gawain/batch.h @@ -73,7 +73,7 @@ void Batch_draw(Batch*); 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]); - +void Batch_draw_stupid_instanced_with_batch(Batch*, Batch*); diff --git a/intern/gawain/src/batch.c b/intern/gawain/src/batch.c index 86dca0a214e..a1e173f6685 100644 --- a/intern/gawain/src/batch.c +++ b/intern/gawain/src/batch.c @@ -374,3 +374,69 @@ void Batch_draw_stupid_instanced(Batch* batch, unsigned int instance_vbo, int in // Batch_done_using_program(batch); glBindVertexArray(0); } + +void Batch_draw_stupid_instanced_with_batch(Batch* batch_instanced, Batch* batch_instancing) + { + if (batch_instanced->vao_id) + glBindVertexArray(batch_instanced->vao_id); + else + Batch_prime(batch_instanced); + + if (batch_instanced->program_dirty) + Batch_update_program_bindings(batch_instanced); + + VertexBuffer* verts = batch_instancing->verts[0]; + + const VertexFormat* format = &verts->format; + + const unsigned attrib_ct = format->attrib_ct; + const unsigned stride = format->stride; + + VertexBuffer_use(verts); + + for (unsigned a_idx = 0; a_idx < attrib_ct; ++a_idx) + { + const Attrib* a = format->attribs + a_idx; + + const GLvoid* pointer = (const GLubyte*)0 + a->offset; + + for (unsigned n_idx = 0; n_idx < a->name_ct; ++n_idx) + { + const ShaderInput* input = ShaderInterface_attrib(batch_instanced->interface, a->name[n_idx]); + + if (input == NULL) continue; + + glEnableVertexAttribArray(input->location); + glVertexAttribDivisor(input->location, 1); + + switch (a->fetch_mode) + { + case KEEP_FLOAT: + case CONVERT_INT_TO_FLOAT: + glVertexAttribPointer(input->location, a->comp_ct, a->gl_comp_type, GL_FALSE, stride, pointer); + break; + case NORMALIZE_INT_TO_FLOAT: + glVertexAttribPointer(input->location, a->comp_ct, a->gl_comp_type, GL_TRUE, stride, pointer); + break; + case KEEP_INT: + glVertexAttribIPointer(input->location, a->comp_ct, a->gl_comp_type, stride, pointer); + } + } + } + + // Batch_use_program(batch); + + //gpuBindMatrices(batch->program); + + if (batch_instanced->elem) + { + const ElementList* el = batch_instanced->elem; + + glDrawElementsInstanced(batch_instanced->gl_prim_type, el->index_ct, GL_UNSIGNED_INT, 0, verts->vertex_ct); + } + else + glDrawArraysInstanced(batch_instanced->gl_prim_type, 0, batch_instanced->verts[0]->vertex_ct, verts->vertex_ct); + + // Batch_done_using_program(batch); + glBindVertexArray(0); + }
\ No newline at end of file |