/*
 	                    GraphiXNA Shading Library
    Copyright (C) 2007-2008 Mahdi Khodadadi Fard (mahdi3466@yahoo.com)

    Permission is hereby granted, free of charge, to any person obtaining a copy of
    this software and associated documentation files (the "Software"), to deal in
    the Software without restriction, including without limitation the rights to
    use, copy, modify, merge, publish, distribute, sublicense, and.or sell copies of
    the Software, and to permit persons to whom the Software is furnished to do so,
    subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 */

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Content;
using System.Reflection;
using System.IO;
using Microsoft.Xna.Framework.Graphics;

namespace GraphiXNA
{
    public sealed class ResourceManager : ContentManager
    {
        private static Dictionary<GraphicsDevice, ResourceManager> dict = new Dictionary<GraphicsDevice, ResourceManager>();

        internal static ResourceManager FindBy(GraphicsDevice graphicsDevice)
        {
            if (dict.ContainsKey(graphicsDevice))
            {
                return dict[graphicsDevice];
            }
            else
            {
                ResourceManager conMan = new ResourceManager(graphicsDevice);
                dict.Add(graphicsDevice, conMan);

                return conMan;
            }
        }


        public static Texture2D GetWhiteTexture(GraphicsDevice graphicsDevice)
        {
            return FindBy(graphicsDevice).White;
        }

        public static Texture2D GetSmokeTexture(GraphicsDevice graphicsDevice)
        {
            return FindBy(graphicsDevice).Smoke;
        }

        public static Texture2D GetCoronaTexture(GraphicsDevice graphicsDevice)
        {
            return FindBy(graphicsDevice).Corona;
        }


        internal static Texture2D GetLogoTexture(GraphicsDevice graphicsDevice)
        {
            return FindBy(graphicsDevice).Logo;
        }

        public static Texture2D GetFlameTexture(GraphicsDevice graphicsDevice)
        {
            return FindBy(graphicsDevice).Flame;
        }

        internal static Texture2D GetNoise0Texture(GraphicsDevice graphicsDevice)
        {
            return FindBy(graphicsDevice).Noise0;
        }

        internal static Texture2D GetMarbleTexture(GraphicsDevice graphicsDevice)
        {
            return FindBy(graphicsDevice).Marble;
        }

        internal static Texture2D GetNormal0Texture(GraphicsDevice graphicsDevice)
        {
            return FindBy(graphicsDevice).Normal0;
        }


        internal static Texture2D GetNormal1Texture(GraphicsDevice graphicsDevice)
        {
            return FindBy(graphicsDevice).Normal1;
        }

        internal static Effect GetParticleEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).ParticleEffect;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetNoPostProcessEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).NoPostProcess;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetTextureMappingEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).TextureMapping;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetDepthBufferEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).DepthBuffer;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetSkyBoxEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).SkyBox;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetWaterEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).Water;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetLambertianEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).Lambertian;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetNormalMappingEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).NormalMapping;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetGoochyEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).Goochy;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetParallaxOcclusionMappingEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).ParallaxOcclusionMapping;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }

        internal static Effect GetParallaxMappingEffect(GraphicsDevice graphicsDevice, bool clone)
        {
            Effect effect = FindBy(graphicsDevice).ParallaxMapping;

            if (clone)
            {
                effect = effect.Clone(graphicsDevice);
            }

            return effect;
        }



        internal static Effect GetVelvetyEffect(GraphicsDevice GraphicsDevice, bool clone)
        {
            Effect effect = FindBy(GraphicsDevice).Velvety;

            if (clone)
            {
                effect = effect.Clone(GraphicsDevice);
            }

            return effect;
        }


        internal GraphicsDevice GraphicsDevice = null;

        private ResourceManager(GraphicsDevice graphicsDevice)
            : base(new InternalGameServiceContainer(graphicsDevice))
        { GraphicsDevice = graphicsDevice; }

        private static Assembly thisAssembly = Assembly.GetExecutingAssembly();

        protected override Stream OpenStream(string assetName)
        {
            return thisAssembly.GetManifestResourceStream("GraphiXNA.Internal." + assetName + ".xnb");
        }

        private Texture2D Noise0
        {
            get
            {
                return Load<Texture2D>("Textures.Noise.Noise0");
            }
        }

        private Texture2D Marble
        {
            get
            {
                return Load<Texture2D>("Textures.Noise.Marble");
            }
        }

        private Texture2D Normal0
        {
            get
            {
                return Load<Texture2D>("Textures.Noise.Normal0");
            }
        }

        private Texture2D Normal1
        {
            get
            {
                return Load<Texture2D>("Textures.Noise.Normal1");
            }
        }

        private Texture2D White
        {
            get
            {
                return Load<Texture2D>("Textures.Color.White");
            }
        }

        private Texture2D Flame
        {
            get
            {
                return Load<Texture2D>("Textures.Flame");
            }
        }

        private Texture2D Corona
        {
            get
            {
                return Load<Texture2D>("Textures.Corona");
            }
        }

        private Texture2D Smoke
        {
            get
            {
                return Load<Texture2D>("Textures.Smoke");
            }
        }

        private Texture2D Logo
        {
            get
            {
                return Load<Texture2D>("Textures.Logo");
            }
        }

        private Effect SkyBox
        {
            get
            {
                return Load<Effect>("Effects.SkyBox");
            }
        }

        private Effect ParticleEffect
        {
            get
            {
                return Load<Effect>("Particle.ParticleEffect");
            }
        }

        private Effect DepthBuffer
        {
            get
            {
                return Load<Effect>("Effects.Materials.DepthBuffer");
            }
        }

        private Effect ParallaxMapping
        {
            get
            {
                return Load<Effect>("Effects.Materials.ParallaxMapping");
            }
        }
        private Effect ParallaxOcclusionMapping
        {
            get
            {
                return Load<Effect>("Effects.Materials.ParallaxOcclusionMapping");
            }
        }

        private Effect NormalMapping
        {
            get
            {
                return Load<Effect>("Effects.Materials.NormalMapping");
            }
        }

        private Effect Goochy
        {
            get
            {
                return Load<Effect>("Effects.Materials.Goochy");
            }
        }

        private Effect Water
        {
            get
            {
                return Load<Effect>("Effects.Materials.Water");
            }
        }

        private Effect Lambertian
        {
            get
            {
                return Load<Effect>("Effects.Materials.Lambertian");
            }
        }

        private Effect TextureMapping
        {
            get
            {
                return Load<Effect>("Effects.Materials.TextureMapping");
            }
        }

        private Effect Velvety
        {
            get
            {
                return Load<Effect>("Effects.Materials.Velvety");
            }
        }

        private Effect NoPostProcess
        {
            get
            {
                return Load<Effect>("Effect2D.NoPostProcess");
            }
        }

        internal Effect Transparent
        {
            get
            {
                return Load<Effect>("Effect2D.Transparent");
            }
        }
        internal Effect ToneMapping
        {
            get
            {
                return Load<Effect>("Effect2D.ToneMapping");
            }
        }

        internal Effect HeatHaze
        {
            get
            {
                return Load<Effect>("Effect2D.HeatHaze");
            }
        }

        internal Effect Perturb
        {
            get
            {
                return Load<Effect>("Effect2D.Perturb");
            }
        }

        internal Effect RadialBlur
        {
            get
            {
                return Load<Effect>("Effect2D.RadialBlur");
            }
        }
        internal Effect GrowablePoissonDisc
        {
            get
            {
                return Load<Effect>("Effect2D.GrowablePoissonDisc");
            }
        }
        internal Effect Pinch
        {
            get
            {
                return Load<Effect>("Effect2D.Pinch");
            }
        }
        internal Effect ColorTone
        {
            get
            {
                return Load<Effect>("Effect2D.ColorTone");
            }
        }
        internal Effect AverageBlur
        {
            get
            {
                return Load<Effect>("Effect2D.AverageBlur");
            }
        }
        internal Effect SmartBlur
        {
            get
            {
                return Load<Effect>("Effect2D.SmartBlur");
            }
        }

        internal Effect GaussianBlur
        {
            get
            {
                return Load<Effect>("Effect2D.GaussianBlur");
            }
        }

        internal Effect BrightExtract
        {
            get
            {
                return Load<Effect>("Effect2D.BrightExtract");
            }
        }

        internal Effect ColorInverse
        {
            get
            {
                return Load<Effect>("Effect2D.ColorInverse");
            }
        }

        internal Effect Distort
        {
            get
            {
                return Load<Effect>("Effect2D.Distort");
            }
        }

        internal Effect Pixelate
        {
            get
            {
                return Load<Effect>("Effect2D.Pixelate");
            }
        }

        internal Effect TextureCombine
        {
            get
            {
                return Load<Effect>("Effect2D.TextureCombine");
            }
        }

        internal Effect Embossed
        {
            get
            {
                return Load<Effect>("Effect2D.Embossed");
            }
        }

        internal Effect Bloom
        {
            get
            {
                return Load<Effect>("Effect2D.Bloom");
            }
        }

        internal Effect Ripple
        {
            get
            {
                return Load<Effect>("Effect2D.Ripple");
            }
        }

        internal Effect Monochrome
        {
            get
            {
                return Load<Effect>("Effect2D.Monochrome");
            }
        }

        internal Effect ContrastAdjust
        {
            get
            {
                return Load<Effect>("Effect2D.ContrastAdjust");
            }
        }

        internal Effect LightStreak
        {
            get
            {
                return Load<Effect>("Effect2D.LightStreak");
            }
        }

        internal Effect Gloom
        {
            get
            {
                return Load<Effect>("Effect2D.Gloom");
            }
        }

        internal Effect Sharpen
        {
            get
            {
                return Load<Effect>("Effect2D.Sharpen");
            }
        }

        internal Effect Brick
        {
            get
            {
                return Load<Effect>("Effect2D.Procedural.Brick");
            }
        }
    }
}
