예제 #1
0
        private bool RegisterHLSL(string name, IMCEffect effect)
        {
            if (!m_nameHLSLIndex.ContainsKey(name))
            {
                m_nameHLSLIndex[name] = new WeakReference <IMCEffect>(effect);
                return(true);
            }

            return(true);
        }
예제 #2
0
 /// <summary>
 /// エフェクトをセットする
 /// </summary>
 /// <param name="effect"></param>
 public void SetEffect(IMCEffect effect)
 {
     if (m_spCoreEffect != effect)
     {
         AllClear();
     }
     if (m_spCoreEffect == null)
     {
         m_spCoreEffect = effect;
     }
 }
예제 #3
0
 public bool GetEffect(string srcFile, out IMCEffect effect)
 {
     effect = null;
     if (m_nameHLSLIndex.ContainsKey(srcFile))
     {
         IMCEffect target;
         if (!m_nameHLSLIndex[srcFile].TryGetTarget(out target))
         {
             m_nameHLSLIndex.Remove(srcFile);
             return(false);
         }
         effect = target;
         return(true);
     }
     return(false);
 }
예제 #4
0
        public int GetCreateEffectFromFile(string srcFile, out IMCEffect effect, out string errMsg)
        {
            errMsg = "";
            effect = null;
            // 既に存在するか?
            if (GetEffect(srcFile, out effect))
            {
                return(0);
            }


            Effect effectTmp;

            if (Path.GetExtension(srcFile) == ".cfx")
            {
                byte[] effectByteCode;
                var    fs = new System.IO.FileStream(
                    srcFile,
                    System.IO.FileMode.Open,
                    System.IO.FileAccess.Read);
                effectByteCode = new byte[fs.Length];
                fs.Read(effectByteCode, 0, (int)fs.Length);
                fs.Close();
                effectTmp = new Effect(App.DXDevice, effectByteCode);
            }
            else
            {
                var effectByteCode = ShaderBytecode.CompileFromFile("HLSL\\" + srcFile, "fx_5_0", ShaderFlags.None, EffectFlags.None, null, new HLSLIncludeFile());
                if (effectByteCode.HasErrors)
                {
                    Debug.WriteLine(errMsg);
                    errMsg = effectByteCode.Message;
                    return(-1);
                }
                Debug.WriteLine(errMsg);
                effectTmp = new Effect(App.DXDevice, effectByteCode);
            }


            effect = new MCEffect(effectTmp, HLSLRSC_SOURCELOCATION.FILE, srcFile);
            RegisterHLSL(srcFile, effect);

            return(0);
        }
예제 #5
0
        public int GetCreateEffectFromResource(string resourcePrefix, string srcFile, out IMCEffect effect, out string errMsg)
        {
            errMsg = "";
            effect = null;
            // 既に存在するか?
            if (GetEffect(srcFile, out effect))
            {
                return(0);
            }



            //System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            //string[] names = myAssembly.GetManifestResourceNames(); // it is really there by its name "shader.tkb"
            //Stream myStream = myAssembly.GetManifestResourceStream(names[0]);


            Effect effectTmp;

            if (Path.GetExtension(srcFile) == ".cfx")
            {
                byte[] effectByteCode;
                using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePrefix + "." + srcFile))
                {
                    effectByteCode = new byte[s.Length];
                    s.Read(effectByteCode, 0, (int)s.Length);
                }
                effectTmp = new Effect(App.DXDevice, effectByteCode);
            }
            else
            {
                string hlslText;
                using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePrefix + "." + srcFile))
                {
                    using (StreamReader r = new StreamReader(s))
                    {
                        hlslText = r.ReadToEnd();
                    }
                }
                var effectByteCode = ShaderBytecode.Compile(hlslText, "fx_5_0", ShaderFlags.None, EffectFlags.None, null, new HLSLIncludeResource(resourcePrefix));
                if (effectByteCode.HasErrors)
                {
                    Debug.WriteLine(errMsg);
                    errMsg = effectByteCode.Message;
                    return(-1);
                }
                Debug.WriteLine(errMsg);
                effectTmp = new Effect(App.DXDevice, effectByteCode.Bytecode);
            }

            effect = new MCEffect(effectTmp, HLSLRSC_SOURCELOCATION.RESOURCE, srcFile);
            RegisterHLSL(srcFile, effect);

            return(0);
        }