egui_skia icon indicating copy to clipboard operation
egui_skia copied to clipboard

broken ColorTest with cpu rendering

Open yjh0502 opened this issue 2 years ago • 4 comments

While tracking down rendering errors, I found that color rendering is broken with cpu rendering (cpu_fix). Here's a code snippet to render ColorTest.

use egui_skia::rasterize;
use skia_safe::{EncodedImageFormat, Paint, Point};
use std::fs::File;
use std::io::Write;

pub fn main() {
    let mut demo = egui_demo_lib::ColorTest::default();

    let mut surface = rasterize(
        (800, 2000),
        |ctx| {
            egui::CentralPanel::default().show(ctx, |ui| {
                demo.ui(ui);
            });
        },
        None,
    );

    let data = surface
        .image_snapshot()
        .encode_to_data(EncodedImageFormat::PNG)
        .expect("Failed to encode image");

    File::create("output.png")
        .unwrap()
        .write_all(&data)
        .unwrap();

    println!("wrote output.png");
}

This is cpu-rendered image, generate from a code above, which shows errors. output

Here's a side-by-side screenshot, comparing cpu-rendered with webgl one (from https://egui.rs) image

yjh0502 avatar Jan 29 '23 10:01 yjh0502