summaryrefslogtreecommitdiff
path: root/engine/src/renderer.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-03-25 20:09:13 +0100
committerHampusM <hampus@hampusmat.com>2026-03-25 20:09:13 +0100
commitde74c71eb6d6a67e8c7ac006a1e906175ca32a72 (patch)
tree72671f280ff791312679963779d1d6b7cbc4145b /engine/src/renderer.rs
parentcee8b3a19833e1143d0551e8031aa812f7c5a92b (diff)
refactor(engine): store textures as assets instead of images
Diffstat (limited to 'engine/src/renderer.rs')
-rw-r--r--engine/src/renderer.rs38
1 files changed, 8 insertions, 30 deletions
diff --git a/engine/src/renderer.rs b/engine/src/renderer.rs
index 8b37989..7865ac4 100644
--- a/engine/src/renderer.rs
+++ b/engine/src/renderer.rs
@@ -1,7 +1,5 @@
use std::any::type_name;
use std::collections::VecDeque;
-use std::path::Path;
-use std::sync::LazyLock;
use std::sync::atomic::{AtomicU64, Ordering};
use bitflags::bitflags;
@@ -12,12 +10,9 @@ use ecs::query::term::Without;
use ecs::sole::Single;
use ecs::{Component, Query, declare_entity};
-use crate::asset::{Assets, Label as AssetLabel};
+use crate::asset::{Assets, Handle as AssetHandle};
use crate::builder;
-use crate::color::Color;
-use crate::data_types::dimens::Dimens;
use crate::draw_flags::{DrawFlags, NoDraw, PolygonModeConfig};
-use crate::image::Image;
use crate::mesh::Mesh;
use crate::model::{MaterialSearchResult, Model};
use crate::renderer::object::{Id as ObjectId, Store as ObjectStore};
@@ -33,7 +28,7 @@ use crate::shader::{
Program as ShaderProgram,
Shader,
};
-use crate::texture::{Properties as TextureProperties, Texture};
+use crate::texture::{Texture, WHITE_1X1_ASSET_LABEL as TEXTURE_WHITE_1X1_ASSET_LABEL};
use crate::windowing::window::Window;
pub mod object;
@@ -41,12 +36,6 @@ pub mod opengl;
static NEXT_SURFACE_ID: AtomicU64 = AtomicU64::new(0);
-pub static DEFAULT_TEXTURE_ASSET_LABEL: LazyLock<AssetLabel> =
- LazyLock::new(|| AssetLabel {
- path: Path::new("").into(),
- name: Some("default_texture".into()),
- });
-
declare_entity!(
pub PRE_RENDER_PHASE,
(
@@ -163,7 +152,7 @@ pub enum Command
CreateShaderProgram(ObjectId, ShaderProgram),
ActivateShader(ObjectId),
SetShaderBinding(ShaderBindingLocation, ShaderBindingValue),
- CreateTexture(Texture),
+ CreateTexture(AssetHandle<Texture>),
CreateMesh(ObjectId, Mesh),
DrawMesh(ObjectId),
SetPolygonModeConfig(PolygonModeConfig),
@@ -221,14 +210,6 @@ type RenderableEntity<'a> = (
Option<&'a mut PendingShaderBindings>,
);
-pub fn init(mut assets: Single<Assets>)
-{
- assets.store_with_label(
- DEFAULT_TEXTURE_ASSET_LABEL.clone(),
- Image::from_color(Dimens { width: 1, height: 1 }, Color::WHITE_U8),
- );
-}
-
#[tracing::instrument(skip_all)]
pub fn enqueue_commands(
renderer_ctx_query: Query<(
@@ -291,16 +272,13 @@ pub fn enqueue_commands(
command_queue.push(Command::MakeCurrent(surface_spec.id));
let default_texture_asset = assets
- .get_handle_to_loaded::<Image>(DEFAULT_TEXTURE_ASSET_LABEL.clone())
+ .get_handle_to_loaded::<Texture>(TEXTURE_WHITE_1X1_ASSET_LABEL.clone())
.expect("Not possible");
if !object_store
.contains_with_id(&ObjectId::Asset(default_texture_asset.id()))
{
- command_queue.push(Command::CreateTexture(Texture {
- asset_handle: default_texture_asset,
- properties: TextureProperties::default(),
- }));
+ command_queue.push(Command::CreateTexture(default_texture_asset));
}
command_queue.push(Command::ClearBuffers(
@@ -373,7 +351,7 @@ pub fn enqueue_commands(
unreachable!();
};
- for texture in [
+ for texture_asset in [
&model_material.ambient_map,
&model_material.diffuse_map,
&model_material.specular_map,
@@ -382,9 +360,9 @@ pub fn enqueue_commands(
.flatten()
{
if !object_store
- .contains_with_id(&ObjectId::Asset(texture.asset_handle.id()))
+ .contains_with_id(&ObjectId::Asset(texture_asset.id()))
{
- command_queue.push(Command::CreateTexture(texture.clone()));
+ command_queue.push(Command::CreateTexture(texture_asset.clone()));
}
}