当前位置: 首页>>代码示例>>C#>>正文


C# DynamicVertexBuffer类代码示例

本文整理汇总了C#中DynamicVertexBuffer的典型用法代码示例。如果您正苦于以下问题:C# DynamicVertexBuffer类的具体用法?C# DynamicVertexBuffer怎么用?C# DynamicVertexBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DynamicVertexBuffer类属于命名空间,在下文中一共展示了DynamicVertexBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SpriteRenderer

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="maxSprites">The maximum number of sprites which can be batched.</param>
        public SpriteRenderer(GraphicsContext graphics, int maxSprites)
        {
            if (graphics == null)
                throw new ArgumentNullException("graphics");

            if (maxSprites <= 0)
                throw new ArgumentOutOfRangeException("maxSprites", "MaxSprites must be >= 1.");

            this.graphics = graphics;

            this.vertices = new Vertex[maxSprites * 4];

            this.vertexBuffer = new DynamicVertexBuffer<Vertex>(this.graphics);

            ushort[] indices = new ushort[1024 * 6];
            for (ushort i = 0, vertex = 0; i < indices.Length; i += 6, vertex += 4)
            {
                indices[i] = vertex;
                indices[i + 1] = (ushort)(vertex + 1);
                indices[i + 2] = (ushort)(vertex + 3);
                indices[i + 3] = (ushort)(vertex + 1);
                indices[i + 4] = (ushort)(vertex + 2);
                indices[i + 5] = (ushort)(vertex + 3);
            }

            this.indexBuffer = new StaticIndexBuffer<ushort>(this.graphics, indices);

            this.transform = new Matrix4()
            {
                M33 = 1f,
                M44 = 1f,
                M41 = -1f,
                M42 = 1f
            };
        }
开发者ID:smack0007,项目名称:Samurai,代码行数:40,代码来源:SpriteRenderer.cs

示例2: GenerateInstanceInfo

        public void GenerateInstanceInfo(GraphicsDevice device)
        {
            if (_subMeshes.Count == 0)
                return;
            if (_instanceTransforms.Length < _subMeshes.Count)
                _instanceTransforms = new Matrix[_subMeshes.Count * 2];
            for (int index = 0; index < _subMeshes.Count; index++)
            {
                Mesh.SubMesh subMesh = _subMeshes[index];
                _instanceTransforms[index] = subMesh.GlobalTransform;
            }

            // If we have more instances than room in our vertex buffer, grow it to the necessary size.
            if ((_instanceVertexBuffer == null) ||
                (_instanceTransforms.Length > _instanceVertexBuffer.VertexCount))
            {
                if (_instanceVertexBuffer != null)
                    _instanceVertexBuffer.Dispose();

                _instanceVertexBuffer = new DynamicVertexBuffer(device, _instanceVertexDeclaration,
                                                               _instanceTransforms.Length, BufferUsage.WriteOnly);
            }
            // Transfer the latest instance transform matrices into the instanceVertexBuffer.
            _instanceVertexBuffer.SetData(_instanceTransforms, 0, _subMeshes.Count, SetDataOptions.Discard);
        }
开发者ID:justshiv,项目名称:LightSavers,代码行数:25,代码来源:InstancingGroup.cs

示例3: Batcher

		public Batcher( GraphicsDevice graphicsDevice )
		{
			Assert.isTrue( graphicsDevice != null );

			this.graphicsDevice = graphicsDevice;

			_vertexInfo = new VertexPositionColorTexture4[MAX_SPRITES];
			_textureInfo = new Texture2D[MAX_SPRITES];
			_vertexBuffer = new DynamicVertexBuffer( graphicsDevice, typeof( VertexPositionColorTexture ), MAX_VERTICES, BufferUsage.WriteOnly );
			_indexBuffer = new IndexBuffer( graphicsDevice, IndexElementSize.SixteenBits, MAX_INDICES, BufferUsage.WriteOnly );
			_indexBuffer.SetData( _indexData );

			_spriteEffect = new SpriteEffect();
			_spriteEffectPass = _spriteEffect.CurrentTechnique.Passes[0];

			_projectionMatrix = new Matrix(
				0f, //(float)( 2.0 / (double)viewport.Width ) is the actual value we will use
				0.0f,
				0.0f,
				0.0f,
				0.0f,
				0f, //(float)( -2.0 / (double)viewport.Height ) is the actual value we will use
				0.0f,
				0.0f,
				0.0f,
				0.0f,
				1.0f,
				0.0f,
				-1.0f,
				1.0f,
				0.0f,
				1.0f
			);
		}
开发者ID:prime31,项目名称:Nez,代码行数:34,代码来源:Batcher.cs

示例4: Allocate

		private void Allocate()
		{
			if (this.vertexBuffer == null || this.vertexBuffer.IsDisposed)
			{
				this.vertexBuffer = new DynamicVertexBuffer(this.graphicsDevice, typeof(VertexPositionColorTexture), 8192, BufferUsage.WriteOnly);
				this.vertexBufferPosition = 0;
				this.vertexBuffer.ContentLost += delegate(object sender, EventArgs e)
				{
					this.vertexBufferPosition = 0;
				};
			}
			if (this.indexBuffer == null || this.indexBuffer.IsDisposed)
			{
				if (this.fallbackIndexData == null)
				{
					this.fallbackIndexData = new short[12288];
					for (int i = 0; i < 2048; i++)
					{
						this.fallbackIndexData[i * 6] = (short)(i * 4);
						this.fallbackIndexData[i * 6 + 1] = (short)(i * 4 + 1);
						this.fallbackIndexData[i * 6 + 2] = (short)(i * 4 + 2);
						this.fallbackIndexData[i * 6 + 3] = (short)(i * 4);
						this.fallbackIndexData[i * 6 + 4] = (short)(i * 4 + 2);
						this.fallbackIndexData[i * 6 + 5] = (short)(i * 4 + 3);
					}
				}
				this.indexBuffer = new DynamicIndexBuffer(this.graphicsDevice, typeof(short), 12288, BufferUsage.WriteOnly);
				this.indexBuffer.SetData<short>(this.fallbackIndexData);
				this.indexBuffer.ContentLost += delegate(object sender, EventArgs e)
				{
					this.indexBuffer.SetData<short>(this.fallbackIndexData);
				};
			}
		}
开发者ID:thegamingboffin,项目名称:Ulterraria_Reborn_GitHub,代码行数:34,代码来源:TileBatch.cs

示例5: Append

        public unsafe void Append(TextAnalyzer analyzer, FontFace font, string text)
        {
            var layout = new TextLayout();
            var format = new TextFormat {
                Font = font,
                Size = 32.0f
            };

            analyzer.AppendText(text, format);
            analyzer.PerformLayout(0, 32, 1000, 1000, layout);

            var memBlock = new MemoryBlock(text.Length * 6 * PosColorTexture.Layout.Stride);
            var mem = (PosColorTexture*)memBlock.Data;
            foreach (var thing in layout.Stuff) {
                var width = thing.Width;
                var height = thing.Height;
                var region = new Vector4(thing.SourceX, thing.SourceY, width, height) / 4096;
                var origin = new Vector2(thing.DestX, thing.DestY);
                *mem++ = new PosColorTexture(origin + new Vector2(0, height), new Vector2(region.X, region.Y + region.W), unchecked((int)0xff000000));
                *mem++ = new PosColorTexture(origin + new Vector2(width, height), new Vector2(region.X + region.Z, region.Y + region.W), unchecked((int)0xff000000));
                *mem++ = new PosColorTexture(origin + new Vector2(width, 0), new Vector2(region.X + region.Z, region.Y), unchecked((int)0xff000000));
                *mem++ = new PosColorTexture(origin, new Vector2(region.X, region.Y), unchecked((int)0xff000000));
                count++;
            }

            vertexBuffer = new DynamicVertexBuffer(memBlock, PosColorTexture.Layout);
        }
开发者ID:bitzhuwei,项目名称:SharpFont,代码行数:27,代码来源:TextBuffer.cs

示例6: Initialize

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            zNear = 0.001f;
            zFar = 1000.0f;
            fov = MathHelper.Pi * 70.0f / 180.0f;
            eye = new Vector3(0.0f, 0.7f, 1.5f);
            at = new Vector3(0.0f, 0.0f, 0.0f);
            up = new Vector3(0.0f, 1.0f, 0.0f);

            cube = new VertexPositionColor[8];
            cube[0] = new VertexPositionColor(new Vector3(-0.5f, -0.5f, -0.5f), new Color(0.0f, 0.0f, 0.0f));
            cube[1] = new VertexPositionColor(new Vector3(-0.5f, -0.5f,  0.5f), new Color(0.0f, 0.0f, 1.0f));
            cube[2] = new VertexPositionColor(new Vector3(-0.5f,  0.5f, -0.5f), new Color(0.0f, 1.0f, 0.0f));
            cube[3] = new VertexPositionColor(new Vector3(-0.5f,  0.5f,  0.5f), new Color(0.0f, 1.0f, 1.0f));
            cube[4] = new VertexPositionColor(new Vector3( 0.5f, -0.5f, -0.5f), new Color(1.0f, 0.0f, 0.0f));
            cube[5] = new VertexPositionColor(new Vector3( 0.5f, -0.5f,  0.5f), new Color(1.0f, 0.0f, 1.0f));
            cube[6] = new VertexPositionColor(new Vector3( 0.5f,  0.5f, -0.5f), new Color(1.0f, 1.0f, 0.0f));
            cube[7] = new VertexPositionColor(new Vector3( 0.5f,  0.5f,  0.5f), new Color(1.0f, 1.0f, 1.0f));

            vertexBuffer = new DynamicVertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly);
            indexBuffer = new DynamicIndexBuffer(graphics.GraphicsDevice, typeof(ushort), 36, BufferUsage.WriteOnly);

            basicEffect = new BasicEffect(graphics.GraphicsDevice); //(device, null);
            basicEffect.LightingEnabled = false;
            basicEffect.VertexColorEnabled = true;
            basicEffect.TextureEnabled = false;

            graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            base.Initialize();
        }
开发者ID:BrainSlugs83,项目名称:MonoGame,代码行数:37,代码来源:Game1.cs

示例7: ParticleEngine

		/// <summary>
		/// 
		/// </summary>
		/// <param name="drawer">パーティクルを描画するためのシェーダー</param>
		/// <param name="device"></param>
		/// <param name="tex">パーティクルのテクスチャ</param>
		/// <param name="number">パーティクル最大数</param>
		public ParticleEngine(Effect drawer, GraphicsDevice device, Texture2D tex, ushort number,
			ParticleMode mode, Matrix projection, Vector2 fieldSize)
			:base(tex, number)
		{
			Device = device;
			
			//int[] x = { -1, -1, 1, 1 };
			//int[] y = { 1, -1, -1, 1 };
			
			VertexDataBuffer = new DynamicVertexBuffer(device, typeof(ParticleVertex), ParticleNum * 1, BufferUsage.WriteOnly);

		
			IndexVertexBuffer = new VertexBuffer(device, typeof(ParticleIndexVertex), indexVertex.Length, BufferUsage.WriteOnly);
			IndexVertexBuffer.SetData(indexVertex);

			short[] index = new short[] { 0, 1, 2, 0, 2, 3 };
			Index = new IndexBuffer(device, IndexElementSize.SixteenBits, index.Length, BufferUsage.WriteOnly);
			Index.SetData(index);
			
			Drawer = drawer;
			InitEffectParam();
			Mode = mode;
			Projection = projection;
			FieldSize = fieldSize;
			BlendColor = Vector4.One;
			Enable = true;

			SetVertex();//初期化
			bind = new VertexBufferBinding(VertexDataBuffer, 0, 1);
		}
开发者ID:MasakiMuto,项目名称:MasaLibs,代码行数:37,代码来源:ParticleEngine.cs

示例8: ParticleSystem

        public ParticleSystem(ParticleSettings settings, Effect effect)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (effect == null) throw new ArgumentNullException("effect");
            if (settings.Texture == null) throw new ArgumentException("Texture is null.");

            Enabled = true;

            this.settings = settings;

            //----------------------------------------------------------------
            // システム名

            Name = settings.Name;

            //----------------------------------------------------------------
            // エフェクト

            particleEffect = new ParticleEffect(effect);
            particleEffect.Initialize(settings, settings.Texture);

            graphicsDevice = particleEffect.GraphicsDevice;

            //----------------------------------------------------------------
            // パーティクル

            particles = new ParticleVertex[settings.MaxParticles * 4];

            for (int i = 0; i < settings.MaxParticles; i++)
            {
                particles[i * 4 + 0].Corner = new Short2(-1, -1);
                particles[i * 4 + 1].Corner = new Short2(1, -1);
                particles[i * 4 + 2].Corner = new Short2(1, 1);
                particles[i * 4 + 3].Corner = new Short2(-1, 1);
            }

            //----------------------------------------------------------------
            // 頂点バッファ

            vertexBuffer = new DynamicVertexBuffer(
                graphicsDevice, ParticleVertex.VertexDeclaration, settings.MaxParticles * 4, BufferUsage.WriteOnly);

            //----------------------------------------------------------------
            // インデックス バッファ

            var indices = new ushort[settings.MaxParticles * 6];
            for (int i = 0; i < settings.MaxParticles; i++)
            {
                indices[i * 6 + 0] = (ushort) (i * 4 + 0);
                indices[i * 6 + 1] = (ushort) (i * 4 + 1);
                indices[i * 6 + 2] = (ushort) (i * 4 + 2);

                indices[i * 6 + 3] = (ushort) (i * 4 + 0);
                indices[i * 6 + 4] = (ushort) (i * 4 + 2);
                indices[i * 6 + 5] = (ushort) (i * 4 + 3);
            }

            indexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort), indices.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);
        }
开发者ID:willcraftia,项目名称:TestBlocks,代码行数:60,代码来源:ParticleSystem.cs

示例9: CalcVertexBuffer

        public void CalcVertexBuffer()
        {
            if (instanceVertexBuffer != null)
                instanceVertexBuffer.Dispose();

            instanceVertexBuffer = new DynamicVertexBuffer(BaseClass.Device, instanceVertexDeclaration, instanceTransformMatrices.Count, BufferUsage.WriteOnly);
            instanceVertexBuffer.SetData(instanceTransformMatrices.Values.ToArray(), 0, instanceTransformMatrices.Count, SetDataOptions.Discard);
        }
开发者ID:Andrusza,项目名称:PiratesArr,代码行数:8,代码来源:Instancer.cs

示例10: StoreOnGPU

        public void StoreOnGPU(GraphicsDevice device)
        {
            GPUMode = true;
            GPUBlendVertexBuffer = new DynamicVertexBuffer(device, MeshVertex.SizeInBytes * BlendVertexBuffer.Length, BufferUsage.None);
            GPUBlendVertexBuffer.SetData(BlendVertexBuffer);

            GPUIndexBuffer = new IndexBuffer(device, sizeof(short) * IndexBuffer.Length, BufferUsage.None, IndexElementSize.SixteenBits);
            GPUIndexBuffer.SetData(IndexBuffer);
        }
开发者ID:ddfczm,项目名称:Project-Dollhouse,代码行数:9,代码来源:Mesh.cs

示例11: CreateBuffers

		private void CreateBuffers()
		{
			var vertexDeclaration = new VertexDeclaration(Format.Stride,
				nativeVertexFormat.ConvertFrom(Format));
			vertexBuffer = new DynamicVertexBuffer(nativeDevice, vertexDeclaration, NumberOfVertices,
				BufferUsage.WriteOnly);
			indexBuffer = new DynamicIndexBuffer(nativeDevice, IndexElementSize.SixteenBits,
				NumberOfIndices, BufferUsage.WriteOnly);
		}
开发者ID:caihuanqing0617,项目名称:DeltaEngine.Xna,代码行数:9,代码来源:XnaGeometry.cs

示例12: DebugDraw

        public DebugDraw(GraphicsDevice device)
        {
            vertexBuffer = new DynamicVertexBuffer(device, typeof(VertexPositionColor), MAX_VERTS, BufferUsage.WriteOnly);
            indexBuffer = new DynamicIndexBuffer(device, typeof(ushort), MAX_INDICES, BufferUsage.WriteOnly);

            basicEffect = new BasicEffect(device); //(device, null);
            basicEffect.LightingEnabled = false;
            basicEffect.VertexColorEnabled = true;
            basicEffect.TextureEnabled = false;
        }
开发者ID:mikkamikka,项目名称:AlfaTestInterface,代码行数:10,代码来源:DebugDraw.cs

示例13: EditingVoxture

        public EditingVoxture(string _name, OutpostColor baseColor, GraphicsDevice graphics)
        {
            name = new StringBuilder(_name);
            vox = new Voxture(baseColor);

            vBuff = new DynamicVertexBuffer(graphics, typeof(VertexPositionColorNormal), numVerts, BufferUsage.WriteOnly);
            iBuff = new IndexBuffer(graphics, IndexElementSize.SixteenBits, numInds, BufferUsage.WriteOnly);
            wfVBuff = new DynamicVertexBuffer(graphics, typeof(VertexPositionColor), numWfVerts, BufferUsage.WriteOnly);
            wfIBuff = new IndexBuffer(graphics, IndexElementSize.SixteenBits, numWfInds, BufferUsage.WriteOnly);

            makeIndices();

            _rotation = Matrix.Identity;
        }
开发者ID:littlebeast,项目名称:Outpost,代码行数:14,代码来源:EditingVoxture.cs

示例14: Initialize

 protected override void Initialize()
 {
     //Создаем буффер индексов и вершин
     graphics.GraphicsDevice.Flush();
     vertexBuffer = new DynamicVertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionNormalTexture), vertex.Length, BufferUsage.WriteOnly);
     indexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(int), indices.Length, BufferUsage.WriteOnly);
     //Создаем вершины для наших частиц.
     CreateVertex();
     //Переносим данные в буффер для видеокарты.
     indexBuffer.SetData(indices);
     vertexBuffer.SetData(vertex);
     //Вызываем иниталайз для базового класса и всех компоненетов, если они у нас есть.
     base.Initialize();
 }
开发者ID:Winbringer,项目名称:MonoGame3DKezumieParticles,代码行数:14,代码来源:Game1.cs

示例15: MMDCPUModelPartP

 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="triangleCount">三角形の個数</param>
 /// <param name="vertices">頂点配列</param>
 /// <param name="indexBuffer">インデックスバッファ</param>
 public MMDCPUModelPartP(int triangleCount, MMDVertex[] vertices,int[] vertMap, IndexBuffer indexBuffer)
     : base(triangleCount, vertices.Length, vertMap, indexBuffer)
 {
     this.vertices = vertices;
     //GPUリソース作成
     gpuVertices = new VertexPosition[vertices.Length];
     vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPosition), vertices.Length, BufferUsage.WriteOnly);
     //初期値代入
     for (int i = 0; i < vertices.Length; i++)
     {
         gpuVertices[i].Position = vertices[i].Position;
     }
     // put the vertices into our vertex buffer
     vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
 }
开发者ID:himapo,项目名称:ccm,代码行数:21,代码来源:MMDCPUModelPart.cs


注:本文中的DynamicVertexBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。