Esempio n. 1
0
        public void Recreate(GraphicsAdapter adapter, GraphicsProfile[] profile, DeviceCreationFlags deviceCreationFlags, WindowHandle windowHandle)
        {
            if (adapter == null)
            {
                throw new ArgumentNullException("adapter");
            }
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }

            Adapter     = adapter;
            IsDebugMode = (deviceCreationFlags & DeviceCreationFlags.Debug) != 0;

            // Initialize this instance
            InitializePlatformDevice(profile, deviceCreationFlags, windowHandle);

            InitializeFactories();

            // Create a new graphics device
            Features = new GraphicsDeviceFeatures(this);

            SamplerStates      = new SamplerStateFactory(this);
            BlendStates        = new BlendStateFactory(this);
            RasterizerStates   = new RasterizerStateFactory(this);
            DepthStencilStates = new DepthStencilStateFactory(this);

            currentState = null;
            allocatedStates.Clear();
            currentStateIndex = -1;
            PushState();

            ClearState();
        }
Esempio n. 2
0
        /// <summary>
        /// Clears the state and restore the state of the device.
        /// </summary>
        public void ClearState()
        {
            ClearStateImpl();

            currentStateIndex = 0;
            currentState      = allocatedStates[currentStateIndex];

            // Setup empty viewports
            for (int i = 0; i < currentState.Viewports.Length; i++)
            {
                currentState.Viewports[i] = new Viewport();
            }

            // Setup default states
            SetBlendState(BlendStates.Default);
            SetRasterizerState(RasterizerStates.CullBack);
            SetDepthStencilState(DepthStencilStates.Default);

            // Setup the default render target
            Texture depthStencilBuffer = null;
            Texture backBuffer         = null;

            if (Presenter != null)
            {
                depthStencilBuffer = Presenter.DepthStencilBuffer;
                backBuffer         = Presenter.BackBuffer;
            }
            SetDepthAndRenderTarget(depthStencilBuffer, backBuffer);
        }
Esempio n. 3
0
        /// <summary>
        /// Restore the state and targets.
        /// </summary>
        public void PopState()
        {
            if (currentStateIndex <= 0)
            {
                throw new InvalidOperationException("Cannot pop more than push");
            }
            currentStateIndex--;

            currentState = allocatedStates[currentStateIndex];
            currentState.Restore(this);
        }
Esempio n. 4
0
        /// <summary>
        /// Pushes the state of <see cref="DepthStencilState"/>, <see cref="RasterizerState"/>, <see cref="BlendState"/> and the Render targets bound to this instance. To restore the state, use <see cref="PopState"/>.
        /// </summary>
        public void PushState()
        {
            var previousState = currentState;

            // Check if we need to allocate a new StateAndTargets
            if (currentStateIndex == (allocatedStates.Count - 1))
            {
                currentState = new StateAndTargets();
                allocatedStates.Add(currentState);
            }
            currentStateIndex++;
            currentState = allocatedStates[currentStateIndex];
            currentState.Initialize(this, previousState);
        }
Esempio n. 5
0
        /// <summary>
        /// Pushes render targets and viewport state.
        /// </summary>
        public void PushRenderTargets()
        {
            // Check if we need to allocate a new StateAndTargets
            StateAndTargets newState;

            currentStateIndex++;
            if (currentStateIndex == allocatedStates.Count)
            {
                newState = new StateAndTargets();
                allocatedStates.Add(newState);
            }
            else
            {
                newState = allocatedStates[currentStateIndex];
            }
            newState.Capture(CommandList);
        }
Esempio n. 6
0
            public void Initialize(GraphicsDevice device, StateAndTargets parentState)
            {
                int renderTargetCount = MaxRenderTargetCount;

                switch (device.Features.Profile)
                {
                case GraphicsProfile.Level_9_1:
                case GraphicsProfile.Level_9_2:
                case GraphicsProfile.Level_9_3:
                    renderTargetCount = 1;
                    break;
                }

                if (RenderTargets == null || RenderTargets.Length != renderTargetCount)
                {
                    RenderTargets = new Texture[renderTargetCount];
                    Viewports     = new Viewport[renderTargetCount];
                }

                if (parentState != null)
                {
                    this.BlendState      = parentState.BlendState;
                    this.BlendFactor     = parentState.BlendFactor;
                    BlendMultiSampleMask = parentState.BlendMultiSampleMask;

                    this.DepthStencilState = parentState.DepthStencilState;
                    this.StencilReference  = parentState.StencilReference;

                    DepthStencilBuffer = parentState.DepthStencilBuffer;

                    for (int i = 0; i < renderTargetCount; i++)
                    {
                        Viewports[i]     = parentState.Viewports[i];
                        RenderTargets[i] = parentState.RenderTargets[i];
                    }
                }

                device.needViewportUpdate = true;
            }