Improve vertex usage
This commit is contained in:
parent
d7a19d3ac1
commit
ef6e259313
10 changed files with 83 additions and 64 deletions
|
@ -598,12 +598,12 @@ impl Button {
|
|||
let top = self.framable.top() as f32;
|
||||
let bottom = self.framable.bottom() as f32;
|
||||
|
||||
frame[0].position = ortho * vec4(left - offset, bottom + offset, 0.0, 1.0);
|
||||
frame[1].position = ortho * vec4(right + offset, bottom + offset, 0.0, 1.0);
|
||||
frame[2].position = ortho * vec4(right + offset, top - offset, 0.0, 1.0);
|
||||
frame[3].position = ortho * vec4(right + offset, top - offset, 0.0, 1.0);
|
||||
frame[4].position = ortho * vec4(left - offset, top - offset, 0.0, 1.0);
|
||||
frame[5].position = ortho * vec4(left - offset, bottom + offset, 0.0, 1.0);
|
||||
frame[0].position = (ortho * vec4(left - offset, bottom + offset, 0.0, 1.0)).xy();
|
||||
frame[1].position = (ortho * vec4(right + offset, bottom + offset, 0.0, 1.0)).xy();
|
||||
frame[2].position = (ortho * vec4(right + offset, top - offset, 0.0, 1.0)).xy();
|
||||
frame[3].position = (ortho * vec4(right + offset, top - offset, 0.0, 1.0)).xy();
|
||||
frame[4].position = (ortho * vec4(left - offset, top - offset, 0.0, 1.0)).xy();
|
||||
frame[5].position = (ortho * vec4(left - offset, bottom + offset, 0.0, 1.0)).xy();
|
||||
|
||||
frame[0].texture_coordinates = vec2(0.0, 1.0);
|
||||
frame[1].texture_coordinates = vec2(1.0, 1.0);
|
||||
|
@ -622,12 +622,12 @@ impl Button {
|
|||
let top = self.framable.top() as f32;
|
||||
let bottom = self.framable.bottom() as f32;
|
||||
|
||||
frame[0].position = ortho * vec4(left - offset, bottom + offset, 0.0, 1.0);
|
||||
frame[1].position = ortho * vec4(right + offset, bottom + offset, 0.0, 1.0);
|
||||
frame[2].position = ortho * vec4(right + offset, top - offset, 0.0, 1.0);
|
||||
frame[3].position = ortho * vec4(right + offset, top - offset, 0.0, 1.0);
|
||||
frame[4].position = ortho * vec4(left - offset, top - offset, 0.0, 1.0);
|
||||
frame[5].position = ortho * vec4(left - offset, bottom + offset, 0.0, 1.0);
|
||||
frame[0].position = (ortho * vec4(left - offset, bottom + offset, 0.0, 1.0)).xy();
|
||||
frame[1].position = (ortho * vec4(right + offset, bottom + offset, 0.0, 1.0)).xy();
|
||||
frame[2].position = (ortho * vec4(right + offset, top - offset, 0.0, 1.0)).xy();
|
||||
frame[3].position = (ortho * vec4(right + offset, top - offset, 0.0, 1.0)).xy();
|
||||
frame[4].position = (ortho * vec4(left - offset, top - offset, 0.0, 1.0)).xy();
|
||||
frame[5].position = (ortho * vec4(left - offset, bottom + offset, 0.0, 1.0)).xy();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use anyhow::Result;
|
|||
use utilities::{impl_reprc, prelude::*};
|
||||
use vulkan_rs::prelude::*;
|
||||
|
||||
use cgmath::{vec4, Vector4};
|
||||
use cgmath::vec4;
|
||||
|
||||
use std::sync::atomic::{AtomicI32, Ordering::SeqCst};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
@ -177,12 +177,12 @@ impl Colorable {
|
|||
let top = y_start + height * *self.top_factor.read().unwrap();
|
||||
let bottom = y_start + height * *self.bottom_factor.read().unwrap();
|
||||
|
||||
frame[0].position = self.framable.ortho() * vec4(left, bottom, 0.0, 1.0);
|
||||
frame[1].position = self.framable.ortho() * vec4(right, bottom, 0.0, 1.0);
|
||||
frame[2].position = self.framable.ortho() * vec4(right, top, 0.0, 1.0);
|
||||
frame[3].position = self.framable.ortho() * vec4(right, top, 0.0, 1.0);
|
||||
frame[4].position = self.framable.ortho() * vec4(left, top, 0.0, 1.0);
|
||||
frame[5].position = self.framable.ortho() * vec4(left, bottom, 0.0, 1.0);
|
||||
frame[0].position = (self.framable.ortho() * vec4(left, bottom, 0.0, 1.0)).xy();
|
||||
frame[1].position = (self.framable.ortho() * vec4(right, bottom, 0.0, 1.0)).xy();
|
||||
frame[2].position = (self.framable.ortho() * vec4(right, top, 0.0, 1.0)).xy();
|
||||
frame[3].position = (self.framable.ortho() * vec4(right, top, 0.0, 1.0)).xy();
|
||||
frame[4].position = (self.framable.ortho() * vec4(left, top, 0.0, 1.0)).xy();
|
||||
frame[5].position = (self.framable.ortho() * vec4(left, bottom, 0.0, 1.0)).xy();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -192,7 +192,10 @@ impl_reprc!(
|
|||
#[derive(Debug)]
|
||||
pub struct ColorableVertex {
|
||||
#[assume_reprc]
|
||||
position: Vector4<f32>,
|
||||
pub position: cgmath::Vector2<f32>,
|
||||
|
||||
#[assume_reprc]
|
||||
filler: [f32; 2],
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -200,7 +203,7 @@ impl VertexInputDescription for ColorableVertex {
|
|||
fn bindings() -> Vec<VkVertexInputBindingDescription> {
|
||||
vec![VkVertexInputBindingDescription {
|
||||
binding: 0,
|
||||
stride: std::mem::size_of::<Vector4<f32>>() as u32,
|
||||
stride: std::mem::size_of::<Self>() as u32,
|
||||
inputRate: VK_VERTEX_INPUT_RATE_VERTEX,
|
||||
}]
|
||||
}
|
||||
|
@ -209,7 +212,7 @@ impl VertexInputDescription for ColorableVertex {
|
|||
vec![VkVertexInputAttributeDescription {
|
||||
location: 0,
|
||||
binding: 0,
|
||||
format: VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||
format: VK_FORMAT_R32G32_SFLOAT,
|
||||
offset: 0,
|
||||
}]
|
||||
}
|
||||
|
|
|
@ -286,12 +286,12 @@ impl Displayable {
|
|||
let top = y_start + height * *self.top_factor.read().unwrap();
|
||||
let bottom = y_start + height * *self.bottom_factor.read().unwrap();
|
||||
|
||||
frame[0].position = self.framable.ortho() * vec4(left, bottom, 0.0, 1.0);
|
||||
frame[1].position = self.framable.ortho() * vec4(right, bottom, 0.0, 1.0);
|
||||
frame[2].position = self.framable.ortho() * vec4(right, top, 0.0, 1.0);
|
||||
frame[3].position = self.framable.ortho() * vec4(right, top, 0.0, 1.0);
|
||||
frame[4].position = self.framable.ortho() * vec4(left, top, 0.0, 1.0);
|
||||
frame[5].position = self.framable.ortho() * vec4(left, bottom, 0.0, 1.0);
|
||||
frame[0].position = (self.framable.ortho() * vec4(left, bottom, 0.0, 1.0)).xy();
|
||||
frame[1].position = (self.framable.ortho() * vec4(right, bottom, 0.0, 1.0)).xy();
|
||||
frame[2].position = (self.framable.ortho() * vec4(right, top, 0.0, 1.0)).xy();
|
||||
frame[3].position = (self.framable.ortho() * vec4(right, top, 0.0, 1.0)).xy();
|
||||
frame[4].position = (self.framable.ortho() * vec4(left, top, 0.0, 1.0)).xy();
|
||||
frame[5].position = (self.framable.ortho() * vec4(left, bottom, 0.0, 1.0)).xy();
|
||||
|
||||
frame[0].texture_coordinates = vec2(
|
||||
*self.left_uv_factor.read().unwrap(),
|
||||
|
|
|
@ -248,12 +248,12 @@ impl Iconizable {
|
|||
let abs_top = top + margin as f32;
|
||||
let abs_bottom = bottom - margin as f32;
|
||||
|
||||
frame[0].position = ortho * cgmath::Vector4::new(abs_left, abs_bottom, 0.0, 1.0);
|
||||
frame[1].position = ortho * cgmath::Vector4::new(abs_right, abs_bottom, 0.0, 1.0);
|
||||
frame[2].position = ortho * cgmath::Vector4::new(abs_right, abs_top, 0.0, 1.0);
|
||||
frame[3].position = ortho * cgmath::Vector4::new(abs_right, abs_top, 0.0, 1.0);
|
||||
frame[4].position = ortho * cgmath::Vector4::new(abs_left, abs_top, 0.0, 1.0);
|
||||
frame[5].position = ortho * cgmath::Vector4::new(abs_left, abs_bottom, 0.0, 1.0);
|
||||
frame[0].position = (ortho * cgmath::Vector4::new(abs_left, abs_bottom, 0.0, 1.0)).xy();
|
||||
frame[1].position = (ortho * cgmath::Vector4::new(abs_right, abs_bottom, 0.0, 1.0)).xy();
|
||||
frame[2].position = (ortho * cgmath::Vector4::new(abs_right, abs_top, 0.0, 1.0)).xy();
|
||||
frame[3].position = (ortho * cgmath::Vector4::new(abs_right, abs_top, 0.0, 1.0)).xy();
|
||||
frame[4].position = (ortho * cgmath::Vector4::new(abs_left, abs_top, 0.0, 1.0)).xy();
|
||||
frame[5].position = (ortho * cgmath::Vector4::new(abs_left, abs_bottom, 0.0, 1.0)).xy();
|
||||
|
||||
frame[0].texture_coordinates = cgmath::Vector2::new(0.0, 1.0);
|
||||
frame[1].texture_coordinates = cgmath::Vector2::new(1.0, 1.0);
|
||||
|
|
|
@ -380,13 +380,14 @@ impl Textable {
|
|||
let x = (mod_number - (y as u32 * letters_in_row)) as f32;
|
||||
|
||||
buffer_mapping[i] = TexturedVertex {
|
||||
position: ortho
|
||||
position: (ortho
|
||||
* cgmath::Vector4::new(
|
||||
win_x + offset,
|
||||
win_y + letter_height,
|
||||
priority,
|
||||
1.0,
|
||||
),
|
||||
))
|
||||
.xy(),
|
||||
texture_coordinates: cgmath::Vector2::new(
|
||||
inverse_row * x,
|
||||
inverse_col + inverse_col * y,
|
||||
|
@ -396,13 +397,14 @@ impl Textable {
|
|||
i += 1;
|
||||
|
||||
buffer_mapping[i] = TexturedVertex {
|
||||
position: ortho
|
||||
position: (ortho
|
||||
* cgmath::Vector4::new(
|
||||
win_x + offset + letter_width,
|
||||
win_y + letter_height,
|
||||
priority,
|
||||
1.0,
|
||||
),
|
||||
))
|
||||
.xy(),
|
||||
texture_coordinates: cgmath::Vector2::new(
|
||||
inverse_row + inverse_row * x,
|
||||
inverse_col + inverse_col * y,
|
||||
|
@ -412,13 +414,14 @@ impl Textable {
|
|||
i += 1;
|
||||
|
||||
buffer_mapping[i] = TexturedVertex {
|
||||
position: ortho
|
||||
position: (ortho
|
||||
* cgmath::Vector4::new(
|
||||
win_x + offset + letter_width,
|
||||
win_y,
|
||||
priority,
|
||||
1.0,
|
||||
),
|
||||
))
|
||||
.xy(),
|
||||
texture_coordinates: cgmath::Vector2::new(
|
||||
inverse_row + inverse_row * x,
|
||||
inverse_col * y,
|
||||
|
@ -428,13 +431,14 @@ impl Textable {
|
|||
i += 1;
|
||||
|
||||
buffer_mapping[i] = TexturedVertex {
|
||||
position: ortho
|
||||
position: (ortho
|
||||
* cgmath::Vector4::new(
|
||||
win_x + offset + letter_width,
|
||||
win_y,
|
||||
priority,
|
||||
1.0,
|
||||
),
|
||||
))
|
||||
.xy(),
|
||||
texture_coordinates: cgmath::Vector2::new(
|
||||
inverse_row + inverse_row * x,
|
||||
inverse_col * y,
|
||||
|
@ -444,8 +448,9 @@ impl Textable {
|
|||
i += 1;
|
||||
|
||||
buffer_mapping[i] = TexturedVertex {
|
||||
position: ortho
|
||||
* cgmath::Vector4::new(win_x + offset, win_y, priority, 1.0),
|
||||
position: (ortho
|
||||
* cgmath::Vector4::new(win_x + offset, win_y, priority, 1.0))
|
||||
.xy(),
|
||||
texture_coordinates: cgmath::Vector2::new(
|
||||
inverse_row * x,
|
||||
inverse_col * y,
|
||||
|
@ -455,13 +460,14 @@ impl Textable {
|
|||
i += 1;
|
||||
|
||||
buffer_mapping[i] = TexturedVertex {
|
||||
position: ortho
|
||||
position: (ortho
|
||||
* cgmath::Vector4::new(
|
||||
win_x + offset,
|
||||
win_y + letter_height,
|
||||
priority,
|
||||
1.0,
|
||||
),
|
||||
))
|
||||
.xy(),
|
||||
texture_coordinates: cgmath::Vector2::new(
|
||||
inverse_row * x,
|
||||
inverse_col + inverse_col * y,
|
||||
|
|
|
@ -6,12 +6,22 @@ use std::mem;
|
|||
impl_reprc!(
|
||||
pub struct TexturedVertex {
|
||||
#[assume_reprc]
|
||||
position: cgmath::Vector4<f32>,
|
||||
pub position: cgmath::Vector2<f32>,
|
||||
|
||||
#[assume_reprc]
|
||||
texture_coordinates: cgmath::Vector2<f32>,
|
||||
pub texture_coordinates: cgmath::Vector2<f32>,
|
||||
}
|
||||
);
|
||||
|
||||
impl TexturedVertex {
|
||||
pub fn new(position: cgmath::Vector2<f32>, texture_coordinates: cgmath::Vector2<f32>) -> Self {
|
||||
Self {
|
||||
position,
|
||||
texture_coordinates,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VertexInputDescription for TexturedVertex {
|
||||
fn bindings() -> Vec<VkVertexInputBindingDescription> {
|
||||
vec![VkVertexInputBindingDescription {
|
||||
|
@ -26,14 +36,14 @@ impl VertexInputDescription for TexturedVertex {
|
|||
VkVertexInputAttributeDescription {
|
||||
location: 0,
|
||||
binding: 0,
|
||||
format: VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||
format: VK_FORMAT_R32G32_SFLOAT,
|
||||
offset: 0,
|
||||
},
|
||||
VkVertexInputAttributeDescription {
|
||||
location: 1,
|
||||
binding: 0,
|
||||
format: VK_FORMAT_R32G32_SFLOAT,
|
||||
offset: 16, // mem::size_of::<cgmath::Vector4<f32>>() as u32
|
||||
offset: 8, // mem::size_of::<cgmath::Vector2<f32>>() as u32
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -42,7 +52,7 @@ impl VertexInputDescription for TexturedVertex {
|
|||
impl Default for TexturedVertex {
|
||||
fn default() -> TexturedVertex {
|
||||
TexturedVertex {
|
||||
position: cgmath::Vector4::zero(),
|
||||
position: cgmath::Vector2::zero(),
|
||||
texture_coordinates: cgmath::Vector2::zero(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use super::{
|
|||
},
|
||||
};
|
||||
|
||||
use cgmath::{ortho, vec2, vec4};
|
||||
use cgmath::{ortho, vec2};
|
||||
|
||||
use std::sync::Weak;
|
||||
use std::sync::{
|
||||
|
@ -129,27 +129,27 @@ impl TextToScreen {
|
|||
|
||||
let edges = [
|
||||
TexturedVertex {
|
||||
position: vec4(-1.0, -1.0, 0.0, 1.0),
|
||||
position: vec2(-1.0, -1.0),
|
||||
texture_coordinates: vec2(0.0, 0.0),
|
||||
},
|
||||
TexturedVertex {
|
||||
position: vec4(-1.0, 1.0, 0.0, 1.0),
|
||||
position: vec2(-1.0, 1.0),
|
||||
texture_coordinates: vec2(0.0, 1.0),
|
||||
},
|
||||
TexturedVertex {
|
||||
position: vec4(1.0, 1.0, 0.0, 1.0),
|
||||
position: vec2(1.0, 1.0),
|
||||
texture_coordinates: vec2(1.0, 1.0),
|
||||
},
|
||||
TexturedVertex {
|
||||
position: vec4(1.0, 1.0, 0.0, 1.0),
|
||||
position: vec2(1.0, 1.0),
|
||||
texture_coordinates: vec2(1.0, 1.0),
|
||||
},
|
||||
TexturedVertex {
|
||||
position: vec4(1.0, -1.0, 0.0, 1.0),
|
||||
position: vec2(1.0, -1.0),
|
||||
texture_coordinates: vec2(1.0, 0.0),
|
||||
},
|
||||
TexturedVertex {
|
||||
position: vec4(-1.0, -1.0, 0.0, 1.0),
|
||||
position: vec2(-1.0, -1.0),
|
||||
texture_coordinates: vec2(0.0, 0.0),
|
||||
},
|
||||
];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 position;
|
||||
layout (location = 0) in vec2 position;
|
||||
layout (location = 1) in vec2 texcoord;
|
||||
|
||||
layout (location = 0) out vec2 uv;
|
||||
|
@ -8,5 +8,5 @@ layout (location = 0) out vec2 uv;
|
|||
void main()
|
||||
{
|
||||
uv = texcoord;
|
||||
gl_Position = position;
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 position;
|
||||
layout (location = 0) in vec2 position;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = position;
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 position;
|
||||
layout (location = 0) in vec2 position;
|
||||
layout (location = 1) in vec2 texcoord;
|
||||
|
||||
layout (location = 0) out vec2 uv;
|
||||
|
@ -8,5 +8,5 @@ layout (location = 0) out vec2 uv;
|
|||
void main()
|
||||
{
|
||||
uv = texcoord;
|
||||
gl_Position = position;
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
}
|
Loading…
Reference in a new issue