Skip to content

Commit

Permalink
Attempts to fix hdr_texture_loader.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
mnmaita committed Mar 13, 2024
1 parent c08b474 commit 1bca769
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions crates/bevy_render/src/texture/hdr_texture_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
texture::{Image, TextureFormatPixelInfo},
};
use bevy_asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext};
use image::ImageDecoder;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use wgpu::{Extent3d, TextureDimension, TextureFormat};
Expand Down Expand Up @@ -47,17 +48,9 @@ impl AssetLoader for HdrTextureLoader {
reader.read_to_end(&mut bytes).await?;
let decoder = image::codecs::hdr::HdrDecoder::new(bytes.as_slice())?;
let info = decoder.metadata();
let rgb_data = decoder.read_image_hdr()?;
let mut rgba_data = Vec::with_capacity(rgb_data.len() * format.pixel_size());

for rgb in rgb_data {
let alpha = 1.0f32;

rgba_data.extend_from_slice(&rgb.0[0].to_ne_bytes());
rgba_data.extend_from_slice(&rgb.0[1].to_ne_bytes());
rgba_data.extend_from_slice(&rgb.0[2].to_ne_bytes());
rgba_data.extend_from_slice(&alpha.to_ne_bytes());
}
let buffer_size = decoder.total_bytes().try_into().unwrap();
let mut rgba_data = Vec::with_capacity(buffer_size);
decoder.read_image(rgba_data.as_mut_slice())?;

Ok(Image::new(
Extent3d {
Expand Down

0 comments on commit 1bca769

Please sign in to comment.