Skip to content

Commit

Permalink
Add glGetFramebufferAttachmentParameter and `glGetFramebufferParame…
Browse files Browse the repository at this point in the history
…ter`
  • Loading branch information
chyyran committed Aug 9, 2024
1 parent ec1f7d7 commit 03ed28e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,28 @@ pub trait HasContext: __private::Sealed {

unsafe fn get_parameter_string(&self, parameter: u32) -> String;

unsafe fn get_framebuffer_parameter_i32(&self, target: u32, parameter: u32) -> i32;

unsafe fn get_named_framebuffer_parameter_i32(
&self,
framebuffer: Option<Self::Framebuffer>,
parameter: u32,
) -> i32;

unsafe fn get_framebuffer_attachment_parameter_i32(
&self,
target: u32,
attachment: u32,
parameter: u32,
) -> i32;

unsafe fn get_named_framebuffer_attachment_parameter_i32(
&self,
framebuffer: Option<Self::Framebuffer>,
attachment: u32,
parameter: u32,
) -> i32;

unsafe fn get_active_uniform_block_parameter_i32(
&self,
program: Self::Program,
Expand Down
51 changes: 51 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,57 @@ impl HasContext for Context {
.to_owned()
}

unsafe fn get_framebuffer_parameter_i32(&self, target: u32, parameter: u32) -> i32 {
let gl = &self.raw;
let mut value = 0;
gl.GetFramebufferParameteriv(target, parameter, &mut value);
value
}

unsafe fn get_named_framebuffer_parameter_i32(
&self,
framebuffer: Option<Self::Framebuffer>,
parameter: u32,
) -> i32 {
let gl = &self.raw;
let mut value = 0;
gl.GetNamedFramebufferParameteriv(
framebuffer.map(|f| f.0.get()).unwrap_or(0),
parameter,
&mut value,
);
value
}

unsafe fn get_framebuffer_attachment_parameter_i32(
&self,
target: u32,
attachment: u32,
parameter: u32,
) -> i32 {
let gl = &self.raw;
let mut value = 0;
gl.GetFramebufferAttachmentParameteriv(target, attachment, parameter, &mut value);
value
}

unsafe fn get_named_framebuffer_attachment_parameter_i32(
&self,
framebuffer: Option<Self::Framebuffer>,
attachment: u32,
parameter: u32,
) -> i32 {
let gl = &self.raw;
let mut value = 0;
gl.GetNamedFramebufferAttachmentParameteriv(
framebuffer.map(|f| f.0.get()).unwrap_or(0),
attachment,
parameter,
&mut value,
);
value
}

unsafe fn get_uniform_location(
&self,
program: Self::Program,
Expand Down
43 changes: 43 additions & 0 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,49 @@ impl HasContext for Context {
.unwrap_or_else(|| String::from(""))
}

unsafe fn get_framebuffer_parameter_i32(&self, _target: u32, _parameter: u32) -> i32 {
panic!("Get framebuffer parameter is not supported");
}

unsafe fn get_named_framebuffer_parameter_i32(
&self,
_framebuffer: Option<Self::Framebuffer>,
_parameter: u32,
) -> i32 {
panic!("Named framebuffers are not supported");
}

unsafe fn get_framebuffer_attachment_parameter_i32(
&self,
target: u32,
attachment: u32,
parameter: u32,
) -> i32 {
match self.raw {
RawRenderingContext::WebGl1(ref gl) => {
gl.get_framebuffer_attachment_parameter(target, attachment, parameter)
}
RawRenderingContext::WebGl2(ref gl) => {
gl.get_framebuffer_attachment_parameter(target, attachment, parameter)
}
}
.unwrap()
.as_f64()
.map(|v| v as i32)
// Errors will be caught by the browser or through `get_error`
// so return a default instead
.unwrap_or(0)
}

unsafe fn get_named_framebuffer_attachment_parameter_i32(
&self,
_framebuffer: Option<Self::Framebuffer>,
_attachment: u32,
_parameter: u32,
) -> i32 {
panic!("Named framebuffers are not supported");
}

unsafe fn get_uniform_location(
&self,
program: Self::Program,
Expand Down

0 comments on commit 03ed28e

Please sign in to comment.