Esempio n. 1
0
        public Renderer(int passes, ViewportPolicy viewportPolicy, RenderOptions renderOptions)
        {
            this.Passes     = passes;
            this.Policy     = viewportPolicy;
            this.Options    = renderOptions;
            this.sortMode   = Renderer.ToSortMode(renderOptions);
            this.blendState = Renderer.ToBlendState(renderOptions);

            // Doing a GlobalRenderLock because Renderer objects might be constructed in different threads.
            lock (PhantomGame.Game.GlobalRenderLock)
            {
                if ((renderOptions & RenderOptions.Canvas) == RenderOptions.Canvas)
                {
                    this.canvas = new Canvas(PhantomGame.Game.GraphicsDevice);
                }
                this.batch = new SpriteBatch(PhantomGame.Game.GraphicsDevice);
            }

            if (this.sortMode == SpriteSortMode.Immediate)
            {
                this.activeRenderPass = this.RenderPassFullLock;
            }
            else
            {
                this.activeRenderPass = this.RenderPassEndLock;
            }
            this.stopWatch = new Stopwatch();
            this.stopWatch.Start();
        }
Esempio n. 2
0
        public void ChangeOptions(ViewportPolicy viewportPolicy, RenderOptions renderOptions)
        {
            this.Policy = viewportPolicy;

            this.Options = renderOptions;
            bool wantCanvas = (renderOptions & RenderOptions.Canvas) == RenderOptions.Canvas;

            if (this.canvas == null && wantCanvas)
            {
                this.canvas = new Canvas(PhantomGame.Game.GraphicsDevice);
            }
            else if (this.canvas != null && !wantCanvas)
            {
                this.canvas = null;
            }

            if (!renderOptions.HasFlag(RenderOptions.ApplyEffect))
            {
                this.fx = null;
            }

            this.sortMode   = Renderer.ToSortMode(renderOptions);
            this.blendState = Renderer.ToBlendState(renderOptions);

            if (this.sortMode == SpriteSortMode.Immediate)
            {
                this.activeRenderPass = this.RenderPassFullLock;
            }
            else
            {
                this.activeRenderPass = this.RenderPassEndLock;
            }
        }