Skip to content

Commit

Permalink
Simplify the screenshot API
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 27, 2024
1 parent 0676584 commit e0524cb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
4 changes: 0 additions & 4 deletions ComputeShader/Sources/compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions Shader/Sources/shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 0 additions & 4 deletions Texture/Sources/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit e0524cb

Please sign in to comment.