Esempio n. 1
0
        public AudioDevice(string device = null)
        {
            if (device == null)
            {
                device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier);
            }

            deviceId      = Alc.OpenDevice(device);
            contextHandle = Alc.CreateContext(deviceId, new int[] { });
            this.Use();
        }
Esempio n. 2
0
        public AudioDevice(string device = null)
        {
            if (device == null)
            {
                device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier);
            }

            deviceId = Alc.OpenDevice(device);
            if (deviceId == IntPtr.Zero)
            {
                throw new Exception("unable to open the specified audio device");
            }
            contextHandle = Alc.CreateContext(deviceId, new int[] { });
            this.Use();
        }
Esempio n. 3
0
        private void CreateContext(GraphicsMode mode, CocoaWindowInfo cocoaWindow, IntPtr shareContextRef, int majorVersion, int minorVersion, bool fullscreen)
        {
            // Prepare attributes
            List <NSOpenGLPixelFormatAttribute> attributes = new List <NSOpenGLPixelFormatAttribute>();

            var profile = NSOpenGLProfile.VersionLegacy;

            if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 2))
            {
                profile = NSOpenGLProfile.Version3_2Core;
                Debug.Print("Running the OpenGL core profile.");
            }
            else
            {
                Debug.Print("Running the legacy OpenGL profile. Start with version major=3, minor=2 or later for the 3.2 profile.");
            }

            Debug.Print("NSGL pixel format attributes:");
            Debug.Indent();

            AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.OpenGLProfile, (int)profile);
            AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.DoubleBuffer);
            AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.Accelerated);
            AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.ColorSize, mode.ColorFormat.BitsPerPixel);

            if (mode.Depth > 0)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.DepthSize, mode.Depth);
            }

            if (mode.Stencil > 0)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.StencilSize, mode.Stencil);
            }

            if (mode.AccumulatorFormat.BitsPerPixel > 0)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.AccumSize, mode.AccumulatorFormat.BitsPerPixel);
            }

            if (mode.Samples > 1)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.SampleBuffers, 1);
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.Samples, mode.Samples);
            }

            AddPixelAttrib(attributes, (NSOpenGLPixelFormatAttribute)0);

            Debug.Unindent();

            Debug.Write("Attribute array:  ");
            for (int i = 0; i < attributes.Count; i++)
            {
                Debug.Write(attributes[i].ToString() + "  ");
            }
            Debug.WriteLine("");

            // Create pixel format
            var pixelFormat = Cocoa.SendIntPtr(Class.Get("NSOpenGLPixelFormat"), Selector.Alloc);

            unsafe
            {
                fixed(NSOpenGLPixelFormatAttribute *ptr = attributes.ToArray())
                {
                    pixelFormat = Cocoa.SendIntPtr(pixelFormat, Selector.Get("initWithAttributes:"), (IntPtr)ptr);
                }
            }

            // Create context
            var context = Cocoa.SendIntPtr(NSOpenGLContext, Selector.Alloc);

            context = Cocoa.SendIntPtr(context, Selector.Get("initWithFormat:shareContext:"), pixelFormat, shareContextRef);

            // Release pixel format
            Cocoa.SendVoid(pixelFormat, Selector.Release);
            pixelFormat = IntPtr.Zero;

            // Attach the view
            Cocoa.SendVoid(context, Selector.Get("setView:"), cocoaWindow.ViewHandle);
            Cocoa.SendVoid(cocoaWindow.ViewHandle, Selector.Get("setWantsBestResolutionOpenGLSurface:"), true);

            // Finalize
            Handle = new ContextHandle(context);
            Mode   = GetGraphicsMode(context);

            Update(cocoaWindow);
            MakeCurrent(cocoaWindow);
        }