Use BufferSubData instead of MapBuffer

This commit is contained in:
Thinkofname 2016-03-19 20:35:31 +00:00
parent 65370ccfe0
commit edee182bf9
4 changed files with 11 additions and 4 deletions

View File

@ -668,6 +668,12 @@ impl Buffer {
}
}
pub fn re_set_data(&self, target: BufferTarget, data: &[u8]) {
unsafe {
gl::BufferSubData(target, 0, data.len() as isize, data.as_ptr() as *const _);
}
}
/// Maps the memory in the buffer on the gpu to memory which the program
/// can access. The access flag will specify how the program plans to use the
/// returned data. It'll unmap itself once the returned value is dropped.

View File

@ -211,6 +211,9 @@ fn handle_window_event(window: &glutin::Window,
}
Event::KeyboardInput(glutin::ElementState::Pressed, key, virt) => {
println!("Key: {:?} {:?}", key, virt);
if virt == Some(VirtualKeyCode::H) {
game.server.world.flag_dirty_all();
}
}
_ => (),

View File

@ -365,8 +365,7 @@ impl Renderer {
info.buffer_size = data.len();
info.buffer.set_data(gl::ARRAY_BUFFER, data, gl::DYNAMIC_DRAW);
} else {
let mut target = info.buffer.map(gl::ARRAY_BUFFER, gl::WRITE_ONLY, data.len());
target.write_all(data).unwrap();
info.buffer.re_set_data(gl::ARRAY_BUFFER, data);
}
self.chunk_shader.position.vertex_pointer(3, gl::FLOAT, false, 40, 0);

View File

@ -169,8 +169,7 @@ impl UIState {
self.prev_size = self.data.len();
self.buffer.set_data(gl::ARRAY_BUFFER, &self.data, gl::STREAM_DRAW);
} else {
let mut target = self.buffer.map(gl::ARRAY_BUFFER, gl::WRITE_ONLY, self.data.len());
target.write_all(&self.data[..]).unwrap();
self.buffer.re_set_data(gl::ARRAY_BUFFER, &self.data);
}
gl::draw_elements(gl::TRIANGLES, self.count, self.index_type, 0);
}