Beispiel #1
0
        /// <summary>
        /// Draws a fullscreen quad with the specified effect and parameters.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="effect">The effect.</param>
        /// <param name="parameters">The parameters.</param>
        /// <exception cref="System.ArgumentNullException">effect</exception>
        public static void DrawQuad(this GraphicsDevice device, Effect effect, ParameterCollection parameters = null)
        {
            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }

            // Apply the effect
            if (parameters != null)
            {
                effect.Apply(device, parameters, false);
            }
            else
            {
                effect.Apply(device, false);
            }

            // Draw a full screen quad
            device.DrawQuad();

            // Unapply
            effect.UnbindResources(device);
        }
        /// <summary>
        /// Draws a fullscreen quad with the specified effect and parameters.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="effect">The effect.</param>
        /// <param name="parameterCollections">The parameter collections.</param>
        /// <exception cref="System.ArgumentNullException">effect</exception>
        public static void DrawQuad <TList>(this GraphicsDevice device, Effect effect, TList parameterCollections) where TList : class, IEnumerable <ParameterCollection>
        {
            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }

            // Apply the effect
            effect.Apply(device, parameterCollections, false);

            // Draw a full screen quad
            device.DrawQuad();

            // Unapply
            effect.UnbindResources(device);
        }
Beispiel #3
0
        protected virtual void PrepareForRendering()
        {
            // Use LinearClamp for sampler state
            var localSamplerState = SamplerState ?? GraphicsDevice.SamplerStates.LinearClamp;

            // Sets the sampler state of the effect
            Parameters.Set(TexturingKeys.Sampler, localSamplerState);
            Effect.Apply(Parameters);

            // Setup states (Blend, DepthStencil, Rasterizer)
            GraphicsDevice.SetBlendState(BlendState ?? GraphicsDevice.BlendStates.AlphaBlend);
            GraphicsDevice.SetDepthStencilState(DepthStencilState ?? GraphicsDevice.DepthStencilStates.Default, StencilReferenceValue);
            GraphicsDevice.SetRasterizerState(RasterizerState ?? GraphicsDevice.RasterizerStates.CullBack);

            // Set VertexInputLayout
            GraphicsDevice.SetVertexArrayObject(ResourceContext.VertexArrayObject);

            // If this is a deferred D3D context, reset position so the first Map call will use D3D11_MAP_WRITE_DISCARD.
            if (GraphicsDevice.IsDeferred)
            {
                ResourceContext.VertexBufferPosition = 0;
            }
        }