Provides static methods to manage an OpenTK application.
Inheritance: IDisposable
示例#1
0
文件: OculusRift.cs 项目: caomw/rift
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenTK.OculusRift"/> class.
        /// </summary>
        public OculusRift()
        {
            if (Interlocked.Increment(ref instance_count) == 1)
            {
                opentk = Toolkit.Init();
                NativeMethods.Init();
            }

            instance = NativeMethods.Create();
        }
示例#2
0
        static Device()
        {
            OpenTK.Graphics.GraphicsContext.ShareContexts = true;
            toolkit = OpenTK.Toolkit.Init();

            sharedWindow = new GameWindow(10, 10, GraphicsMode.Default, "shared context window", GameWindowFlags.Default, DisplayDevice.Default, 4, 0, GraphicsContextFlags.Default);
            sharedContext = new Context(sharedWindow.Context, sharedWindow.WindowInfo);
            sharedWindow.Disposed += (sender, args) => { throw new Exception(); };

            capabilities = new Capabilities();
        }
        private int isExiting; // int, so we can use Interlocked.Increment
        
		public OpenTKGamePlatform(Game game)
            : base(game)
        {
            toolkit = Toolkit.Init();
            _view = new OpenTKGameWindow(game);
            this.Window = _view;

			// Setup our OpenALSoundController to handle our SoundBuffer pools
            try
            {
                soundControllerInstance = OpenALSoundController.GetInstance;
            }
            catch (DllNotFoundException ex)
            {
                throw (new NoAudioHardwareException("Failed to init OpenALSoundController", ex));
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                if (toolkit != null)
                {
                    toolkit.Dispose();
                    toolkit = null;
                }

                if (_view != null)
                {
                    _view.Dispose();
                    _view = null;
                }
            }

			base.Dispose(disposing);
        }
示例#5
0
 void Dispose(bool manual)
 {
     if (manual)
     {
         lock (InitLock)
         {
             if (initialized)
             {
                 platform_factory.Dispose();
                 platform_factory = null;
                 toolkit = null;
                 initialized = false;
             }
         }
     }
     else
     {
         Debug.Print("OpenTK.Toolkit leaked, did you forget to call Dispose()?");
         platform_factory = null;
         toolkit = null;
         initialized = false;
     }
 }
示例#6
0
        /// <summary>
        /// Initializes OpenTK with the specified options. Use this method
        /// to influence the OpenTK.Platform implementation that will be used.
        /// </summary>
        /// <remarks>
        /// <para>
        /// You *must* call this method if you are combining OpenTK with a
        /// third-party windowing toolkit (e.g. GTK#). In this case, this should be the
        /// first method called by your application:
        /// <code>
        /// static void Main()
        /// {
        ///     using (OpenTK.Toolkit.Init())
        ///     {
        ///      ...
        ///     }
        /// }
        /// </code>
        /// </para>
        /// <para>
        /// The reason is that some toolkits do not configure the underlying platform
        /// correctly or configure it in a way that is incompatible with OpenTK.
        /// Calling this method first ensures that OpenTK is given the chance to
        /// initialize itself and configure the platform correctly.
        /// </para>
        /// </remarks>
        /// <param name="options">A <c>ToolkitOptions</c> instance
        /// containing the desired options.</param>
        /// <returns>
        /// An IDisposable instance that you can use to dispose of the resources
        /// consumed by OpenTK.
        /// </returns>
        public static Toolkit Init(ToolkitOptions options)
        {
            if (options == null)
                throw new ArgumentNullException("options");

            lock (InitLock)
            {
                if (!initialized)
                {
                    initialized = true;
                    Configuration.Init(options);
                    Options = options;

                    // The actual initialization takes place in the
                    // platform-specific factory constructors.
                    toolkit = new Toolkit(new Factory());
                }
                return toolkit;
            }
        }
示例#7
0
 void Dispose(bool manual)
 {
     if (manual)
     {
         lock (InitLock)
         {
             if (initialized)
             {
                 platform_factory.Dispose();
                 platform_factory = null;
                 toolkit = null;
                 initialized = false;
             }
         }
     }
 }
示例#8
0
        private int isExiting; // int, so we can use Interlocked.Increment
        
		public OpenTKGamePlatform(Game game)
            : base(game)
        {
            toolkit = Toolkit.Init();
            _view = new OpenTKGameWindow(game);
            this.Window = _view;

			// Setup our OpenALSoundController to handle our SoundBuffer pools
            try
            {
                soundControllerInstance = OpenALSoundController.GetInstance;
            }
            catch (DllNotFoundException ex)
            {
                throw (new NoAudioHardwareException("Failed to init OpenALSoundController", ex));
            }
            
#if LINUX
            // also set up SdlMixer to play background music. If one of these functions fails, we will not get any background music (but that should rarely happen)
            Tao.Sdl.Sdl.SDL_InitSubSystem(Tao.Sdl.Sdl.SDL_INIT_AUDIO);
            Tao.Sdl.SdlMixer.Mix_OpenAudio(44100, (short)Tao.Sdl.Sdl.AUDIO_S16SYS, 2, 1024);			

            //even though this method is called whenever IsMouseVisible is changed it needs to be called during startup
            //so that the cursor can be put in the correct inital state (hidden)
            OnIsMouseVisibleChanged();
#endif
        }
示例#9
0
文件: OculusRift.cs 项目: caomw/rift
        void Dispose(bool manual)
        {
            if (!disposed)
            {
                if (manual)
                {
                    NativeMethods.Destroy(instance);
                    if (Interlocked.Decrement(ref instance_count) == 0)
                    {
                        NativeMethods.Shutdown();
                        opentk.Dispose();
                        opentk = null;
                    }
                }

                disposed = true;
            }
        }