Inheritance: GraphicsResource
Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the StateFactory
        /// </summary>
        /// <param name="device"></param>
        /// <param name="enumType"></param>
        /// <param name="ubershader"></param>
        /// <param name="vertexInputElements"></param>
        /// <param name="blendState"></param>
        /// <param name="rasterizerState"></param>
        private StateFactory(Ubershader ubershader, Type enumType, Primitive primitive, VertexInputElement[] vertexInputElements)
            : base(ubershader.GraphicsDevice)
        {
            this.ubershader = ubershader;

            Enumerate(enumType, ubershader, (ps, i) => { ps.VertexInputElements = vertexInputElements; ps.Primitive = primitive; });
        }
		public PointsGisLayerCPU(Game game, int maxPointsCount, bool isDynamic = true) : base(game)
		{
			PointsCountToDraw = maxPointsCount;
			indeces = new int[maxPointsCount*6];
			PointsDrawOffset = 0;

			SizeMultiplier = 1;

			var vbOptions = isDynamic ? VertexBufferOptions.Dynamic : VertexBufferOptions.Default;

			currentBuffer	= new VertexBuffer(Game.GraphicsDevice, typeof(Gis.CartPoint), maxPointsCount * 4, vbOptions);
			PointsCpu		= new Gis.CartPoint[maxPointsCount*4];

			indBuf = new IndexBuffer(Game.GraphicsDevice, indeces.Length);
			for (int i = 0; i < maxPointsCount; i += 1) {
				indeces[i*6 + 0] = i*4 + 0;
				indeces[i*6 + 1] = i*4 + 1;
				indeces[i*6 + 2] = i*4 + 2;

				indeces[i*6 + 3] = i*4 + 1;
				indeces[i*6 + 4] = i*4 + 3;
				indeces[i*6 + 5] = i*4 + 2;
			}
			indBuf.SetData(indeces);

			shader	= Game.Content.Load<Ubershader>("globe.Debug.hlsl");
			factory = shader.CreateFactory(typeof(PointFlags), Primitive.TriangleList, VertexInputElement.FromStructure<Gis.CartPoint>(), BlendState.AlphaBlend, RasterizerState.CullCW, DepthStencilState.None);

		}
		/// <summary>
		/// Initializes a new instance of the StateFactory
		/// </summary>
		/// <param name="device"></param>
		/// <param name="enumType"></param>
		/// <param name="ubershader"></param>
		/// <param name="vertexInputElements"></param>
		/// <param name="blendState"></param>
		/// <param name="rasterizerState"></param>
		private StateFactory ( Ubershader ubershader, Type enumType, Primitive primitive, VertexInputElement[] vertexInputElements ) 
		 : base(ubershader.GraphicsDevice)
		{
			this.ubershader		= ubershader;

			Enumerate( enumType, ubershader, (ps,i) => { ps.VertexInputElements = vertexInputElements; ps.Primitive = primitive; } );
		}
		public DebugGisLayer(Game game) : base(game)
		{
			shader	= game.Content.Load<Ubershader>("globe.Debug.hlsl");
			factory = shader.CreateFactory(typeof(DebugFlags), Primitive.LineList, VertexInputElement.FromStructure<Gis.CartPoint>(), BlendState.AlphaBlend, RasterizerState.CullCW, DepthStencilState.Default);

			buf = new VertexBuffer(Game.GraphicsDevice, typeof(Gis.CartPoint), 10000, VertexBufferOptions.Dynamic);

			boxes = new List<Gis.CartPoint>();
			lines = new List<Gis.CartPoint>();
		}
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="?"></param>
        void Enumerate(Type enumType, Ubershader ubershader, Action <PipelineState, int> enumAction)
        {
            pipelineStates = new Dictionary <int, PipelineState>();

            combinerEnum = enumType;

            //
            //	validate enum :
            //
            if (Enum.GetUnderlyingType(enumType) != typeof(int))
            {
                throw new ArgumentException("Underlying type should be Int32");
            }

            Dictionary <string, int> enumDict = new Dictionary <string, int>();

            foreach (var enumValue in Enum.GetValues(enumType))
            {
                if (!MathUtil.IsPowerOfTwo((int)enumValue) && (int)enumValue != 0)
                {
                    throw new ArgumentException("Each value must be zero or power of two");
                }
                enumDict.Add(enumValue.ToString(), (int)enumValue);
            }



            //
            //	Enumerate :
            //
            var defineList = ubershader.Defines;

            foreach (var defines in defineList)
            {
                int combination = 0;

                if (GetCombinerSet(enumDict, defines, out combination))
                {
                    var ps = new PipelineState(device);

                    ps.PixelShader    = ubershader.GetPixelShader(defines);
                    ps.VertexShader   = ubershader.GetVertexShader(defines);
                    ps.GeometryShader = ubershader.GetGeometryShader(defines);
                    ps.HullShader     = ubershader.GetHullShader(defines);
                    ps.DomainShader   = ubershader.GetDomainShader(defines);
                    ps.ComputeShader  = ubershader.GetComputeShader(defines);

                    enumAction(ps, combination);

                    pipelineStates.Add(combination, ps);
                }
            }
        }
Exemple #6
0
		public TilesGisLayer(Game engine, GlobeCamera camera) : base(engine)
		{
			RegisterMapSources();

			CurrentMapSource = MapSources[9];

			this.camera = camera;

			frame	= Game.Content.Load<Texture2D>("redframe.tga");
			shader	= Game.Content.Load<Ubershader>("globe.Tile.hlsl");
			factory = shader.CreateFactory( typeof(TileFlags), Primitive.TriangleList, VertexInputElement.FromStructure<Gis.GeoPoint>(), BlendState.AlphaBlend, RasterizerState.CullCW, DepthStencilState.Default);
		}
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the StateFactory
        /// </summary>
        /// <param name="device"></param>
        /// <param name="ubershader"></param>
        private StateFactory(Ubershader ubershader, Type enumType, Primitive primitive, VertexInputElement[] vertexInputElements, BlendState blendState, RasterizerState rasterizerState)
            : base(ubershader.GraphicsDevice)
        {
            this.ubershader = ubershader;

            Enumerate(enumType, ubershader, (ps, i) => {
                ps.Primitive           = primitive;
                ps.VertexInputElements = vertexInputElements;
                ps.BlendState          = blendState;
                ps.RasterizerState     = rasterizerState;
            });
        }
		/// <summary>
		/// Initializes a new instance of the StateFactory
		/// </summary>
		/// <param name="device"></param>
		/// <param name="ubershader"></param>
		private StateFactory ( Ubershader ubershader, Type enumType, Primitive primitive, VertexInputElement[] vertexInputElements, BlendState blendState, RasterizerState rasterizerState )
		 : base(ubershader.GraphicsDevice)
		{
			this.ubershader		= ubershader;

			Enumerate( enumType, ubershader, (ps,i) => { 
					ps.Primitive = primitive;
					ps.VertexInputElements = vertexInputElements; 
					ps.BlendState		=	blendState;
					ps.RasterizerState	=	rasterizerState;
				} );
		}
Exemple #9
0
		/// <summary>
		/// Initialization
		/// </summary>
		public override void Initialize ()
		{
			var dev		= Game.GraphicsDevice;

			effect		= Game.Content.Load<Ubershader>("debugRender.hlsl");
			factory		= effect.CreateFactory( typeof(RenderFlags), Primitive.LineList, VertexInputElement.FromStructure( typeof(LineVertex) ), BlendState.AlphaBlend, RasterizerState.CullNone );

			constData	= new ConstData();
			constBuffer = new ConstantBuffer(dev, typeof(ConstData));


			//	create vertex buffer :
			vertexBuffer		= new VertexBuffer(dev, typeof(LineVertex), vertexBufferSize, VertexBufferOptions.Dynamic );
			vertexDataAccum.Capacity = vertexBufferSize;
		}
Exemple #10
0
		public PointsGisLayer(Game engine, int maxPointsCount, bool isDynamic = false) : base(engine)
		{
			DotsBuffer	= new ConstantBuffer(engine.GraphicsDevice, typeof(DotsData));
			ColorBuffer = new ConstantBuffer(engine.GraphicsDevice, typeof(ColorData), 16);

			PointsCountToDraw	= maxPointsCount;
			PointsDrawOffset	= 0;

			SizeMultiplier	= 1;
			IsDynamic		= isDynamic;

			var vbOptions = isDynamic ? VertexBufferOptions.Dynamic : VertexBufferOptions.Default;

			firstBuffer		= new VertexBuffer(engine.GraphicsDevice, typeof(Gis.GeoPoint), maxPointsCount, vbOptions);
			currentBuffer	= firstBuffer;

			PointsCpu	= new Gis.GeoPoint[maxPointsCount];
			
			Flags		= (int) (PointFlags.DOTS_WORLDSPACE);

			shader	= Game.Content.Load<Ubershader>("globe.Point.hlsl");
			factory = shader.CreateFactory( typeof(PointFlags), Primitive.PointList, VertexInputElement.FromStructure<Gis.GeoPoint>(), BlendState.AlphaBlend, RasterizerState.CullCCW, DepthStencilState.None);

			ColorDatas = new ColorData[16];
			for (int i = 0; i < ColorDatas.Length; i++) {
				ColorDatas[i] = new ColorData {Color = Color.White};
			}

			ColorBuffer.SetData(ColorDatas);
		}
Exemple #11
0
		/// <summary>
		/// 
		/// </summary>
		void LoadContent ()
		{
			shader	=	Game.Content.Load<Ubershader>("dof");
			factory	=	shader.CreateFactory( typeof(Flags), (ps,i) => EnumAction(ps, (Flags)i ) );
		}
Exemple #12
0
		public ModelLayer(Game engine, DVector2 lonLatPosition, string fileName, int maxInstancedCount = 0) : base(engine)
		{
			model = engine.Content.Load<Scene>(fileName);

			transforms = new Matrix[model.Nodes.Count];
			model.ComputeAbsoluteTransforms(transforms);

			LonLatPosition	= lonLatPosition;

			Transparency = 1.0f;

			constData	= new ConstDataStruct();
			modelBuf	= new ConstantBuffer(Game.GraphicsDevice, typeof(ConstDataStruct));
			shader		= Game.Content.Load<Ubershader>("globe.Model.hlsl");
			
			factory		= shader.CreateFactory( typeof(ModelFlags), Primitive.TriangleList, VertexInputElement.FromStructure<VertexColorTextureTBNRigid>(), BlendState.AlphaBlend, RasterizerState.CullCW, DepthStencilState.Default);
			factoryXray = shader.CreateFactory( typeof(ModelFlags), Primitive.TriangleList, VertexInputElement.FromStructure<VertexColorTextureTBNRigid>(), BlendState.AlphaBlend, RasterizerState.CullCW, DepthStencilState.Default);
			
			if (maxInstancedCount > 0) {
				InstancedCountToDraw	= maxInstancedCount;
				InstancedDataCPU		= new InstancedDataStruct[maxInstancedCount];

				instDataGpu = new StructuredBuffer(engine.GraphicsDevice, typeof(InstancedDataStruct), maxInstancedCount, StructuredBufferFlags.None);
			}

			selectInfo = new SelectInfo[model.Nodes.Count];
			for (int i = 0; i < model.Nodes.Count; i++)
			{
				var meshindex = model.Nodes[i].MeshIndex;
				if (meshindex < 0) continue;

				selectInfo[i] = new SelectInfo
				{
					BoundingBox = model.Meshes[meshindex].ComputeBoundingBox(),
					MeshIndex = meshindex,
					NodeIndex = i,
					NodeName = model.Nodes[i].Name
				};
			}

		}
Exemple #13
0
		protected void Initialize(Gis.GeoPoint[] points, int[] indeces, bool isDynamic)
		{
			shader		= Game.Content.Load<Ubershader>("globe.Poly.hlsl");
			factory		= shader.CreateFactory(typeof(PolyFlags), EnumFunc);
			factoryXray = shader.CreateFactory(typeof(PolyFlags), Primitive.TriangleList, VertexInputElement.FromStructure<Gis.GeoPoint>(), BlendState.Additive, RasterizerState.CullCW, DepthStencilState.None);

			var vbOptions = isDynamic ? VertexBufferOptions.Dynamic : VertexBufferOptions.Default;

			firstBuffer = new VertexBuffer(Game.GraphicsDevice, typeof(Gis.GeoPoint), points.Length, vbOptions);
			firstBuffer.SetData(points);
			currentBuffer = firstBuffer;

			indexBuffer = new IndexBuffer(Game.Instance.GraphicsDevice, indeces.Length);
			indexBuffer.SetData(indeces);

			PointsCpu = points;

			cb			= new ConstantBuffer(Game.GraphicsDevice, typeof(ConstData));
			constData	= new ConstData();
			constData.Data = Vector4.One;
		}
		void LoadContent ()
		{
			shader		=	device.Game.Content.Load<Ubershader>("sprite");
			factory		=	shader.CreateFactory( typeof(Flags), (ps,i) => StateEnum( ps, (Flags)i) );
		}
		/// <summary>
		/// 
		/// </summary>
		void LoadContent ()
		{
			surfaceShader	=	Game.Content.Load<Ubershader>("surface");
			factory			=	surfaceShader.CreateFactory( typeof(SurfaceFlags), (ps,i) => Enum(ps, (SurfaceFlags)i ) );
		}
Exemple #16
0
		/// <summary>
		/// 
		/// </summary>
		void LoadContent ()
		{
			shader		=	Game.Content.Load<Ubershader>("bitonicSort");
			factory		=	shader.CreateFactory( typeof(ShaderFlags), Primitive.TriangleList, VertexInputElement.Empty );
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void InstancingDemo_Reloading ( object sender, EventArgs e )
		{
			SafeDispose( ref factory );
			us		=	Content.Load<Ubershader>("test");
			factory	=	new StateFactory( us, typeof(UberFlags), Primitive.TriangleList, VertexInputElement.FromStructure( typeof(Vertex) ), BlendState.Additive, RasterizerState.CullNone, DepthStencilState.None );
			tex		=	Content.Load<Texture2D>("block" );
		}
Exemple #18
0
        /// <summary>
        /// Initializes a new instance of the StateFactory
        /// </summary>
        /// <param name="ubershader"></param>
        /// <param name="enumType"></param>
        /// <param name="enumAction"></param>
        internal StateFactory(Ubershader ubershader, Type enumType, Action <PipelineState, int> enumAction) : base(ubershader.GraphicsDevice)
        {
            this.ubershader = ubershader;

            Enumerate(enumType, ubershader, enumAction);
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="?"></param>
		void Enumerate ( Type enumType, Ubershader ubershader, Action<PipelineState,int> enumAction )
		{
			pipelineStates	=	new Dictionary<int,PipelineState>();

			combinerEnum	=	enumType;

			//
			//	validate enum :
			//
			if (Enum.GetUnderlyingType(enumType)!=typeof(int)) {
				throw new ArgumentException("Underlying type should be Int32");
			}

			Dictionary<string,int> enumDict = new Dictionary<string,int>();

			foreach ( var enumValue in Enum.GetValues( enumType ) ) {
				if ( !MathUtil.IsPowerOfTwo( (int)enumValue ) && (int)enumValue!=0 ) {
					throw new ArgumentException("Each value must be zero or power of two");
				}
				enumDict.Add( enumValue.ToString(), (int)enumValue );
			}



			//
			//	Enumerate :
			//
			var defineList = ubershader.Defines;

			foreach ( var defines in defineList ) {
				
				int combination = 0;

				if ( GetCombinerSet( enumDict, defines, out combination ) ) {
					
					var ps = new PipelineState( device );

					ps.PixelShader		=	ubershader.GetPixelShader		( defines );
					ps.VertexShader		=	ubershader.GetVertexShader		( defines );
					ps.GeometryShader	=	ubershader.GetGeometryShader	( defines );
					ps.HullShader		=	ubershader.GetHullShader		( defines );
					ps.DomainShader		=	ubershader.GetDomainShader		( defines );
					ps.ComputeShader	=	ubershader.GetComputeShader		( defines );
					
					enumAction( ps, combination );

					pipelineStates.Add( combination, ps );
				}	
			}
		}
		void Game_Reloading ( object sender, EventArgs e )
		{
			SafeDispose( ref factory );

			texture		=	Game.Content.Load<Texture2D>("particle2");
			shader		=	Game.Content.Load<Ubershader>("test");
			factory		=	new StateFactory( shader, typeof(Flags), (ps,i) => EnumAction( ps, (Flags)i ) );
		}
		/// <summary>
		/// Initializes a new instance of the StateFactory
		/// </summary>
		/// <param name="ubershader"></param>
		/// <param name="enumType"></param>
		/// <param name="enumAction"></param>
		internal StateFactory ( Ubershader ubershader, Type enumType, Action<PipelineState,int> enumAction ) : base(ubershader.GraphicsDevice)
		{
			this.ubershader		= ubershader;

			Enumerate( enumType, ubershader, enumAction );
		}
Exemple #22
0
		/// <summary>
		/// Load content
		/// </summary>
		public void LoadContent ()
		{
			SafeDispose( ref factory );
			SafeDispose( ref vertexBuffers );
			SafeDispose( ref indexBuffers );

			uberShader	=	Content.Load<Ubershader>("render");

			factory		=	new StateFactory( 
								uberShader, 
								typeof(RenderFlags), 
								Primitive.TriangleList, 
								VertexColorTextureNormal.Elements,
								BlendState.Opaque,
								RasterizerState.CullCW,
								DepthStencilState.Default 
							);

			scene		=	Content.Load<Scene>(@"Scenes\testScene");


			vertexBuffers	=	scene.Meshes
							.Select( m => VertexBuffer.Create( GraphicsDevice, m.Vertices.Select( v => VertexColorTextureNormal.Convert(v) ).ToArray() ) )
							.ToArray();

			indexBuffers	=	scene.Meshes
							.Select( m => IndexBuffer.Create( GraphicsDevice, m.GetIndices() ) )
							.ToArray();

			textures		=	scene.Materials
							.Select( mtrl => Content.Load<Texture2D>( mtrl.TexturePath ) )
							.ToArray();

			worldMatricies	=	new Matrix[ scene.Nodes.Count ];
			scene.CopyAbsoluteTransformsTo( worldMatricies );

			//Log.Message("{0}", scene.Nodes.Count( n => n.MeshIndex >= 0 ) );
		}
Exemple #23
0
		/// <summary>
		/// 
		/// </summary>
		void LoadContent ()
		{
			sky			=	Game.Content.Load<Ubershader>("sky");
			factory		=	sky.CreateFactory( typeof(SkyFlags), (ps,i) => EnumFunc(ps, (SkyFlags)i) );
		}
Exemple #24
0
		public LinesGisLayer(Game engine, int linesPointsCount, bool isDynamic = false) : base(engine)
		{
			shader		= Game.Content.Load<Ubershader>("globe.Line.hlsl");
			factory		= shader.CreateFactory( typeof(LineFlags), Primitive.LineList, VertexInputElement.FromStructure<Gis.GeoPoint>(), BlendState.AlphaBlend, RasterizerState.CullNone, DepthStencilState.None);
			thinFactory = shader.CreateFactory( typeof(LineFlags), Primitive.LineList, VertexInputElement.FromStructure<Gis.GeoPoint>(), BlendState.AlphaBlend, RasterizerState.CullNone, DepthStencilState.Readonly);
			
			TransparencyMultiplayer = 1.0f;
			OverallColor			= Color4.White;
			linesConstantBuffer		= new ConstantBuffer(engine.GraphicsDevice, typeof(LinesConstDataStruct));
			//linesConstantBuffer.SetData(linesConstData);

			var vbOptions = isDynamic ? VertexBufferOptions.Dynamic : VertexBufferOptions.Default;

			firstBuffer		= new VertexBuffer(engine.GraphicsDevice, typeof(Gis.GeoPoint), linesPointsCount, vbOptions);
			currentBuffer	= firstBuffer;

			PointsCpu	= new Gis.GeoPoint[linesPointsCount];
			Flags		= (int)(LineFlags.ARC_LINE);
		}
Exemple #25
0
		/// <summary>
		/// 
		/// </summary>
		void LoadContent ()
		{
			shader	=	Game.Content.Load<Ubershader>("hdr");
			factory	=	shader.CreateFactory( typeof(Flags), Primitive.TriangleList, VertexInputElement.Empty, BlendState.Opaque, RasterizerState.CullNone, DepthStencilState.None );
		}
		/// <summary>
		/// Loads content
		/// </summary>
		void LoadContent ( object sender, EventArgs args )
		{
			shader	=	rs.Game.Content.Load<Ubershader>("particles.hlsl");
			factory	=	shader.CreateFactory( typeof(Flags), (ps,i) => EnumAction( ps, (Flags)i ) );
		}
Exemple #27
0
		/// <summary>
		/// 
		/// </summary>
		void LoadContent ()
		{
			shaders = Game.Content.Load<Ubershader>( "filter" );
			factory	= shaders.CreateFactory( typeof(ShaderFlags), (ps,i) => Enum(ps, (ShaderFlags)i) );
		}
		/// <summary>
		/// 
		/// </summary>
		void LoadContent ()
		{
			lightingShader	=	Game.Content.Load<Ubershader>("lighting");
			factory			=	lightingShader.CreateFactory( typeof(LightingFlags), Primitive.TriangleList, VertexInputElement.Empty );
		}