diff --git a/Backends/Graphics5/Metal/Sources/kope/metal/commandlist.m b/Backends/Graphics5/Metal/Sources/kope/metal/commandlist.m index 0c4b33091..9d743fae6 100644 --- a/Backends/Graphics5/Metal/Sources/kope/metal/commandlist.m +++ b/Backends/Graphics5/Metal/Sources/kope/metal/commandlist.m @@ -17,22 +17,23 @@ void kope_metal_command_list_destroy(kope_g5_command_list *list) {} void kope_metal_command_list_begin_render_pass(kope_g5_command_list *list, const kope_g5_render_pass_parameters *parameters) { id texture = (__bridge id)parameters->color_attachments[0].texture.texture->metal.texture; - MTLRenderPassDescriptor *renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor]; - renderPassDescriptor.colorAttachments[0].texture = texture; - renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear; - renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore; - renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0); - renderPassDescriptor.depthAttachment.clearDepth = 1; - renderPassDescriptor.depthAttachment.loadAction = MTLLoadActionClear; - renderPassDescriptor.depthAttachment.storeAction = MTLStoreActionStore; - renderPassDescriptor.depthAttachment.texture = nil; // depthTexture; - renderPassDescriptor.stencilAttachment.clearStencil = 0; - renderPassDescriptor.stencilAttachment.loadAction = MTLLoadActionDontCare; - renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionDontCare; - renderPassDescriptor.stencilAttachment.texture = nil; // depthTexture; + + MTLRenderPassDescriptor *render_pass_descriptor = [MTLRenderPassDescriptor renderPassDescriptor]; + render_pass_descriptor.colorAttachments[0].texture = texture; + render_pass_descriptor.colorAttachments[0].loadAction = MTLLoadActionClear; + render_pass_descriptor.colorAttachments[0].storeAction = MTLStoreActionStore; + render_pass_descriptor.colorAttachments[0].clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0); + render_pass_descriptor.depthAttachment.clearDepth = 1; + render_pass_descriptor.depthAttachment.loadAction = MTLLoadActionClear; + render_pass_descriptor.depthAttachment.storeAction = MTLStoreActionStore; + render_pass_descriptor.depthAttachment.texture = nil; // depthTexture; + render_pass_descriptor.stencilAttachment.clearStencil = 0; + render_pass_descriptor.stencilAttachment.loadAction = MTLLoadActionDontCare; + render_pass_descriptor.stencilAttachment.storeAction = MTLStoreActionDontCare; + render_pass_descriptor.stencilAttachment.texture = nil; // depthTexture; id command_buffer = (__bridge id)list->metal.command_buffer; - list->metal.render_command_encoder = (__bridge_retained void *)[command_buffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; + list->metal.render_command_encoder = (__bridge_retained void *)[command_buffer renderCommandEncoderWithDescriptor:render_pass_descriptor]; } void kope_metal_command_list_end_render_pass(kope_g5_command_list *list) { @@ -42,7 +43,12 @@ void kope_metal_command_list_end_render_pass(kope_g5_command_list *list) { } void kope_metal_command_list_present(kope_g5_command_list *list) { - //[command_buffer presentDrawable:drawable]; + id command_buffer = (__bridge id)list->metal.command_buffer; + + CAMetalLayer *metal_layer = getMetalLayer(); + id drawable = [metal_layer nextDrawable]; + + [command_buffer presentDrawable:drawable]; } void kope_metal_command_list_set_index_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer, kope_g5_index_format index_format, uint64_t offset, diff --git a/Backends/Graphics5/Metal/Sources/kope/metal/device.m b/Backends/Graphics5/Metal/Sources/kope/metal/device.m index 06b893dad..a09e8c3a9 100644 --- a/Backends/Graphics5/Metal/Sources/kope/metal/device.m +++ b/Backends/Graphics5/Metal/Sources/kope/metal/device.m @@ -10,8 +10,6 @@ #include -CAMetalLayer *getMetalLayer(void); - void kope_metal_device_create(kope_g5_device *device, const kope_g5_device_wishlist *wishlist) { id metal_device = MTLCreateSystemDefaultDevice(); getMetalLayer().device = metal_device; @@ -58,9 +56,17 @@ void kope_metal_device_create_texture(kope_g5_device *device, const kope_g5_text return &framebuffer; } +kope_g5_texture_format kope_metal_device_framebuffer_format(kope_g5_device *device) { + return KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM; +} + void kope_metal_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list) { id command_buffer = (__bridge id)list->metal.command_buffer; [command_buffer commit]; + + id command_queue = (__bridge id)list->metal.command_queue; + command_buffer = [command_queue commandBuffer]; + list->metal.command_buffer = (__bridge_retained void *)[command_queue commandBuffer]; } void kope_metal_device_wait_until_idle(kope_g5_device *device) {} diff --git a/Backends/Graphics5/Metal/Sources/kope/metal/device_functions.h b/Backends/Graphics5/Metal/Sources/kope/metal/device_functions.h index 1586c4940..e1efdcda6 100644 --- a/Backends/Graphics5/Metal/Sources/kope/metal/device_functions.h +++ b/Backends/Graphics5/Metal/Sources/kope/metal/device_functions.h @@ -30,6 +30,8 @@ void kope_metal_device_create_sampler(kope_g5_device *device, const kope_g5_samp kope_g5_texture *kope_metal_device_get_framebuffer(kope_g5_device *device); +kope_g5_texture_format kope_metal_device_framebuffer_format(kope_g5_device *device); + void kope_metal_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list); void kope_metal_device_wait_until_idle(kope_g5_device *device); diff --git a/Backends/Graphics5/Metal/Sources/kope/metal/metalunit.m b/Backends/Graphics5/Metal/Sources/kope/metal/metalunit.m index db845511b..8a687bb0f 100644 --- a/Backends/Graphics5/Metal/Sources/kope/metal/metalunit.m +++ b/Backends/Graphics5/Metal/Sources/kope/metal/metalunit.m @@ -6,6 +6,8 @@ #import +CAMetalLayer *getMetalLayer(void); + #include "buffer.m" #include "commandlist.m" #include "descriptorset.m"