Fixed some more imports/documentation.

This commit is contained in:
shan 2022-10-06 19:41:00 -07:00
parent 72feba51be
commit f9a6efcaa0
12 changed files with 28 additions and 26 deletions

View file

@ -22,8 +22,7 @@ pub struct GradientUniformData {
struct GradientUniformLocations {
gradient_direction_location: <Context as HasContext>::UniformLocation,
color_stops_size_location: <Context as HasContext>::UniformLocation,
//currently the maximum number of stops is 64 due to needing to allocate the
//memory for the array of stops with a const value in GLSL
//currently the maximum number of stops is 16 due to lack of SSBO in GL2.1
color_stops_location: <Context as HasContext>::UniformLocation,
transform_location: <Context as HasContext>::UniformLocation,
}
@ -140,7 +139,7 @@ impl GradientUniformData {
let transform_location =
unsafe { gl.get_uniform_location(program, "u_Transform") }
.expect("Get transform location.");
.expect("Gradient - Get u_Transform.");
GradientUniformData {
gradient: Gradient::Linear(Linear {

View file

@ -25,12 +25,12 @@ impl SolidUniformData {
color_location: unsafe {
gl.get_uniform_location(program, "color")
}
.expect("Solid - Color uniform location."),
.expect("Solid - Get color."),
transform: Transformation::identity(),
transform_location: unsafe {
gl.get_uniform_location(program, "u_Transform")
}
.expect("Get transform location."),
.expect("Solid - Get u_Transform."),
}
}
}
@ -74,10 +74,13 @@ impl SolidProgram {
}
}
pub fn use_program(&mut self, gl: &Context, color: &Color, transform: &Transformation) {
unsafe {
gl.use_program(Some(self.program))
}
pub fn use_program(
&mut self,
gl: &Context,
color: &Color,
transform: &Transformation,
) {
unsafe { gl.use_program(Some(self.program)) }
self.write_uniforms(gl, color, transform)
}
}

View file

@ -3,8 +3,7 @@ mod linear;
pub use crate::gradient::linear::Linear;
use crate::widget::canvas::frame::Transform;
use crate::Point;
use iced_native::Color;
use crate::{Point, Color};
#[derive(Debug, Clone, PartialEq)]
/// A fill which transitions colors progressively along a direction, either linearly, radially (TBD),

View file

@ -42,7 +42,7 @@ impl<'a> From<Color> for Fill<'a> {
}
}
/// The color or gradient of a [`Fill`].
/// The style of a [`Fill`].
#[derive(Debug, Clone)]
pub enum Style<'a> {
/// A solid color

View file

@ -1,4 +1,4 @@
//! Create lines from a [crate::widget::canvas::Path] and render with various attributes/styles.
//! Create lines from a [crate::widget::canvas::Path] and assigns them various attributes/styles.
use iced_native::Color;
use crate::gradient::Gradient;
@ -60,7 +60,7 @@ impl<'a> Default for Stroke<'a> {
}
}
/// The color or gradient of a [`Stroke`].
/// The style of a [`Stroke`].
#[derive(Debug, Clone, Copy)]
pub enum Style<'a> {
/// A solid color

View file

@ -88,7 +88,7 @@ impl<T: Pod + Zeroable> StaticBuffer<T> {
let bytes = bytemuck::cast_slice(content);
let bytes_size = bytes.len() as u64;
if let Some(buffer_size) = wgpu::BufferSize::new(bytes_size as u64) {
if let Some(buffer_size) = wgpu::BufferSize::new(bytes_size) {
let mut buffer = staging_belt.write_buffer(
encoder,
&self.gpu,

View file

@ -50,6 +50,7 @@ impl DynamicBufferType {
}
}
/// A dynamic buffer is any type of buffer which does not have a static offset.
pub(crate) struct DynamicBuffer<T: ShaderType> {
offsets: Vec<wgpu::DynamicOffset>,
cpu: DynamicBufferType,
@ -124,13 +125,15 @@ impl<T: ShaderType + WriteInto> DynamicBuffer<T> {
/// Write a new value to the CPU buffer with proper alignment. Stores the returned offset value
/// in the buffer for future use.
pub fn push(&mut self, value: &T) {
//this write operation on the buffer will adjust for uniform alignment requirements
//this write operation on the cpu buffer will adjust for uniform alignment requirements
let offset = self.cpu.write(value);
self.offsets.push(offset as u32);
}
/// Resize buffer contents if necessary. This will re-create the GPU buffer if current size is
/// less than the newly computed size from the CPU buffer.
///
/// If the gpu buffer is resized, its bind group will need to be recreated!
pub fn resize(&mut self, device: &wgpu::Device) -> bool {
let new_size = self.cpu.get_ref().len() as u64;
@ -144,7 +147,6 @@ impl<T: ShaderType + WriteInto> DynamicBuffer<T> {
}
};
//Re-create the GPU buffer since it needs to be resized.
self.gpu = DynamicBuffer::<T>::create_gpu_buffer(
device, self.label, usages, new_size,
);

View file

@ -1,9 +1,8 @@
// uniforms
struct GradientUniforms {
transform: mat4x4<f32>,
//xy = start, wz = end
position: vec4<f32>,
//x = start, y = end, zw = padding
//x = start stop, y = end stop, zw = padding
stop_range: vec4<i32>,
}
@ -32,6 +31,7 @@ fn vs_main(@location(0) input: vec2<f32>) -> VertexOutput {
return output;
}
//TODO: rewrite without branching
@fragment
fn fs_gradient(input: VertexOutput) -> @location(0) vec4<f32> {
let start = uniforms.position.xy;

View file

@ -1,4 +1,3 @@
// uniforms
struct SolidUniforms {
transform: mat4x4<f32>,
color: vec4<f32>

View file

@ -12,9 +12,9 @@ use crate::triangle::solid::SolidPipeline;
pub use iced_graphics::triangle::{Mesh2D, Vertex2D};
use layer::mesh;
mod solid;
mod gradient;
mod msaa;
mod solid;
/// Triangle pipeline for all mesh layers in a [`iced_graphics::Canvas`] widget.
#[derive(Debug)]
@ -60,7 +60,7 @@ impl TrianglePipelines {
}
impl Pipeline {
/// Creates supported GL programs, listed in [TrianglePipelines].
/// Creates supported pipelines, listed in [TrianglePipelines].
pub fn new(
device: &wgpu::Device,
format: wgpu::TextureFormat,

View file

@ -26,7 +26,7 @@ pub(super) struct GradientUniforms {
transform: glam::Mat4,
//xy = start, zw = end
direction: Vec4,
//x = start, y = end, zw = padding
//x = start stop, y = end stop, zw = padding
stop_range: IVec4,
}
@ -55,7 +55,7 @@ impl GradientPipeline {
);
//Note: with a WASM target storage buffers are not supported. Will need to use UBOs & static
// sized array (eg like the 64-sized array on OpenGL side right now) to make gradients work
// sized array (eg like the 32-sized array on OpenGL side right now) to make gradients work
let storage_buffer = DynamicBuffer::storage(
device,
"iced_wgpu::triangle [GRADIENT] storage",

View file

@ -10,13 +10,13 @@ use iced_graphics::Transformation;
pub struct SolidPipeline {
pipeline: wgpu::RenderPipeline,
pub(crate) buffer: DynamicBuffer<SolidUniforms>,
pub(super) buffer: DynamicBuffer<SolidUniforms>,
bind_group_layout: wgpu::BindGroupLayout,
bind_group: wgpu::BindGroup,
}
#[derive(Debug, Clone, Copy, ShaderType)]
pub struct SolidUniforms {
pub(super) struct SolidUniforms {
transform: glam::Mat4,
color: Vec4,
}