| 1 | use super::Params; |
| 2 | |
| 3 | const UNIFORMARRAY_SIZE: usize = 14; |
| 4 | |
| 5 | pub struct UniformArray([f32; UNIFORMARRAY_SIZE * 4]); |
| 6 | |
| 7 | impl Default for UniformArray { |
| 8 | fn default() -> Self { |
| 9 | Self([ |
| 10 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
| 11 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
| 12 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
| 13 | ]) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | impl UniformArray { |
| 18 | pub fn as_slice(&self) -> &[f32] { |
| 19 | &self.0 |
| 20 | } |
| 21 | |
| 22 | pub fn set_scissor_mat(&mut self, mat: [f32; 12]) { |
| 23 | self.0[0..12].copy_from_slice(&mat); |
| 24 | } |
| 25 | |
| 26 | pub fn set_paint_mat(&mut self, mat: [f32; 12]) { |
| 27 | self.0[12..24].copy_from_slice(&mat); |
| 28 | } |
| 29 | |
| 30 | pub fn set_inner_col(&mut self, col: [f32; 4]) { |
| 31 | self.0[24..28].copy_from_slice(&col); |
| 32 | } |
| 33 | |
| 34 | pub fn set_outer_col(&mut self, col: [f32; 4]) { |
| 35 | self.0[28..32].copy_from_slice(&col); |
| 36 | } |
| 37 | |
| 38 | pub fn set_scissor_ext(&mut self, ext: [f32; 2]) { |
| 39 | self.0[32..34].copy_from_slice(&ext); |
| 40 | } |
| 41 | |
| 42 | pub fn set_scissor_scale(&mut self, scale: [f32; 2]) { |
| 43 | self.0[34..36].copy_from_slice(&scale); |
| 44 | } |
| 45 | |
| 46 | pub fn set_extent(&mut self, ext: [f32; 2]) { |
| 47 | self.0[36..38].copy_from_slice(&ext); |
| 48 | } |
| 49 | |
| 50 | pub fn set_radius(&mut self, radius: f32) { |
| 51 | self.0[38] = radius; |
| 52 | } |
| 53 | |
| 54 | pub fn set_feather(&mut self, feather: f32) { |
| 55 | self.0[39] = feather; |
| 56 | } |
| 57 | |
| 58 | pub fn set_stroke_mult(&mut self, stroke_mult: f32) { |
| 59 | self.0[40] = stroke_mult; |
| 60 | } |
| 61 | |
| 62 | pub fn set_stroke_thr(&mut self, stroke_thr: f32) { |
| 63 | self.0[41] = stroke_thr; |
| 64 | } |
| 65 | |
| 66 | pub fn set_tex_type(&mut self, tex_type: f32) { |
| 67 | self.0[42] = tex_type; |
| 68 | } |
| 69 | |
| 70 | pub fn set_shader_type(&mut self, shader_type: f32) { |
| 71 | self.0[43] = shader_type; |
| 72 | } |
| 73 | |
| 74 | pub fn set_glyph_texture_type(&mut self, glyph_texture_type: f32) { |
| 75 | self.0[44] = glyph_texture_type; |
| 76 | } |
| 77 | |
| 78 | pub fn set_image_blur_filter_direction(&mut self, direction: [f32; 2]) { |
| 79 | self.0[45..47].copy_from_slice(&direction); |
| 80 | } |
| 81 | |
| 82 | pub fn set_image_blur_filter_sigma(&mut self, sigma: f32) { |
| 83 | self.0[47] = sigma; |
| 84 | } |
| 85 | |
| 86 | pub fn set_image_blur_filter_coeff(&mut self, coeff: [f32; 3]) { |
| 87 | self.0[48..51].copy_from_slice(&coeff); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | impl From<&Params> for UniformArray { |
| 92 | fn from(params: &Params) -> Self { |
| 93 | let mut arr = Self::default(); |
| 94 | |
| 95 | arr.set_scissor_mat(params.scissor_mat); |
| 96 | arr.set_paint_mat(params.paint_mat); |
| 97 | arr.set_inner_col(params.inner_col); |
| 98 | arr.set_outer_col(params.outer_col); |
| 99 | arr.set_scissor_ext(params.scissor_ext); |
| 100 | arr.set_scissor_scale(params.scissor_scale); |
| 101 | arr.set_extent(params.extent); |
| 102 | arr.set_radius(params.radius); |
| 103 | arr.set_feather(params.feather); |
| 104 | arr.set_stroke_mult(params.stroke_mult); |
| 105 | arr.set_stroke_thr(params.stroke_thr); |
| 106 | arr.set_shader_type(params.shader_type.to_f32()); |
| 107 | arr.set_tex_type(params.tex_type); |
| 108 | arr.set_glyph_texture_type(params.glyph_texture_type as f32); |
| 109 | arr.set_image_blur_filter_direction(params.image_blur_filter_direction); |
| 110 | arr.set_image_blur_filter_sigma(params.image_blur_filter_sigma); |
| 111 | arr.set_image_blur_filter_coeff(params.image_blur_filter_coeff); |
| 112 | |
| 113 | arr |
| 114 | } |
| 115 | } |
| 116 | |