Beispiel #1
0
 public static void ThrowIfFailed(this CGLErrorCode errorCode, string methodName)
 {
     if (errorCode != CGLErrorCode.NoError)
     {
         throw new Exception(methodName + " failed: " + errorCode);
     }
 }
        public CGLPixelFormat(CGLPixelFormatAttribute[] attributes, out int npix)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }
            var pixelFormatOut = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
            var npixOut        = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
            var marshalAttribs = new CGLPixelFormatAttribute [attributes.Length + 1];

            Array.Copy(attributes, marshalAttribs, attributes.Length);

            CGLErrorCode ret = CGLChoosePixelFormat(marshalAttribs, pixelFormatOut, npixOut);

            if (ret != CGLErrorCode.NoError)
            {
                Marshal.FreeHGlobal(pixelFormatOut);
                Marshal.FreeHGlobal(npixOut);
                throw new Exception("CGLChoosePixelFormat returned: " + ret);
            }

            this.handle = Marshal.ReadIntPtr(pixelFormatOut);
            npix        = Marshal.ReadInt32(npixOut);
            Marshal.FreeHGlobal(pixelFormatOut);
            Marshal.FreeHGlobal(npixOut);
        }
        void Initialize(CGLPixelFormatAttribute[] attributes, out int npix)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }
            IntPtr pixelFormatOut;
            var    marshalAttribs = new CGLPixelFormatAttribute [attributes.Length + 1];

            Array.Copy(attributes, marshalAttribs, attributes.Length);

            CGLErrorCode ret = CGLChoosePixelFormat(marshalAttribs, out pixelFormatOut, out npix);

            if (ret != CGLErrorCode.NoError)
            {
                throw new Exception("CGLChoosePixelFormat returned: " + ret);
            }

            this.handle = pixelFormatOut;
        }
Beispiel #4
0
        static IntPtr Create(CGLPixelFormatAttribute[] attributes, out int npix)
        {
            if (attributes is null)
            {
                throw new ArgumentNullException(nameof(attributes));
            }
            IntPtr pixelFormatOut;
            var    marshalAttribs = new CGLPixelFormatAttribute [attributes.Length + 1];

            Array.Copy(attributes, marshalAttribs, attributes.Length);

            CGLErrorCode ret = CGLChoosePixelFormat(marshalAttribs, out pixelFormatOut, out npix);

            if (ret != CGLErrorCode.NoError)
            {
                throw new Exception("CGLChoosePixelFormat returned: " + ret);
            }

            return(pixelFormatOut);
        }