From 055837db326b75dcc29d7cccdedf3b682d64a09f Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 9 Aug 2024 16:53:49 -0400 Subject: [PATCH 1/9] Add `glClearNamedFramebuffer*` --- src/lib.rs | 33 +++++++++++++++++++++++++ src/native.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/web_sys.rs | 41 +++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 240e4af..7ac0479 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -571,6 +571,39 @@ pub trait HasContext: __private::Sealed { stencil: i32, ); + unsafe fn clear_named_framebuffer_i32_slice( + &self, + framebuffer: Option, + target: u32, + draw_buffer: u32, + values: &[i32], + ); + + unsafe fn clear_named_framebuffer_u32_slice( + &self, + framebuffer: Option, + target: u32, + draw_buffer: u32, + values: &[u32], + ); + + unsafe fn clear_named_framebuffer_f32_slice( + &self, + framebuffer: Option, + target: u32, + draw_buffer: u32, + values: &[f32], + ); + + unsafe fn clear_named_framebuffer_depth_stencil( + &self, + framebuffer: Option, + target: u32, + draw_buffer: u32, + depth: f32, + stencil: i32, + ); + unsafe fn client_wait_sync(&self, fence: Self::Fence, flags: u32, timeout: i32) -> u32; unsafe fn wait_sync(&self, fence: Self::Fence, flags: u32, timeout: u64); diff --git a/src/native.rs b/src/native.rs index 5db0445..8118047 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1342,6 +1342,72 @@ impl HasContext for Context { gl.ClearBufferfi(target, draw_buffer as i32, depth, stencil); } + unsafe fn clear_named_framebuffer_i32_slice( + &self, + framebuffer: Option, + target: u32, + draw_buffer: u32, + values: &[i32], + ) { + let gl = &self.raw; + gl.ClearNamedFramebufferiv( + framebuffer.map(|f| f.0.get()).unwrap_or(0), + target, + draw_buffer as i32, + values.as_ptr(), + ); + } + + unsafe fn clear_named_framebuffer_u32_slice( + &self, + framebuffer: Option, + target: u32, + draw_buffer: u32, + values: &[u32], + ) { + let gl = &self.raw; + gl.ClearNamedFramebufferuiv( + framebuffer.map(|f| f.0.get()).unwrap_or(0), + target, + draw_buffer as i32, + values.as_ptr(), + ); + } + + unsafe fn clear_named_framebuffer_f32_slice( + &self, + framebuffer: Option, + target: u32, + draw_buffer: u32, + values: &[f32], + ) { + let gl = &self.raw; + gl.ClearNamedFramebufferfv( + framebuffer.map(|f| f.0.get()).unwrap_or(0), + target, + draw_buffer as i32, + values.as_ptr(), + ); + } + + unsafe fn clear_named_framebuffer_depth_stencil( + &self, + framebuffer: Option, + target: u32, + draw_buffer: u32, + depth: f32, + stencil: i32, + ) { + let gl = &self.raw; + gl.ClearNamedFramebufferfi( + framebuffer.map(|f| f.0.get()).unwrap_or(0), + target, + draw_buffer as i32, + depth, + stencil, + ); + } + unsafe fn client_wait_sync(&self, fence: Self::Fence, flags: u32, timeout: i32) -> u32 { let gl = &self.raw; gl.ClientWaitSync(fence.0, flags, timeout as u64) diff --git a/src/web_sys.rs b/src/web_sys.rs index 003d9b4..b3958f4 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -2664,6 +2664,47 @@ impl HasContext for Context { } } + unsafe fn clear_named_framebuffer_i32_slice( + &self, + _framebuffer: Option, + _target: u32, + _draw_buffer: u32, + _values: &[i32], + ) { + panic!("Named framebuffers are not supported"); + } + + unsafe fn clear_named_framebuffer_u32_slice( + &self, + _framebuffer: Option, + _target: u32, + _draw_buffer: u32, + _values: &[u32], + ) { + panic!("Named framebuffers are not supported"); + } + + unsafe fn clear_named_framebuffer_f32_slice( + &self, + _framebuffer: Option, + _target: u32, + _draw_buffer: u32, + _values: &[f32], + ) { + panic!("Named framebuffers are not supported"); + } + + unsafe fn clear_named_framebuffer_depth_stencil( + &self, + _framebuffer: Option, + _target: u32, + _draw_buffer: u32, + _depth: f32, + _stencil: i32, + ) { + panic!("Named framebuffers are not supported"); + } + unsafe fn client_wait_sync(&self, fence: Self::Fence, flags: u32, timeout: i32) -> u32 { let fences = self.fences.borrow(); let raw_fence = fences.get_unchecked(fence); From 1beb03f19e62820b1b9d00b120f6f18c713d0072 Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 9 Aug 2024 16:59:07 -0400 Subject: [PATCH 2/9] Add `glCheckNamedFramebufferStatus` --- src/lib.rs | 6 ++++++ src/native.rs | 9 +++++++++ src/web_sys.rs | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 7ac0479..1d3ae36 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -557,6 +557,12 @@ pub trait HasContext: __private::Sealed { unsafe fn check_framebuffer_status(&self, target: u32) -> u32; + unsafe fn check_named_framebuffer_status( + &self, + framebuffer: Option, + target: u32, + ) -> u32; + unsafe fn clear_buffer_i32_slice(&self, target: u32, draw_buffer: u32, values: &[i32]); unsafe fn clear_buffer_u32_slice(&self, target: u32, draw_buffer: u32, values: &[u32]); diff --git a/src/native.rs b/src/native.rs index 8118047..b46a263 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1316,6 +1316,15 @@ impl HasContext for Context { gl.CheckFramebufferStatus(target) } + unsafe fn check_named_framebuffer_status( + &self, + framebuffer: Option, + target: u32, + ) -> u32 { + let gl = &self.raw; + gl.CheckNamedFramebufferStatus(framebuffer.map(|f| f.0.get()).unwrap_or(0), target) + } + unsafe fn clear_buffer_i32_slice(&self, target: u32, draw_buffer: u32, values: &[i32]) { let gl = &self.raw; gl.ClearBufferiv(target, draw_buffer as i32, values.as_ptr()); diff --git a/src/web_sys.rs b/src/web_sys.rs index b3958f4..66543f4 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -2614,6 +2614,14 @@ impl HasContext for Context { } } + unsafe fn check_named_framebuffer_status( + &self, + _framebuffer: Option, + _target: u32, + ) -> u32 { + panic!("Named framebuffers are not supported"); + } + unsafe fn clear_buffer_i32_slice(&self, target: u32, draw_buffer: u32, values: &[i32]) { match self.raw { RawRenderingContext::WebGl1(ref _gl) => { From cfc0b9077bb419768c5daa86d5a2e16ff50f7ae7 Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 9 Aug 2024 17:09:12 -0400 Subject: [PATCH 3/9] Add `glNamedFramebufferTexture*` and `glNamedFramebufferRenderBuffer` --- src/lib.rs | 25 +++++++++++++++++++++++++ src/native.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/web_sys.rs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 1d3ae36..4c1e610 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -820,6 +820,31 @@ pub trait HasContext: __private::Sealed { layer: i32, ); + unsafe fn named_framebuffer_renderbuffer( + &self, + framebuffer: Option, + attachment: u32, + renderbuffer_target: u32, + renderbuffer: Option, + ); + + unsafe fn named_framebuffer_texture( + &self, + framebuffer: Option, + attachment: u32, + texture: Option, + level: i32, + ); + + unsafe fn named_framebuffer_texture_layer( + &self, + framebuffer: Option, + attachment: u32, + texture: Option, + level: i32, + layer: i32, + ); + unsafe fn front_face(&self, value: u32); unsafe fn get_error(&self) -> u32; diff --git a/src/native.rs b/src/native.rs index b46a263..b83c129 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1845,6 +1845,56 @@ impl HasContext for Context { ); } + unsafe fn named_framebuffer_renderbuffer( + &self, + framebuffer: Option, + attachment: u32, + renderbuffer_target: u32, + renderbuffer: Option, + ) { + let gl = &self.raw; + gl.NamedFramebufferRenderbuffer( + framebuffer.map(|f| f.0.get()).unwrap_or(0), + attachment, + renderbuffer_target, + renderbuffer.map(|rb| rb.0.get()).unwrap_or(0), + ); + } + + unsafe fn named_framebuffer_texture( + &self, + framebuffer: Option, + attachment: u32, + texture: Option, + level: i32, + ) { + let gl = &self.raw; + gl.NamedFramebufferTexture( + framebuffer.map(|f| f.0.get()).unwrap_or(0), + attachment, + texture.map(|t| t.0.get()).unwrap_or(0), + level, + ); + } + + unsafe fn named_framebuffer_texture_layer( + &self, + framebuffer: Option, + attachment: u32, + texture: Option, + level: i32, + layer: i32, + ) { + let gl = &self.raw; + gl.NamedFramebufferTextureLayer( + framebuffer.map(|f| f.0.get()).unwrap_or(0), + attachment, + texture.map(|t| t.0.get()).unwrap_or(0), + level, + layer, + ); + } + unsafe fn front_face(&self, value: u32) { let gl = &self.raw; gl.FrontFace(value as u32); diff --git a/src/web_sys.rs b/src/web_sys.rs index 66543f4..7311e96 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -3214,6 +3214,37 @@ impl HasContext for Context { } } + unsafe fn named_framebuffer_renderbuffer( + &self, + _framebuffer: Option, + _attachment: u32, + _renderbuffer_target: u32, + _renderbuffer: Option, + ) { + panic!("Named framebuffers are not supported"); + } + + unsafe fn named_framebuffer_texture( + &self, + _framebuffer: Option, + _attachment: u32, + _texture: Option, + _level: i32, + ) { + panic!("Named framebuffers are not supported"); + } + + unsafe fn named_framebuffer_texture_layer( + &self, + _framebuffer: Option, + _attachment: u32, + _texture: Option, + _level: i32, + _layer: i32, + ) { + panic!("Named framebuffers are not supported"); + } + unsafe fn front_face(&self, value: u32) { match self.raw { RawRenderingContext::WebGl1(ref gl) => gl.front_face(value as u32), From ad84650efda3aac0b0d7bd01176ed35a87b160d8 Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 9 Aug 2024 17:13:29 -0400 Subject: [PATCH 4/9] Add `glNamedFramebufferReadBuffer` and `glNamedFramebufferDrawBuffer` --- src/lib.rs | 12 ++++++++++++ src/native.rs | 18 ++++++++++++++++++ src/web_sys.rs | 16 ++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4c1e610..7a57252 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -719,6 +719,12 @@ pub trait HasContext: __private::Sealed { unsafe fn draw_buffer(&self, buffer: u32); + unsafe fn named_framebuffer_draw_buffer( + &self, + framebuffer: Option, + draw_buffer: u32, + ); + unsafe fn draw_buffers(&self, buffers: &[u32]); unsafe fn draw_elements(&self, mode: u32, count: i32, element_type: u32, offset: i32); @@ -1623,6 +1629,12 @@ pub trait HasContext: __private::Sealed { unsafe fn read_buffer(&self, src: u32); + unsafe fn named_framebuffer_read_buffer( + &self, + framebuffer: Option, + src: u32, + ); + unsafe fn read_pixels( &self, x: i32, diff --git a/src/native.rs b/src/native.rs index b83c129..edbcdab 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1629,6 +1629,15 @@ impl HasContext for Context { gl.DrawBuffer(draw_buffer); } + unsafe fn named_framebuffer_draw_buffer( + &self, + framebuffer: Option, + draw_buffer: u32, + ) { + let gl = &self.raw; + gl.NamedFramebufferDrawBuffer(framebuffer.map(|f| f.0.get()).unwrap_or(0), draw_buffer); + } + unsafe fn draw_buffers(&self, buffers: &[u32]) { let gl = &self.raw; gl.DrawBuffers(buffers.len() as i32, buffers.as_ptr()); @@ -3703,6 +3712,15 @@ impl HasContext for Context { gl.ReadBuffer(src); } + unsafe fn named_framebuffer_read_buffer( + &self, + framebuffer: Option, + src: u32, + ) { + let gl = &self.raw; + gl.NamedFramebufferReadBuffer(framebuffer.map(|f| f.0.get()).unwrap_or(0), src); + } + unsafe fn read_pixels( &self, x: i32, diff --git a/src/web_sys.rs b/src/web_sys.rs index 7311e96..f16828a 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -2986,6 +2986,14 @@ impl HasContext for Context { } } + unsafe fn named_framebuffer_draw_buffer( + &self, + _framebuffer: Option, + _draw_buffer: u32, + ) { + panic!("Named framebuffers are not supported"); + } + unsafe fn draw_buffers(&self, buffers: &[u32]) { match self.raw { RawRenderingContext::WebGl1(ref _gl) => { @@ -5204,6 +5212,14 @@ impl HasContext for Context { } } + unsafe fn named_framebuffer_read_buffer( + &self, + _framebuffer: Option, + _src: u32, + ) { + panic!("Named framebuffers are not supported"); + } + unsafe fn read_pixels( &self, x: i32, From ec1f7d73c520c2309062b8dedbcf7e667d3c9e80 Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 9 Aug 2024 17:17:41 -0400 Subject: [PATCH 5/9] Add `glBlitNamedFramebuffer` --- src/lib.rs | 16 ++++++++++++++++ src/native.rs | 32 ++++++++++++++++++++++++++++++++ src/web_sys.rs | 18 ++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 7a57252..1da08c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -508,6 +508,22 @@ pub trait HasContext: __private::Sealed { filter: u32, ); + unsafe fn blit_named_framebuffer( + &self, + read_buffer: Option, + draw_buffer: Option, + src_x0: i32, + src_y0: i32, + src_x1: i32, + src_y1: i32, + dst_x0: i32, + dst_y0: i32, + dst_x1: i32, + dst_y1: i32, + mask: u32, + filter: u32, + ); + unsafe fn create_vertex_array(&self) -> Result; unsafe fn delete_vertex_array(&self, vertex_array: Self::VertexArray); diff --git a/src/native.rs b/src/native.rs index edbcdab..5e3e9c0 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1159,6 +1159,38 @@ impl HasContext for Context { ); } + unsafe fn blit_named_framebuffer( + &self, + read_buffer: Option, + draw_buffer: Option, + src_x0: i32, + src_y0: i32, + src_x1: i32, + src_y1: i32, + dst_x0: i32, + dst_y0: i32, + dst_x1: i32, + dst_y1: i32, + mask: u32, + filter: u32, + ) { + let gl = &self.raw; + gl.BlitNamedFramebuffer( + read_buffer.map(|f| f.0.get()).unwrap_or(0), + draw_buffer.map(|f| f.0.get()).unwrap_or(0), + src_x0, + src_y0, + src_x1, + src_y1, + dst_x0, + dst_y0, + dst_x1, + dst_y1, + mask, + filter, + ); + } + unsafe fn create_vertex_array(&self) -> Result { let gl = &self.raw; let mut vertex_array = 0; diff --git a/src/web_sys.rs b/src/web_sys.rs index f16828a..13e8d12 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -2431,6 +2431,24 @@ impl HasContext for Context { } } + unsafe fn blit_named_framebuffer( + &self, + _read_buffer: Option, + _draw_buffer: Option, + _src_x0: i32, + _src_y0: i32, + _src_x1: i32, + _src_y1: i32, + _dst_x0: i32, + _dst_y0: i32, + _dst_x1: i32, + _dst_y1: i32, + _mask: u32, + _filter: u32, + ) { + panic!("Named framebuffers are not supported"); + } + unsafe fn create_vertex_array(&self) -> Result { let raw_vertex_array = match self.raw { RawRenderingContext::WebGl1(ref _gl) => { From 64dc44e6f9d703fff3098fc7c34e833f3a68fb76 Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 9 Aug 2024 17:28:28 -0400 Subject: [PATCH 6/9] Add `glGetFramebufferAttachmentParameter` and `glGetFramebufferParameter` --- src/lib.rs | 22 ++++++++++++++++++++++ src/native.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/web_sys.rs | 43 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 1da08c7..b5605ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, + 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, + attachment: u32, + parameter: u32, + ) -> i32; + unsafe fn get_active_uniform_block_parameter_i32( &self, program: Self::Program, diff --git a/src/native.rs b/src/native.rs index 5e3e9c0..e4a1938 100644 --- a/src/native.rs +++ b/src/native.rs @@ -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, + 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, + 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, diff --git a/src/web_sys.rs b/src/web_sys.rs index 13e8d12..34ffe6a 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -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, + _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, + _attachment: u32, + _parameter: u32, + ) -> i32 { + panic!("Named framebuffers are not supported"); + } + unsafe fn get_uniform_location( &self, program: Self::Program, From 9000e31dfee9dc2e725ce974fe3f9c7b8f7e097a Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 9 Aug 2024 18:47:45 -0400 Subject: [PATCH 7/9] Add `glCreateVertexArrays` as `create_named_vertex_array` --- src/lib.rs | 2 ++ src/native.rs | 7 +++++++ src/web_sys.rs | 3 +++ 3 files changed, 12 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b5605ac..a191a66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -526,6 +526,8 @@ pub trait HasContext: __private::Sealed { unsafe fn create_vertex_array(&self) -> Result; + unsafe fn create_named_vertex_array(&self) -> Result; + unsafe fn delete_vertex_array(&self, vertex_array: Self::VertexArray); unsafe fn bind_vertex_array(&self, vertex_array: Option); diff --git a/src/native.rs b/src/native.rs index e4a1938..80dca2d 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1198,6 +1198,13 @@ impl HasContext for Context { Ok(NativeVertexArray(non_zero_gl_name(vertex_array))) } + unsafe fn create_named_vertex_array(&self) -> Result { + let gl = &self.raw; + let mut vertex_array = 0; + gl.CreateVertexArrays(1, &mut vertex_array); + Ok(NativeVertexArray(non_zero_gl_name(vertex_array))) + } + unsafe fn delete_vertex_array(&self, vertex_array: Self::VertexArray) { let gl = &self.raw; gl.DeleteVertexArrays(1, &vertex_array.0.get()); diff --git a/src/web_sys.rs b/src/web_sys.rs index 34ffe6a..41c7007 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -2469,6 +2469,9 @@ impl HasContext for Context { } } + unsafe fn create_named_vertex_array(&self) -> Result { + unimplemented!() + } unsafe fn delete_vertex_array(&self, vertex_array: Self::VertexArray) { let mut vertex_arrays = self.vertex_arrays.borrow_mut(); if let Some(ref va) = vertex_arrays.remove(vertex_array) { From 21509148f502be220ce950e17d978d2c13ebb208 Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 9 Aug 2024 18:59:06 -0400 Subject: [PATCH 8/9] Add `glCreateFramebuffers` --- src/lib.rs | 2 ++ src/native.rs | 7 +++++++ src/web_sys.rs | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a191a66..8c3a8f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,6 +122,8 @@ pub trait HasContext: __private::Sealed { unsafe fn create_framebuffer(&self) -> Result; + unsafe fn create_named_framebuffer(&self) -> Result; + unsafe fn is_framebuffer(&self, framebuffer: Self::Framebuffer) -> bool; unsafe fn create_query(&self) -> Result; diff --git a/src/native.rs b/src/native.rs index 80dca2d..70014d7 100644 --- a/src/native.rs +++ b/src/native.rs @@ -220,6 +220,13 @@ impl HasContext for Context { Ok(NativeFramebuffer(non_zero_gl_name(name))) } + unsafe fn create_named_framebuffer(&self) -> Result { + let gl = &self.raw; + let mut name = 0; + gl.CreateFramebuffers(1, &mut name); + Ok(NativeFramebuffer(non_zero_gl_name(name))) + } + unsafe fn is_framebuffer(&self, framebuffer: Self::Framebuffer) -> bool { let gl = &self.raw; gl.IsFramebuffer(framebuffer.0.get()) != 0 diff --git a/src/web_sys.rs b/src/web_sys.rs index 41c7007..d415004 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -1587,6 +1587,10 @@ impl HasContext for Context { } } + unsafe fn create_named_framebuffer(&self) -> Result { + panic!("Named framebuffers are not supported"); + } + unsafe fn is_framebuffer(&self, framebuffer: Self::Framebuffer) -> bool { let framebuffers = self.framebuffers.borrow_mut(); if let Some(ref f) = framebuffers.get(framebuffer) { From c9f51bd6921093cad4d174db590aba7f035b197c Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 9 Aug 2024 19:01:02 -0400 Subject: [PATCH 9/9] Add `glNamedFramebufferDrawBuffers` --- src/lib.rs | 6 ++++++ src/native.rs | 13 +++++++++++++ src/web_sys.rs | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8c3a8f2..86856f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -745,6 +745,12 @@ pub trait HasContext: __private::Sealed { draw_buffer: u32, ); + unsafe fn named_framebuffer_draw_buffers( + &self, + framebuffer: Option, + buffers: &[u32], + ); + unsafe fn draw_buffers(&self, buffers: &[u32]); unsafe fn draw_elements(&self, mode: u32, count: i32, element_type: u32, offset: i32); diff --git a/src/native.rs b/src/native.rs index 70014d7..197a7c1 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1689,6 +1689,19 @@ impl HasContext for Context { gl.DrawBuffers(buffers.len() as i32, buffers.as_ptr()); } + unsafe fn named_framebuffer_draw_buffers( + &self, + framebuffer: Option, + buffers: &[u32], + ) { + let gl = &self.raw; + gl.NamedFramebufferDrawBuffers( + framebuffer.map(|f| f.0.get()).unwrap_or(0), + buffers.len() as i32, + buffers.as_ptr(), + ); + } + unsafe fn draw_elements(&self, mode: u32, count: i32, element_type: u32, offset: i32) { let gl = &self.raw; gl.DrawElements( diff --git a/src/web_sys.rs b/src/web_sys.rs index d415004..fd4524d 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -3042,6 +3042,14 @@ impl HasContext for Context { } } + unsafe fn named_framebuffer_draw_buffers( + &self, + _framebuffer: Option, + _draw_buffers: &[u32], + ) { + panic!("Named framebuffers are not supported"); + } + unsafe fn draw_elements(&self, mode: u32, count: i32, element_type: u32, offset: i32) { match self.raw { RawRenderingContext::WebGl1(ref gl) => {