Repository: glium/glium (language: rust)

Issue:
Implement multisample render buffers
Add a `new_multisample` for render buffers.
There's no need to create new types.



Discussion / hints:

Fix patch:
diff --git a/src/framebuffer/render_buffer.rs b/src/framebuffer/render_buffer.rs
index 19ab4b8a59..9ec2022fcd 100644
--- a/src/framebuffer/render_buffer.rs
+++ b/src/framebuffer/render_buffer.rs
@@ -73,6 +73,17 @@ impl RenderBuffer {
             buffer: RenderBufferAny::new(facade, format, TextureKind::Float, width, height, None)
         })
     }
+    /// Builds a new render buffer with multisampling.
+    pub fn new_multisample<F: ?Sized>(facade: &F, format: UncompressedFloatFormat, width: u32, height: u32, samples: u32)
+                  -> Result<RenderBuffer, CreationError> where F: Facade
+    {
+        let format = image_format::TextureFormatRequest::Specific(image_format::TextureFormat::UncompressedFloat(format));
+        let format = image_format::format_request_to_glenum(&facade.get_context(), format, image_format::RequestType::Renderbuffer)?;
+
+        Ok(RenderBuffer {
+            buffer: RenderBufferAny::new(facade, format, TextureKind::Float, width, height, Some(samples))
+        })
+    }
 }
 
 impl<'a> ToColorAttachment<'a> for &'a RenderBuffer {
@@ -126,6 +137,17 @@ impl DepthRenderBuffer {
             buffer: RenderBufferAny::new(facade, format, TextureKind::Depth, width, height, None)
         })
     }
+    /// Builds a new render buffer with multisampling.
+    pub fn new_multisample<F: ?Sized>(facade: &F, format: DepthFormat, width: u32, height: u32, samples: u32)
+                  -> Result<DepthRenderBuffer, CreationError> where F: Facade
+    {
+        let format = image_format::TextureFormatRequest::Specific(image_format::TextureFormat::DepthFormat(format));
+        let format = image_format::format_request_to_glenum(&facade.get_context(), format, image_format::RequestType::Renderbuffer)?;
+
+        Ok(DepthRenderBuffer {
+            buffer: RenderBufferAny::new(facade, format, TextureKind::Depth, width, height, Some(samples))
+        })
+    }
 }
 
 impl<'a> ToDepthAttachment<'a> for &'a DepthRenderBuffer {
@@ -178,6 +200,17 @@ impl StencilRenderBuffer {
             buffer: RenderBufferAny::new(facade, format, TextureKind::Stencil, width, height, None)
         })
     }
+    /// Builds a new render buffer with multisampling.
+    pub fn new_multisample<F: ?Sized>(facade: &F, format: StencilFormat, width: u32, height: u32, samples: u32)
+                  -> Result<StencilRenderBuffer, CreationError> where F: Facade
+    {
+        let format = image_format::TextureFormatRequest::Specific(image_format::TextureFormat::StencilFormat(format));
+        let format = image_format::format_request_to_glenum(&facade.get_context(), format, image_format::RequestType::Renderbuffer)?;
+
+        Ok(StencilRenderBuffer {
+            buffer: RenderBufferAny::new(facade, format, TextureKind::Stencil, width, height, Some(samples))
+        })
+    }
 }
 
 impl<'a> ToStencilAttachment<'a> for &'a StencilRenderBuffer {
@@ -231,6 +264,17 @@ impl DepthStencilRenderBuffer {
             buffer: RenderBufferAny::new(facade, format, TextureKind::DepthStencil, width, height, None)
         })
     }
+    /// Builds a new render buffer with multisampling.
+    pub fn new_multisample<F: ?Sized>(facade: &F, format: DepthStencilFormat, width: u32, height: u32, samples: u32)
+                  -> Result<DepthStencilRenderBuffer, CreationError> where F: Facade
+    {
+        let format = image_format::TextureFormatRequest::Specific(image_format::TextureFormat::DepthStencilFormat(format));
+        let format = image_format::format_request_to_glenum(&facade.get_context(), format, image_format::RequestType::Renderbuffer)?;
+
+        Ok(DepthStencilRenderBuffer {
+            buffer: RenderBufferAny::new(facade, format, TextureKind::DepthStencil, width, height, Some(samples))
+        })
+    }
 }
 
 impl<'a> ToDepthStencilAttachment<'a> for &'a DepthStencilRenderBuffer {


Test patch: