OnApply() protected méthode

protected OnApply ( ) : bool
Résultat bool
Exemple #1
0
        public void Apply()
        {
            // Set/get the correct shader handle/cleanups.

            var current = _effect.CurrentTechnique;

            _effect.OnApply();
            if (_effect.CurrentTechnique != current)
            {
                _effect.CurrentTechnique.Passes[0].Apply();
                return;
            }

            var device = _effect.GraphicsDevice;

            if (_vertexShader != null)
            {
                device.VertexShader = _vertexShader;

                // Update the texture parameters.
                SetShaderSamplers(_vertexShader, device.VertexTextures, device.VertexSamplerStates);

                // Update the constant buffers.
                for (var c = 0; c < _vertexShader.CBuffers.Length; c++)
                {
                    var cb = _effect.ConstantBuffers[_vertexShader.CBuffers[c]];
                    cb.Update(_effect.Parameters);
                    device.SetConstantBuffer(ShaderStage.Vertex, c, cb);
                }
            }

            if (_pixelShader != null)
            {
                device.PixelShader = _pixelShader;

                // Update the texture parameters.
                SetShaderSamplers(_pixelShader, device.Textures, device.SamplerStates);

                // Update the constant buffers.
                for (var c = 0; c < _pixelShader.CBuffers.Length; c++)
                {
                    var cb = _effect.ConstantBuffers[_pixelShader.CBuffers[c]];
                    cb.Update(_effect.Parameters);
                    device.SetConstantBuffer(ShaderStage.Pixel, c, cb);
                }
            }

            // Set the render states if we have some.
            //            if (_rasterizerState != null)
            //                device.RasterizerState = _rasterizerState;
            //            if (_blendState != null)
            //                device.BlendState = _blendState;
            //            if (_depthStencilState != null)
            //                device.DepthStencilState = _depthStencilState;
        }
Exemple #2
0
 public void Apply()
 {
     if (parentTechnique != parentEffect.CurrentTechnique.TechniquePointer)
     {
         throw new InvalidOperationException(
                   "Applied a pass not in the current technique!"
                   );
     }
     parentEffect.OnApply();
     parentEffect.INTERNAL_applyEffect(pass);
 }
Exemple #3
0
        public void Apply()
        {
            // Set/get the correct shader handle/cleanups.
            //
            // TODO: This "reapply" if the shader index changes
            // trick is sort of ugly.  We should probably rework
            // this to use some sort of "technique/pass redirect".
            //
            if (_effect.OnApply())
            {
                _effect.CurrentTechnique.Passes[0].Apply();
                return;
            }

            var device = _effect.GraphicsDevice;

#if OPENGL || DIRECTX
            if (_vertexShader != null)
            {
                device.VertexShader = _vertexShader;

                // Update the texture parameters.
                SetShaderSamplers(_vertexShader, device.VertexTextures, device.VertexSamplerStates);

                // Update the constant buffers.
                for (var c = 0; c < _vertexShader.CBuffers.Length; c++)
                {
                    var cb = _effect.ConstantBuffers[_vertexShader.CBuffers[c]];
                    cb.Update(_effect.Parameters);
                    device.SetConstantBuffer(ShaderStage.Vertex, c, cb);
                }
            }

            if (_pixelShader != null)
            {
                device.PixelShader = _pixelShader;

                // Update the texture parameters.
                SetShaderSamplers(_pixelShader, device.Textures, device.SamplerStates);

                // Update the constant buffers.
                for (var c = 0; c < _pixelShader.CBuffers.Length; c++)
                {
                    var cb = _effect.ConstantBuffers[_pixelShader.CBuffers[c]];
                    cb.Update(_effect.Parameters);
                    device.SetConstantBuffer(ShaderStage.Pixel, c, cb);
                }
            }
#endif

            // Set the render states if we have some.
            if (_rasterizerState != null)
            {
                device.RasterizerState = _rasterizerState;
            }
            if (_blendState != null)
            {
                device.BlendState = _blendState;
            }
            if (_depthStencilState != null)
            {
                device.DepthStencilState = _depthStencilState;
            }

#if PSM
            _effect.GraphicsDevice._graphics.SetShaderProgram(_shaderProgram);

            #warning We are only setting one hardcoded parameter here. Need to do this properly by iterating _effect.Parameters (Happens in Shader)

            float[] data;
            if (_effect.Parameters["WorldViewProj"] != null)
            {
                data = (float[])_effect.Parameters["WorldViewProj"].Data;
            }
            else
            {
                data = (float[])_effect.Parameters["MatrixTransform"].Data;
            }
            Sce.PlayStation.Core.Matrix4 matrix4 = PSSHelper.ToPssMatrix4(data);
            matrix4 = matrix4.Transpose();  //When .Data is set the matrix is transposed, we need to do it again to undo it
            _shaderProgram.SetUniformValue(0, ref matrix4);

            if (_effect.Parameters["Texture0"].Data != null && _effect.Parameters["Texture0"].Data != null)
            {
                _effect.GraphicsDevice._graphics.SetTexture(0, ((Texture2D)_effect.Parameters["Texture0"].Data)._texture2D);
            }
#endif
        }
Exemple #4
0
        public void Apply()
        {
            // Set/get the correct shader handle/cleanups.
            //
            // TODO: This "reapply" if the shader index changes
            // trick is sort of ugly.  We should probably rework
            // this to use some sort of "technique/pass redirect".
            //
            if (_effect.OnApply())
            {
                _effect.CurrentTechnique.Passes[0].Apply();
                return;
            }

            var device = _effect.GraphicsDevice;

#if OPENGL || DIRECTX
            if (_vertexShader != null)
            {
                device.VertexShader = _vertexShader;

                // Update the texture parameters.
                SetShaderSamplers(_vertexShader, device.VertexTextures, device.VertexSamplerStates);

                // Update the constant buffers.
                for (var c = 0; c < _vertexShader.CBuffers.Length; c++)
                {
                    var cb = _effect.ConstantBuffers[_vertexShader.CBuffers[c]];
                    cb.Update(_effect.Parameters);
                    device.SetConstantBuffer(ShaderStage.Vertex, c, cb);
                }
            }

            if (_pixelShader != null)
            {
                device.PixelShader = _pixelShader;

                // Update the texture parameters.
                SetShaderSamplers(_pixelShader, device.Textures, device.SamplerStates);

                // Update the constant buffers.
                for (var c = 0; c < _pixelShader.CBuffers.Length; c++)
                {
                    var cb = _effect.ConstantBuffers[_pixelShader.CBuffers[c]];
                    cb.Update(_effect.Parameters);
                    device.SetConstantBuffer(ShaderStage.Pixel, c, cb);
                }
            }
#endif

            // Set the render states if we have some.
            if (_rasterizerState != null)
            {
                device.RasterizerState = _rasterizerState;
            }
            if (_blendState != null)
            {
                device.BlendState = _blendState;
            }
            if (_depthStencilState != null)
            {
                device.DepthStencilState = _depthStencilState;
            }
        }