removed the colored vertex and combined into one. Half fixed texturing. Fully fixed images and compute swapping
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
#version 450
|
||||
|
||||
// These come in from the vertex definition
|
||||
layout(location = 0) in vec2 position;
|
||||
layout(location = 0) in vec2 v_position;
|
||||
layout(location = 1) in vec4 color;
|
||||
layout(location = 2) in vec2 ti_position;
|
||||
|
||||
// These are made up in the shader themselves
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
void main() {
|
||||
out_color = color;
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
gl_Position = vec4(v_position, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,35 +36,35 @@ void main() {
|
||||
uint idx = get_idx(0,0);
|
||||
|
||||
ivec4 p = separate(read_buffer.buf[get_idx(0 , 0)]);
|
||||
ivec4 p0 = separate(read_buffer.buf[get_idx(0 , 1)]);
|
||||
ivec4 p1 = separate(read_buffer.buf[get_idx(0 ,-1)]);
|
||||
ivec4 p2 = separate(read_buffer.buf[get_idx(1 , 1)]);
|
||||
ivec4 p3 = separate(read_buffer.buf[get_idx(-1,-1)]);
|
||||
ivec4 p4 = separate(read_buffer.buf[get_idx(1 , 0)]);
|
||||
ivec4 p5 = separate(read_buffer.buf[get_idx(-1, 0)]);
|
||||
ivec4 p6 = separate(read_buffer.buf[get_idx(1 ,-1)]);
|
||||
ivec4 p7 = separate(read_buffer.buf[get_idx(-1, 1)]);
|
||||
// ivec4 p0 = separate(read_buffer.buf[get_idx(0 , 1)]);
|
||||
// ivec4 p1 = separate(read_buffer.buf[get_idx(0 ,-1)]);
|
||||
// ivec4 p2 = separate(read_buffer.buf[get_idx(1 , 1)]);
|
||||
// ivec4 p3 = separate(read_buffer.buf[get_idx(-1,-1)]);
|
||||
// ivec4 p4 = separate(read_buffer.buf[get_idx(1 , 0)]);
|
||||
// ivec4 p5 = separate(read_buffer.buf[get_idx(-1, 0)]);
|
||||
// ivec4 p6 = separate(read_buffer.buf[get_idx(1 ,-1)]);
|
||||
// ivec4 p7 = separate(read_buffer.buf[get_idx(-1, 1)]);
|
||||
//
|
||||
// ivec3 d0 = abs(p0.xyz - p1.xyz);
|
||||
// ivec3 d1 = abs(p2.xyz - p3.xyz);
|
||||
// ivec3 d2 = abs(p4.xyz - p5.xyz);
|
||||
// ivec3 d3 = abs(p6.xyz - p7.xyz);
|
||||
//
|
||||
// ivec3 m = max(max(max(d0, d1), d2), d3);
|
||||
//
|
||||
// if ((m.x + m.y + m.z) > 200){
|
||||
// p.x = 0;
|
||||
// p.y = 0;
|
||||
// p.z = 255;
|
||||
// }
|
||||
// else {
|
||||
// //p.w = 125;
|
||||
// }
|
||||
|
||||
ivec3 d0 = abs(p0.xyz - p1.xyz);
|
||||
ivec3 d1 = abs(p2.xyz - p3.xyz);
|
||||
ivec3 d2 = abs(p4.xyz - p5.xyz);
|
||||
ivec3 d3 = abs(p6.xyz - p7.xyz);
|
||||
|
||||
ivec3 m = max(max(max(d0, d1), d2), d3);
|
||||
|
||||
if ((m.x + m.y + m.z) > 200){
|
||||
p.x = 0;
|
||||
p.y = 0;
|
||||
p.z = 255;
|
||||
}
|
||||
else {
|
||||
//p.w = 125;
|
||||
}
|
||||
|
||||
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
|
||||
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
|
||||
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
|
||||
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24);
|
||||
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
|
||||
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
|
||||
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
|
||||
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SIMPLE TEXTURE : FRAGMENT SHADER
|
||||
|
||||
// These come in from the previous shader (vertex)
|
||||
layout(location = 0) in vec2 img_coords;
|
||||
layout(location = 0) in vec2 position;
|
||||
|
||||
// This goes out to the bound image in window_size_dependent setup
|
||||
layout(location = 0) out vec4 f_color;
|
||||
@@ -15,8 +15,9 @@ void main() {
|
||||
|
||||
ivec2 pos = ivec2(gl_FragCoord.x, gl_FragCoord.y);
|
||||
|
||||
f_color = imageLoad(img, ivec2(pos)) / (255.0);
|
||||
f_color = imageLoad(img, ivec2(position)) / (255.0);
|
||||
|
||||
float gamma = 0.5;
|
||||
f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma));
|
||||
|
||||
}
|
||||
@@ -2,15 +2,17 @@
|
||||
// SIMPLE IMAGE : VERTEX SHADER
|
||||
|
||||
// These come in from the vertex definition
|
||||
layout(location = 0) in vec2 position;
|
||||
layout(location = 0) in vec2 v_position;
|
||||
layout(location = 1) in vec4 color;
|
||||
layout(location = 2) in vec2 ti_position;
|
||||
|
||||
// These are made up in the shader themselves
|
||||
layout(location = 0) out vec2 img_coords;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
img_coords = position;
|
||||
gl_Position = vec4(v_position, 0.0, 1.0);
|
||||
img_coords = ti_position;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SIMPLE TEXTURE : FRAGMENT SHADER
|
||||
|
||||
// These come in from the previous shader (vertex)
|
||||
layout(location = 0) in vec2 tex_coords;
|
||||
layout(location = 0) in vec2 texture_position;
|
||||
|
||||
// This goes out to the bound image in window_size_dependent setup
|
||||
layout(location = 0) out vec4 f_color;
|
||||
@@ -13,14 +13,9 @@ layout(set = 0, binding = 0) uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
|
||||
ivec2 pos = ivec2(gl_FragCoord.x, gl_FragCoord.y);
|
||||
ivec2 pixel_pos = ivec2(gl_FragCoord.x, gl_FragCoord.y);
|
||||
|
||||
// f_color = imageLoad(img, ivec2(pos)) / (255.0);
|
||||
//
|
||||
// float gamma = 0.5;
|
||||
// f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma));
|
||||
|
||||
f_color = texture(tex, tex_coords);
|
||||
float gamma = 0.5;
|
||||
f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma));
|
||||
f_color = texture(tex, texture_position);
|
||||
float gamma = 0.5;
|
||||
f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma));
|
||||
}
|
||||
@@ -3,16 +3,17 @@
|
||||
|
||||
// These come in from the vertex definition
|
||||
// TODO : Need to add texture coordinate attribute so I can single VBO all these sumbitches
|
||||
layout(location = 0) in vec2 position;
|
||||
layout(location = 0) in vec2 v_position;
|
||||
layout(location = 1) in vec4 color;
|
||||
layout(location = 2) in vec2 ti_position;
|
||||
|
||||
// These are made up in the shader themselves
|
||||
layout(location = 0) out vec2 tex_coords;
|
||||
|
||||
void main() {
|
||||
|
||||
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
tex_coords = position;
|
||||
gl_Position = vec4(v_position, 0.0, 1.0);
|
||||
tex_coords = ti_position;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::vertex_2d::{ColoredVertex2D, Vertex2D};
|
||||
use crate::vertex_2d::{Vertex2D};
|
||||
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
||||
use std::collections::HashMap;
|
||||
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
|
||||
@@ -24,33 +24,24 @@ use std::hash::Hash;
|
||||
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
|
||||
use crate::canvas_buffer::{CanvasImage, CanvasTexture};
|
||||
|
||||
/// Vertex trait for Drawable Vertices.
|
||||
pub trait Vertex {
|
||||
fn position(&self) -> (f32, f32) {
|
||||
(0.0, 0.0)
|
||||
}
|
||||
fn color(&self) -> Option<(f32, f32, f32, f32)> {
|
||||
Some((0., 0., 0., 0.))
|
||||
}
|
||||
}
|
||||
|
||||
impl Vertex for ColoredVertex2D {
|
||||
fn position(&self) -> (f32, f32) {
|
||||
(0.0, 0.0)
|
||||
}
|
||||
|
||||
fn color(&self) -> Option<(f32, f32, f32, f32)> {
|
||||
Some((0., 0., 0., 0.))
|
||||
}
|
||||
}
|
||||
|
||||
/// A drawable object can be passed into a CanvasFrame to be rendered
|
||||
/// Allows Texture or Image drawing via their handles
|
||||
pub trait Drawable {
|
||||
fn get_vertices(&self) -> Vec<(f32, f32)>;
|
||||
fn get_color(&self) -> (f32, f32, f32, f32);
|
||||
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
||||
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>>;
|
||||
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>>;
|
||||
|
||||
fn collect(&self) -> Vec<Vertex2D> {
|
||||
let color = self.get_color();
|
||||
self.get_vertices().iter().zip(self.get_ti_coords().iter()).map(|(a,b)|
|
||||
Vertex2D{
|
||||
v_position: [a.0, a.1],
|
||||
color: [color.0, color.1, color.2, color.3],
|
||||
ti_position: [b.0, b.1],
|
||||
}).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Legacy ShaderType enum for single type shaders.
|
||||
@@ -90,7 +81,7 @@ pub struct CanvasState {
|
||||
|
||||
// Hold onto the vertices we get from the Compu and Canvas Frames
|
||||
// When the run comes around, push the vertices to the GPU
|
||||
colored_drawables: Vec<ColoredVertex2D>,
|
||||
colored_drawables: Vec<Vertex2D>,
|
||||
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync)>>,
|
||||
|
||||
textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<Vertex2D>>>,
|
||||
@@ -173,8 +164,10 @@ impl CanvasState {
|
||||
|
||||
CanvasState {
|
||||
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
|
||||
sampler: Sampler::new(device.clone(), Filter::Linear, Filter::Linear,
|
||||
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
||||
sampler: Sampler::new(device.clone(),
|
||||
Filter::Linear, Filter::Linear,
|
||||
MipmapMode::Nearest,
|
||||
SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
||||
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap(),
|
||||
image_buffers: vec![],
|
||||
texture_buffers: vec![],
|
||||
@@ -295,7 +288,7 @@ impl CanvasState {
|
||||
|
||||
let shader = match shader_type {
|
||||
ShaderType::SOLID => {
|
||||
Arc::new(CanvasShader::new_colored(
|
||||
Arc::new(CanvasShader::new(
|
||||
filename.clone(),
|
||||
capabilities.clone(),
|
||||
self.queue.clone(),
|
||||
@@ -306,7 +299,7 @@ impl CanvasState {
|
||||
)
|
||||
}
|
||||
ShaderType::IMAGE | ShaderType::TEXTURED => {
|
||||
Arc::new(CanvasShader::new_textured(
|
||||
Arc::new(CanvasShader::new(
|
||||
filename.clone(),
|
||||
capabilities.clone(),
|
||||
self.queue.clone(),
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::vertex_2d::{ColoredVertex2D, Vertex2D};
|
||||
use crate::vertex_2d::{Vertex2D};
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
use crate::canvas::{Drawable, CanvasTextureHandle, CanvasImageHandle};
|
||||
|
||||
pub struct CanvasFrame {
|
||||
pub colored_drawables: Vec<ColoredVertex2D>,
|
||||
pub colored_drawables: Vec<Vertex2D>,
|
||||
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<Vertex2D>>>,
|
||||
pub image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<Vertex2D>>>,
|
||||
}
|
||||
@@ -25,11 +25,7 @@ impl CanvasFrame {
|
||||
self.textured_drawables
|
||||
.entry(handle.clone())
|
||||
.or_insert(Vec::new())
|
||||
.push(drawable.get_vertices().iter().map(|n|
|
||||
Vertex2D {
|
||||
position: [n.0, n.1],
|
||||
}
|
||||
).collect::<Vec<Vertex2D>>());
|
||||
.push(drawable.collect());
|
||||
}
|
||||
None => {
|
||||
match drawable.get_image_handle() {
|
||||
@@ -37,23 +33,10 @@ impl CanvasFrame {
|
||||
self.image_drawables
|
||||
.entry(handle.clone())
|
||||
.or_insert(Vec::new())
|
||||
.push(drawable.get_vertices().iter().map(|n|
|
||||
Vertex2D {
|
||||
position: [n.0, n.1],
|
||||
}
|
||||
).collect());
|
||||
.push(drawable.collect());
|
||||
}
|
||||
None => {
|
||||
let colors = drawable.get_color();
|
||||
|
||||
self.colored_drawables.extend(
|
||||
drawable.get_vertices().iter().map(|n|
|
||||
ColoredVertex2D {
|
||||
position: [n.0, n.1],
|
||||
color: [colors.0, colors.1, colors.2, colors.3],
|
||||
}
|
||||
)
|
||||
);
|
||||
self.colored_drawables.extend(drawable.collect());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use shade_runner as sr;
|
||||
use vulkano::framebuffer::{Subpass, RenderPassAbstract, Framebuffer, FramebufferAbstract};
|
||||
use vulkano::pipeline::shader::{GraphicsShaderType, ShaderModule, SpecializationConstants, SpecializationMapEntry};
|
||||
use vulkano::swapchain::Capabilities;
|
||||
use crate::vertex_2d::{ColoredVertex2D, Vertex2D};
|
||||
use crate::vertex_2d::Vertex2D;
|
||||
|
||||
/// Typed wrapper for a u32 shader handle (index id)
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
@@ -54,130 +54,9 @@ impl CanvasShader {
|
||||
self.graphics_pipeline.clone().unwrap()
|
||||
}
|
||||
|
||||
/// Create a new `Colored` shader. Which just means that it uses ColoredVertex2D's
|
||||
/// Create a new shader.
|
||||
/// This will explode when the shader does not want to compile
|
||||
pub fn new_colored(filename: String,
|
||||
capabilities: Capabilities,
|
||||
queue: Arc<Queue>,
|
||||
physical: PhysicalDevice,
|
||||
device: Arc<Device>,
|
||||
handle: Arc<CanvasShaderHandle>,
|
||||
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>,) -> CanvasShader {
|
||||
|
||||
let format = capabilities.supported_formats[0].0;
|
||||
|
||||
let filenames = CanvasShader::get_path(filename.clone());
|
||||
|
||||
// TODO: better compile message, run til successful compile
|
||||
let shader = sr::load(filenames.0, filenames.1)
|
||||
.expect("Shader didn't compile");
|
||||
|
||||
let vulkano_entry =
|
||||
sr::parse(&shader)
|
||||
.expect("failed to parse");
|
||||
|
||||
let fragment_shader_module: Arc<ShaderModule> = unsafe {
|
||||
let filenames1 = CanvasShader::get_path(filename.clone());
|
||||
let shader1 = sr::load(filenames1.0, filenames1.1)
|
||||
.expect("Shader didn't compile");
|
||||
vulkano::pipeline::shader::ShaderModule::from_words(device.clone(), &shader1.fragment.clone())
|
||||
}.unwrap();
|
||||
|
||||
let vertex_shader_module: Arc<ShaderModule> = unsafe {
|
||||
let filenames1 = CanvasShader::get_path(filename.clone());
|
||||
let shader1 = sr::load(filenames1.0, filenames1.1)
|
||||
.expect("Shader didn't compile");
|
||||
vulkano::pipeline::shader::ShaderModule::from_words(device.clone(), &shader1.vertex.clone())
|
||||
}.unwrap();
|
||||
|
||||
let filenames = CanvasShader::get_path(filename.clone());
|
||||
|
||||
|
||||
let frag_entry_point = unsafe {
|
||||
Some(fragment_shader_module.graphics_entry_point(CStr::from_bytes_with_nul_unchecked(b"main\0"),
|
||||
vulkano_entry.frag_input,
|
||||
vulkano_entry.frag_output,
|
||||
vulkano_entry.frag_layout,
|
||||
GraphicsShaderType::Fragment))
|
||||
};
|
||||
|
||||
let vertex_entry_point = unsafe {
|
||||
Some(vertex_shader_module.graphics_entry_point(CStr::from_bytes_with_nul_unchecked(b"main\0"),
|
||||
vulkano_entry.vert_input,
|
||||
vulkano_entry.vert_output,
|
||||
vulkano_entry.vert_layout,
|
||||
GraphicsShaderType::Vertex))
|
||||
};
|
||||
|
||||
|
||||
let render_pass = Arc::new(vulkano::single_pass_renderpass!(
|
||||
device.clone(),
|
||||
|
||||
// Attachments are outgoing like f_color
|
||||
attachments: {
|
||||
// `color` is a custom name we give to the first and only attachment.
|
||||
color: {
|
||||
// `load: Clear` means that we ask the GPU to clear the content of this
|
||||
// attachment at the start of the drawing.
|
||||
load: Clear,
|
||||
// `store: Store` means that we ask the GPU to store the output of the draw
|
||||
// in the actual image. We could also ask it to discard the result.
|
||||
store: Store,
|
||||
// `format: <ty>` indicates the type of the format of the image. This has to
|
||||
// be one of the types of the `vulkano::format` module (or alternatively one
|
||||
// of your structs that implements the `FormatDesc` trait). Here we use the
|
||||
// same format as the swapchain.
|
||||
format: format,
|
||||
// TODO:
|
||||
samples: 1,
|
||||
}
|
||||
},
|
||||
pass: {
|
||||
// We use the attachment named `color` as the one and only color attachment.
|
||||
color: [color],
|
||||
//color: [],
|
||||
// No depth-stencil attachment is indicated with empty brackets.
|
||||
depth_stencil: {}
|
||||
}
|
||||
).unwrap());
|
||||
|
||||
|
||||
CanvasShader {
|
||||
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()
|
||||
|
||||
.vertex_input_single_buffer::<ColoredVertex2D>()
|
||||
|
||||
.vertex_shader(vertex_entry_point.clone().unwrap(), ShaderSpecializationConstants {
|
||||
first_constant: 0,
|
||||
second_constant: 0,
|
||||
third_constant: 0.0,
|
||||
})
|
||||
|
||||
.triangle_list()
|
||||
// Use a resizable viewport set to draw over the entire window
|
||||
.viewports_dynamic_scissors_irrelevant(1)
|
||||
|
||||
.fragment_shader(frag_entry_point.clone().unwrap(), ShaderSpecializationConstants {
|
||||
first_constant: 0,
|
||||
second_constant: 0,
|
||||
third_constant: 0.0,
|
||||
})
|
||||
// We have to indicate which subpass of which render pass this pipeline is going to be used
|
||||
// in. The pipeline will only be usable from this particular subpass.
|
||||
.render_pass(Subpass::from(render_pass.clone(), 0).unwrap())
|
||||
|
||||
.build(device.clone())
|
||||
.unwrap())),
|
||||
|
||||
device: device,
|
||||
handle: handle.clone(),
|
||||
name: filename.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new `Textured` shader. Which just means that it uses plain Vertex2D's
|
||||
/// This will explode when the shader does not want to compile
|
||||
pub fn new_textured(filename: String,
|
||||
pub fn new(filename: String,
|
||||
capabilities: Capabilities,
|
||||
queue: Arc<Queue>,
|
||||
physical: PhysicalDevice,
|
||||
|
||||
@@ -2,7 +2,9 @@ use crate::canvas::{CanvasImageHandle, Drawable, CanvasTextureHandle};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct CompuSprite {
|
||||
vertices: [(f32, f32); 6],
|
||||
pub vertices: [(f32, f32); 6],
|
||||
pub ti_position: [(f32, f32); 6],
|
||||
|
||||
position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
color: (f32, f32, f32, f32),
|
||||
@@ -12,19 +14,27 @@ pub struct CompuSprite {
|
||||
impl CompuSprite {
|
||||
pub fn new(position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
image_size: (f32, f32),
|
||||
image_handle: Arc<CanvasImageHandle>) -> CompuSprite {
|
||||
let fsize = (size.0 as f32, size.1 as f32);
|
||||
|
||||
CompuSprite {
|
||||
vertices: [
|
||||
(position.0, position.1), // top left
|
||||
(position.0, position.1 + fsize.1), // bottom left
|
||||
(position.0 + fsize.0, position.1 + fsize.1), // bottom right
|
||||
(position.0, position.1 + size.1), // bottom left
|
||||
(position.0 + size.0, position.1 + size.1), // bottom right
|
||||
(position.0, position.1), // top left
|
||||
(position.0 + fsize.0, position.1 + fsize.1), // bottom right
|
||||
(position.0 + fsize.0, position.1), // top right
|
||||
(position.0 + size.0, position.1 + size.1), // bottom right
|
||||
(position.0 + size.0, position.1), // top right
|
||||
],
|
||||
|
||||
ti_position: [
|
||||
(0.0 , 0.0 ), // top left
|
||||
(0.0 , image_size.1), // bottom left
|
||||
(image_size.0, image_size.1), // bottom right
|
||||
(0.0 , 0.0 ), // top left
|
||||
(image_size.0, image_size.1), // bottom right
|
||||
(image_size.0, 0.0 ), // top right
|
||||
],
|
||||
position: position,
|
||||
size: size,
|
||||
color: (0.0, 0.0, 0.0, 0.0),
|
||||
@@ -42,6 +52,10 @@ impl Drawable for CompuSprite {
|
||||
self.color
|
||||
}
|
||||
|
||||
fn get_ti_coords(&self) -> Vec<(f32, f32)> {
|
||||
self.ti_position.to_vec()
|
||||
}
|
||||
|
||||
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
|
||||
None
|
||||
}
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -99,11 +99,11 @@ pub fn main() {
|
||||
let sprite = Sprite::new_with_color((0., 0.), (0.1, 0.1), (1., 0., 0., 1.));
|
||||
let sprite2 = Sprite::new_with_color((-0.3, -0.5), (0.1, 0.1), (0., 1., 0., 1.));
|
||||
|
||||
let compu_sprite1 = CompuSprite::new((-1., -0.5), (0.4, 0.4),
|
||||
let compu_sprite1 = CompuSprite::new((-1., -0.5), (1.0, 1.0), (400.0, 400.0),
|
||||
// This swap image needs to match the size of the compute
|
||||
processor.new_swap_image((720, 756)));
|
||||
processor.new_swap_image((400, 400)));
|
||||
|
||||
let image_data = load_raw(String::from("funky-bird.jpg"));
|
||||
let image_data = load_raw(String::from("test2.png"));
|
||||
let compute_buffer = processor.new_compute_buffer(image_data.0, image_data.1, 4);
|
||||
|
||||
let compute_kernel = processor.get_kernel_handle(String::from("simple-edge.compute"))
|
||||
@@ -111,7 +111,7 @@ pub fn main() {
|
||||
|
||||
let handle = processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap();
|
||||
|
||||
let sprite3 = Sprite::new_with_texture((0.3, 0.5), (0.1, 0.1), handle.clone());
|
||||
let sprite3 = Sprite::new_with_texture((0.3, 0.5), (0.5, 0.5), handle.clone());
|
||||
|
||||
drop(q2);
|
||||
drop(q1);
|
||||
@@ -166,12 +166,12 @@ pub fn main() {
|
||||
|
||||
let mut compu_frame = CompuFrame::new();
|
||||
compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
||||
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
||||
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
||||
|
||||
let mut canvas = CanvasFrame::new();
|
||||
// canvas.draw(&sprite);
|
||||
// canvas.draw(&sprite2);
|
||||
// canvas.draw(&sprite3);
|
||||
canvas.draw(&sprite);
|
||||
canvas.draw(&sprite2);
|
||||
canvas.draw(&sprite3);
|
||||
canvas.draw(&compu_sprite1);
|
||||
|
||||
canvas.draw(&Sprite::new_with_color((
|
||||
|
||||
@@ -3,7 +3,9 @@ use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Sprite {
|
||||
|
||||
pub vertices: [(f32, f32); 6],
|
||||
pub ti_position: [(f32, f32); 6],
|
||||
|
||||
position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
@@ -37,6 +39,14 @@ impl Sprite {
|
||||
],
|
||||
|
||||
position: position,
|
||||
ti_position: [
|
||||
(-1.0, -1.0), // top left
|
||||
(-1.0, 1.0), // bottom left
|
||||
( 1.0, 1.0), // bottom right
|
||||
(-1.0, -1.0), // top left
|
||||
( 1.0, 1.0), // bottom right
|
||||
( 1.0, -1.0), // top right
|
||||
],
|
||||
size: size,
|
||||
color: color,
|
||||
textured: false,
|
||||
@@ -58,6 +68,14 @@ impl Sprite {
|
||||
(position.0 + fsize.0, position.1 ), // top right
|
||||
],
|
||||
position: position,
|
||||
ti_position: [
|
||||
(-1.0, -1.0), // top left
|
||||
(-1.0, 1.0), // bottom left
|
||||
( 1.0, 1.0), // bottom right
|
||||
(-1.0, -1.0), // top left
|
||||
( 1.0, 1.0), // bottom right
|
||||
( 1.0, -1.0), // top right
|
||||
],
|
||||
size: size,
|
||||
color: (0.0, 0.0, 0.0, 0.0),
|
||||
textured: true,
|
||||
@@ -78,6 +96,10 @@ impl Drawable for Sprite {
|
||||
self.color.clone()
|
||||
}
|
||||
|
||||
fn get_ti_coords(&self) -> Vec<(f32, f32)> {
|
||||
self.ti_position.to_vec()
|
||||
}
|
||||
|
||||
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
|
||||
match self.textured {
|
||||
true => {
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Vertex2D {
|
||||
pub position: [f32; 2]
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct ColoredVertex2D {
|
||||
pub position: [f32; 2],
|
||||
pub v_position: [f32; 2],
|
||||
pub color : [f32; 4],
|
||||
pub ti_position: [f32; 2],
|
||||
}
|
||||
|
||||
vulkano::impl_vertex!(ColoredVertex2D, position, color);
|
||||
vulkano::impl_vertex!(Vertex2D, position);
|
||||
vulkano::impl_vertex!(Vertex2D, v_position, color, ti_position);
|
||||
|
||||
|
||||
|
||||
impl From<(f32, f32)> for Vertex2D {
|
||||
fn from(item: (f32, f32)) -> Self {
|
||||
Vertex2D { position: [item.0, item.1] }
|
||||
}
|
||||
}
|
||||
//impl From<(f32, f32)> for Vertex2D {
|
||||
// fn from(item: (f32, f32)) -> Self {
|
||||
// Vertex2D {
|
||||
// v_position: [],
|
||||
// color: [],
|
||||
// ti_position: []
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//impl From<((f32,f32),(f32, f32))> for Vertex2D {
|
||||
// fn from(item: ((f32,f32),(f32, f32))) -> Self {
|
||||
// Vertex2D {
|
||||
// v_position: [],
|
||||
// color: [],
|
||||
// ti_position: []
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user