Skip to content

Commit

Permalink
feat: add bind_texture_unit, texture_{storage,sub_image}_2d
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Dec 24, 2023
1 parent c4a5f71 commit 196d00c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,15 @@ pub trait HasContext {
height: i32,
);

unsafe fn texture_storage_2d(
&self,
texture: Self::Texture,
levels: i32,
internal_format: u32,
width: i32,
height: i32,
);

unsafe fn tex_storage_2d_multisample(
&self,
target: u32,
Expand Down Expand Up @@ -915,6 +924,8 @@ pub trait HasContext {

unsafe fn bind_texture(&self, target: u32, texture: Option<Self::Texture>);

unsafe fn bind_texture_unit(&self, unit: u32, texture: Option<Self::Texture>);

unsafe fn bind_sampler(&self, unit: u32, sampler: Option<Self::Sampler>);

unsafe fn active_texture(&self, unit: u32);
Expand Down Expand Up @@ -944,6 +955,19 @@ pub trait HasContext {
pixels: PixelUnpackData,
);

unsafe fn texture_sub_image_2d(
&self,
texture: Self::Texture,
level: i32,
x_offset: i32,
y_offset: i32,
width: i32,
height: i32,
format: u32,
ty: u32,
pixels: PixelUnpackData,
);

unsafe fn compressed_tex_sub_image_2d(
&self,
target: u32,
Expand Down
46 changes: 46 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,18 @@ impl HasContext for Context {
gl.TexStorage2D(target, levels, internal_format, width, height);
}

unsafe fn texture_storage_2d(
&self,
texture: Self::Texture,
levels: i32,
internal_format: u32,
width: i32,
height: i32,
) {
let gl = &self.raw;
gl.TextureStorage2D(texture.0.get(), levels, internal_format, width, height);
}

unsafe fn tex_storage_2d_multisample(
&self,
target: u32,
Expand Down Expand Up @@ -2120,6 +2132,11 @@ impl HasContext for Context {
gl.BindTexture(target, texture.map(|t| t.0.get()).unwrap_or(0));
}

unsafe fn bind_texture_unit(&self, unit: u32, texture: Option<Self::Texture>) {
let gl = &self.raw;
gl.BindTextureUnit(unit, texture.map(|t| t.0.get()).unwrap_or(0));
}

unsafe fn bind_sampler(&self, unit: u32, sampler: Option<Self::Sampler>) {
let gl = &self.raw;
gl.BindSampler(unit, sampler.map(|s| s.0.get()).unwrap_or(0));
Expand Down Expand Up @@ -2189,6 +2206,35 @@ impl HasContext for Context {
);
}

unsafe fn texture_sub_image_2d(
&self,
texture: Self::Texture,
level: i32,
x_offset: i32,
y_offset: i32,
width: i32,
height: i32,
format: u32,
ty: u32,
pixels: PixelUnpackData,
) {
let gl = &self.raw;
gl.TextureSubImage2D(
texture.0.get(),
level,
x_offset,
y_offset,
width,
height,
format,
ty,
match pixels {
PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void,
PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void,
},
);
}

unsafe fn compressed_tex_sub_image_2d(
&self,
target: u32,
Expand Down
30 changes: 30 additions & 0 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3172,6 +3172,17 @@ impl HasContext for Context {
}
}

unsafe fn texture_storage_2d(
&self,
_texture: Self::Texture,
_levels: i32,
_internal_format: u32,
_width: i32,
_height: i32,
) {
unimplemented!()
}

unsafe fn tex_storage_2d_multisample(
&self,
_target: u32,
Expand Down Expand Up @@ -3775,6 +3786,10 @@ impl HasContext for Context {
}
}

unsafe fn bind_texture_unit(&self, _unit: u32, _texture: Option<Self::Texture>) {
unimplemented!()
}

unsafe fn bind_sampler(&self, unit: u32, sampler: Option<Self::Sampler>) {
let samplers = self.samplers.borrow();
let raw_sampler = sampler.map(|s| samplers.get_unchecked(s));
Expand Down Expand Up @@ -3885,6 +3900,21 @@ impl HasContext for Context {
}
}

unsafe fn texture_sub_image_2d(
&self,
_texture: Self::Texture,
_level: i32,
_x_offset: i32,
_y_offset: i32,
_width: i32,
_height: i32,
_format: u32,
_ty: u32,
_pixels: PixelUnpackData,
) {
unimplemented!()
}

unsafe fn texture_sub_image_3d(
&self,
_texture: Self::Texture,
Expand Down

0 comments on commit 196d00c

Please sign in to comment.