diff options
Diffstat (limited to 'engine/src/rendering/backend/opengl.rs')
| -rw-r--r-- | engine/src/rendering/backend/opengl.rs | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/engine/src/rendering/backend/opengl.rs b/engine/src/rendering/backend/opengl.rs index b5ebd81..0323f29 100644 --- a/engine/src/rendering/backend/opengl.rs +++ b/engine/src/rendering/backend/opengl.rs @@ -67,7 +67,7 @@ use raw_window_handle::WindowHandle; use safer_ffi::layout::ReprC; use zerocopy::{Immutable, IntoBytes}; -use crate::asset::{Assets, Handle as AssetHandle}; +use crate::asset::Assets; use crate::data_types::dimens::Dimens; use crate::ecs::actions::Actions; use crate::ecs::query::term::Without; @@ -697,12 +697,13 @@ fn handle_commands( ) .unwrap(); } - Command::CreateTexture(texture_asset) => { + Command::CreateTexture(texture_object_id, texture) => { if let Err(err) = create_texture_object( gl_context, object_store, assets, - &texture_asset, + texture_object_id, + texture, ) { tracing::error!("Failed to create texture object: {err}"); } @@ -1066,23 +1067,31 @@ fn create_texture_object( curr_gl_ctx: &MaybeCurrentContextWithFns, object_store: &mut ObjectStore, assets: &Assets, - texture_asset: &AssetHandle<Texture>, + texture_object_id: ObjectId, + texture: AssetOrValue<Texture>, ) -> Result<(), GlTextureGenerateError> { - let object_id = ObjectId::Asset(texture_asset.id()); - - if object_store.contains_non_pending_with_id(&object_id) { + if object_store.contains_non_pending_with_id(&texture_object_id) { tracing::error!( - texture_object_id=?object_id, - texture_asset_label=?assets.get_label(texture_asset), - " object store already contains object with this ID" + texture_object_id=?texture_object_id, + "Object store already contains object with this ID" ); return Ok(()); } - let Some(texture) = assets.get(&texture_asset) else { - tracing::error!("Texture asset is not loaded",); - return Ok(()); + let texture = match &texture { + AssetOrValue::Asset(texture_asset) => { + let Some(texture) = assets.get(&texture_asset) else { + tracing::error!( + texture_asset_id=?texture_asset.id(), + "Texture asset does not exist" + ); + return Ok(()); + }; + + texture + } + AssetOrValue::Value(texture) => texture, }; let texture_image = match texture.image.color_type() { @@ -1096,16 +1105,12 @@ fn create_texture_object( // To prevent this, the image is converted to RGBA8. RGBA8 images have a pixel // size of 4 bytes so they cannot have any alignment problems - tracing::warn!( - texture_asset = %assets - .get_label(&texture_asset) - .expect("Not possible"), - concat!( - "Converting texture image from RGB8 to RGBA8 to prevent alignment ", - "problems. This conversion may be slow. Consider changing the ", - "texture image's pixel format to RGBA8" - ) - ); + // TODO: Make it clearer in warning log which texture is being talked about + tracing::warn!(concat!( + "Converting texture image from RGB8 to RGBA8 to prevent alignment ", + "problems. This conversion may be slow. Consider changing the ", + "texture image's pixel format to RGBA8" + )); &texture.image.to_rgba8() } @@ -1113,7 +1118,7 @@ fn create_texture_object( }; object_store.insert( - object_id, + texture_object_id, Object::from_raw( create_gl_texture(curr_gl_ctx, texture_image, &texture.properties)? .into_raw(), |
