Skip to content

Commit

Permalink
feat: add named_buffer_{data_size,sub_data_u8_slice}
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin authored and grovesNL committed Jan 3, 2024
1 parent e33eebf commit 908cad7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,21 @@ pub trait HasContext {

unsafe fn buffer_data_size(&self, target: u32, size: i32, usage: u32);

unsafe fn named_buffer_data_size(&self, buffer: Self::Buffer, size: i32, usage: u32);

unsafe fn buffer_data_u8_slice(&self, target: u32, data: &[u8], usage: u32);

unsafe fn named_buffer_data_u8_slice(&self, buffer: Self::Buffer, data: &[u8], usage: u32);

unsafe fn buffer_sub_data_u8_slice(&self, target: u32, offset: i32, src_data: &[u8]);

unsafe fn named_buffer_sub_data_u8_slice(
&self,
buffer: Self::Buffer,
offset: i32,
src_data: &[u8],
);

unsafe fn get_buffer_sub_data(&self, target: u32, offset: i32, dst_data: &mut [u8]);

unsafe fn buffer_storage(&self, target: u32, size: i32, data: Option<&[u8]>, flags: u32);
Expand Down
20 changes: 20 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ impl HasContext for Context {
gl.BufferData(target, size as isize, std::ptr::null(), usage);
}

unsafe fn named_buffer_data_size(&self, buffer: Self::Buffer, size: i32, usage: u32) {
let gl = &self.raw;
gl.NamedBufferData(buffer.0.get(), size as isize, std::ptr::null(), usage);
}

unsafe fn buffer_data_u8_slice(&self, target: u32, data: &[u8], usage: u32) {
let gl = &self.raw;
gl.BufferData(
Expand Down Expand Up @@ -701,6 +706,21 @@ impl HasContext for Context {
);
}

unsafe fn named_buffer_sub_data_u8_slice(
&self,
buffer: Self::Buffer,
offset: i32,
src_data: &[u8],
) {
let gl = &self.raw;
gl.NamedBufferSubData(
buffer.0.get(),
offset as isize,
src_data.len() as isize,
src_data.as_ptr() as *const std::ffi::c_void,
);
}

unsafe fn get_buffer_sub_data(&self, target: u32, offset: i32, dst_data: &mut [u8]) {
let gl = &self.raw;
gl.GetBufferSubData(
Expand Down
13 changes: 13 additions & 0 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,10 @@ impl HasContext for Context {
}
}

unsafe fn named_buffer_data_size(&self, _buffer: Self::Buffer, _size: i32, _usage: u32) {
unimplemented!()
}

unsafe fn buffer_data_u8_slice(&self, target: u32, data: &[u8], usage: u32) {
match self.raw {
RawRenderingContext::WebGl1(ref gl) => {
Expand Down Expand Up @@ -2057,6 +2061,15 @@ impl HasContext for Context {
}
}

unsafe fn named_buffer_sub_data_u8_slice(
&self,
_buffer: Self::Buffer,
_offset: i32,
_src_data: &[u8],
) {
unimplemented!()
}

unsafe fn get_buffer_sub_data(&self, target: u32, offset: i32, dst_data: &mut [u8]) {
match self.raw {
RawRenderingContext::WebGl1(ref _gl) => panic!("get_buffer_sub_data not supported"),
Expand Down

0 comments on commit 908cad7

Please sign in to comment.