| 211 | 211 |
|
| 212 | 212 |
//
|
| 213 | 213 |
|
| 214 | |
pub struct VertexArray {
|
| 214 |
pub struct VertexArray<'p> {
|
| 215 | 215 |
idx: u32,
|
| 216 | |
}
|
| 217 | |
|
| 218 | |
impl Drop for VertexArray {
|
| 216 |
program: &'p Program,
|
| 217 |
}
|
| 218 |
|
| 219 |
impl<'p> Drop for VertexArray<'p> {
|
| 219 | 220 |
fn drop(&mut self) {
|
| 220 | 221 |
unsafe { gl::DeleteVertexArrays(1, &self.idx); }
|
| 221 | 222 |
}
|
| 222 | 223 |
}
|
| 223 | 224 |
|
| 224 | |
pub struct VertexBuffer<Vtx> {
|
| 225 |
pub struct VertexBuffer<'p, Vtx> {
|
| 225 | 226 |
idx: u32,
|
| 226 | |
data: VertexArray,
|
| 227 |
data: VertexArray<'p>,
|
| 227 | 228 |
phantom: PhantomData<Vtx>,
|
| 228 | 229 |
len: usize,
|
| 229 | 230 |
}
|
| 230 | 231 |
|
| 231 | |
impl<Vtx> Drop for VertexBuffer<Vtx> {
|
| 232 |
impl<'p, Vtx> Drop for VertexBuffer<'p, Vtx> {
|
| 232 | 233 |
fn drop(&mut self) {
|
| 233 | 234 |
unsafe { gl::DeleteBuffers(1, &self.idx); }
|
| 234 | 235 |
}
|
| 235 | 236 |
}
|
| 236 | 237 |
|
| 237 | |
impl VertexArray {
|
| 238 | |
pub fn new() -> VertexArray {
|
| 238 |
impl<'p> VertexArray<'p> {
|
| 239 |
pub fn new(program: &'p Program) -> VertexArray<'p> {
|
| 239 | 240 |
let mut idx = 0;
|
| 240 | 241 |
unsafe {
|
| 241 | 242 |
gl::GenVertexArrays(1, &mut idx);
|
| 242 | 243 |
gl::BindVertexArray(idx);
|
| 243 | 244 |
}
|
| 244 | 245 |
|
| 245 | |
VertexArray { idx }
|
| 246 |
VertexArray { idx, program }
|
| 246 | 247 |
}
|
| 247 | 248 |
|
| 248 | 249 |
pub fn bind(&self) {
|
|
| 258 | 259 |
}
|
| 259 | 260 |
}
|
| 260 | 261 |
|
| 261 | |
impl<Vtx: vertices::Vertex> VertexBuffer<Vtx> {
|
| 262 |
impl<'p, Vtx: vertices::Vertex> VertexBuffer<'p, Vtx> {
|
| 262 | 263 |
pub fn new_array_buffer(
|
| 263 | |
data: VertexArray,
|
| 264 |
data: VertexArray<'p>,
|
| 264 | 265 |
vertex_data: &[Vtx],
|
| 265 | |
) -> VertexBuffer<Vtx> {
|
| 266 |
) -> VertexBuffer<'p, Vtx> {
|
| 266 | 267 |
let mut idx = 0;
|
| 267 | 268 |
unsafe {
|
| 268 | 269 |
gl::GenBuffers(1, &mut idx);
|
|
| 280 | 281 |
VertexBuffer { idx, data, phantom, len }
|
| 281 | 282 |
}
|
| 282 | 283 |
|
| 283 | |
pub fn bind_position(&self, p: &Program, name: &str) -> Result<(), Error> {
|
| 284 | |
let attr = p.get_attrib_location(name)?;
|
| 284 |
pub fn bind_position(&self, name: &str) -> Result<(), Error> {
|
| 285 |
let attr = self.data.program.get_attrib_location(name)?;
|
| 285 | 286 |
let (offset, num) = Vtx::pos_location();
|
| 286 | 287 |
unsafe {
|
| 287 | 288 |
let off = ptr::null::<u8>().offset(
|
|
| 299 | 300 |
Ok(())
|
| 300 | 301 |
}
|
| 301 | 302 |
|
| 302 | |
pub fn bind_uv(&self, p: &Program, name: &str) -> Result<(), Error> {
|
| 303 | |
let attr = p.get_attrib_location(name)?;
|
| 303 |
pub fn bind_uv(&self, name: &str) -> Result<(), Error> {
|
| 304 |
let attr = self.data.program.get_attrib_location(name)?;
|
| 304 | 305 |
let (offset, num) = Vtx::uv_location();
|
| 305 | 306 |
unsafe {
|
| 306 | 307 |
let off = ptr::null::<u8>().offset(
|