Beispiel #1
0
        public override void Init(IntPtr display, IntPtr window, uint samples, bool vsync, bool sRGB)
        {
            _display = display;
            _window  = window;

            while (!_dev.SupportsTextureSampleCount(samples))
            {
                samples >>= 1;
            }
            _samples = samples;

            _layer                 = new CAMetalLayer();
            _layer.Device          = _dev;
            _layer.PixelFormat     = sRGB ? MTLPixelFormat.BGRA8Unorm_sRGB : MTLPixelFormat.BGRA8Unorm;
            _layer.FramebufferOnly = true;

#if __IOS__
            UIView view = (UIView)ObjCRuntime.Runtime.GetNSObject(window);
            view.Layer.AddSublayer(_layer);
#else
            // Mac
            NSView view = (NSView)ObjCRuntime.Runtime.GetNSObject(window);
            view.Layer.AddSublayer(_layer);
#endif
            _cmdQueue = _dev.CreateCommandQueue();

            _descriptor = new MTLRenderPassDescriptor();
            _descriptor.ColorAttachments[0].ClearColor = new MTLClearColor(0.0, 1.0, 0.0, 0.0);

            if (samples > 1)
            {
                _descriptor.ColorAttachments[0].StoreAction = MTLStoreAction.MultisampleResolve;
            }
            else
            {
                _descriptor.ColorAttachments[0].StoreAction = MTLStoreAction.Store;
            }

            _descriptor.StencilAttachment.ClearStencil = 0;
            _descriptor.StencilAttachment.LoadAction   = MTLLoadAction.Clear;
            _descriptor.StencilAttachment.StoreAction  = MTLStoreAction.DontCare;

            _device = new Noesis.RenderDeviceMTL(_dev.Handle, sRGB);
        }