summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2021-01-30 20:54:41 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2021-01-30 21:08:02 -0300
commitc0089dd0567b8d6538360a21f042cbb0913fff99 (patch)
tree9b2ba19e5adc480ff77239d0b596e819ebba0fdc /src/lib.rs
parent8c81561f9eb2922e16e4ce2b81a2b25b2e51ac0f (diff)
downloadbezier-c0089dd0567b8d6538360a21f042cbb0913fff99.tar.gz
bezier-c0089dd0567b8d6538360a21f042cbb0913fff99.zip
Output better error messages for shader programs
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs61
1 files changed, 33 insertions, 28 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 218d5b4..4662f08 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,29 +16,6 @@ pub struct Bezier {
pub dpy: Poly,
}
-pub fn to_poly(v: &Vec<f32>) -> Poly {
- match v.len() {
- 0 => Poly::new(vec![0.0]),
- 1 => Poly::new(vec![v[0]]),
- 2 => Poly::new(vec![v[0], v[1] - v[0]]),
- _ => {
- let mut pv = Vec::new();
- for i in 0..v.len() - 1 {
- pv.push(Poly::new(vec![v[i], v[i + 1] - v[i]]));
- }
- while pv.len() > 1 {
- let mut npv = Vec::new();
- for i in 0..pv.len() - 1 {
- let c = &pv[i + 1] - &pv[i];
- npv.push(&pv[i] + &c.shift());
- }
- pv = npv;
- }
- pv[0].clone()
- }
- }
-}
-
impl Bezier {
pub fn new() -> Bezier {
Bezier {
@@ -169,10 +146,9 @@ impl Bezier {
float inside(vec2 pos) {{
float closest = inf;
float t = 0.0;
- float dstep = 0.0;
- while (t < 1.0 - dstep) {{
- dstep = step_size / length(vec2(eval_dpx(t), eval_dpy(t)));
- float step = t + dstep;
+ while (t < 1.0) {{
+ float dstep = step_size / length(vec2(eval_dpx(t), eval_dpy(t)));
+ float step = min(t + dstep, 1.0);
vec2 a = vec2(eval_px(t), eval_py(t));
vec2 b = vec2(eval_px(step), eval_py(step));
float c = pow(length(a - b), 2);
@@ -226,6 +202,29 @@ impl Bezier {
}
}
+fn to_poly(v: &Vec<f32>) -> Poly {
+ match v.len() {
+ 0 => Poly::new(vec![0.0]),
+ 1 => Poly::new(vec![v[0]]),
+ 2 => Poly::new(vec![v[0], v[1] - v[0]]),
+ _ => {
+ let mut pv = Vec::new();
+ for i in 0..v.len() - 1 {
+ pv.push(Poly::new(vec![v[i], v[i + 1] - v[i]]));
+ }
+ while pv.len() > 1 {
+ let mut npv = Vec::new();
+ for i in 0..pv.len() - 1 {
+ let c = &pv[i + 1] - &pv[i];
+ npv.push(&pv[i] + &c.shift());
+ }
+ pv = npv;
+ }
+ pv[0].clone()
+ }
+ }
+}
+
fn shader_from_source(source: &CStr, shader_type: GLenum) -> GLuint {
unsafe {
let shader: GLuint = gl::CreateShader(shader_type);
@@ -234,7 +233,13 @@ fn shader_from_source(source: &CStr, shader_type: GLenum) -> GLuint {
let mut success: gl::types::GLint = 1;
gl::GetShaderiv(shader, gl::COMPILE_STATUS, &mut success);
if success == 0 {
- println!("Compilation error: {}", source.to_str().unwrap());
+ let mut length: GLint = 0;
+ gl::GetShaderiv(shader, gl::INFO_LOG_LENGTH, &mut length);
+ let mut buffer: Vec<u8> = Vec::with_capacity(length as usize + 1);
+ buffer.extend([b' '].iter().cycle().take(length as usize));
+ let error: CString = CString::from_vec_unchecked(buffer);
+ gl::GetShaderInfoLog(shader, length, std::ptr::null_mut(), error.as_ptr() as *mut GLchar);
+ println!("Compilation error: {}", error.to_str().unwrap());
}
shader
}