Added dynamic size for max particles in particle systems, added fallback texture

This commit is contained in:
2025-06-15 15:07:16 +02:00
parent 69bafff6e9
commit 0692e0c8b7
2 changed files with 18 additions and 6 deletions

View File

@@ -37,11 +37,11 @@ Particle_System :: struct {
scene: *Scene;
}
create_particle_system :: (pipeline: Pipeline_State_Handle, update_func: (*Particle_System, float), owning_entity: *Entity = null, scene: *Scene = null) -> *Particle_System {
create_particle_system :: (pipeline: Pipeline_State_Handle, update_func: (*Particle_System, float), owning_entity: *Entity = null, scene: *Scene = null, max_particles := MAX_PARTICLES) -> *Particle_System {
lvl := ifx scene == null then engine.current_scene else scene;
particle_system, locator := find_and_occupy_empty_slot(*scene.particle_systems);
particle_system._locator = locator;
particle_system.vertex_buffer = create_vertex_buffer(engine.renderer, null, size_of(Particle_Vertex) * MAX_PARTICLES, stride=size_of(Particle_Vertex), mappable=true);
particle_system.vertex_buffer = create_vertex_buffer(engine.renderer, null, xx (size_of(Particle_Vertex) * max_particles), stride=size_of(Particle_Vertex), mappable=true);
particle_system.pipeline = pipeline;
particle_system.on_particle_update = update_func;
particle_system.owning_entity = owning_entity;

View File

@@ -630,6 +630,10 @@ Renderer :: struct {
clamp : Sampler_Handle;
}
default_textures : struct {
fallback : Texture_Handle;
}
watcher: File_Watcher(string);
vsync: bool = true;
@@ -684,6 +688,11 @@ create_renderer :: (window: *Window) -> *Renderer {
engine.renderer.render_graph = new_render_graph();
data := u8.[255];
engine.renderer.default_textures.fallback = create_texture(engine.renderer, data.data, 1, 1, 1, "engine/fallback", generate_mips=false, .R8_UNORM);
return engine.renderer;
}
@@ -972,11 +981,14 @@ create_texture :: (using renderer: *Renderer, path: string, generate_mips: bool
data : [32] u8;
stbi_load_from_memory(data.data, 32, *image_width, *image_height, *image_channels, image_desired_channels);
assert(image_data != null);
if image_data {
defer stbi_image_free(image_data);
defer stbi_image_free(image_data);
return create_texture(renderer, image_data, xx image_width, xx image_height, xx image_desired_channels, path, generate_mips=generate_mips, format);
return create_texture(renderer, image_data, xx image_width, xx image_height, xx image_desired_channels, path, generate_mips=generate_mips, format);
} else {
log_error("Unable to load texture '%'\n", path);
return renderer.default_textures.fallback;
}
}
create_texture :: (using renderer: *Renderer, data: *void, width: u32, height: u32, channels: u32, path: string = "", generate_mips: bool = true, format: Format = .R8G8B8A8_UNORM_SRGB) -> Texture_Handle {