8000 gl: give a buffer a new store each time it's updated by benface · Pull Request #682 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,8 @@ pub trait RenderingBackend {
/// ```
fn new_buffer(&mut self, type_: BufferType, usage: BufferUsage, data: BufferSource)
-> BufferId;
/// Replace the buffer's contents with `data`, which can be shorter than
/// the buffer: what lies past it is undefined afterwards.
fn buffer_update(&mut self, buffer: BufferId, data: BufferSource);

/// Size of buffer in bytes.
Expand Down
9 changes: 8 additions & 1 deletion src/graphics/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub mod raw_gl {
struct Buffer {
gl_buf: GLuint,
buffer_type: BufferType,
/// The `usage` hint its stores get.
gl_usage: GLenum,
size: usize,
// Dimension of the indices for this buffer,
// used only as a type argument for glDrawElements and can be
Expand Down Expand Up @@ -1376,6 +1378,7 @@ impl RenderingBackend for GlContext {
let buffer = Buffer {
gl_buf,
buffer_type: type_,
gl_usage,
size,
index_type,
};
Expand Down Expand Up @@ -1404,7 +1407,11 @@ impl RenderingBackend for GlContext {
self.cache.store_buffer_binding(gl_target);
self.cache
.bind_buffer(gl_target, buffer.gl_buf, buffer.index_type);
unsafe { glBufferSubData(gl_target, 0, size as _, data.ptr as _) };
// A new store for each update, as Metal gives each update a buffer
// of its own. Writing into the store that draws already queued
// still read makes the driver copy it first, and Mali's driver
// waits on all the work it has queued to do so.
unsafe { glBufferData(gl_target, size as _, data.ptr as _, buffer.gl_usage) };
self.cache.restore_buffer_binding(gl_target);
}

Expand Down
Loading
0