Skip to content

Commit

Permalink
Merge pull request godotengine#96349 from pkdawson/metal-idx-offset
Browse files Browse the repository at this point in the history
Metal: Bind index buffer with offset
  • Loading branch information
akien-mga committed Aug 30, 2024
2 parents ace4529 + f381cee commit 61598c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions drivers/metal/metal_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDCommandBuffer {
id<MTLRenderCommandEncoder> encoder = nil;
id<MTLBuffer> __unsafe_unretained index_buffer = nil; // Buffer is owned by RDD.
MTLIndexType index_type = MTLIndexTypeUInt16;
uint32_t index_offset = 0;
LocalVector<id<MTLBuffer> __unsafe_unretained> vertex_buffers;
LocalVector<NSUInteger> vertex_offsets;
// clang-format off
Expand Down
8 changes: 6 additions & 2 deletions drivers/metal/metal_objects.mm
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@

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,
Expand All @@ -729,13 +730,16 @@

id<MTLRenderCommandEncoder> 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];
}

Expand Down

0 comments on commit 61598c5

Please sign in to comment.