internal D3D10EffectTechnique Clone(D3D.EffectTechnique tech, D3D10EffectImplementation parent)
        {
            D3D10EffectTechnique clone = new D3D10EffectTechnique(parent, tech);

            clone._passes = _passes.Clone(tech);
            return(clone);
        }
        /// <summary>
        /// Clones the pass collection using the new effect technique,
        /// used for when the effect implementation is cloned.
        /// </summary>
        /// <param name="tech">The D3D10 effect technique.</param>
        /// <returns>Cloned collection</returns>
        internal D3D10EffectPassCollection Clone(D3D.EffectTechnique tech)
        {
            D3D10EffectPassCollection clone = new D3D10EffectPassCollection();

            for (int i = 0; i < Count; i++)
            {
                clone.Add(_passes[i].Clone(tech.GetPassByIndex(i)));
            }
            return(clone);
        }
        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectTechnique"/>.
        /// </summary>
        /// <param name="parent">The implementation parent.</param>
        /// <param name="effect">The D3D10 effect.</param>
        /// <param name="tech">The D3D10 technique.</param>
        internal D3D10EffectTechnique(D3D10EffectImplementation parent, D3D.Effect effect, D3D.EffectTechnique tech)
        {
            _tech   = tech;
            _parent = parent;

            D3D.EffectTechniqueDescription desc = _tech.Description;
            _name = desc.Name;

            //Fetch annotations
            int annoCount = desc.AnnotationCount;

            _annotations = new D3D10EffectAnnotationCollection();
            for (int i = 0; i < annoCount; i++)
            {
                D3D.EffectVariable            anno     = _tech.GetAnnotationByIndex(i);
                D3D.EffectVariableDescription annoDesc = anno.Description;
                D3D.EffectVariable            annoVar  = anno.AsString();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Object, EffectParameterType.String));
                }
                annoVar = anno.AsScalar();
                if (annoVar != null)
                {
                    //Need to find a way to get the param type...
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Scalar, EffectParameterType.Unknown));
                }
                annoVar = anno.AsMatrix();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Matrix, EffectParameterType.Single));
                }
            }

            _passes = new D3D10EffectPassCollection();
            for (int i = 0; i < desc.PassCount; i++)
            {
                _passes.Add(new D3D10EffectPass(parent, effect, tech.GetPassByIndex(i)));
            }
        }
Exemple #4
0
        //creation functions
        public Terrain(int q, StreamReader file)
        {
            quadSize = q;
            //loading effect
            effect = ResourceManager.mainManager.LoadEffect("Resources\\Effects\\Terrain.fx", ResourceManager.mainManager.GetDefaultEffectPool());
            technique = effect.GetTechniqueByName("Render");
            pass = technique.GetPassByIndex(0);
            //creating layout
            D3D10.InputElement[] elements = new SlimDX.Direct3D10.InputElement[1];
            elements[0] = new SlimDX.Direct3D10.InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32_Float, 0, 0, D3D10.InputClassification.PerVertexData, 0);
            layout = new SlimDX.Direct3D10.InputLayout(Game.gameClass.GetDevice(), elements, pass.Description.Signature);

            //loading texture
            D3D10.ImageLoadInformation load = new SlimDX.Direct3D10.ImageLoadInformation();
            load.BindFlags = D3D10.BindFlags.ShaderResource;
            load.CpuAccessFlags = D3D10.CpuAccessFlags.None;
            load.MipLevels = 1;
            load.Usage=D3D10.ResourceUsage.Default;
            load.OptionFlags = D3D10.ResourceOptionFlags.None;
            load.FilterFlags = D3D10.FilterFlags.Point;
            load.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
            normalTexture = D3D10.Texture2D.FromFile(Game.gameClass.GetDevice(), Path.GetDirectoryName(Game.gameClass.GetLvLFilePath()) + "\\normals.png", load);
            Globals.mapSize = normalTexture.Description.Width;

            if (Game.gameClass.GetEngineState() != EngineState.play)
            {
                D3D10.Texture2DDescription desc = new SlimDX.Direct3D10.Texture2DDescription();
                desc.ArraySize = 1;
                desc.BindFlags = D3D10.BindFlags.None;
                desc.CpuAccessFlags = D3D10.CpuAccessFlags.Write;
                desc.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
                desc.Height = Globals.mapSize;
                desc.Width = Globals.mapSize;
                desc.Usage = D3D10.ResourceUsage.Staging;
                desc.MipLevels = 1;
                SlimDX.DXGI.SampleDescription sampleDescription = new SlimDX.DXGI.SampleDescription();
                sampleDescription.Count = 1;
                sampleDescription.Quality = 0;
                desc.SampleDescription = sampleDescription;
                normalTexUpdater = new SlimDX.Direct3D10.Texture2D(Game.gameClass.GetDevice(), desc);
                normalData = normalTexUpdater.Map(0, D3D10.MapMode.Write, D3D10.MapFlags.DoNotWait);
                normalTexUpdater.Unmap(0);
            }

               // LoadTextureArray(file);
            //setting up vertices and creating vertex buffer
            LoadVertexInfo();
            CreateVertexBuffer();

            //constant buffer variables
            effect.GetVariableByName("mapSize").AsScalar().Set(Globals.mapSize);
            using(D3D10.ShaderResourceView normalView=new D3D10.ShaderResourceView(Game.gameClass.GetDevice(),normalTexture))
                effect.GetVariableByName("normalMap").AsResource().SetResource(normalView);
              //  using (D3D10.ShaderResourceView texturesView = new D3D10.ShaderResourceView(Game.gameClass.GetDevice(), textures))
            //    effect.GetVariableByName("textures").AsResource().SetResource(texturesView);

            orientations=effect.GetVariableByName("orientations").AsVector();
               // effect.GetVariableByName("texCoordMul").AsScalar().Set(TextureInfo.texCoordMul);
            heightMul = effect.GetVariableByName("heightMul").AsScalar();
            heightMul.Set(Globals.heightMultiplier);

            //handles edit mode
            if (Game.gameClass.GetEngineState() != EngineState.play)
            {
                techniqueEdit = effect.GetTechniqueByName("Edit");
                passEdit = techniqueEdit.GetPassByIndex(0);
                mousePick = effect.GetVariableByName("mousePick").AsVector();
                pickOptions = effect.GetVariableByName("pickOpt").AsVector();
            }
            Globals.SetMap(map);
        }