From 83857d4d0d30e98f2833706e6b1506480aac6434 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 4 Jan 2024 19:01:22 -0800 Subject: [PATCH] Added constants --- crates/constants/src/lib.rs | 6 ++++ .../render/src/globaluniform/atlascontent.rs | 5 ++-- .../render/src/globaluniform/globaluniform.rs | 29 +++++++++++++------ .../render/src/globaluniform/spritecontent.rs | 5 ++-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/crates/constants/src/lib.rs b/crates/constants/src/lib.rs index 8745938..b1c7a43 100644 --- a/crates/constants/src/lib.rs +++ b/crates/constants/src/lib.rs @@ -55,3 +55,9 @@ pub const PARTICLE_SPRITE_INSTANCE_LIMIT: u64 = 1000; /// Must be small enough to fit in an i32 pub const STARFIELD_SPRITE_INSTANCE_LIMIT: u64 = STARFIELD_COUNT * 24; + +/// The maximum number of sprites we can define +pub const SPRITE_LIMIT: u32 = 1024; + +/// The maximum number of images we can load +pub const IMAGE_LIMIT: u32 = 1024; diff --git a/crates/render/src/globaluniform/atlascontent.rs b/crates/render/src/globaluniform/atlascontent.rs index d5a3c86..3570764 100644 --- a/crates/render/src/globaluniform/atlascontent.rs +++ b/crates/render/src/globaluniform/atlascontent.rs @@ -1,4 +1,5 @@ use bytemuck::{Pod, Zeroable}; +use galactica_constants::IMAGE_LIMIT; use std::mem; use wgpu; @@ -14,14 +15,14 @@ pub struct ImageLocation { #[derive(Debug, Copy, Clone)] pub struct ImageLocationArray { - pub data: [ImageLocation; 108], + pub data: [ImageLocation; IMAGE_LIMIT as usize], } unsafe impl Pod for ImageLocationArray {} unsafe impl Zeroable for ImageLocationArray { fn zeroed() -> Self { Self { - data: [ImageLocation::zeroed(); 108], + data: [ImageLocation::zeroed(); IMAGE_LIMIT as usize], } } } diff --git a/crates/render/src/globaluniform/globaluniform.rs b/crates/render/src/globaluniform/globaluniform.rs index 3477ec3..9dbaea3 100644 --- a/crates/render/src/globaluniform/globaluniform.rs +++ b/crates/render/src/globaluniform/globaluniform.rs @@ -1,3 +1,4 @@ +use galactica_constants::{IMAGE_LIMIT, SPRITE_LIMIT}; use wgpu; use super::{AtlasContent, DataContent, SpriteContent}; @@ -30,7 +31,7 @@ impl GlobalUniform { starfield_size_limits: vec2, current_time: vec2, }; - "#, + "#, ); out.push_str("\n"); @@ -44,11 +45,16 @@ impl GlobalUniform { width: f32, height: f32, }; - struct AtlasUniform { - data: array, - }; - "#, + "#, ); + out.push_str(&format!( + r#" + struct AtlasUniform {{ + data: array, + }}; + "#, + IMAGE_LIMIT, + )); out.push_str("\n"); // TODO: document @@ -72,11 +78,16 @@ impl GlobalUniform { padding_b: f32, padding_c: f32, }; - struct SpriteUniform { - data: array, - }; - "#, + "#, ); + out.push_str(&format!( + r#" + struct SpriteUniform {{ + data: array, + }}; + "#, + SPRITE_LIMIT, + )); out.push_str("\n"); return out; diff --git a/crates/render/src/globaluniform/spritecontent.rs b/crates/render/src/globaluniform/spritecontent.rs index f724c89..59e034d 100644 --- a/crates/render/src/globaluniform/spritecontent.rs +++ b/crates/render/src/globaluniform/spritecontent.rs @@ -1,4 +1,5 @@ use bytemuck::{Pod, Zeroable}; +use galactica_constants::SPRITE_LIMIT; use std::mem; use wgpu; @@ -19,14 +20,14 @@ pub struct SpriteData { #[derive(Debug, Copy, Clone)] pub struct SpriteDataArray { - pub data: [SpriteData; 108], + pub data: [SpriteData; SPRITE_LIMIT as usize], } unsafe impl Pod for SpriteDataArray {} unsafe impl Zeroable for SpriteDataArray { fn zeroed() -> Self { Self { - data: [SpriteData::zeroed(); 108], + data: [SpriteData::zeroed(); SPRITE_LIMIT as usize], } } }