Наследование: System.DisposableBase
Пример #1
0
		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);

		}
Пример #2
0
		/// <summary>
		/// Creates buffer from given indices
		/// </summary>
		/// <param name="device"></param>
		/// <param name="indices"></param>
		/// <returns></returns>
		public static IndexBuffer Create ( GraphicsDevice device, int[] indices )
		{
			var ib = new IndexBuffer( device, indices.Length );
			ib.SetData( indices );
			return ib;
		}
Пример #3
0
		void GenerateTileGrid(int density, ref VertexBuffer vb, out IndexBuffer ib, double left, double right, double top, double bottom, int zoom)
		{
			int[]			indexes;
			Gis.GeoPoint[]	vertices;

			DisposableBase.SafeDispose(ref vb);

			CalculateVertices(out vertices, out indexes, density, left, right, top, bottom);

			vb = new VertexBuffer(Game.GraphicsDevice, typeof(Gis.GeoPoint), vertices.Length);
			ib = new IndexBuffer(Game.GraphicsDevice, indexes.Length);
			ib.SetData(indexes);
			vb.SetData(vertices, 0, vertices.Length);
		}
Пример #4
0
		/// <summary>
		/// Sets index and vertex buffers.
		/// </summary>
		/// <param name="vertexBuffers">Vertex buffers to apply. Provide null if no vertex buffers are required.</param>
		/// <param name="offsets">Offsets in each vertex buffer.</param>
		/// <param name="indexBuffer">Index buffers to apply.</param>
		public void SetupVertexInput ( VertexBuffer[] vertexBuffers, int[] offsets, IndexBuffer indexBuffer )
		{
			lock (deviceContext) {
				if (indexBuffer!=null) {
					deviceContext.InputAssembler.SetIndexBuffer( indexBuffer.Buffer, DXGI.Format.R32_UInt, 0 );
				} else {	
					deviceContext.InputAssembler.SetIndexBuffer( null, Format.Unknown, 0 );
				}


				if (vertexBuffers==null) {
					deviceContext.InputAssembler.SetVertexBuffers( 0, new VertexBufferBinding( null, 0, 0 ) );
				} else {

					if (vertexBuffers.Length!=offsets.Length) {
						throw new InvalidOperationException("vertexBuffers.Length != offsets.Length");
					}
					if (vertexBuffers.Length>16) {
						throw new InvalidOperationException("vertexBuffers.Length > 16");
					}

					int count = vertexBuffers.Length;

					//#warning Remove allocation!
					var inputVertexBufferBinding = new VertexBufferBinding[count];

					for (int i=0; i<count; i++) {
						inputVertexBufferBinding[i].Buffer	=	( vertexBuffers[i]==null ) ? null : vertexBuffers[i].Buffer;
						inputVertexBufferBinding[i].Stride	=	( vertexBuffers[i]==null ) ? 0 : vertexBuffers[i].Stride;
						inputVertexBufferBinding[i].Offset	=	offsets[i];
					}
					deviceContext.InputAssembler.SetVertexBuffers( 0, inputVertexBufferBinding );
				}
			}
		}
Пример #5
0
		/// <summary>
		/// Sets index and vertex buffer.
		/// </summary>
		/// <param name="vertexBuffer">Vertex buffer to apply</param>
		/// <param name="indexBuffer">Index buffer to apply.</param>
		public void SetupVertexInput ( VertexBuffer vertexBuffer, IndexBuffer indexBuffer )
		{
			SetupVertexInput( new[]{ vertexBuffer }, new[]{ 0 }, indexBuffer );
		}
Пример #6
0
		/// <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();
			}
		}
Пример #7
0
 /// <summary>
 /// Sets index and vertex buffer.
 /// </summary>
 /// <param name="vertexBuffer">Vertex buffer to apply</param>
 /// <param name="indexBuffer">Index buffer to apply.</param>
 public void SetupVertexInput(VertexBuffer vertexBuffer, IndexBuffer indexBuffer)
 {
     SetupVertexInput(new[] { vertexBuffer }, new[] { 0 }, indexBuffer);
 }
Пример #8
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;
		}