Skip to content

Commit 7c9c925

Browse files
committed
paint: fix bgra swap
1 parent f6a5bcd commit 7c9c925

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

paint/sources/ui/ui_view2d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void ui_view2d_init() {
3636
}
3737

3838
void ui_view2d_capture_output(void *_) {
39-
util_texture_capture_output(ui_view2d_tex, "tex_capture");
39+
util_texture_capture_output(ui_view2d_tex, "tex_capture", false);
4040
}
4141

4242
void ui_view2d_draw_edit() {

paint/sources/util/util_nodes.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,13 @@ void ui_nodes_capture_output() {
233233
ui_nodes_t *ui_nodes = ui_nodes_get_nodes();
234234
ui_node_canvas_t *c = ui_nodes_get_canvas(true);
235235
ui_node_t *sel = ui_get_node(c->nodes, ui_nodes->nodes_selected_id->buffer[0]);
236-
util_texture_capture_output(ui_nodes_get_node_preview_image(sel), "node_preview");
236+
237+
bool bgra = false;
238+
#ifdef IRON_BGRA
239+
bgra = string_equals(sel->type, "TEX_IMAGE") || starts_with(sel->type, "NEURAL_");
240+
#endif
241+
242+
util_texture_capture_output(ui_nodes_get_node_preview_image(sel), "node_preview", bgra);
237243
}
238244

239245
void ui_viewnodes_on_canvas_capture_output(void *_) {

paint/sources/util/util_texture.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#include "../global.h"
33

4-
void util_texture_capture_output(gpu_texture_t *img, char *basename) {
4+
void util_texture_capture_output(gpu_texture_t *img, char *basename, bool bgra) {
55
if (img == NULL) {
66
return;
77
}
@@ -21,7 +21,15 @@ void util_texture_capture_output(gpu_texture_t *img, char *basename) {
2121
}
2222
}
2323

24-
u8_array_t *bytes = iron_encode_png(gpu_get_texture_pixels(img), img->width, img->height, 0);
24+
buffer_t *buf = gpu_get_texture_pixels(img);
25+
26+
#ifdef IRON_BGRA
27+
if (bgra) {
28+
buf = buffer_bgra_swap(buf); // Vulkan non-rt textures need a flip
29+
}
30+
#endif
31+
32+
u8_array_t *bytes = iron_encode_png(buf, img->width, img->height, 0);
2533
packed_asset_t *pa = GC_ALLOC_INIT(packed_asset_t, {.name = abs, .bytes = bytes});
2634
any_array_push(g_project->packed_assets, pa);
2735
gpu_texture_t *copy = gpu_create_texture_from_encoded_bytes(bytes, ".png");

0 commit comments

Comments
 (0)