pub fn new(width: u16, height: u16, render_type: RenderTargetType) -> RenderTarget {
        unsafe {
            // Find the currently bound frame buffer (so we can rebind it)
            let mut old_frame_buffer = 0;
            gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut old_frame_buffer);
            panic_on_gl_error("Get old framebuffer");

            // Create the frame buffer
            let mut frame_buffer = 0;
            gl::GenFramebuffers(1, &mut frame_buffer);
            gl::BindFramebuffer(gl::FRAMEBUFFER, frame_buffer);
            panic_on_gl_error("Bind new framebuffer");

            // Generate the texture or the render buffer for the render target
            let texture;
            let render_buffer;

            match render_type {
                RenderTargetType::Standard | RenderTargetType::StandardForReading => {
                    // Use a backing texture for the rendering
                    let mut backing_texture = Texture::new();
                    backing_texture.create_empty(width, height);

                    gl::FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, *backing_texture, 0);

                    // This type of render target uses a backing texture
                    texture         = Some(backing_texture);
                    render_buffer   = None;
                }

                RenderTargetType::Multisampled => {
                    // Uses a render buffer for the backing layer 
                    let mut backing_renderbuffer = 0;
                    gl::GenRenderbuffers(1, &mut backing_renderbuffer);

                    let mut old_renderbuffer = 0;
                    gl::GetIntegerv(gl::RENDERBUFFER_BINDING, &mut old_renderbuffer);

                    // Define as a MSAA renderbuffer
                    gl::BindRenderbuffer(gl::RENDERBUFFER, backing_renderbuffer);
                    gl::RenderbufferStorageMultisample(gl::RENDERBUFFER, 4, gl::RGBA8, width as gl::types::GLsizei, height as gl::types::GLsizei);
                    gl::FramebufferRenderbuffer(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::RENDERBUFFER, backing_renderbuffer);

                    gl::BindRenderbuffer(gl::RENDERBUFFER, old_renderbuffer as u32);

                    // This type of render target uses a render buffer
                    texture         = None;
                    render_buffer   = Some(backing_renderbuffer);
                },

                RenderTargetType::MultisampledTexture => {
                    // Use a backing texture for the rendering
                    let mut backing_texture = Texture::new();
                    backing_texture.create_empty_multisampled(width, height, 4);

                    gl::FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D_MULTISAMPLE, *backing_texture, 0);

                    // This type of render target uses a backing texture
                    texture         = Some(backing_texture);
                    render_buffer   = None;
                }

                RenderTargetType::Monochrome => {
                    // Use a backing texture for the rendering
                    let mut backing_texture = Texture::new();
                    backing_texture.create_monochrome(width, height);

                    gl::FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, *backing_texture, 0);

                    // This type of render target uses a backing texture
                    texture         = Some(backing_texture);
                    render_buffer   = None;
                }

                RenderTargetType::MonochromeMultisampledTexture => {
                    // Use a backing texture for the rendering
                    let mut backing_texture = Texture::new();
                    backing_texture.create_monochrome_multisampled(width, height, 4);

                    gl::FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D_MULTISAMPLE, *backing_texture, 0);

                    // This type of render target uses a backing texture
                    texture         = Some(backing_texture);
                    render_buffer   = None;
                }
            };

            panic_on_gl_error("Create framebuffer");

            // Bind back to the original framebuffer
            gl::BindFramebuffer(gl::FRAMEBUFFER, old_frame_buffer as _);

            // Create the render target
            RenderTarget {
                frame_buffer:       frame_buffer,
                texture:            texture,
                render_buffer:      render_buffer,
                size:               (width, height),
                _render_type:       render_type,
                drop_frame_buffer:  true
            }
        }
    }
///
/// Creates a new OpenGL render target
///
Creates a new OpenGL render target
Creates a new OpenGL render target
pub fn new(width: u16, height: u16, render_type: RenderTargetType) -> RenderTarget {
        unsafe {
            // Find the currently bound frame buffer (so we can rebind it)
            let mut old_frame_buffer = 0;
            gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut old_frame_buffer);
            panic_on_gl_error("Get old framebuffer");
            // Create the frame buffer
            let mut frame_buffer = 0;
            gl::GenFramebuffers(1, &mut frame_buffer);
            gl::BindFramebuffer(gl::FRAMEBUFFER, frame_buffer);
            panic_on_gl_error("Bind new framebuffer");
            // Generate the texture or the render buffer for the render target
            let texture;
            let render_buffer;
            match render_type {
                RenderTargetType::Standard | RenderTargetType::StandardForReading => {
                    // Use a backing texture for the rendering
                    let mut backing_texture = Texture::new();
                    backing_texture.create_empty(width, height);
                    gl::FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, *backing_texture, 0);
                    // This type of render target uses a backing texture
                    texture         = Some(backing_texture);
                    render_buffer   = None;
                }
                RenderTargetType::Multisampled => {
                    // Uses a render buffer for the backing layer 
                    let mut backing_renderbuffer = 0;
                    gl::GenRenderbuffers(1, &mut backing_renderbuffer);
                    let mut old_renderbuffer = 0;
                    gl::GetIntegerv(gl::RENDERBUFFER_BINDING, &mut old_renderbuffer);
                    // Define as a MSAA renderbuffer
                    gl::BindRenderbuffer(gl::RENDERBUFFER, backing_renderbuffer);
                    gl::RenderbufferStorageMultisample(gl::RENDERBUFFER, 4, gl::RGBA8, width as gl::types::GLsizei, height as gl::types::GLsizei);
                    gl::FramebufferRenderbuffer(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::RENDERBUFFER, backing_renderbuffer);
                    gl::BindRenderbuffer(gl::RENDERBUFFER, old_renderbuffer as u32);
                    // This type of render target uses a render buffer
                    texture         = None;
                    render_buffer   = Some(backing_renderbuffer);
                },
                RenderTargetType::MultisampledTexture => {
                    // Use a backing texture for the rendering
                    let mut backing_texture = Texture::new();
                    backing_texture.create_empty_multisampled(width, height, 4);
                    gl::FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D_MULTISAMPLE, *backing_texture, 0);
                    // This type of render target uses a backing texture
                    texture         = Some(backing_texture);
                    render_buffer   = None;
                }
                RenderTargetType::Monochrome => {
                    // Use a backing texture for the rendering
                    let mut backing_texture = Texture::new();
                    backing_texture.create_monochrome(width, height);
                    gl::FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, *backing_texture, 0);
                    // This type of render target uses a backing texture
                    texture         = Some(backing_texture);
                    render_buffer   = None;
                }
                RenderTargetType::MonochromeMultisampledTexture => {
                    // Use a backing texture for the rendering
                    let mut backing_texture = Texture::new();
                    backing_texture.create_monochrome_multisampled(width, height, 4);
                    gl::FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D_MULTISAMPLE, *backing_texture, 0);
                    // This type of render target uses a backing texture
                    texture         = Some(backing_texture);
                    render_buffer   = None;
                }
            };
            panic_on_gl_error("Create framebuffer");
            // Bind back to the original framebuffer
            gl::BindFramebuffer(gl::FRAMEBUFFER, old_frame_buffer as _);
            // Create the render target
            RenderTarget {
                frame_buffer:       frame_buffer,
                texture:            texture,
                render_buffer:      render_buffer,
                size:               (width, height),
                _render_type:       render_type,
                drop_frame_buffer:  true
            }
        }
    }
pub fn new ( width : u16 , height : u16 , render_type : RenderTargetType ) -> RenderTarget { unsafe { // Find the currently bound frame buffer (so we can rebind it) let mut old_frame_buffer = 0 ; gl :: GetIntegerv ( gl :: DRAW_FRAMEBUFFER_BINDING , & mut old_frame_buffer ) ; panic_on_gl_error ( " " ) ; // Create the frame buffer let mut frame_buffer = 0 ; gl :: GenFramebuffers ( 1 , & mut frame_buffer ) ; gl :: BindFramebuffer ( gl :: FRAMEBUFFER , frame_buffer ) ; panic_on_gl_error ( " " ) ; // Generate the texture or the render buffer for the render target let texture ; let render_buffer ; match render_type { RenderTargetType :: Standard | RenderTargetType :: StandardForReading => { // Use a backing texture for the rendering let mut backing_texture = Texture :: new ( ) ; backing_texture . create_empty ( width , height ) ; gl :: FramebufferTexture2D ( gl :: FRAMEBUFFER , gl :: COLOR_ATTACHMENT0 , gl :: TEXTURE_2D , * backing_texture , 0 ) ; // This type of render target uses a backing texture texture = Some ( backing_texture ) ; render_buffer = None ; } RenderTargetType :: Multisampled => { // Uses a render buffer for the backing layer  let mut backing_renderbuffer = 0 ; gl :: GenRenderbuffers ( 1 , & mut backing_renderbuffer ) ; let mut old_renderbuffer = 0 ; gl :: GetIntegerv ( gl :: RENDERBUFFER_BINDING , & mut old_renderbuffer ) ; // Define as a MSAA renderbuffer gl :: BindRenderbuffer ( gl :: RENDERBUFFER , backing_renderbuffer ) ; gl :: RenderbufferStorageMultisample ( gl :: RENDERBUFFER , 4 , gl :: RGBA8 , width as gl :: types :: GLsizei , height as gl :: types :: GLsizei ) ; gl :: FramebufferRenderbuffer ( gl :: FRAMEBUFFER , gl :: COLOR_ATTACHMENT0 , gl :: RENDERBUFFER , backing_renderbuffer ) ; gl :: BindRenderbuffer ( gl :: RENDERBUFFER , old_renderbuffer as u32 ) ; // This type of render target uses a render buffer texture = None ; render_buffer = Some ( backing_renderbuffer ) ; } , RenderTargetType :: MultisampledTexture => { // Use a backing texture for the rendering let mut backing_texture = Texture :: new ( ) ; backing_texture . create_empty_multisampled ( width , height , 4 ) ; gl :: FramebufferTexture2D ( gl :: FRAMEBUFFER , gl :: COLOR_ATTACHMENT0 , gl :: TEXTURE_2D_MULTISAMPLE , * backing_texture , 0 ) ; // This type of render target uses a backing texture texture = Some ( backing_texture ) ; render_buffer = None ; } RenderTargetType :: Monochrome => { // Use a backing texture for the rendering let mut backing_texture = Texture :: new ( ) ; backing_texture . create_monochrome ( width , height ) ; gl :: FramebufferTexture2D ( gl :: FRAMEBUFFER , gl :: COLOR_ATTACHMENT0 , gl :: TEXTURE_2D , * backing_texture , 0 ) ; // This type of render target uses a backing texture texture = Some ( backing_texture ) ; render_buffer = None ; } RenderTargetType :: MonochromeMultisampledTexture => { // Use a backing texture for the rendering let mut backing_texture = Texture :: new ( ) ; backing_texture . create_monochrome_multisampled ( width , height , 4 ) ; gl :: FramebufferTexture2D ( gl :: FRAMEBUFFER , gl :: COLOR_ATTACHMENT0 , gl :: TEXTURE_2D_MULTISAMPLE , * backing_texture , 0 ) ; // This type of render target uses a backing texture texture = Some ( backing_texture ) ; render_buffer = None ; } } ; panic_on_gl_error ( " " ) ; // Bind back to the original framebuffer gl :: BindFramebuffer ( gl :: FRAMEBUFFER , old_frame_buffer as _ ) ; // Create the render target RenderTarget { frame_buffer : frame_buffer , texture : texture , render_buffer : render_buffer , size : ( width , height ) , _render_type : render_type , drop_frame_buffer : true } } }
Creates a new OpenGL render target
Creates a new OpenGL render target
width
u16
height
u16
render_type
RenderTargetType