示例#1
0
        /// <summary>
        /// Load an effect from an hlsl .fx file
        /// </summary>
        public static BasicShader LoadFromFXFile(IXNAGame game, IGameFile file)
        {
            BasicShader shader = new BasicShader(game);

            //obs?
            // Dispose old shader
            if (shader.effect != null)
            {
                shader.effect.Dispose();
                shader.effect = null;
            }
            CompiledEffect compiledEffect;

            try
            {
                compiledEffect = Effect.CompileEffectFromFile(file.GetFullFilename(), null, null, CompilerOptions.None, TargetPlatform.Windows);

                shader.effect = new Effect(game.GraphicsDevice, compiledEffect.GetEffectCode(), CompilerOptions.None, null);
            } // try
            catch (Exception ex)
            {
                /*Log.Write( "Failed to load shader " + shaderContentName + ". " +
                 *  "Error: " + ex.ToString() );*/
                // Rethrow error, app can't continue!
                throw ex;
            }



            shader.LoadParameters();

            return(shader);
        } // Load()
        /// <summary>
        /// Init LineManager
        /// TODO: this class should be adapted so that it can be fully created even when the device isn't fully initialized.
        /// </summary>
        public LineManager3D(IXNAGame nGame)
        {
            game = nGame;

            /*if ( HoofdObject.XNAGame.Graphics.GraphicsDevice  == null )
             *  throw new NullReferenceException(
             *      "XNA device is not initialized, can't init line manager." );*/

            shader = BasicShader.LoadFromFXFile(game, game.EngineFiles.LineRenderingShader);
            shader.SetTechnique("LineRendering3D");

            decl = new VertexDeclaration(game.GraphicsDevice, VertexPositionColor.VertexElements);
        } // LineManager()