glow
glow copied to clipboard
passing null pointers to glBufferData/glBufferNamedData (orphaning)
So it looks like, in theory, glBufferData
and glNamedBufferData
support passing a null pointer to the data argument, which tells the driver to orphan the old data and allocate new space. Doing this seems to be a performance optimization in some cases (when you want to update a buffer the gpu is currently reading for a draw call)
Right now in glow, these functions are replaced by type-explicit ones, ie. named_buffer_data_u8_slice
, so it doesn't look like there's a way for me to try out this orphaning concept yet. Would this be something okay to add to glow?
I imagine it would have to be some new function like named_buffer_data_null
, or outright including named_buffer_data
but making the data argument Option<&[u8]>
- working similar to how glow handles buffer_storage
. I definitely wouldn't want to introduce a breaking change to the API though, I'm just curious if either of these would be a fine addition?
i believe the functions would just look like this:
unsafe fn buffer_data_null(&self, target: u32, length: isize, usage: u32) {
let gl = &self.raw;
gl.BufferData(
target,
length,
std::ptr::null() as *const std::ffi::c_void,
usage,
);
}
unsafe fn named_buffer_data_null(&mut self, buffer: glow::Buffer, length: isize, usage: u32) {
let gl = &self.raw;
gl.NamedBufferData(
buffer.0.get(),
length,
std::ptr::null() as *const std::ffi::c_void,
usage,
);
}
A small breaking change to the API to support Option
would probably be ok. We could add the extra null functions but maybe it would be slightly more consistent to accept Option