summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar shan <shankern@protonmail.com>2022-10-06 19:41:00 -0700
committerLibravatar shan <shankern@protonmail.com>2022-10-06 19:41:00 -0700
commitf9a6efcaa03728f43aaa105af8936c1ed4778388 (patch)
treef3a4e90a94afc20d300e25a96fdc74c9c9c34c95
parent72feba51bed41db0bc04b43167d5d3b43007fd44 (diff)
downloadiced-f9a6efcaa03728f43aaa105af8936c1ed4778388.tar.gz
iced-f9a6efcaa03728f43aaa105af8936c1ed4778388.tar.bz2
iced-f9a6efcaa03728f43aaa105af8936c1ed4778388.zip
Fixed some more imports/documentation.
-rw-r--r--glow/src/triangle/gradient.rs5
-rw-r--r--glow/src/triangle/solid.rs15
-rw-r--r--graphics/src/gradient.rs3
-rw-r--r--graphics/src/widget/canvas/fill.rs2
-rw-r--r--graphics/src/widget/canvas/stroke.rs4
-rw-r--r--wgpu/src/buffers.rs2
-rw-r--r--wgpu/src/buffers/dynamic.rs6
-rw-r--r--wgpu/src/shader/triangle_gradient.wgsl4
-rw-r--r--wgpu/src/shader/triangle_solid.wgsl1
-rw-r--r--wgpu/src/triangle.rs4
-rw-r--r--wgpu/src/triangle/gradient.rs4
-rw-r--r--wgpu/src/triangle/solid.rs4
12 files changed, 28 insertions, 26 deletions
diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs
index 4b157890..a8bb5ec5 100644
--- a/glow/src/triangle/gradient.rs
+++ b/glow/src/triangle/gradient.rs
@@ -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 {
diff --git a/glow/src/triangle/solid.rs b/glow/src/triangle/solid.rs
index 3d4d1968..5ba7f91c 100644
--- a/glow/src/triangle/solid.rs
+++ b/glow/src/triangle/solid.rs
@@ -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)
}
}
diff --git a/graphics/src/gradient.rs b/graphics/src/gradient.rs
index 683a7413..d785fb2a 100644
--- a/graphics/src/gradient.rs
+++ b/graphics/src/gradient.rs
@@ -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),
diff --git a/graphics/src/widget/canvas/fill.rs b/graphics/src/widget/canvas/fill.rs
index 768c2b9c..cd56aa9e 100644
--- a/graphics/src/widget/canvas/fill.rs
+++ b/graphics/src/widget/canvas/fill.rs
@@ -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
diff --git a/graphics/src/widget/canvas/stroke.rs b/graphics/src/widget/canvas/stroke.rs
index aaac15bb..5cb63a91 100644
--- a/graphics/src/widget/canvas/stroke.rs
+++ b/graphics/src/widget/canvas/stroke.rs
@@ -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
diff --git a/wgpu/src/buffers.rs b/wgpu/src/buffers.rs
index 7a15692b..6b9f487c 100644
--- a/wgpu/src/buffers.rs
+++ b/wgpu/src/buffers.rs
@@ -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,
diff --git a/wgpu/src/buffers/dynamic.rs b/wgpu/src/buffers/dynamic.rs
index 75cc202c..dc30c56f 100644
--- a/wgpu/src/buffers/dynamic.rs
+++ b/wgpu/src/buffers/dynamic.rs
@@ -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,
);
diff --git a/wgpu/src/shader/triangle_gradient.wgsl b/wgpu/src/shader/triangle_gradient.wgsl
index 4efda260..03ba9d88 100644
--- a/wgpu/src/shader/triangle_gradient.wgsl
+++ b/wgpu/src/shader/triangle_gradient.wgsl
@@ -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;
diff --git a/wgpu/src/shader/triangle_solid.wgsl b/wgpu/src/shader/triangle_solid.wgsl
index be51ebb0..9eb2df24 100644
--- a/wgpu/src/shader/triangle_solid.wgsl
+++ b/wgpu/src/shader/triangle_solid.wgsl
@@ -1,4 +1,3 @@
-// uniforms
struct SolidUniforms {
transform: mat4x4<f32>,
color: vec4<f32>
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs
index 791c9833..48ddf28a 100644
--- a/wgpu/src/triangle.rs
+++ b/wgpu/src/triangle.rs
@@ -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,
diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs
index 11c072ca..07551368 100644
--- a/wgpu/src/triangle/gradient.rs
+++ b/wgpu/src/triangle/gradient.rs
@@ -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",
diff --git a/wgpu/src/triangle/solid.rs b/wgpu/src/triangle/solid.rs
index d2b4d13b..abba4851 100644
--- a/wgpu/src/triangle/solid.rs
+++ b/wgpu/src/triangle/solid.rs
@@ -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,
}