Skip to content

Commit

Permalink
Added push constants to shader generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundo-villa committed Aug 6, 2023
1 parent 03890e5 commit 9e89196
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Application for GraphicsApplication {
let visibility_render_domain_handle = orchestrator.spawn_entity(render_domain::VisibilityWorldRenderDomain::new);

orchestrator.spawn_entity(rendering::render_orchestrator::RenderOrchestrator::new);
orchestrator.spawn_system(resource_manager::ResourceManager::new_as_system);
orchestrator.spawn_entity(resource_manager::ResourceManager::new_as_system);

GraphicsApplication { application, file_tracker_handle: file_tracker_handle, window_system_handle, input_system_handle, mouse_device_handle, visibility_render_domain_handle, tick_count: 0, render_system_handle }
}
Expand Down
90 changes: 44 additions & 46 deletions src/rendering/visibility_shader_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,71 @@ impl VisibilityShaderGenerator {

impl ShaderGenerator for VisibilityShaderGenerator {
fn process(&self) -> (&'static str, json::JsonValue) {
let mut value = json::JsonValue::new_object();

let mut vertex_input = json::object! {
let value = json::object! {
"in_position": {
type: "in",
location: 0,
type_name: "vec3f",
interpolation: "smooth"
in_position: {
type: "member",
data_type: "vec3f",
}
},
"in_normal": {
type: "in",
location: 1,
type_name: "vec3f",
interpolation: "smooth"
in_normal: {
type: "member",
data_type: "vec3f",
}
},
};

let push_constant = json::object! {
"camera": {
type_name: "Camera*"
"pc": {
type: "push_constant",
"camera": {
type: "member",
data_type: "Camera*"
},
"model": {
type: "member",
data_type: "Model*"
},
},
"model": {
type_name: "Model*"
}
};

let mut items = json::object! {
"Camera": {
type: "struct",
members: {
"view": {
type: "mat4f",
},
"projection": {
type: "mat4f",
},
"view_projection": {
type: "vec3f",
}
"view": {
type: "member",
data_type: "mat4f",
},
"projection": {
type: "member",
data_type: "mat4f",
},
"view_projection": {
type: "member",
data_type: "mat4f",
}
},
"Model": {
type: "struct",
members: {
"model": {
type: "mat4f",
},
}
"model": {
type: "member",
data_type: "mat4f",
},
},
};

let mut interface = json::object! {
"in_instance_index": {
type: "in",
location: 0,
type_name: "i32",
in_instance_index: {
type: "memeber",
data_type: "u32",
},
interpolation: "flat"
},
"out_color": {
type: "in",
location: 0,
type_name: "vec4",
way: "out",
interpolation: "smooth"
type: "out",
out_Color: {
type: "member",
data_type: "vec4f",
}
}
};

("visibility", value)
("Visibility", value)
}
}
2 changes: 1 addition & 1 deletion src/resource_manager/image_resource_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl ResourceHandler for ImageResourceHandler {
fn can_handle_type(&self, resource_type: &str) -> bool {
match resource_type {
"image/png" => true,
".png" => true,
"png" => true,
_ => false
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/resource_manager/material_resource_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ impl MaterialResourcerHandler {
impl ResourceHandler for MaterialResourcerHandler {
fn can_handle_type(&self, resource_type: &str) -> bool {
match resource_type {
"image/png" => true,
".png" => true,
"json" => true,
_ => false
}
}
Expand All @@ -34,8 +33,11 @@ impl ResourceHandler for MaterialResourcerHandler {
let vertex = material_json["vertex"].as_str().unwrap();
let fragment = material_json["fragment"].as_str().unwrap();

let vertex_shader_code = std::fs::read_to_string(vertex).unwrap();
let fragment_shader_code = std::fs::read_to_string(fragment).unwrap();
let vertex_path = "resources/".to_string() + vertex;
let fragment_path = "resources/".to_string() + fragment;

let vertex_shader_code = std::fs::read_to_string(vertex_path).unwrap();
let fragment_shader_code = std::fs::read_to_string(fragment_path).unwrap();

let vertex_shader = beshader_compiler::parse(beshader_compiler::tokenize(&vertex_shader_code));
let fragment_shader = beshader_compiler::parse(beshader_compiler::tokenize(&fragment_shader_code));
Expand All @@ -46,7 +48,6 @@ impl ResourceHandler for MaterialResourcerHandler {

let c = common.process();

shader_spec["root"] = json::JsonValue::new_object();
shader_spec["root"][c.0] = c.1;

let visibility = crate::rendering::visibility_shader_generator::VisibilityShaderGenerator::new();
Expand Down
18 changes: 11 additions & 7 deletions src/resource_manager/mesh_resource_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use polodb_core::bson::Document;
use serde::Serialize;

use super::ResourceHandler;

Expand All @@ -16,6 +17,7 @@ impl ResourceHandler for MeshResourceHandler {
fn can_handle_type(&self, resource_type: &str) -> bool {
match resource_type {
"mesh" => true,
"gltf" => true,
_ => false
}
}
Expand Down Expand Up @@ -89,15 +91,17 @@ impl ResourceHandler for MeshResourceHandler {
return Err("Mesh does not have indices".to_string());
}

let resource = polodb_core::bson::doc!{
"bouding_box": [[]],
"vertex_components": [],
"index_type": "U16",
"vertex_count": 0,
"index_count": 0
let mesh = Mesh {
bounding_box,
vertex_components,
index_count,
vertex_count,
index_type
};

Ok((resource, buf))
let serialized_mesh = mesh.serialize(polodb_core::bson::Serializer::new()).unwrap();

Ok((serialized_mesh.as_document().unwrap().clone(), buf))
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/resource_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl ResourceManager {
},
"local" => {
let files = if let Ok(r) = std::fs::read_dir("resources") { r } else { return None; };
let files = files.filter(|f| if let Ok(f) = f { f.path().to_str().unwrap().starts_with(path) } else { false });
let files = files.filter(|f| if let Ok(f) = f { f.path().to_str().unwrap().contains(path) } else { false });
let p = files.last().unwrap().unwrap().path();

let mut file = std::fs::File::open(&p).unwrap();
Expand Down Expand Up @@ -233,6 +233,8 @@ impl ResourceManager {

file.write_all(bytes.as_slice()).unwrap();

let document = self.db.collection::<Document>("resources").find_one(doc!{ "_id": resource_id }).unwrap().unwrap();

return Some(document);
}

Expand Down Expand Up @@ -305,7 +307,9 @@ impl ResourceManager {
}
};

let resource: T = T::deserialize(polodb_core::bson::Deserializer::new(document.clone().into())).unwrap();
dbg!(&document);

let resource: T = T::deserialize(polodb_core::bson::Deserializer::new(document.get("resource").unwrap().into())).unwrap();

return Some(Request { document, resource, id: path.to_string() });
}
Expand Down
Loading

0 comments on commit 9e89196

Please sign in to comment.