Add V3D and make some things nullable
Getty Ritter
6 years ago
9 | 9 |
LinkError(String),
|
10 | 10 |
GlutinCreation(glutin::CreationError),
|
11 | 11 |
GlutinContext(glutin::ContextError),
|
| 12 |
OtherError(String),
|
12 | 13 |
}
|
13 | 14 |
|
14 | 15 |
impl convert::From<glutin::CreationError> for Error {
|
302 | 302 |
|
303 | 303 |
pub fn bind_uv(&self, name: &str) -> Result<(), Error> {
|
304 | 304 |
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 |
};
|
306 | 310 |
unsafe {
|
307 | 311 |
let off = ptr::null::<u8>().offset(
|
308 | 312 |
(mem::size_of::<gl::GLfloat>() * offset as usize) as isize);
|
1 | 1 |
#![allow(dead_code)]
|
2 | 2 |
use gl;
|
3 | 3 |
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 |
}
|
4 | 12 |
|
5 | 13 |
pub struct V2D {
|
6 | 14 |
pub x: gl::GLfloat,
|
|
20 | 28 |
}
|
21 | 29 |
}
|
22 | 30 |
|
23 | |
|
24 | |
pub trait Vertex {
|
25 | |
fn size() -> i32;
|
26 | |
fn pos_location() -> (i32, i32);
|
27 | |
fn uv_location() -> (i32, i32);
|
28 | |
}
|
29 | |
|
30 | 31 |
impl Vertex for V2D {
|
31 | 32 |
fn size() -> i32 {
|
32 | 33 |
mem::size_of::<V2D>() as i32
|
|
36 | 37 |
(0, 2)
|
37 | 38 |
}
|
38 | 39 |
|
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
|
41 | 46 |
}
|
42 | 47 |
}
|
| 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 |
}
|