diff --git a/drivers/metal/metal_objects.h b/drivers/metal/metal_objects.h index f0a3e85f88b..97f33bb1e84 100644 --- a/drivers/metal/metal_objects.h +++ b/drivers/metal/metal_objects.h @@ -227,6 +227,7 @@ public: id encoder = nil; id __unsafe_unretained index_buffer = nil; // Buffer is owned by RDD. MTLIndexType index_type = MTLIndexTypeUInt16; + uint32_t index_offset = 0; LocalVector __unsafe_unretained> vertex_buffers; LocalVector vertex_offsets; // clang-format off diff --git a/drivers/metal/metal_objects.mm b/drivers/metal/metal_objects.mm index c66b683e236..abdcccf00c6 100644 --- a/drivers/metal/metal_objects.mm +++ b/drivers/metal/metal_objects.mm @@ -717,6 +717,7 @@ void MDCommandBuffer::render_bind_index_buffer(RDD::BufferID p_buffer, RDD::Inde render.index_buffer = rid::get(p_buffer); render.index_type = p_format == RDD::IndexBufferFormat::INDEX_BUFFER_FORMAT_UINT16 ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32; + render.index_offset = p_offset; } void MDCommandBuffer::render_draw_indexed(uint32_t p_index_count, @@ -729,13 +730,16 @@ void MDCommandBuffer::render_draw_indexed(uint32_t p_index_count, id enc = render.encoder; + uint32_t index_offset = render.index_offset; + index_offset += p_first_index * (render.index_type == MTLIndexTypeUInt16 ? sizeof(uint16_t) : sizeof(uint32_t)); + [enc drawIndexedPrimitives:render.pipeline->raster_state.render_primitive indexCount:p_index_count indexType:render.index_type indexBuffer:render.index_buffer - indexBufferOffset:p_vertex_offset + indexBufferOffset:index_offset instanceCount:p_instance_count - baseVertex:p_first_index + baseVertex:p_vertex_offset baseInstance:p_first_instance]; }