From 29ff917a2b2ff7ce0a81b2cc5681de6d4735b36e Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Sun, 29 Oct 2023 00:34:57 -0400 Subject: [PATCH] Add uniform_matrix_CxR_f32_slice --- src/lib.rs | 42 ++++++++++++++++++++ src/native.rs | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ src/web_sys.rs | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 408b713..25d3855 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -816,6 +816,27 @@ pub trait HasContext { v: &[f32], ); + unsafe fn uniform_matrix_2x3_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ); + + unsafe fn uniform_matrix_2x4_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ); + + unsafe fn uniform_matrix_3x2_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ); + unsafe fn uniform_matrix_3_f32_slice( &self, location: Option<&Self::UniformLocation>, @@ -823,6 +844,27 @@ pub trait HasContext { v: &[f32], ); + unsafe fn uniform_matrix_3x4_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ); + + unsafe fn uniform_matrix_4x2_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ); + + unsafe fn uniform_matrix_4x3_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ); + unsafe fn uniform_matrix_4_f32_slice( &self, location: Option<&Self::UniformLocation>, diff --git a/src/native.rs b/src/native.rs index 85fe17a..4016b26 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1893,6 +1893,57 @@ impl HasContext for Context { } } + unsafe fn uniform_matrix_2x3_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + let gl = &self.raw; + if let Some(loc) = location { + gl.UniformMatrix2x3fv( + loc.0 as i32, + v.len() as i32 / 6, + transpose as u8, + v.as_ptr(), + ); + } + } + + unsafe fn uniform_matrix_2x4_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + let gl = &self.raw; + if let Some(loc) = location { + gl.UniformMatrix2x4fv( + loc.0 as i32, + v.len() as i32 / 8, + transpose as u8, + v.as_ptr(), + ); + } + } + + unsafe fn uniform_matrix_3x2_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + let gl = &self.raw; + if let Some(loc) = location { + gl.UniformMatrix3x2fv( + loc.0 as i32, + v.len() as i32 / 6, + transpose as u8, + v.as_ptr(), + ); + } + } + unsafe fn uniform_matrix_3_f32_slice( &self, location: Option<&Self::UniformLocation>, @@ -1910,6 +1961,57 @@ impl HasContext for Context { } } + unsafe fn uniform_matrix_3x4_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + let gl = &self.raw; + if let Some(loc) = location { + gl.UniformMatrix3x4fv( + loc.0 as i32, + v.len() as i32 / 12, + transpose as u8, + v.as_ptr(), + ); + } + } + + unsafe fn uniform_matrix_4x2_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + let gl = &self.raw; + if let Some(loc) = location { + gl.UniformMatrix4x2fv( + loc.0 as i32, + v.len() as i32 / 8, + transpose as u8, + v.as_ptr(), + ); + } + } + + unsafe fn uniform_matrix_4x3_f32_slice( + &self, + location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + let gl = &self.raw; + if let Some(loc) = location { + gl.UniformMatrix4x3fv( + loc.0 as i32, + v.len() as i32 / 12, + transpose as u8, + v.as_ptr(), + ); + } + } + unsafe fn uniform_matrix_4_f32_slice( &self, location: Option<&Self::UniformLocation>, diff --git a/src/web_sys.rs b/src/web_sys.rs index 157cd42..ba48293 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -3535,6 +3535,54 @@ impl HasContext for Context { } } + unsafe fn uniform_matrix_2x3_f32_slice( + &self, + uniform_location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + match self.raw { + RawRenderingContext::WebGl1(ref gl) => { + panic!("2x3 matrices not supported in uniforms"); + } + RawRenderingContext::WebGl2(ref gl) => { + gl.uniform_matrix2x3fv_with_f32_array(uniform_location, transpose, v) + } + } + } + + unsafe fn uniform_matrix_2x4_f32_slice( + &self, + uniform_location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + match self.raw { + RawRenderingContext::WebGl1(ref gl) => { + panic!("2x4 matrices not supported in uniforms"); + } + RawRenderingContext::WebGl2(ref gl) => { + gl.uniform_matrix2x4fv_with_f32_array(uniform_location, transpose, v) + } + } + } + + unsafe fn uniform_matrix_3x2_f32_slice( + &self, + uniform_location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + match self.raw { + RawRenderingContext::WebGl1(ref gl) => { + panic!("3x2 matrices not supported in uniforms"); + } + RawRenderingContext::WebGl2(ref gl) => { + gl.uniform_matrix3x2fv_with_f32_array(uniform_location, transpose, v) + } + } + } + unsafe fn uniform_matrix_3_f32_slice( &self, uniform_location: Option<&Self::UniformLocation>, @@ -3551,6 +3599,54 @@ impl HasContext for Context { } } + unsafe fn uniform_matrix_3x4_f32_slice( + &self, + uniform_location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + match self.raw { + RawRenderingContext::WebGl1(ref gl) => { + panic!("3x4 matrices not supported in uniforms"); + } + RawRenderingContext::WebGl2(ref gl) => { + gl.uniform_matrix3x4fv_with_f32_array(uniform_location, transpose, v) + } + } + } + + unsafe fn uniform_matrix_4x2_f32_slice( + &self, + uniform_location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + match self.raw { + RawRenderingContext::WebGl1(ref gl) => { + panic!("4x2 matrices not supported in uniforms"); + } + RawRenderingContext::WebGl2(ref gl) => { + gl.uniform_matrix4x2fv_with_f32_array(uniform_location, transpose, v) + } + } + } + + unsafe fn uniform_matrix_4x3_f32_slice( + &self, + uniform_location: Option<&Self::UniformLocation>, + transpose: bool, + v: &[f32], + ) { + match self.raw { + RawRenderingContext::WebGl1(ref gl) => { + panic!("4x3 matrices not supported in uniforms"); + } + RawRenderingContext::WebGl2(ref gl) => { + gl.uniform_matrix4x3fv_with_f32_array(uniform_location, transpose, v) + } + } + } + unsafe fn uniform_matrix_4_f32_slice( &self, uniform_location: Option<&Self::UniformLocation>,