Esempio n. 1
0
        public static IOSurface Create(Size <Pixels> size)
        {
            var width  = (int)size.Width;
            var height = (int)size.Height;

            if (width == 0 || height == 0)
            {
                throw new ArgumentOutOfRangeException("size", "IOSurface dimensions must be greater or equal to 1");
            }

            using (var properties = NSDictionary.FromObjectsAndKeys(
                       new object[] {
                width,                     // IOSurfaceWidth
                height,                    // IOSurfaceHeight
                4,                         // IOSurfaceBytesPerElement
                true                       // IOSurfaceIsGlobal
            },
                       new object[] {
                "IOSurfaceWidth",
                "IOSurfaceHeight",
                "IOSurfaceBytesPerElement",
                "IOSurfaceIsGlobal"
            }))
            {
                var surface = new IOSurface(IOSurfaceCreate(properties.Handle));
                return(surface);
            }
        }
Esempio n. 2
0
        public static TextureHandle Create(Size <Pixels> size, IOSurface surface)
        {
            GL.ActiveTexture(TextureUnit.Texture0);
            var texture = new TextureHandle(GL.GenTexture());

            GL.BindTexture(TextureTarget.TextureRectangle, texture);
            GL.TexParameter(TextureTarget.TextureRectangle, TextureParameterName.TextureMagFilter, (int)(TextureMagFilter.Nearest));
            GL.TexParameter(TextureTarget.TextureRectangle, TextureParameterName.TextureMinFilter, (int)(TextureMinFilter.Linear));
            GL.TexParameter(TextureTarget.TextureRectangle, TextureParameterName.TextureWrapS, (int)(TextureWrapMode.ClampToEdge));
            GL.TexParameter(TextureTarget.TextureRectangle, TextureParameterName.TextureWrapT, (int)(TextureWrapMode.ClampToEdge));
            Resize(texture, size, surface);
            return(texture);
        }
Esempio n. 3
0
 public static void Resize(TextureHandle texture, Size <Pixels> size, IOSurface surface)
 {
     GL.BindTexture(TextureTarget.TextureRectangle, texture);
     CGLTexImageIOSurface2D(
         CGLContext.CurrentContext.Handle,
         (int)TextureTarget.TextureRectangle,
         (int)PixelInternalFormat.Rgba,
         (int)size.Width,
         (int)size.Height,
         (int)PixelFormat.Bgra,
         (int)PixelType.UnsignedInt8888Reversed,
         surface.Handle,
         0);
     GL.BindTexture(TextureTarget.TextureRectangle, 0);
 }
        public static FramebufferInfo CreateFramebuffer(this IOSurface surface)
        {
            var size = surface.Size.Max(1, 1);

            var handles = new int[1];

            GL.GenFramebuffers(1, handles);
            var handle = new FramebufferHandle(handles[0]);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, handle);

            var depthbuffer = CreateDepthBuffer(size);

            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, depthbuffer);

            var colorbuffer = IOSurfaceTexture.Create(size, surface);

            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.TextureRectangle, colorbuffer, 0);

            CheckStatus();

            return(new FramebufferInfo(handle, depthbuffer, Optional.None(), colorbuffer));
        }
 public static TextureHandle CreateTexture(this IOSurface surface)
 {
     return(IOSurfaceTexture.Create(surface.Size, surface));
 }
Esempio n. 6
0
 public IOSurfaceRenderTargetBuffer(Size <Pixels> size)
 {
     Size    = size;
     Surface = IOSurface.Create(new Size <Pixels>(size.Width, size.Height));
 }