From e0524cb9508c88d49ca1867a59b3121affc0d01b Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Fri, 27 Sep 2024 02:04:56 +0200 Subject: [PATCH] Simplify the screenshot API --- ComputeShader/Sources/compute.c | 4 ---- Shader/Sources/shader.c | 4 ---- Texture/Sources/texture.c | 4 ---- screenshot.h | 12 ++++++------ 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/ComputeShader/Sources/compute.c b/ComputeShader/Sources/compute.c index 68d5981..b39d573 100644 --- a/ComputeShader/Sources/compute.c +++ b/ComputeShader/Sources/compute.c @@ -109,10 +109,6 @@ int kickstart(int argc, char **argv) { kope_g5_device_create_command_list(&device, &list); -#ifdef SCREENSHOT - screenshot_init_buffer(&device, width, height); -#endif - kong_create_buffer_vertex_in(&device, 3, &vertices); { vertex_in *v = kong_vertex_in_buffer_lock(&vertices); diff --git a/Shader/Sources/shader.c b/Shader/Sources/shader.c index 94a4c2c..640c5c3 100644 --- a/Shader/Sources/shader.c +++ b/Shader/Sources/shader.c @@ -64,10 +64,6 @@ int kickstart(int argc, char **argv) { kope_g5_device_create_command_list(&device, &list); -#ifdef SCREENSHOT - screenshot_init_buffer(&device, width, height); -#endif - kong_create_buffer_vertex_in(&device, 3, &vertices); vertex_in *v = kong_vertex_in_buffer_lock(&vertices); diff --git a/Texture/Sources/texture.c b/Texture/Sources/texture.c index 4b0cb25..34dc965 100644 --- a/Texture/Sources/texture.c +++ b/Texture/Sources/texture.c @@ -102,10 +102,6 @@ int kickstart(int argc, char **argv) { kope_g5_device_create_command_list(&device, &list); -#ifdef SCREENSHOT - screenshot_init_buffer(&device, width, height); -#endif - kope_g5_buffer_parameters buffer_parameters; buffer_parameters.size = kope_g5_device_align_texture_row_bytes(&device, 250 * 4) * 250; buffer_parameters.usage_flags = KOPE_G5_BUFFER_USAGE_CPU_WRITE; diff --git a/screenshot.h b/screenshot.h index c558edf..a28860f 100644 --- a/screenshot.h +++ b/screenshot.h @@ -5,21 +5,21 @@ static kope_g5_buffer screenshot_buffer; -static void screenshot_init_buffer(kope_g5_device *device, int width, int height) { +static void screenshot_take(kope_g5_device *device, kope_g5_command_list *list, kope_g5_texture *framebuffer, int width, int height) { + uint32_t row_bytes = kope_g5_device_align_texture_row_bytes(device, width * 4); + kope_g5_buffer_parameters buffer_parameters; - buffer_parameters.size = kope_g5_device_align_texture_row_bytes(device, width * 4) * height; + buffer_parameters.size = row_bytes * height; buffer_parameters.usage_flags = KOPE_G5_BUFFER_USAGE_CPU_READ; kope_g5_device_create_buffer(device, &buffer_parameters, &screenshot_buffer); -} -static void screenshot_take(kope_g5_device *device, kope_g5_command_list *list, kope_g5_texture *framebuffer, int width, int height) { kope_g5_image_copy_texture source = {0}; source.texture = framebuffer; source.mip_level = 0; kope_g5_image_copy_buffer destination = {0}; destination.buffer = &screenshot_buffer; - destination.bytes_per_row = kope_g5_device_align_texture_row_bytes(device, width * 4); + destination.bytes_per_row = row_bytes; kope_g5_command_list_copy_texture_to_buffer(list, &source, &destination, width, height, 1); @@ -29,7 +29,7 @@ static void screenshot_take(kope_g5_device *device, kope_g5_command_list *list, uint8_t *pixels = (uint8_t *)kope_g5_buffer_lock(&screenshot_buffer); - stbi_write_png("test.png", width, height, 4, pixels, kope_g5_device_align_texture_row_bytes(device, width * 4)); + stbi_write_png("test.png", width, height, 4, pixels, row_bytes); kope_g5_buffer_unlock(&screenshot_buffer);