Implement generator test

This commit is contained in:
hodasemi 2024-03-25 10:12:52 +01:00
parent 14236e1cd8
commit e777af9758
3 changed files with 46 additions and 6 deletions

3
.gitignore vendored
View file

@ -1,4 +1,5 @@
Cargo.lock
target/
*.spv
*.spv
example.png

View file

@ -13,5 +13,19 @@ layout (location = 0) out vec4 out_color;
void main()
{
out_color = vec4(descriptor.color, 1.0);
vec2 st = gl_FragCoord.xy/vec2((float)descriptor.width, (float)descriptor.height);
if ((uint)st.x <= descriptor.border_thickness ||
(uint)st.x >= (descriptor.width - descriptor.border_thickness))
{
out_color = descriptor.border_color;
}
else if (
(uint)st.y <= descriptor.border_thickness ||
(uint)st.y >= (descriptor.height - descriptor.border_thickness)
) {
out_color = descriptor.border_color;
} else {
out_color = descriptor.background_color;
}
}

View file

@ -53,7 +53,7 @@ impl ElementDescriptor {
}
impl_reprc!(
pub struct FragmentShaderInfo {
pub(crate) struct FragmentShaderInfo {
#[assume_reprc]
background_color: [f32; 4],
#[assume_reprc]
@ -229,7 +229,7 @@ impl Generator {
Ok(())
})
.wait_for_timeout(Duration::from_secs(5))
// .wait_for_timeout(Duration::from_secs(5))
.submit()?;
Ok(image)
@ -274,7 +274,6 @@ impl Generator {
fn pipeline(
&self,
descriptor_layout: &Arc<DescriptorSetLayout>,
render_target: &RenderTarget,
width: u32,
@ -315,7 +314,7 @@ impl Generator {
}
fn vertex_buffer(&self, width: u32, height: u32) -> Result<Arc<Buffer<PositionOnlyVertex>>> {
let ortho = ortho(0.0, width as f32, 0.00, height as f32, -1.0, 1.0);
let ortho = cgmath::ortho(0.0, width as f32, 0.0, height as f32, -1.0, 1.0);
let vertices = PositionOnlyVertex::from_2d_corners(
ortho,
@ -334,3 +333,29 @@ impl Generator {
.build(self.device.clone())
}
}
#[cfg(test)]
mod test {
use utilities::color::Color;
use vulkan_rs::create_vk_handles;
use super::{ElementDefinition, Generator};
#[test]
fn generate_example() -> anyhow::Result<()> {
let (device, queue) = create_vk_handles()?;
let generator = Generator::new(device, queue)?;
let image = generator.generate(ElementDefinition {
width: 120,
height: 40,
background_color: Color::try_from("#935615")?,
border_color: Color::try_from("#61401c")?,
border_thickness: 5,
})?;
image.to_file("example.png")?;
Ok(())
}
}