Exemplo n.º 1
0
        public void SetupContext(IWindowInfo wnd, MgGraphicsDeviceCreateInfo createInfo)
        {
            if (Context != null)
            {
                Context.Dispose();
            }

            GraphicsMode mode;
            // Create an OpenGL compatibility context
            var flags = GraphicsContextFlags.Default;
            int major = 1;
            int minor = 0;

            if (Context == null || Context.IsDisposed)
            {
                var color      = GetColorFormat(createInfo.Color);
                var depthBit   = GetDepthBit(createInfo.DepthStencil);
                var stencilBit = GetStencilBit(createInfo.DepthStencil);
                var samples    = (int)createInfo.Samples;
                if (samples == 0)
                {
                    // Use a default of 4x samples if PreferMultiSampling is enabled
                    // without explicitly setting the desired MultiSampleCount.
                    samples = 4;
                }
                mode = new GraphicsMode(color, depthBit, stencilBit, samples);
                try
                {
                    Context = new GraphicsContext(mode, wnd, major, minor, flags);
                }
                catch (Exception e)
                {
                    mLogger.Log(string.Format("Failed to create OpenGL context, retrying. Error: {0}", e));
                    major   = 1;
                    minor   = 0;
                    flags   = GraphicsContextFlags.Default;
                    Context = new GraphicsContext(mode, wnd, major, minor, flags);
                }
            }
            Context.MakeCurrent(wnd);
            (Context as IGraphicsContextInternal).LoadAll();
            //Context.SwapInterval = mDeviceQuery.GetSwapInterval (mPresentation.PresentationInterval);
            // TODO : background threading
            // Provide the graphics context for background loading
            // Note: this context should use the same GraphicsMode,
            // major, minor version and flags parameters as the main
            // context. Otherwise, context sharing will very likely fail.
            //			if (Threading.BackgroundContext == null)
            //			{
            //				Threading.BackgroundContext = new GraphicsContext(mode, wnd, major, minor, flags);
            //				Threading.WindowInfo = wnd;
            //				Threading.BackgroundContext.MakeCurrent(null);
            //			}
            Context.MakeCurrent(wnd);
        }