示例#1
0
        /// <summary>
        ///     コンストラクタ
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="context"></param>
        /// <param name="effect">解釈対象のエフェクト</param>
        /// <param name="model">使用対象のモデル</param>
        /// <param name="loader"></param>
        private MMEEffectManager(string fileName, RenderContext context, SlimDX.Direct3D11.Effect effect, IDrawable model, ISubresourceLoader loader)
        {
            this.fileName     = fileName;
            SubresourceLoader = loader;
            if (!fileName.Equals(MMFDefaultShaderResourcePath))
            {
                //ファイルパスがデフォルトのシェーダーと等しくない時は、デフォルトのシェーダーも読み込んでおく。
                DefaultShader = LoadFromResource(MMFDefaultShaderResourcePath, model, context, new BasicSubresourceLoader("Shader"));
            }
            else
            {
                DefaultShader = this; //等しい時は自身がデフォルトのシェーダーと等しい。
            }
            Context    = context;
            EffectFile = effect;
            EffectInfo = new MMEEffectInfo(effect);
            ActiveSubscriberByMaterial = new Dictionary <EffectVariable, SubscriberBase>();
            ActiveSubscriberByModel    = new Dictionary <EffectVariable, SubscriberBase>();
            ActivePeculiarSubscriber   = new Dictionary <EffectVariable, PeculiarValueSubscriberBase>();
            Techniques = new List <MMEEffectTechnique>();
            RenderColorTargetViewes   = new Dictionary <string, RenderTargetView>();
            RenderDepthStencilTargets = new Dictionary <string, DepthStencilView>();
            this.model = model;
            //グローバル変数の登録
            int valCount = effect.Description.GlobalVariableCount;

            for (int i = 0; i < valCount; i++)
            {
                string semantic         = Regex.Replace(effect.GetVariableByIndex(i).Description.Semantic, "[0-9]", "");
                string semanticIndexStr = Regex.Replace(effect.GetVariableByIndex(i).Description.Semantic, "[^0-9]", "");
                int    semanticIndex    = string.IsNullOrEmpty(semanticIndexStr)?0:int.Parse(semanticIndexStr);
                string typeName         = effect.GetVariableByIndex(i).GetVariableType().Description.TypeName.ToLower();
                semantic = semantic.ToUpper(); //小文字でもいいようにするため大文字に全て変換
                if (EffectSubscriber.ContainsKey(semantic))
                {                              //通常はセマンティクスに応じて登録
                    SubscriberBase subs     = EffectSubscriber[semantic];
                    EffectVariable variable = effect.GetVariableByIndex(i);
                    subs.CheckType(variable);
                    if (subs.UpdateTiming == UpdateBy.Material)
                    {
                        ActiveSubscriberByMaterial.Add(variable, subs.GetSubscriberInstance(variable, context, this, semanticIndex));
                    }
                    else
                    {
                        ActiveSubscriberByModel.Add(variable, subs.GetSubscriberInstance(variable, context, this, semanticIndex));
                    }
                }
                else if (typeName.Equals("texture") || typeName.Equals("texture2d") || typeName.Equals("texture3d") ||
                         typeName.Equals("texturecube")) //テクスチャのみ例外で、変数型に応じて登録する
                {
                    SubscriberBase subs     = new TextureSubscriber();
                    EffectVariable variable = effect.GetVariableByIndex(i);
                    subs.CheckType(variable);
                    ActiveSubscriberByModel.Add(variable, subs.GetSubscriberInstance(variable, context, this, semanticIndex));
                }
                else//特殊変数は変数名に応じて登録する
                {
                    string name = effect.GetVariableByIndex(i).Description.Name;
                    name = name.ToLower();
                    if (PeculiarEffectSubscriber.ContainsKey(name))
                    {
                        ActivePeculiarSubscriber.Add(effect.GetVariableByIndex(i), PeculiarEffectSubscriber[name]);
                    }
                }
            }
            //定数バッファの登録
            valCount = effect.Description.ConstantBufferCount;
            for (int i = 0; i < valCount; i++)
            {
                string name = effect.GetConstantBufferByIndex(i).Description.Name;
                name = name.ToUpper();
                if (EffectSubscriber.ContainsKey(name))
                {
                    SubscriberBase       subs     = EffectSubscriber[name]; //定数バッファにはセマンティクスが付けられないため、変数名で代用
                    EffectConstantBuffer variable = effect.GetConstantBufferByIndex(i);
                    subs.CheckType(variable);
                    if (subs.UpdateTiming == UpdateBy.Material)
                    {
                        ActiveSubscriberByMaterial.Add(variable, subs.GetSubscriberInstance(variable, context, this, 0));
                    }
                    else
                    {
                        ActiveSubscriberByModel.Add(variable, subs.GetSubscriberInstance(variable, context, this, 0));
                    }
                }
            }

            int subsetCount = model is ISubsetDivided ? ((ISubsetDivided)model).SubsetCount : 1;

            foreach (EffectTechnique t in EffectInfo.SortedTechnique)//MMEEffectTechniqueもソートしておく
            {
                //テクニックをすべて読みだす
                Techniques.Add(new MMEEffectTechnique(this, t, subsetCount, context));
            }
        }
示例#2
0
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="context"></param>
        /// <param name="effect">Effects of being interpreted</param>
        /// <param name="model">Want to use models</param>
        /// <param name="loader"></param>
        private MMEEffectManager(string fileName, RenderContext context, Effect effect, IDrawable model, ISubresourceLoader loader)
        {
            this.fileName          = fileName;
            this.SubresourceLoader = loader;
            if (!fileName.Equals(MMFDefaultShaderResourcePath))
            {
                //The default shaders loaded and the default file path is not equal:。
                this.DefaultShader = LoadFromResource(MMFDefaultShaderResourcePath, model, context, new BasicSubresourceLoader("Shader"));
            }
            else
            {
                this.DefaultShader = this; //Equal to itself is equal to the default shader。
            }
            this.Context    = context;
            this.EffectFile = effect;
            this.EffectInfo = new MMEEffectInfo(effect);
            this.ActiveSubscriberByMaterial = new Dictionary <EffectVariable, SubscriberBase>();
            this.ActiveSubscriberByModel    = new Dictionary <EffectVariable, SubscriberBase>();
            this.ActivePeculiarSubscriber   = new Dictionary <EffectVariable, PeculiarValueSubscriberBase>();
            this.Techniques = new List <MMEEffectTechnique>();
            this.RenderColorTargetViewes   = new Dictionary <string, RenderTargetView>();
            this.RenderDepthStencilTargets = new Dictionary <string, DepthStencilView>();
            this.model = model;
            //Creating global variables
            int valCount = effect.Description.GlobalVariableCount;

            for (int i = 0; i < valCount; i++)
            {
                string semantic         = Regex.Replace(effect.GetVariableByIndex(i).Description.Semantic, "[0-9]", "");
                string semanticIndexStr = Regex.Replace(effect.GetVariableByIndex(i).Description.Semantic, "[^0-9]", "");
                int    semanticIndex    = string.IsNullOrEmpty(semanticIndexStr)?0:int.Parse(semanticIndexStr);
                string typeName         = effect.GetVariableByIndex(i).GetVariableType().Description.TypeName.ToLower();
                semantic = semantic.ToUpper(); //A good case for all converted to uppercase
                if (EffectSubscriber.ContainsKey(semantic))
                {                              //Usually the register according to the semantics
                    SubscriberBase subs     = EffectSubscriber[semantic];
                    EffectVariable variable = effect.GetVariableByIndex(i);
                    subs.CheckType(variable);
                    if (subs.UpdateTiming == UpdateBy.Material)
                    {
                        this.ActiveSubscriberByMaterial.Add(variable, subs.GetSubscriberInstance(variable, context, this, semanticIndex));
                    }
                    else
                    {
                        this.ActiveSubscriberByModel.Add(variable, subs.GetSubscriberInstance(variable, context, this, semanticIndex));
                    }
                }
                else if (typeName.Equals("texture") || typeName.Equals("texture2d") || typeName.Equals("texture3d") ||
                         typeName.Equals("texturecube")) //Textures only in exceptions, depending on the variable type to register
                {
                    SubscriberBase subs     = new TextureSubscriber();
                    EffectVariable variable = effect.GetVariableByIndex(i);
                    subs.CheckType(variable);
                    this.ActiveSubscriberByModel.Add(variable, subs.GetSubscriberInstance(variable, context, this, semanticIndex));
                }
                else//Special variable to register according to the variable name
                {
                    string name = effect.GetVariableByIndex(i).Description.Name;
                    name = name.ToLower();
                    if (PeculiarEffectSubscriber.ContainsKey(name))
                    {
                        this.ActivePeculiarSubscriber.Add(effect.GetVariableByIndex(i), PeculiarEffectSubscriber[name]);
                    }
                }
            }
            //Constant buffer register
            valCount = effect.Description.ConstantBufferCount;
            for (int i = 0; i < valCount; i++)
            {
                string name = effect.GetConstantBufferByIndex(i).Description.Name;
                name = name.ToUpper();
                if (EffectSubscriber.ContainsKey(name))
                {
                    SubscriberBase       subs     = EffectSubscriber[name]; //A constant buffer semantics, so instead the variable name
                    EffectConstantBuffer variable = effect.GetConstantBufferByIndex(i);
                    subs.CheckType(variable);
                    if (subs.UpdateTiming == UpdateBy.Material)
                    {
                        this.ActiveSubscriberByMaterial.Add(variable, subs.GetSubscriberInstance(variable, context, this, 0));
                    }
                    else
                    {
                        this.ActiveSubscriberByModel.Add(variable, subs.GetSubscriberInstance(variable, context, this, 0));
                    }
                }
            }

            int subsetCount = model is ISubsetDivided ? ((ISubsetDivided)model).SubsetCount : 1;

            foreach (EffectTechnique t in this.EffectInfo.SortedTechnique)//MMEEffectTechnique are sorted by
            {
                //All techniques will be read
                this.Techniques.Add(new MMEEffectTechnique(this, t, subsetCount, context));
            }
        }