Example #1
0
        //Set all states that should only be done once for the Effect
        public void Begin(DeviceContext context)
        {
            if (_vs != null)
            {
                context.VertexShader.Set(_vs);
            }
            else
            {
                context.VertexShader.Set(null);
            }
            if (_gs != null)
            {
                context.GeometryShader.Set(_gs);
            }
            else
            {
                context.GeometryShader.Set(null);
            }
            if (_ps != null)
            {
                context.PixelShader.Set(_ps);
            }
            else
            {
                context.PixelShader.Set(null);
            }

            if (_inputLayout != null)
            {
                if (D3DEngine.SingleThreadRenderingOptimization)
                {
                    // Input Layout changed ?? ==> Need to send it to the InputAssembler
                    if (HLSLShaderWrap.LastEffectSet != _inputLayout.GetHashCode())
                    {
                        context.InputAssembler.InputLayout = _inputLayout;
                        HLSLShaderWrap.LastEffectSet       = _inputLayout.GetHashCode();
                    }
                }
                else
                {
                    context.InputAssembler.InputLayout = _inputLayout;
                }
            }

            //Set the constants for the Effect
            for (int i = 0; i < _cBuffers.Length; i++)
            {
                _cBuffers[i].Set2Device(context);
            }

            //Set the resources (forced)
            for (int i = 0; i < _shaderResources.Length; i++)
            {
                _shaderResources[i].Set2Device(context);
            }

            //Set the samplers (forced)
            for (int i = 0; i < _shaderSamplers.Length; i++)
            {
                _shaderSamplers[i].Set2Device(context, false);
            }
        }