multi texturing works
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::vertex_2d::{Vertex2D};
|
||||
use crate::vertex_2d::Vertex2D;
|
||||
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
||||
use std::collections::HashMap;
|
||||
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
|
||||
@@ -68,7 +68,6 @@ pub struct CanvasImageHandle {
|
||||
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
||||
#[derive(Clone)]
|
||||
pub struct CanvasState {
|
||||
|
||||
/// Generated during new()
|
||||
dynamic_state: DynamicState,
|
||||
/// Generated during new()
|
||||
@@ -98,11 +97,9 @@ pub struct CanvasState {
|
||||
|
||||
|
||||
impl CanvasState {
|
||||
|
||||
/// This method is called once during initialization, then again whenever the window is resized
|
||||
pub fn window_size_dependent_setup(&mut self, images: &[Arc<SwapchainImage<Window>>])
|
||||
-> Vec<Arc<dyn FramebufferAbstract + Send + Sync>> {
|
||||
|
||||
let dimensions = images[0].dimensions();
|
||||
|
||||
self.dynamic_state.viewports =
|
||||
@@ -126,8 +123,6 @@ impl CanvasState {
|
||||
device: Arc<Device>,
|
||||
physical: PhysicalDevice,
|
||||
capabilities: Capabilities) -> CanvasState {
|
||||
|
||||
|
||||
let format = capabilities.supported_formats[0].0;
|
||||
|
||||
let render_pass = Arc::new(vulkano::single_pass_renderpass!(
|
||||
@@ -188,7 +183,6 @@ impl CanvasState {
|
||||
|
||||
/// Using the dimensions and suggested usage, load a CanvasImage and return it's handle
|
||||
pub fn create_image(&mut self, dimensions: (u32, u32), usage: ImageUsage) -> Arc<CanvasImageHandle> {
|
||||
|
||||
let handle = Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32 });
|
||||
|
||||
let image = CanvasImage {
|
||||
@@ -281,7 +275,6 @@ impl CanvasState {
|
||||
shader_type: ShaderType,
|
||||
physical: PhysicalDevice,
|
||||
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
|
||||
|
||||
let handle = Arc::new(CanvasShaderHandle {
|
||||
handle: self.shader_buffers.len() as u32
|
||||
});
|
||||
@@ -378,10 +371,16 @@ impl CanvasState {
|
||||
{
|
||||
let g = hprof::enter("Textured Vertex Buffer");
|
||||
for (k, v) in self.textured_drawables.drain() {
|
||||
let vertex_buffer = v.clone().iter()
|
||||
.fold(Vec::new(), |mut a: Vec<Vertex2D>, b| {
|
||||
a.extend(b);
|
||||
a
|
||||
});
|
||||
|
||||
self.textured_vertex_buffer.insert(
|
||||
k.clone(),
|
||||
ImmutableBuffer::from_iter(
|
||||
v.first().unwrap().iter().cloned(), // I don't think doing a first is the right thing
|
||||
vertex_buffer.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0,
|
||||
@@ -393,11 +392,16 @@ impl CanvasState {
|
||||
{
|
||||
let g = hprof::enter("Image Vertex Buffer");
|
||||
for (k, v) in self.image_drawables.drain() {
|
||||
let vertex_buffer = v.clone().iter()
|
||||
.fold(Vec::new(), |mut a: Vec<Vertex2D>, b| {
|
||||
a.extend(b);
|
||||
a
|
||||
});
|
||||
|
||||
self.image_vertex_buffer.insert(
|
||||
k.clone(),
|
||||
ImmutableBuffer::from_iter(
|
||||
v.iter().fold(Vec::new(), |mut acc, x| [acc.as_slice(), x.as_slice()].concat()).iter(),
|
||||
//v.first().unwrap().iter().cloned(),
|
||||
vertex_buffer.iter().cloned(),
|
||||
BufferUsage::vertex_buffer(),
|
||||
self.queue.clone(),
|
||||
).unwrap().0,
|
||||
@@ -460,6 +464,7 @@ impl CanvasState {
|
||||
|
||||
command_buffer = command_buffer.draw(
|
||||
shader.get_pipeline().clone(),
|
||||
// Multiple vertex buffers must have their definition in the pipeline!
|
||||
&self.dynamic_state.clone(), vec![vertex_buffer],
|
||||
vec![descriptor_set], (),
|
||||
).unwrap();
|
||||
@@ -480,6 +485,7 @@ impl CanvasState {
|
||||
|
||||
command_buffer = command_buffer.draw(
|
||||
shader.get_pipeline().clone(),
|
||||
// Multiple vertex buffers must have their definition in the pipeline!
|
||||
&self.dynamic_state.clone(), vec![vertex_buffer],
|
||||
vec![descriptor_set], (),
|
||||
).unwrap();
|
||||
|
||||
@@ -9,6 +9,7 @@ use vulkano::framebuffer::{Subpass, RenderPassAbstract, Framebuffer, Framebuffer
|
||||
use vulkano::pipeline::shader::{GraphicsShaderType, ShaderModule, SpecializationConstants, SpecializationMapEntry};
|
||||
use vulkano::swapchain::Capabilities;
|
||||
use crate::vertex_2d::Vertex2D;
|
||||
use vulkano::pipeline::vertex::SingleBufferDefinition;
|
||||
|
||||
/// Typed wrapper for a u32 shader handle (index id)
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
@@ -112,7 +113,7 @@ impl CanvasShader {
|
||||
CanvasShader {
|
||||
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()
|
||||
|
||||
.vertex_input_single_buffer::<Vertex2D>()
|
||||
.vertex_input(SingleBufferDefinition::<Vertex2D>::new())
|
||||
|
||||
.vertex_shader(vertex_entry_point.clone().unwrap(), ShaderSpecializationConstants {
|
||||
first_constant: 0,
|
||||
|
||||
@@ -112,7 +112,7 @@ pub fn main() {
|
||||
.expect("Can't find that kernel");
|
||||
|
||||
let funky_handle = processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap();
|
||||
let sfml_handle = processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap();
|
||||
let sfml_handle = processor.get_texture_handle(String::from("sfml.png")).unwrap();
|
||||
|
||||
let sprite3 = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), funky_handle.clone());
|
||||
let sprite4 = Sprite::new_with_texture((0.3, 0.5), (0.9, 0.9), sfml_handle.clone());
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#[derive(Default, Debug, Clone)]
|
||||
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub struct Vertex2D {
|
||||
pub v_position: [f32; 2],
|
||||
pub color : [f32; 4],
|
||||
|
||||
Reference in New Issue
Block a user