summaryrefslogtreecommitdiff
path: root/alligator_render/src
diff options
context:
space:
mode:
Diffstat (limited to 'alligator_render/src')
-rw-r--r--alligator_render/src/renderer.rs11
-rw-r--r--alligator_render/src/texture.rs12
2 files changed, 19 insertions, 4 deletions
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,