Skip to content

Commit

Permalink
sokol_gfx.h d3d11, gl: fix instanced drawing if no pipeline vertex la…
Browse files Browse the repository at this point in the history
…yout is specified
  • Loading branch information
floooh committed Apr 8, 2024
1 parent 1b5d2f4 commit 19903d7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9258,19 +9258,20 @@ _SOKOL_PRIVATE void _sg_gl_draw(int base_element, int num_elements, int num_inst
SOKOL_ASSERT(_sg.gl.cache.cur_pipeline);
const GLenum i_type = _sg.gl.cache.cur_index_type;
const GLenum p_type = _sg.gl.cache.cur_primitive_type;
const bool use_instanced_draw = (num_instances > 1) || (_sg.gl.cache.cur_pipeline->cmn.use_instanced_draw);
if (0 != i_type) {
// indexed rendering
const int i_size = (i_type == GL_UNSIGNED_SHORT) ? 2 : 4;
const int ib_offset = _sg.gl.cache.cur_ib_offset;
const GLvoid* indices = (const GLvoid*)(GLintptr)(base_element*i_size+ib_offset);
if (_sg.gl.cache.cur_pipeline->cmn.use_instanced_draw) {
if (use_instanced_draw) {
glDrawElementsInstanced(p_type, num_elements, i_type, indices, num_instances);
} else {
glDrawElements(p_type, num_elements, i_type, indices);
}
} else {
// non-indexed rendering
if (_sg.gl.cache.cur_pipeline->cmn.use_instanced_draw) {
if (use_instanced_draw) {
glDrawArraysInstanced(p_type, base_element, num_elements, num_instances);
} else {
glDrawArrays(p_type, base_element, num_elements);
Expand Down Expand Up @@ -11185,16 +11186,17 @@ _SOKOL_PRIVATE void _sg_d3d11_apply_uniforms(sg_shader_stage stage_index, int ub
}

_SOKOL_PRIVATE void _sg_d3d11_draw(int base_element, int num_elements, int num_instances) {
const bool use_instanced_draw = (num_instances > 1) || (_sg.d3d11.use_instanced_draw);
if (_sg.d3d11.use_indexed_draw) {
if (_sg.d3d11.use_instanced_draw) {
if (use_instanced_draw) {
_sg_d3d11_DrawIndexedInstanced(_sg.d3d11.ctx, (UINT)num_elements, (UINT)num_instances, (UINT)base_element, 0, 0);
_sg_stats_add(d3d11.draw.num_draw_indexed_instanced, 1);
} else {
_sg_d3d11_DrawIndexed(_sg.d3d11.ctx, (UINT)num_elements, (UINT)base_element, 0);
_sg_stats_add(d3d11.draw.num_draw_indexed, 1);
}
} else {
if (_sg.d3d11.use_instanced_draw) {
if (use_instanced_draw) {
_sg_d3d11_DrawInstanced(_sg.d3d11.ctx, (UINT)num_elements, (UINT)num_instances, (UINT)base_element, 0);
_sg_stats_add(d3d11.draw.num_draw_instanced, 1);
} else {
Expand Down

0 comments on commit 19903d7

Please sign in to comment.