Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

wgpu -> macroquad #97

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2,042 changes: 840 additions & 1,202 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[workspace]
resolver = "2"

members = ["comfy", "comfy-core", "comfy-wgpu", "demos/egui-scaling", "demos/fun"]
members = [
"comfy",
"comfy-core",
"comfy-quad",
"demos/egui-scaling",
"demos/fun",
]

[profile.dev]
opt-level = 3
Expand All @@ -15,3 +21,6 @@ opt-level = 3
# egui-wgpu = { path = "../egui/crates/egui-wgpu" }
# egui-winit = { path = "../egui/crates/egui-winit" }
# egui_plot = { path = "../egui/crates/egui_plot" }
# macroquad = { path = "../macroquad" }

# egui-macroquad = { path = "../egui-macroquad" }
21 changes: 17 additions & 4 deletions comfy-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,30 @@ comfy-git-version = { version = "0.4.0", optional = true }
comfy_include_dir = "0.7.3"

glam = { version = "0.24.1" }
egui = "0.26.2"
egui_plot = "0.26.2"
epaint = "0.26.2"
egui-winit = { version = "0.26.2", default-features = false, features = [] }
egui = "0.25.0"
egui_plot = "0.25.0"
epaint = "0.25.0"

num-traits = "0.2.16"

thunderdome = "0.6.0"
fontdue = "0.7.3"
etagere = "0.2.10"

# egui-macroquad = { git = "https://github.com/darthdeus/egui-macroquad.git", default-features = false, features = [
# ], branch = "pub-things" }

# egui-macroquad = { git = "https://github.com/optozorax/egui-macroquad.git", default-features = false, features = [] }
# egui-macroquad = { git = "https://github.com/darthdeus/egui-macroquad.git", default-features = false, features = [
# ], branch = "pub-things" }

# macroquad = { version = "0.4.4", default-features = false, features = [] }
macroquad = { version = "0.4.5", default-features = false, features = [] }
egui-macroquad = { git = "https://github.com/darthdeus/egui-macroquad.git", default-features = false, features = [
], branch = "pub-things" }
# egui-macroquad = { path = "../../egui-macroquad" }
# macroquad = { path = "../../macroquad", features = [], default-features = false }

jemalloc-ctl = { version = "0.5.0", optional = true }
jemallocator = { version = "0.5.0", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions comfy-core/src/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::sync::atomic::{AtomicU32, AtomicU64, AtomicUsize, Ordering};

use crate::*;

static EGUI_CONTEXT: Lazy<egui::Context> = Lazy::new(egui::Context::default);
// static EGUI_CONTEXT: Lazy<egui::Context> = Lazy::new(egui::Context::default);

pub fn egui() -> &'static egui::Context {
&EGUI_CONTEXT
&egui_macroquad::get_egui().egui_mq.egui_ctx
}

static FRAME_TIME: AtomicU32 =
Expand Down
31 changes: 30 additions & 1 deletion comfy-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ pub use chrono;
pub use crossbeam::atomic::AtomicCell;
pub use egui;
pub use egui_plot;
pub use egui_winit;
pub use env_logger;
pub use epaint;
pub use glam::{
Expand Down Expand Up @@ -1768,3 +1767,33 @@ fn test_vec_flip_h() {
1, 2, 3, 3, 0, 0, 0, 1
]);
}

use chrono::{DateTime, Utc};
use image::RgbaImage;

pub struct ScreenshotItem {
pub image: RgbaImage,
pub time: DateTime<Utc>,
}

#[derive(Copy, Clone, Debug)]
pub struct ScreenshotParams {
pub record_screenshots: bool,
/// When set to 1, a screenshot will be taken every frame.
/// When set to a higher number, a screenshot will be taken every n frames.
pub screenshot_interval_n: usize,
pub history_length: usize,

counter: usize,
}

impl Default for ScreenshotParams {
fn default() -> Self {
Self {
record_screenshots: false,
screenshot_interval_n: 1,
history_length: 10,
counter: 0,
}
}
}
7 changes: 0 additions & 7 deletions comfy-core/src/spatial_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,6 @@ impl SpatialHash {
t += self.grid_size / (end - start).length();
}

// draw_text(
// &format!("{:.1?} {:.1?} {:#.1?}", start, end, closest_intersection),
// start,
// WHITE,
// TextAlign::Center,
// );

closest_intersection
}
}
Expand Down
26 changes: 26 additions & 0 deletions comfy-quad/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "comfy-quad"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []

ci-release = []
tracy = []
record-pngs = []

[dependencies]
comfy-core = { path = "../comfy-core", version = "0.4.0" }

macroquad = { version = "0.4.5", default-features = false, features = [] }
# macroquad = { path = "../../macroquad", default-features = false, features = [] }

# egui-macroquad = { version = "0.15.0", default-features = false, features = [] }
# egui-macroquad = { git = "https://github.com/optozorax/egui-macroquad.git", default-features = false, features = [] }

egui-macroquad = { git = "https://github.com/darthdeus/egui-macroquad.git", default-features = false, features = [
], branch = "pub-things" }
# egui-macroquad = { path = "../../egui-macroquad" }
Binary file added comfy-quad/assets/1px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added comfy-quad/assets/_builtin-comfy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added comfy-quad/assets/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added comfy-quad/assets/test-grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
181 changes: 181 additions & 0 deletions comfy-quad/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
use comfy_core::*;
use macroquad::window::{screen_height, screen_width};
use std::sync::mpsc::{channel, Receiver, Sender};

pub use egui_macroquad;
pub use macroquad;

mod text;

pub use crate::text::*;

#[derive(Copy, Clone, Debug)]
pub enum AddressMode {
ClampToEdge,
}

pub fn blood_canvas_reset() {}

pub type TextureMap = HashMap<TextureHandle, TextureHandle>;

pub fn load_texture_from_engine_bytes(
context: &GraphicsContext,
name: &str,
bytes: &[u8],
address_mode: AddressMode,
) {
}

pub fn sprite_shader_from_fragment(source: &str) -> String {
"".to_string()
// format!("{}{}{}", CAMERA_BIND_GROUP_PREFIX, FRAG_SHADER_PREFIX, source)
}

pub fn watch_shader_path(
path: &str,
shader_id: ShaderId,
) -> notify::Result<()> {
let path = Path::new(path).canonicalize().unwrap().to_path_buf();

// let mut hot_reload = HOT_RELOAD.lock();
// hot_reload.watch_path(path.as_path())?;
// hot_reload.shader_paths.insert(path, shader_id);

Ok(())
}

pub fn blood_canvas_update_and_draw(f: fn(IVec2, &CanvasBlock)) {}

#[derive(Debug)]
pub struct QuadTextureCreator {}

impl QuadTextureCreator {
pub fn new() -> Self {
Self {}
}
}

impl TextureCreator for QuadTextureCreator {
fn handle_from_size(
&self,
name: &str,
size: UVec2,
fill: Color,
) -> TextureHandle {
// TODO:
TextureHandle::Raw(0)
}

fn handle_from_image(
&self,
name: &str,
image: &image::RgbaImage,
) -> TextureHandle {
// TODO:
TextureHandle::Raw(0)
}

fn update_texture(&self, image: &image::RgbaImage, texture: TextureHandle) {
// TODO:
}

fn update_texture_region(
&self,
handle: TextureHandle,
image: &image::RgbaImage,
region: IRect,
) {
// TODO:
}
}

pub static BLOOD_CANVAS: OnceCell<AtomicRefCell<BloodCanvas>> = OnceCell::new();

#[derive(Clone)]
pub struct GraphicsContext {
pub texture_map: Arc<AtomicRefCell<TextureMap>>,
pub texture_creator: Arc<AtomicRefCell<QuadTextureCreator>>,
}

pub struct QuadRenderer {
pub context: GraphicsContext,
pub texture_creator: Arc<AtomicRefCell<QuadTextureCreator>>,
pub loaded_image_recv: Receiver<LoadedImage>,
pub loaded_image_send: Sender<LoadedImage>,
pub text: RefCell<TextRasterizer>,
pub screenshot_params: ScreenshotParams,
pub screenshot_history_buffer: VecDeque<ScreenshotItem>,
}

impl QuadRenderer {
pub async fn new() -> Self {
trace!("Loading builtin engine textures");

let context = GraphicsContext {
texture_map: Arc::new(AtomicRefCell::new(TextureMap::new())),
texture_creator: Arc::new(AtomicRefCell::new(
QuadTextureCreator::new(),
)),
};

{
macro_rules! load_engine_tex {
($name: literal) => {{
load_texture_from_engine_bytes(
&context,
$name,
include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/",
$name,
".png"
)),
AddressMode::ClampToEdge,
);
}};
}

load_engine_tex!("error");
load_engine_tex!("1px");
load_engine_tex!("test-grid");
load_engine_tex!("_builtin-comfy");
}


let texture_creator =
Arc::new(AtomicRefCell::new(QuadTextureCreator::new()));

let (tx_texture, rx_texture) = channel::<LoadedImage>();

QuadRenderer {
text: RefCell::new(TextRasterizer::new(context.clone())),
context,
texture_creator,
loaded_image_recv: rx_texture,
loaded_image_send: tx_texture,
screenshot_params: ScreenshotParams::default(),
screenshot_history_buffer: VecDeque::new(),
}
}

pub fn width(&self) -> f32 {
screen_width()
}

pub fn height(&self) -> f32 {
screen_height()
}

pub fn update(&mut self, params: &mut DrawParams) {}

pub fn draw(&mut self, params: DrawParams, egui: &egui::Context) {}

pub fn end_frame(&mut self) {}
}

pub fn save_screenshots_to_folder(
folder: &str,
screenshot_history_buffer: &VecDeque<ScreenshotItem>,
) {
todo!()
}
Loading
Loading