Implement generator test
This commit is contained in:
parent
14236e1cd8
commit
e777af9758
3 changed files with 46 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ Cargo.lock
|
||||||
target/
|
target/
|
||||||
|
|
||||||
*.spv
|
*.spv
|
||||||
|
example.png
|
|
@ -13,5 +13,19 @@ layout (location = 0) out vec4 out_color;
|
||||||
|
|
||||||
void main()
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl ElementDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_reprc!(
|
impl_reprc!(
|
||||||
pub struct FragmentShaderInfo {
|
pub(crate) struct FragmentShaderInfo {
|
||||||
#[assume_reprc]
|
#[assume_reprc]
|
||||||
background_color: [f32; 4],
|
background_color: [f32; 4],
|
||||||
#[assume_reprc]
|
#[assume_reprc]
|
||||||
|
@ -229,7 +229,7 @@ impl Generator {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.wait_for_timeout(Duration::from_secs(5))
|
// .wait_for_timeout(Duration::from_secs(5))
|
||||||
.submit()?;
|
.submit()?;
|
||||||
|
|
||||||
Ok(image)
|
Ok(image)
|
||||||
|
@ -274,7 +274,6 @@ impl Generator {
|
||||||
|
|
||||||
fn pipeline(
|
fn pipeline(
|
||||||
&self,
|
&self,
|
||||||
|
|
||||||
descriptor_layout: &Arc<DescriptorSetLayout>,
|
descriptor_layout: &Arc<DescriptorSetLayout>,
|
||||||
render_target: &RenderTarget,
|
render_target: &RenderTarget,
|
||||||
width: u32,
|
width: u32,
|
||||||
|
@ -315,7 +314,7 @@ impl Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vertex_buffer(&self, width: u32, height: u32) -> Result<Arc<Buffer<PositionOnlyVertex>>> {
|
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(
|
let vertices = PositionOnlyVertex::from_2d_corners(
|
||||||
ortho,
|
ortho,
|
||||||
|
@ -334,3 +333,29 @@ impl Generator {
|
||||||
.build(self.device.clone())
|
.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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue