- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/Backup/DXGfxLib/EffectGroup.cs

Go to the documentation of this file.

    00001 //BSD License
    00002 //DXGfx® - http://www.eteractions.com
    00003 //Copyright (c) 2005
    00004 //by Guillaume Randon
    00005 //Permission is hereby granted, free of charge, to any person obtaining a copy of this software
    00006 //and associated documentation files (the "Software"), to deal in the Software without restriction,
    00007 //including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00008 //and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
    00009 //subject to the following conditions:
    00010 //The above copyright notice and this permission notice shall be included in all copies or substantial
    00011 //portions of the Software.
    00012 //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
    00013 //INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
    00014 //AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00015 //DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00016 //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00017 using System;
    00018 using System.Collections;
    00019 using System.Collections.Generic;
    00020 using System.Text;
    00021 using System.Diagnostics;
    00022 using System.IO;
    00023 using Microsoft.DirectX;
    00024 using Microsoft.DirectX.Direct3D;
    00025 using Microsoft.Samples.DirectX.UtilityToolkit;
    00026
    00027 namespace DXGfxLib
    00028 {
    00032     public enum EffectCategory
    00033     {
    00034         RenderScene,
    00035         RenderLight,
    00036         RenderEnvMap
    00037     }
    00038
    00045     public class EffectGroup : IComparable, IDisposable
    00046     {
    00050         protected Effect renderScene = null;
    00051
    00055         public Effect RenderScene
    00056         {
    00057             get { return renderScene; }
    00058         }
    00059
    00064         public Effect Default
    00065         {
    00066             get { return renderScene; }
    00067         }
    00068
    00072         protected string renderSceneEffectFile = "";
    00073
    00077         public string RenderSceneEffectFile
    00078         {
    00079             get { return renderSceneEffectFile; }
    00080         }
    00081
    00085         public string DefaultFile
    00086         {
    00087             get { return renderSceneEffectFile; }
    00088         }
    00089
    00093         public string EffectGroupName
    00094         {
    00095             get { return renderSceneEffectFile; }
    00096         }
    00097
    00101         protected Effect renderLight = null;
    00102
    00106         public Effect RenderLight
    00107         {
    00108             get { return renderLight; }
    00109         }
    00110
    00114         protected string renderLightEffectFile = "";
    00115
    00119         public string RenderLightEffectFile
    00120         {
    00121             get { return renderLightEffectFile; }
    00122         }
    00123
    00127         protected Effect renderEnvMap = null;
    00128
    00132         public Effect RenderEnvMap
    00133         {
    00134             get { return renderEnvMap; }
    00135         }
    00136
    00140         protected string renderEnvMapEffectFile = "";
    00141
    00145         public string RenderEnvMapEffectFile
    00146         {
    00147             get { return renderEnvMapEffectFile; }
    00148         }
    00149
    00153         public void Dispose()
    00154         {
    00155             if (renderScene != null)
    00156             {
    00157                 renderScene.Dispose();
    00158             }
    00159             if (renderLight != null)
    00160             {
    00161                 renderLight.Dispose();
    00162             }
    00163             if (renderEnvMap != null)
    00164             {
    00165                 renderEnvMap.Dispose();
    00166             }
    00167         }
    00168
    00174         public void Set(Device d3ddevice, string fileName)
    00175         {
    00176             Set(d3ddevice, fileName, EffectCategory.RenderScene);
    00177         }
    00178
    00185         public void Set(Device d3ddevice, string fileName, EffectCategory category)
    00186         {
    00187             if (!File.Exists(fileName))
    00188             {
    00189                 // Let's try to found it
    00190                 fileName = Utility.FindMediaFile(StringUtil.GetName(fileName));
    00191             }
    00192
    00193             string strErr = "No Problem!";
    00194             Effect effect = null;
    00195             String effectFileName = "";
    00196
    00197             try
    00198             {
    00199                 effect = ResourceCache.GetGlobalInstance().CreateEffectFromFile(d3ddevice, fileName, null, null, ShaderFlags.None, null, out strErr);
    00200                 effect.Technique = "Default";
    00201                 effectFileName = fileName;
    00202             }
    00203             catch (Exception ex)
    00204             {
    00205                 Trace.WriteLine(strErr);
    00206                 throw new EffectException("Exception while creating effect", fileName, strErr, ex);
    00207             }
    00208
    00209             switch (category)
    00210             {
    00211                 case EffectCategory.RenderScene:
    00212                     renderScene = effect;
    00213                     renderSceneEffectFile = effectFileName;
    00214                     break;
    00215                 case EffectCategory.RenderLight:
    00216                     renderLight = effect;
    00217                     renderLightEffectFile = effectFileName;
    00218                     break;
    00219                 case EffectCategory.RenderEnvMap:
    00220                     renderEnvMap = effect;
    00221                     renderEnvMapEffectFile = effectFileName;
    00222                     break;
    00223             }
    00224         }
    00225
    00232         public void Set(Effect effect, string fileName)
    00233         {
    00234             Set(effect, fileName, EffectCategory.RenderScene);
    00235         }
    00236
    00244         public void Set(Effect effect, string fileName, EffectCategory category)
    00245         {
    00246             if (effect.Technique == string.Empty)
    00247             {
    00248                 effect.Technique = "Default";
    00249             }
    00250
    00251             switch (category)
    00252             {
    00253                 case EffectCategory.RenderScene:
    00254                     renderScene = effect;
    00255                     renderSceneEffectFile = fileName;
    00256                     break;
    00257                 case EffectCategory.RenderLight:
    00258                     renderLight = effect;
    00259                     renderLightEffectFile = fileName;
    00260                     break;
    00261                 case EffectCategory.RenderEnvMap:
    00262                     renderEnvMap = effect;
    00263                     renderEnvMapEffectFile = fileName;
    00264                     break;
    00265             }
    00266         }
    00267
    00276         public int CompareTo(Object obj)
    00277         {
    00278             int ret = 1;
    00279             EffectGroup effectGroup = obj as EffectGroup;
    00280
    00281             if (effectGroup != null)
    00282             {
    00283                 ret = renderSceneEffectFile.CompareTo(effectGroup.RenderSceneEffectFile);
    00284             }
    00285             return ret;
    00286         }
    00287
    00296         public int CompareTo(EffectGroup effectGroup)
    00297         {
    00298             return renderSceneEffectFile.CompareTo(effectGroup.RenderSceneEffectFile);
    00299         }
    00300     }
    00301 }