gdritter repos chenoska / 75e972a
Add V3D and make some things nullable Getty Ritter 6 years ago
3 changed file(s) with 59 addition(s) and 10 deletion(s). Collapse all Expand all
99 LinkError(String),
1010 GlutinCreation(glutin::CreationError),
1111 GlutinContext(glutin::ContextError),
12 OtherError(String),
1213 }
1314
1415 impl convert::From<glutin::CreationError> for Error {
302302
303303 pub fn bind_uv(&self, name: &str) -> Result<(), Error> {
304304 let attr = self.data.program.get_attrib_location(name)?;
305 let (offset, num) = Vtx::uv_location();
305 let (offset, num) = match Vtx::uv_location() {
306 Some(p) => p,
307 None => return Err(Error::OtherError(
308 "No UV data for associated vertex".to_owned())),
309 };
306310 unsafe {
307311 let off = ptr::null::<u8>().offset(
308312 (mem::size_of::<gl::GLfloat>() * offset as usize) as isize);
11 #![allow(dead_code)]
22 use gl;
33 use std::mem;
4
5 /// A trait defined on each type used to create a VBO
6 pub trait Vertex {
7 fn size() -> i32;
8 fn pos_location() -> (i32, i32);
9 fn uv_location() -> Option<(i32, i32)>;
10 fn normal_location() -> Option<(i32, i32)>;
11 }
412
513 pub struct V2D {
614 pub x: gl::GLfloat,
2028 }
2129 }
2230
23
24 pub trait Vertex {
25 fn size() -> i32;
26 fn pos_location() -> (i32, i32);
27 fn uv_location() -> (i32, i32);
28 }
29
3031 impl Vertex for V2D {
3132 fn size() -> i32 {
3233 mem::size_of::<V2D>() as i32
3637 (0, 2)
3738 }
3839
39 fn uv_location() -> (i32, i32) {
40 (2, 2)
40 fn uv_location() -> Option<(i32, i32)> {
41 Some((2, 2))
42 }
43
44 fn normal_location() -> Option<(i32, i32)> {
45 None
4146 }
4247 }
48
49
50 pub struct V3D {
51 pub x: gl::GLfloat,
52 pub y: gl::GLfloat,
53 pub z: gl::GLfloat,
54 pub u: gl::GLfloat,
55 pub v: gl::GLfloat,
56 }
57
58 impl V3D {
59 fn new(
60 x: gl::GLfloat,
61 y: gl::GLfloat,
62 z: gl::GLfloat,
63 u: gl::GLfloat,
64 v: gl::GLfloat,
65 ) -> V3D {
66 V3D { x, y, z, u, v }
67 }
68 }
69
70 impl Vertex for V3D {
71 fn size() -> i32 {
72 mem::size_of::<V3D>() as i32
73 }
74
75 fn pos_location() -> (i32, i32) {
76 (0, 3)
77 }
78
79 fn uv_location() -> Option<(i32, i32)> {
80 Some((3, 2))
81 }
82
83 fn normal_location() -> Option<(i32, i32)> {
84 None
85 }
86 }