Пример #1
0
        public SpriteTexture(D3D.Device device, string filename)
            : base(device)
        {
            D3D.ImageLoadInformation iml = new D3D.ImageLoadInformation()
            {
                BindFlags = D3D.BindFlags.ShaderResource,
                CpuAccessFlags = D3D.CpuAccessFlags.None,
                Depth = 1,
                FilterFlags = D3D.FilterFlags.None,
                FirstMipLevel = 0,
                Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                MipFilterFlags = D3D.FilterFlags.None,
                MipLevels = 1,
                OptionFlags = D3D.ResourceOptionFlags.None,
                Usage = D3D.ResourceUsage.Default
            };
            Resource = D3D.Texture2D.FromFile(device, filename, iml);
            View = new D3D.ShaderResourceView(device, Resource);
            Instance = new D3D.SpriteInstance(this.View, new Vector2(0, 0), new Vector2(1, 1));

            UpdateTransform();
        }
Пример #2
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);
        }