aboutsummaryrefslogtreecommitdiff
path: root/stockton-render/src/draw/texture/chunk.rs
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:21 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:21 +0100
commit9d720593e9f4829e2bb81534ef54545a61b3df00 (patch)
tree4f3a90fc71132b671bf097388ccd8f17f0c3517e /stockton-render/src/draw/texture/chunk.rs
parentbbcd377cda8a3d99cee8f2f79d58575e00d0aeb8 (diff)
refactor(render): give some functions less arguments
Diffstat (limited to 'stockton-render/src/draw/texture/chunk.rs')
-rw-r--r--stockton-render/src/draw/texture/chunk.rs30
1 files changed, 11 insertions, 19 deletions
diff --git a/stockton-render/src/draw/texture/chunk.rs b/stockton-render/src/draw/texture/chunk.rs
index 02f2dc5..c2781de 100644
--- a/stockton-render/src/draw/texture/chunk.rs
+++ b/stockton-render/src/draw/texture/chunk.rs
@@ -20,14 +20,15 @@ use hal::prelude::*;
use image::{Rgba, RgbaImage};
use core::mem::replace;
-use std::ops::{Deref, Range};
+use std::ops::Deref;
use crate::{error, types::*};
use super::image::SampledImage;
use super::resolver::TextureResolver;
use log::debug;
-use stockton_levels::prelude::*;
+use std::iter::Iterator;
+use stockton_levels::traits::textures::Texture;
/// The size of a chunk. Needs to match up with the fragment shader
pub const CHUNK_SIZE: usize = 8;
@@ -41,25 +42,18 @@ pub struct TextureChunk {
impl TextureChunk {
/// Create a new texture chunk and load in the textures specified by `range` from `file` using `resolver`
/// Can error if the descriptor pool is too small or if a texture isn't found
- pub fn new<T: HasTextures, R: TextureResolver>(
+ pub fn new<'a, I, R: TextureResolver>(
device: &mut Device,
adapter: &mut Adapter,
command_queue: &mut CommandQueue,
command_pool: &mut CommandPool,
- pool: &mut DescriptorPool,
- layout: &DescriptorSetLayout,
- file: &T,
- range: Range<u32>,
+ descriptor_set: DescriptorSet,
+ textures: I,
resolver: &mut R,
- ) -> Result<TextureChunk, error::CreationError> {
- //
- let descriptor_set = unsafe {
- pool.allocate_set(&layout).map_err(|e| {
- println!("{:?}", e);
- error::CreationError::OutOfMemoryError
- })?
- };
-
+ ) -> Result<TextureChunk, error::CreationError>
+ where
+ I: 'a + Iterator<Item = &'a Texture>,
+ {
let mut store = TextureChunk {
descriptor_set,
sampled_images: Vec::with_capacity(CHUNK_SIZE),
@@ -68,9 +62,7 @@ impl TextureChunk {
let mut local_idx = 0;
debug!("Created descriptor set");
- for tex_idx in range {
- debug!("Loading tex {}", local_idx + 1);
- let tex = file.get_texture(tex_idx);
+ for tex in textures {
if let Some(img) = resolver.resolve(tex) {
store
.put_texture(img, local_idx, device, adapter, command_queue, command_pool)