Beispiel #1
0
        public ShaderTextures(SourceShader source, string techniqueName, Platform platform)
        {
            this.psSamplers  = new List <Register>();
            this.vsSamplers  = new List <Register>();
            this.allSamplers = new Dictionary <string, SharedSampler>();

            AsmTechnique       technique = source.GetAsmTechnique(techniqueName, platform);
            TechniqueExtraData extras    = technique.TechniqueExtraData;

            //pull out the textures that will be used
            textures = new TextureAssociation[extras.TechniqueTextures.Length];
            for (int i = 0; i < extras.TechniqueTextures.Length; i++)
            {
                textures[i] = new TextureAssociation(extras.TechniqueTextures[i]);
            }

            //now do the samplers
            RegisterSet set = technique.PixelShader.RegisterSet;

            //pixel first
            foreach (Register reg in set)
            {
                if (reg.Category == RegisterCategory.Sampler)
                {
                    psSamplers.Add(reg);

                    int textureIndex = extras.PixelSamplerTextureIndex[reg.Index];

                    if (textureIndex == -1)
                    {
                        ThrowSamplerNoTextureException(reg);
                    }

                    textures[textureIndex].PsSamplers.Add(reg.Index);

                    //add the sampler to 'allSamplers'
                    SharedSampler ss = new SharedSampler();
                    ss.PsIndex        = reg.Index;
                    ss.SamplerDetails = reg;
                    ss.Index          = allSamplers.Count;
                    ss.DefaultState   = extras.PixelSamplerStates[reg.Index];
                    allSamplers.Add(reg.Name, ss);
                }
            }

            set = technique.VertexShader.RegisterSet;

            //now vertex
            foreach (Register reg in set)
            {
                if (reg.Category == RegisterCategory.Sampler)
                {
                    vsSamplers.Add(reg);

                    int textureIndex = extras.VertexSamplerTextureIndex[reg.Index];
                    if (textureIndex == -1)
                    {
                        ThrowSamplerNoTextureException(reg);
                    }

                    textures[textureIndex].VsSamplers.Add(reg.Index);

                    //add the sampler to 'allSamplers'
                    SharedSampler ss;
                    if (!allSamplers.TryGetValue(reg.Name, out ss))
                    {
                        ss = new SharedSampler();
                        ss.SamplerDetails = reg;
                        ss.Index          = allSamplers.Count;
                        ss.DefaultState   = extras.VertexSamplerStates[reg.Index];
                        allSamplers.Add(reg.Name, ss);
                    }
                    ss.VsIndex = reg.Index;
                }
            }
        }
		public ShaderTextures(SourceShader source, string techniqueName, Platform platform)
		{
			this.psSamplers = new List<Register>();
			this.vsSamplers = new List<Register>();
			this.allSamplers = new Dictionary<string, SharedSampler>();

			AsmTechnique technique = source.GetAsmTechnique(techniqueName, platform);
			TechniqueExtraData extras = technique.TechniqueExtraData;

			//pull out the textures that will be used
			textures = new TextureAssociation[extras.TechniqueTextures.Length];
			for (int i = 0; i < extras.TechniqueTextures.Length; i++)
				textures[i] = new TextureAssociation(extras.TechniqueTextures[i]);

			//now do the samplers
			RegisterSet set = technique.PixelShader.RegisterSet;

			//pixel first
			foreach (Register reg in set)
			{
				if (reg.Category == RegisterCategory.Sampler)
				{
					psSamplers.Add(reg);

					int textureIndex = extras.PixelSamplerTextureIndex[reg.Index];

					if (textureIndex == -1)
						ThrowSamplerNoTextureException(reg);

					textures[textureIndex].PsSamplers.Add(reg.Index);

					//add the sampler to 'allSamplers'
					SharedSampler ss = new SharedSampler();
					ss.PsIndex = reg.Index;
					ss.SamplerDetails = reg;
					ss.Index = allSamplers.Count;
					ss.DefaultState = extras.PixelSamplerStates[reg.Index];
					allSamplers.Add(reg.Name, ss);
				}
			}

			set = technique.VertexShader.RegisterSet;

			//now vertex
			foreach (Register reg in set)
			{
				if (reg.Category == RegisterCategory.Sampler)
				{
					vsSamplers.Add(reg);

					int textureIndex = extras.VertexSamplerTextureIndex[reg.Index];
					if (textureIndex == -1)
						ThrowSamplerNoTextureException(reg);

					textures[textureIndex].VsSamplers.Add(reg.Index);

					//add the sampler to 'allSamplers'
					SharedSampler ss;
					if (!allSamplers.TryGetValue(reg.Name, out ss))
					{
						ss = new SharedSampler();
						ss.SamplerDetails = reg;
						ss.Index = allSamplers.Count;
						ss.DefaultState = extras.VertexSamplerStates[reg.Index];
						allSamplers.Add(reg.Name, ss);
					}
					ss.VsIndex = reg.Index;
				}
			}
		}