Inheritance: Fusion.Engine.Common.GameModule
		/// <summary>
		/// Creates texture atlas from stream.
		/// </summary>
		/// <param name="device"></param>
		public TextureAtlas ( RenderSystem rs, Stream stream, bool useSRgb = false )
		{
			var device = rs.Game.GraphicsDevice;

			using ( var br = new BinaryReader(stream) ) {
			
				br.ExpectFourCC("ATLS", "texture atlas");
				
				int count = br.ReadInt32();
				
				for ( int i=0; i<count; i++ ) {
					var element = new Element();
					element.Index	=	i;
					element.Name	=	br.ReadString();
					element.X		=	br.ReadInt32();
					element.Y		=	br.ReadInt32();
					element.Width	=	br.ReadInt32();
					element.Height	=	br.ReadInt32();

					elements.Add( element );
				}				

				int ddsFileLength	=	br.ReadInt32();
				
				var ddsImageBytes	=	br.ReadBytes( ddsFileLength );

				texture	=	new UserTexture( rs, ddsImageBytes, useSRgb );
			}


			dictionary	=	elements.ToDictionary( e => e.Name );
		}
		/// <summary>
		///
		/// </summary>
		/// <param name="rs"></param>
		/// <param name="texture"></param>
		private DiscTexture ( RenderSystem rs, Texture2D texture )
		{
			this.texture	=	texture;
			this.Width		=	texture.Width;
			this.Height		=	texture.Height;
			this.Srv		=	texture;
		}
		/// <summary>
		/// Creates texture from file in memory 
		/// </summary>
		/// <param name="rs"></param>
		/// <param name="texture"></param>
		public UserTexture ( RenderSystem rs, byte[] data, bool forceSRgb )
		{
			this.texture	=	new Texture2D( rs.Device, data, forceSRgb );
			this.Width		=	texture.Width;
			this.Height		=	texture.Height;
			this.Srv		=	texture;
		}
Exemple #4
0
        void Reload( RenderSystem rs, ContentManager content )
        {
            if (meshInstance!=null) {
                if (!rs.RenderWorld.Instances.Remove( meshInstance )) {
                    Log.Warning("Failed to remove {0}|{1}", scenePath, nodeName );
                }
            }

            var scene = content.Load<Scene>( scenePath, (Scene)null );

            if (scene==null) {
                return;
            }

            var node  = scene.Nodes.FirstOrDefault( n => n.Name == nodeName );

            if (node==null) {
                Log.Warning("Scene '{0}' does not contain node '{1}'", scenePath, nodeName );
                return;
            }

            if (node.MeshIndex<0) {
                Log.Warning("Node '{0}|{1}' does not contain mesh", scenePath, nodeName );
                return;
            }

            var mesh		=	scene.Meshes[node.MeshIndex];

            meshInstance		= new MeshInstance( rs, scene, mesh );

            rs.RenderWorld.Instances.Add( meshInstance );
        }
		/// <summary>
		/// Creates texture from stream.
		/// </summary>
		/// <param name="rs"></param>
		/// <param name="texture"></param>
		public UserTexture ( RenderSystem rs, Stream stream, bool forceSRgb  )
		{
			this.texture	=	new Texture2D( rs.Device, stream, forceSRgb );
			this.Width		=	texture.Width;
			this.Height		=	texture.Height;
			this.Srv		=	texture;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="rs"></param>
		/// <param name="maxTextures"></param>
		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 );
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="rs"></param>
		internal ParticleSystem ( RenderSystem rs, ViewLayerHdr viewLayer )
		{
			this.rs			=	rs;
			this.Game		=	rs.Game;
			this.viewLayer	=	viewLayer;

			Gravity	=	Vector3.Down * 9.80665f;

			paramsCB		=	new ConstantBuffer( Game.GraphicsDevice, typeof(Params) );

			injectionVB		=	new VertexBuffer( Game.GraphicsDevice, typeof(ParticleVertex), MaxInjectingParticles, VertexBufferOptions.Dynamic );
			simulationSrcVB	=	new VertexBuffer( Game.GraphicsDevice, typeof(ParticleVertex), MaxSimulatedParticles, VertexBufferOptions.VertexOutput );
			simulationDstVB	=	new VertexBuffer( Game.GraphicsDevice, typeof(ParticleVertex), MaxSimulatedParticles, VertexBufferOptions.VertexOutput );

			rs.Game.Reloading += LoadContent;
			LoadContent(this, EventArgs.Empty);
		}
		/// <summary>
		/// Create target texture with specified size and format
		/// </summary>
		/// <param name="width"></param>
		/// <param name="height"></param>
		/// <param name="format"></param>
		public TargetTexture ( RenderSystem rs, int width, int height, TargetFormat format )
		{
			this.Width	=	width;
			this.Height	=	height;
			this.Format	=	format;

			var clrFrmt	=	ColorFormat.Unknown;
			var samples	=	1;

			switch (format) {
				case TargetFormat.LowDynamicRange		: clrFrmt = ColorFormat.Rgba8;	break;
				case TargetFormat.LowDynamicRangeMSAA	: clrFrmt = ColorFormat.Rgba8;	samples = 4; break;
				case TargetFormat.HighDynamicRange		: clrFrmt = ColorFormat.Rgba16F;	break;
				default: throw new ArgumentException("format");
			}

			RenderTarget	=	new RenderTarget2D( rs.Device, clrFrmt, width, height, samples ); 
			Srv	=	RenderTarget;
		}	
		/// <summary>
		/// 
		/// </summary>
		/// <param name="rs"></param>
		internal ParticleSystem ( RenderSystem rs, RenderWorld renderWorld )
		{
			this.rs				=	rs;
			this.Game			=	rs.Game;
			this.renderWorld	=	renderWorld;

			Gravity	=	Vector3.Down * 9.80665f;

			paramsCB		=	new ConstantBuffer( Game.GraphicsDevice, typeof(PrtParams) );
			imagesCB		=	new ConstantBuffer( Game.GraphicsDevice, typeof(Vector4), MaxImages );

			injectionBuffer			=	new StructuredBuffer( Game.GraphicsDevice, typeof(Particle),	MaxInjectingParticles, StructuredBufferFlags.None );
			simulationBuffer		=	new StructuredBuffer( Game.GraphicsDevice, typeof(Particle),	MaxSimulatedParticles, StructuredBufferFlags.None );
			particleLighting		=	new StructuredBuffer( Game.GraphicsDevice, typeof(Vector4),		MaxSimulatedParticles, StructuredBufferFlags.None );
			sortParticlesBuffer		=	new StructuredBuffer( Game.GraphicsDevice, typeof(Vector2),		MaxSimulatedParticles, StructuredBufferFlags.None );
			deadParticlesIndices	=	new StructuredBuffer( Game.GraphicsDevice, typeof(uint),		MaxSimulatedParticles, StructuredBufferFlags.Append );

			rs.Game.Reloading += LoadContent;
			LoadContent(this, EventArgs.Empty);

			//	initialize dead list :
			var device = Game.GraphicsDevice;

			device.SetCSRWBuffer( 1, deadParticlesIndices, 0 );
			device.PipelineState	=	factory[ (int)Flags.INITIALIZE ];
			device.Dispatch( MathUtil.IntDivUp( MaxSimulatedParticles, BlockSize ) );
		}
Exemple #10
0
        /*[ShaderConstantBuffer(typeof(LightingParams), 0)]
         * ConstantBuffer	LightingCB { get { return lightingCB; } }*/


        /// <summary>
        ///
        /// </summary>
        /// <param name="game"></param>
        public LightRenderer(RenderSystem rs) : base(rs)
        {
            SetDefaults();
        }
Exemple #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="game"></param>
 public DofFilter(RenderSystem rs) : base(rs)
 {
 }
Exemple #12
0
		/// <summary>
		/// Creates gpu material
		/// </summary>
		/// <param name="rs"></param>
		/// <returns></returns>
		internal MaterialInstance CreateMaterialInstance ( RenderSystem rs, ContentManager content )
		{
			var data = new MaterialData();
			
			GetMaterialData( ref data );

			var mtrl = new MaterialInstance( rs, content, data, GetTextureBindings(), GetSurfaceFlags() );

			return mtrl;
		}
Exemple #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="rs"></param>
 public Sky(RenderSystem rs) : base(rs)
 {
 }
Exemple #14
0
 /// <summary>
 ///
 /// </summary>
 public RenderComponent(RenderSystem rs) : base(rs.Game)
 {
     this.rs     = rs;
     this.device = rs.Game.GraphicsDevice;
 }
		/// <summary>
		/// Creates instance from mesh in scene.
		/// </summary>
		/// <param name="rs"></param>
		/// <param name="mesh"></param>
		public MeshInstance ( RenderSystem rs, Scene scene, Mesh mesh, MaterialInstance[] materials )
		{
			Visible		=	true;
			World		=	Matrix.Identity;
			Color		=	Color4.Zero;
			Blending	=	new Vector4(1,1,1,1);

			vb			=	mesh.VertexBuffer;
			ib			=	mesh.IndexBuffer;
			
			vertexCount	=	mesh.VertexCount;
			indexCount	=	mesh.IndexCount;

			ShadingGroups	=	mesh.Subsets	
							.Select( s => new ShadingGroup( s, materials[s.MaterialIndex] ) )
							.ToArray();

			IsSkinned	=	mesh.IsSkinned;

			if (IsSkinned && scene.Nodes.Count > SceneRenderer.MaxBones) {
				throw new ArgumentOutOfRangeException( string.Format("Scene contains more than {0} bones and cannot be used for skinning.", SceneRenderer.MaxBones ) );
			}

			if (IsSkinned) {
				BoneTransforms	=	Enumerable
					.Range(0, SceneRenderer.MaxBones)
					.Select( i => Matrix.Identity )
					.ToArray();
			}
		}
Exemple #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rs"></param>
        /// <param name="baseDirectory"></param>
        public VTSystem(RenderSystem rs) : base(rs.Game)
        {
            this.rs = rs;

            MaxPPF = 16;
        }
Exemple #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rs"></param>
 public LightSet(RenderSystem rs)
 {
     AmbientLevel = Color4.Zero;
 }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="Game"></param>
		public SceneRenderer ( Game Game, RenderSystem rs ) : base( Game )
		{
			this.rs	=	rs;
		}
Exemple #19
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="rs"></param>
		public LightSet ( RenderSystem rs )
		{
			AmbientLevel	=	Color4.Zero;
		}
Exemple #20
0
		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="rs"></param>
		/// <param name="capacity">Number of sprites</param>
		public SpriteLayer ( RenderSystem rs, int capacity )
		{
			this.rs		=	rs;

			Order		=	0;

			Visible		=	true;
			Transform	=	Matrix.Identity;
			Color		=	Color.White;
			BlendMode	=	SpriteBlendMode.AlphaBlend;
			FilterMode	=	SpriteFilterMode.LinearClamp;
			StereoMode	=	SpriteStereoMode.All;

			defaultTexture	=	new DynamicTexture( rs, 16,16, typeof(Color), false, false );
			defaultTexture.SetData( Enumerable.Range(0,16*16).Select( i => Color.White ).ToArray() );

			ReallocGpuBuffers( capacity );

			framesBuffer	=	new ConstantBuffer( rs.Device, typeof(SpriteFrame), MaxSpriteFrames );
		}
Exemple #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rs"></param>
 /// <param name="stream"></param>
 public GeometryCache(RenderSystem rs, Stream stream)
 {
     this.rs = rs;
     ReadStream(stream);
 }
Exemple #22
0
 public BitonicSort(RenderSystem rs) : base(rs)
 {
 }
Exemple #23
0
		/// <summary>
		/// Creates ViewLayer instance
		/// </summary>
		/// <param name="Game">Game engine</param>
		public RenderLayer ( Game game )
		{
			Game		=	game;
			this.rs		=	Game.RenderSystem;

			Visible		=	true;
			Order		=	0;

			Camera		=	new Camera();

			SpriteLayers	=	new SpriteLayerCollection();
			GisLayers		=	new List<Gis.GisLayer>();
			GlobeCamera		=	new GlobeCamera(Game);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="rs"></param>
		public SpriteEngine( RenderSystem rs ) : base(rs.Game)
		{
			this.device	=	rs.Device;
		}