Пример #1
0
        /// <summary>
        /// Gets a global shared context.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <returns>RenderContext.</returns>
        public static RenderContext GetShared(IServiceRegistry services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            // Store RenderContext shared into the GraphicsDevice
            var graphicsDevice = services.GetSafeServiceAs <IGraphicsDeviceService>().GraphicsDevice;

            return(graphicsDevice.GetOrCreateSharedData(SharedImageEffectContextKey, d => new RenderContext(services)));
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RenderContext" /> class.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <exception cref="System.ArgumentNullException">services</exception>
        internal RenderContext(IServiceRegistry services)
        {
            Services         = services ?? throw new ArgumentNullException(nameof(services));
            Effects          = services.GetSafeServiceAs <EffectSystem>();
            GraphicsDevice   = services.GetSafeServiceAs <IGraphicsDeviceService>().GraphicsDevice;
            Allocator        = services.GetSafeServiceAs <GraphicsContext>().Allocator ?? new GraphicsResourceAllocator(GraphicsDevice).DisposeBy(GraphicsDevice);
            StreamingManager = services.GetService <StreamingManager>();

            threadContext = new ThreadLocal <RenderDrawContext>(() =>
            {
                lock (threadContextLock)
                {
                    return(new RenderDrawContext(Services, this, new GraphicsContext(GraphicsDevice, Allocator)));
                }
            }, true);
        }