Skip to content

Commit

Permalink
Try to create render passes
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 2, 2025
1 parent 40ee48b commit a16e92f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
24 changes: 21 additions & 3 deletions Backends/Graphics5/Metal/Sources/kope/metal/commandlist.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,33 @@ 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<MTLTexture> texture = (__bridge id<MTLTexture>)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;

id<MTLCommandBuffer> command_buffer = (__bridge id<MTLCommandBuffer>)list->metal.command_buffer;
list->metal.render_command_encoder = (__bridge_retained void *)[command_buffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
}

void kope_metal_command_list_end_render_pass(kope_g5_command_list *list) {

id<MTLRenderCommandEncoder> render_command_encoder = (__bridge id<MTLRenderCommandEncoder>)list->metal.render_command_encoder;
[render_command_encoder endEncoding];
list->metal.render_command_encoder = NULL;
}

void kope_metal_command_list_present(kope_g5_command_list *list) {

//[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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ typedef struct kope_metal_buffer_access {
} kope_metal_buffer_access;

typedef struct kope_metal_command_list {
void *queue;
void *command_queue;
void *command_buffer;
void *render_command_encoder;
} kope_metal_command_list;

#ifdef __cplusplus
Expand Down
18 changes: 13 additions & 5 deletions Backends/Graphics5/Metal/Sources/kope/metal/device.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

#include <assert.h>

CAMetalLayer *get_metal_layer(void);
CAMetalLayer *getMetalLayer(void);

void kope_metal_device_create(kope_g5_device *device, const kope_g5_device_wishlist *wishlist) {
id<MTLDevice> metal_device = MTLCreateSystemDefaultDevice();
get_metal_layer().device = metal_device;
getMetalLayer().device = metal_device;
device->metal.device = (__bridge_retained void *)metal_device;
device->metal.library = (__bridge_retained void *)[metal_device newDefaultLibrary];
}
Expand Down Expand Up @@ -46,19 +46,27 @@ void kope_metal_device_create_buffer(kope_g5_device *device, const kope_g5_buffe

void kope_metal_device_create_command_list(kope_g5_device *device, kope_g5_command_list_type type, kope_g5_command_list *list) {
id<MTLDevice> metal_device = (__bridge id<MTLDevice>)device->metal.device;
list->metal.queue = (__bridge_retained void *)[metal_device newCommandQueue];
id<MTLCommandQueue> command_queue = [metal_device newCommandQueue];
list->metal.command_queue = (__bridge_retained void *)command_queue;
list->metal.command_buffer = (__bridge_retained void *)[command_queue commandBuffer];
}

void kope_metal_device_create_texture(kope_g5_device *device, const kope_g5_texture_parameters *parameters, kope_g5_texture *texture) {

}

static kope_g5_texture framebuffer;

kope_g5_texture *kope_metal_device_get_framebuffer(kope_g5_device *device) {
return NULL;
CAMetalLayer *metal_layer = getMetalLayer();
id<CAMetalDrawable> drawable = [metal_layer nextDrawable];
framebuffer.metal.texture = (__bridge_retained void *)drawable.texture;
return &framebuffer;
}

void kope_metal_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list) {

id<MTLCommandBuffer> command_buffer = (__bridge id<MTLCommandBuffer>)list->metal.command_buffer;
[command_buffer commit];
}

void kope_metal_device_wait_until_idle(kope_g5_device *device) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C" {
#endif

typedef struct kope_metal_texture {
int nothing;
void *texture;
} kope_metal_texture;

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,6 @@ static CAMetalLayer *metalLayer = NULL;
- (id<MTLCommandQueue>)metalQueue {
return commandQueue;
}

CAMetalLayer *get_metal_layer(void) {
return metalLayer;
}

#endif

@end
Expand Down

0 comments on commit a16e92f

Please sign in to comment.