Fusion.Engine.Graphics.MaterialInstance.MaterialInstance C# (CSharp) Method

MaterialInstance() private method

private MaterialInstance ( RenderSystem rs, ContentManager content, MaterialData parameters, IEnumerable textureBinds, SurfaceFlags surfaceFlags ) : System
rs RenderSystem
content ContentManager
parameters MaterialData
textureBinds IEnumerable
surfaceFlags SurfaceFlags
return System
		internal MaterialInstance ( RenderSystem rs, ContentManager content, MaterialData parameters, IEnumerable<TextureMapBind> textureBinds, SurfaceFlags surfaceFlags )
		{
			if (rs==null) {
				throw new ArgumentNullException("rs");
			}

			if (textureBinds.Count()<0 || textureBinds.Count()>MaxTextures) {
				throw new ArgumentException("textureCount", "Must be less or equal to " + MaxTextures.ToString() );
			}


			//
			//	Pipeline states :
			//
			var factory	=	rs.SceneRenderer.Factory;

			var gbufferRigid	=	SurfaceFlags.GBUFFER | SurfaceFlags.RIGID	| surfaceFlags ;
			var gbufferSkinned	=	SurfaceFlags.GBUFFER | SurfaceFlags.SKINNED | surfaceFlags ;
			var shadowRigid		=	SurfaceFlags.SHADOW  | SurfaceFlags.RIGID	| surfaceFlags ;
			var shadowSkinned	=	SurfaceFlags.SHADOW  | SurfaceFlags.SKINNED | surfaceFlags ;

			GBufferRigid	=	factory[ (int)gbufferRigid ];
			GBufferSkinned	=	factory[ (int)gbufferSkinned ];

			ShadowRigid		=	factory[ (int)shadowRigid ];
			ShadowSkinned	=	factory[ (int)shadowSkinned ];


			//
			//	Textures :
			//
			var textures = textureBinds
				.Select( texBind => texBind.TextureMap.LoadTexture( content, texBind.FallbackPath ) );

			var uvMods = new Vector4[MaxTextures];

			textureBinds
				.Select( tb => tb.TextureMap )
				.Select( tm => new Vector4( tm.ScaleU, tm.ScaleV, tm.OffsetU, tm.OffsetV ) )
				.ToArray()
				.CopyTo( uvMods, 0 );

			shaderResources		=	textures.Select( tex => tex.Srv ).ToArray();

			//
			//	Constants :
			//
			constBufferParams	=	new ConstantBuffer( rs.Device, typeof(MaterialData) );
			constBufferParams.SetData( parameters );

			constBufferUVMods	=	new ConstantBuffer( rs.Device, typeof(Vector4), MaxTextures );
			constBufferUVMods.SetData( uvMods );
		}