summaryrefslogtreecommitdiff
path: root/alligator_render
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2023-02-04 13:25:45 -0500
committerMicha White <botahamec@outlook.com>2023-02-04 13:25:45 -0500
commit9fd7d6689d5d90679e4b0c12e463ef4e2f8bf515 (patch)
treea0b127f1094b72d0966c2edea3d171e74001c875 /alligator_render
parent518a87ddb2e6ce908affce2773fc7f92beb52c73 (diff)
Have the renderer take the texture manager
Diffstat (limited to 'alligator_render')
-rw-r--r--alligator_render/Cargo.toml18
-rw-r--r--alligator_render/examples/black.rs13
-rw-r--r--alligator_render/examples/bmp.rs13
-rw-r--r--alligator_render/examples/bunnymark.rs13
-rw-r--r--alligator_render/src/renderer.rs11
-rw-r--r--alligator_render/src/texture.rs12
6 files changed, 63 insertions, 17 deletions
diff --git a/alligator_render/Cargo.toml b/alligator_render/Cargo.toml
index 4ef0ed8..a613dcd 100644
--- a/alligator_render/Cargo.toml
+++ b/alligator_render/Cargo.toml
@@ -7,16 +7,20 @@ rust-version = "1.65"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-winit = "0.28"
-log = "0.4"
-wgpu = "0.15"
-thiserror = "1"
-pollster = "0.2"
+alligator_resources = { path = "../alligator_resources" }
+
bytemuck = { version = "1", features = ["derive"] }
-cgmath = "0.18"
+thiserror = "1"
+profiling = "1"
+wgpu = "0.15"
+winit = "0.28"
image = "0.24"
+cgmath = "0.18"
+pollster = "0.2"
+log = "0.4"
+parking_lot = "0.12"
texture_packer = "0.25"
-profiling = "1"
+
tracy-client = { version = "0.15", optional = true }
dhat = { version = "0.3", optional = true }
diff --git a/alligator_render/examples/black.rs b/alligator_render/examples/black.rs
index 106e0f0..198eef2 100644
--- a/alligator_render/examples/black.rs
+++ b/alligator_render/examples/black.rs
@@ -1,6 +1,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use alligator_render::{RenderWindowConfig, Renderer};
+use alligator_resources::texture::{TextureManager, TextureManagerConfig};
fn update(_renderer: &mut Renderer) {}
@@ -8,14 +9,22 @@ fn main() {
let start = std::time::Instant::now();
// configure the render window
- let config = RenderWindowConfig {
+ let render_config = RenderWindowConfig {
//vsync: false,
//mode: alligator_render::config::WindowMode::BorderlessFullscreen,
title: "Black Screen.exe",
..Default::default()
};
- let renderer = Renderer::new(&config).unwrap();
+ let texture_config = TextureManagerConfig {
+ initial_capacity: 0,
+ max_size: 0,
+ atlas_width: 1,
+ atlas_height: 1,
+ };
+
+ let texture_manager = TextureManager::new(&texture_config);
+ let renderer = Renderer::new(&render_config, texture_manager).unwrap();
println!("Startup time: {:?}", start.elapsed());
renderer.run(update);
diff --git a/alligator_render/examples/bmp.rs b/alligator_render/examples/bmp.rs
index b8ce00c..0bad037 100644
--- a/alligator_render/examples/bmp.rs
+++ b/alligator_render/examples/bmp.rs
@@ -3,6 +3,7 @@
use std::num::NonZeroU32;
use alligator_render::{ImageFormat, Instance, RenderWindowConfig, Renderer};
+use alligator_resources::texture::{TextureManager, TextureManagerConfig};
#[profiling::function]
fn update(renderer: &mut Renderer) {
@@ -12,7 +13,7 @@ fn update(renderer: &mut Renderer) {
fn main() {
// configure the render window
- let config = RenderWindowConfig {
+ let render_config = RenderWindowConfig {
title: "Bumper Stickers",
instance_capacity: 2,
default_width: NonZeroU32::new(1280).unwrap(),
@@ -22,7 +23,15 @@ fn main() {
..Default::default()
};
- let mut renderer = Renderer::new(&config).unwrap();
+ let texture_config = TextureManagerConfig {
+ initial_capacity: 3,
+ max_size: 3_000_000,
+ atlas_height: 150,
+ atlas_width: 150,
+ };
+
+ let texture_manager = TextureManager::new(&texture_config);
+ let mut renderer = Renderer::new(&render_config, texture_manager).unwrap();
// render the alligator
let gator = include_bytes!("res/gator.ff");
diff --git a/alligator_render/examples/bunnymark.rs b/alligator_render/examples/bunnymark.rs
index 5530ef3..ab38b5e 100644
--- a/alligator_render/examples/bunnymark.rs
+++ b/alligator_render/examples/bunnymark.rs
@@ -3,6 +3,7 @@ use std::{num::NonZeroU32, time::Instant};
use alligator_render::{
ImageFormat, Instance, InstanceId, RenderWindowConfig, Renderer, TextureId,
};
+use alligator_resources::texture::{TextureManager, TextureManagerConfig};
fn xorshift_plus(seed: &mut [u64; 2]) -> u64 {
let mut t = seed[0];
@@ -123,7 +124,7 @@ fn main() {
profiling::register_thread!("main");
// configure the render window
- let config = RenderWindowConfig {
+ let render_config = RenderWindowConfig {
title: "BunnyMark",
instance_capacity: 5_000_000,
default_width: NonZeroU32::new(1280).unwrap(),
@@ -133,8 +134,16 @@ fn main() {
..Default::default()
};
+ let texture_config = TextureManagerConfig {
+ initial_capacity: 1,
+ max_size: 10_000,
+ atlas_width: 100,
+ atlas_height: 100,
+ };
+
let bunny = include_bytes!("res/bunny.ff");
- let mut renderer = Renderer::new(&config).unwrap();
+ let texture_manager = TextureManager::new(&texture_config);
+ let mut renderer = Renderer::new(&render_config, texture_manager).unwrap();
let texture_id = renderer
.textures_mut()
.load_from_memory(bunny, ImageFormat::Farbfeld)
diff --git a/alligator_render/src/renderer.rs b/alligator_render/src/renderer.rs
index a7d952a..f448119 100644
--- a/alligator_render/src/renderer.rs
+++ b/alligator_render/src/renderer.rs
@@ -1,8 +1,10 @@
-use std::{convert::TryInto, num::NonZeroU32};
+use std::convert::TryInto;
+use std::num::NonZeroU32;
use crate::{
vertex::SQUARE, Camera, Instance, InstanceBuffer, RenderWindowConfig, TextureAtlas, Vertex,
};
+use alligator_resources::texture::TextureManager;
use pollster::FutureExt;
use thiserror::Error;
use wgpu::{include_wgsl, util::DeviceExt};
@@ -146,7 +148,10 @@ impl Renderer {
/// panic on some platforms.
// TODO make it possible to use without a window (ie, use a bitmap in memory as a surface)
// TODO this function needs to be smaller
- pub fn new(config: &RenderWindowConfig) -> Result<Self, NewRendererError> {
+ pub fn new(
+ config: &RenderWindowConfig,
+ textures: TextureManager,
+ ) -> Result<Self, NewRendererError> {
// build the window
let event_loop = EventLoop::new();
let window = config.to_window().build(&event_loop)?;
@@ -214,6 +219,7 @@ impl Renderer {
// TODO make this configurable
let (textures, texture_layout) = TextureAtlas::new(
&device,
+ textures,
window.inner_size().width,
window.inner_size().height,
);
@@ -321,6 +327,7 @@ impl Renderer {
/// trying to acquire the next frame. There may also be no more memory left
/// that can be used for the new frame.
// TODO this needs to be smaller
+ // TODO don't return wgpu errors
#[profiling::function]
fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
// this will allow us to send commands to the gpu
diff --git a/alligator_render/src/texture.rs b/alligator_render/src/texture.rs
index b60eade..2a86501 100644
--- a/alligator_render/src/texture.rs
+++ b/alligator_render/src/texture.rs
@@ -2,6 +2,7 @@ use std::error::Error;
use std::num::NonZeroU32;
use std::sync::atomic::{AtomicUsize, Ordering};
+use alligator_resources::texture::TextureManager;
use image::error::DecodingError;
use image::{EncodableLayout, GenericImage, ImageError, RgbaImage};
use texture_packer::TexturePacker;
@@ -84,6 +85,7 @@ const fn extent_3d(width: u32, height: u32) -> wgpu::Extent3d {
// TODO make this Debug
// TODO make these resizable
pub struct TextureAtlas {
+ textures: TextureManager,
packer: TexturePacker<'static, image::RgbaImage, TextureId>,
diffuse_texture: wgpu::Texture,
diffuse_bind_group: wgpu::BindGroup,
@@ -108,7 +110,12 @@ impl TextureAtlas {
/// Creates a new texture atlas, with the given size
// TODO why is this u32?
// TODO this is still too large
- pub fn new(device: &wgpu::Device, width: u32, height: u32) -> (Self, wgpu::BindGroupLayout) {
+ pub fn new(
+ device: &wgpu::Device,
+ textures: TextureManager,
+ width: u32,
+ height: u32,
+ ) -> (Self, wgpu::BindGroupLayout) {
let atlas_size = extent_3d(width, height);
let diffuse_texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("Diffuse Texture"),
@@ -167,6 +174,7 @@ impl TextureAtlas {
(
Self {
+ textures,
packer: TexturePacker::new_skyline(TexturePackerConfig {
max_width: width,
max_height: height,
@@ -243,7 +251,7 @@ impl TextureAtlas {
/// Fill the GPU texture atlas
#[profiling::function]
- pub fn fill_textures(&mut self, queue: &wgpu::Queue) {
+ pub(crate) fn fill_textures(&mut self, queue: &wgpu::Queue) {
// saves time if nothing changed since the last time we did this
// FIXME This doesn't do much good once we get procedurally generated animation
// We'll have to create our own texture packer, with mutable subtextures,