本文整理汇总了C#中IndexBuffer.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# IndexBuffer.SetData方法的具体用法?C# IndexBuffer.SetData怎么用?C# IndexBuffer.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IndexBuffer
的用法示例。
在下文中一共展示了IndexBuffer.SetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initilize
public static void Initilize(GraphicsDevice gd)
{
ConstructCube();
vBuffer = new VertexBuffer(gd, VertexPositionNormalTexture.VertexDeclaration, 36, BufferUsage.WriteOnly);
vBuffer.SetData(verts);
gd.SetVertexBuffer(vBuffer);
ib = new IndexBuffer(gd, IndexElementSize.SixteenBits, 14, BufferUsage.WriteOnly);
ib.SetData(new short[14]
{
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
});
gd.Indices = ib;
wireframeRaster = new RasterizerState();
wireframeRaster.FillMode = FillMode.WireFrame;
wireframeRaster.CullMode = CullMode.None;
wireframeEfect = new BasicEffect(gd);
wireframeEfect.Projection = Matrix.CreatePerspectiveFieldOfView(0.7853982f,
wireframeEfect.GraphicsDevice.Viewport.AspectRatio, 0.01f, 3000f);
}
示例2: LoadContent
public void LoadContent(IServiceProvider services)
{
// Get the necessary services.
_graphics = ((IGraphicsDeviceService)services.GetService(typeof(IGraphicsDeviceService))).GraphicsDevice;
// Create a vertex declaration, describing the format of our vertex data.
// Create a vertex buffer, and copy our vertex data into it.
_vertexBuffer = new VertexBuffer(_graphics,
typeof(VertexPositionNormal),
_vertices.Count, BufferUsage.None);
_vertexBuffer.SetData(_vertices.ToArray());
// Create an index buffer, and copy our index data into it.
_indexBuffer = new IndexBuffer(_graphics, typeof(ushort),
_indices.Count, BufferUsage.None);
_indexBuffer.SetData(_indices.ToArray());
// Create a BasicEffect, which will be used to render the primitive.
_basicEffect = new BasicEffect(_graphics);
_basicEffect.EnableDefaultLighting();
}
示例3: DrawColoredRectangle
public static void DrawColoredRectangle(Device dev,RectangleF rect,Color color)
{
VertexBuffer vb=null;
IndexBuffer ib=null;
try{
int colorArgb=color.ToArgb();
CustomVertex.PositionColored[] quadVerts=new CustomVertex.PositionColored[] {
new CustomVertex.PositionColored(rect.Left,rect.Bottom,0,colorArgb),
new CustomVertex.PositionColored(rect.Left,rect.Top,0,colorArgb),
new CustomVertex.PositionColored(rect.Right,rect.Top,0,colorArgb),
new CustomVertex.PositionColored(rect.Right,rect.Bottom,0,colorArgb),
};
vb=new VertexBuffer(typeof(CustomVertex.PositionColored),
CustomVertex.PositionColored.StrideSize*quadVerts.Length,
dev,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
vb.SetData(quadVerts,0,LockFlags.None);
int[] indicies=new int[] { 0,1,2,0,2,3 };
ib=new IndexBuffer(typeof(int),indicies.Length,dev,Usage.None,Pool.Managed);
ib.SetData(indicies,0,LockFlags.None);
dev.VertexFormat=CustomVertex.PositionColored.Format;
dev.SetStreamSource(0,vb,0);
dev.Indices=ib;
dev.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,quadVerts.Length,0,indicies.Length/3);
}finally{
if(vb!=null){
vb.Dispose();
vb=null;
}
if(ib!=null){
ib.Dispose();
ib=null;
}
}
}
示例4: Create
public void Create(short prismSides, float baseRadius, float height)
{
topBase = new Base();
bottomBase = new Base();
side = new Side();
topBase.Create(prismSides, baseRadius, height, true);
bottomBase.Create(prismSides, baseRadius, 0, false, topBase.Vertices.Length);
side.Create(prismSides, bottomBase, topBase);
side.GenerateNormals();
indices = new short[topBase.Indices.Length * 2 + side.Indices.Length];
topBase.Indices.CopyTo(indices, 0);
bottomBase.Indices.CopyTo(indices, topBase.Indices.Length);
side.Indices.CopyTo(indices, topBase.Indices.Length + bottomBase.Indices.Length);
vertices = new VertexPositionNormalTexture[topBase.Vertices.Length * 4];
topBase.Vertices.CopyTo(vertices, 0);
bottomBase.Vertices.CopyTo(vertices, topBase.Vertices.Length);
side.Vertices.CopyTo(vertices, topBase.Vertices.Length + bottomBase.Vertices.Length);
primitiveCountPerBase = prismSides*2-1;
primitiveCountSide = prismSides*2;
indexBuffer = new IndexBuffer(graphicsDevice, typeof(short),
indices.Length, BufferUsage.WriteOnly);
vertexBuffer = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration,
vertices.Length, BufferUsage.WriteOnly);
vertexBuffer.SetData(vertices);
indexBuffer.SetData(indices);
}
示例5: Resolve
public void Resolve(bool injectHardEdges)
{
_vertices = new List<VertexPositionNormalTexture>();
//ushort indIdx = 0;
List<UInt16> indices = new List<UInt16>(_vertexPositions.Count);
foreach (CModel model in _models)
{
model.HardEdgesInserted = injectHardEdges;
model.IndexBufferStart = indices.Count;
model.Polygons.Sort(delegate(Polygon p1, Polygon p2) { return p1.MaterialIndex.CompareTo(p2.MaterialIndex); });
model.Resolve(indices, _vertices, _vertexTextureMap, _vertexPositions);
}
if (_vertices.Count > 0)
{
_vertexBuffer = new VertexBuffer(Engine.Device, VertexPositionNormalTexture.SizeInBytes * _vertices.Count, BufferUsage.WriteOnly);
_vertexBuffer.SetData<VertexPositionNormalTexture>(_vertices.ToArray());
if (!injectHardEdges)
{
_indexBuffer = new IndexBuffer(Engine.Device, typeof(UInt16), indices.Count, BufferUsage.WriteOnly);
_indexBuffer.SetData<UInt16>(indices.ToArray());
_indices = indices;
}
}
_vertexDeclaration = new VertexDeclaration(Engine.Device, VertexPositionNormalTexture.VertexElements);
_vertexTextureMap = null; //dont need this data anymore
}
示例6: InitBuffers
protected virtual void InitBuffers(GraphicsDevice graphics)
{
_vertexBuffer = new VertexBuffer(graphics, VertexPositionColorNormal.VertexDeclaration, _vertices.Length, BufferUsage.None);
_vertexBuffer.SetData<VertexPositionColorNormal>(_vertices);
_indexBuffer = new IndexBuffer(graphics, IndexElementSize.ThirtyTwoBits, _indices.Length, BufferUsage.None);
_indexBuffer.SetData<int>(_indices);
}
示例7: CreateIndices
public static void CreateIndices(GraphicsDevice graphicsDevice, int patchWidth, int patchHeight)
{
IndexCount = (patchWidth - 1) * (patchHeight - 1) * 6;
indexData = new short[IndexCount];
for (int y = 0; y < patchHeight - 1; y++)
for (int x = 0; x < patchWidth - 1; x++)
{
int i = (y * (patchWidth - 1) + x) * 6;
// lower left triangle
indexData[i + 0] = (short)((y + 1) * patchWidth + (x + 0)); // top left vertex
indexData[i + 1] = (short)((y + 1) * patchWidth + (x + 1)); // top right vertex
indexData[i + 2] = (short)((y + 0) * patchWidth + (x + 0)); // lower left vertex
// top right triangle
indexData[i + 3] = (short)((y + 1) * patchWidth + (x + 1)); // top right vertex
indexData[i + 4] = (short)((y + 0) * patchWidth + (x + 1)); // lower right vertex
indexData[i + 5] = (short)((y + 0) * patchWidth + (x + 0)); // lower left vertex
}
Indices = new IndexBuffer(graphicsDevice, typeof(short), IndexCount, BufferUsage.WriteOnly);
Indices.SetData<short>(indexData);
}
示例8: InitializePrimitive
public void InitializePrimitive(GraphicsDevice graphicsDevice)
{
VertexBuffer = new VertexBuffer(graphicsDevice, typeof(Vertex), Vertices.Count, BufferUsage.None);
VertexBuffer.SetData(Vertices.ToArray());
IndexBuffer = new IndexBuffer(graphicsDevice, typeof(int), Indices.Count, BufferUsage.None);
IndexBuffer.SetData(Indices.ToArray());
}
示例9: TextureStrip
public TextureStrip(GraphicsDevice device,Texture2D tex)
{
worldMatrix = Matrix.Identity;
Indices = new int[4];
effect = new BasicEffect(device);
float aspectRatio = (float)device.Viewport.Width /
device.Viewport.Height;
CamX = 0.0f;
CamY = 2.0f;
CamZ = 2.0f;
effect.View = Matrix.CreateLookAt(new Vector3(CamX, CamY, CamZ),Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10.0f);
effect.VertexColorEnabled = false;
textura = tex;
effect.Texture = this.textura;
effect.TextureEnabled = true;
CreateVertices();
Indices[0]=0;
Indices[1]=1;
Indices[2]=2;
Indices[3]=3;
effect.LightingEnabled = true;
effect.DirectionalLight0.DiffuseColor = new Vector3(1, 1, 1);
effect.DirectionalLight0.Direction = new Vector3(0, -1, 0);
effect.DirectionalLight0.SpecularColor = new Vector3(0, 0, 0);
vertexBuffer1 = new VertexBuffer(device, typeof(VertexPositionNormalTexture), vertices.Length, BufferUsage.None);
vertexBuffer1.SetData<VertexPositionNormalTexture>(vertices);
indexBuffer1 = new IndexBuffer(device, typeof(int), Indices.Length, BufferUsage.None);
indexBuffer1.SetData<int>(Indices);
}
示例10: LoadContent
protected override void LoadContent()
{
base.LoadContent();
effect = new BasicEffect(GraphicsDevice, null);
effect.VertexColorEnabled = true;
effect.Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1);
vertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements);
Color c = Color.Red;
for (int x = 0; x <= Constants.WIN_X; x += xMax)
{
listVertices.Add(new VertexPositionColor(new Vector3(x, Constants.WIN_Y - y, 0), Color.Red));
listVertices.Add(new VertexPositionColor(new Vector3(x, Constants.WIN_Y, 0), Color.Blue));
}
for (int i = 0; i < listVertices.Count - 1; i+=2)
{
listIndices.Add((short)(i));
listIndices.Add((short)(3 + i));
listIndices.Add((short)(1 + i));
listIndices.Add((short)(i));
listIndices.Add((short)(2 + i));
listIndices.Add((short)(3 + i));
}
buffVertex = new VertexBuffer(GraphicsDevice, VertexPositionColor.SizeInBytes * listVertices.Count, BufferUsage.WriteOnly);
buffVertex.SetData<VertexPositionColor>(listVertices.ToArray());
buffIndex = new IndexBuffer(GraphicsDevice, typeof(short), listIndices.Count, BufferUsage.WriteOnly);
buffIndex.SetData<short>(listIndices.ToArray());
}
示例11: Sphere
public Sphere(float Radius, GraphicsDevice graphics, Texture2D tex, Texture2D prograde, Texture2D retrograde,
Texture2D maneuverPrograde, Texture2D targetPrograde, Texture2D targetRetrograde)
{
this.prograde = new Bilboard (prograde, Matrix.CreateScale (1.0f));
this.retrograde = new Bilboard (retrograde, Matrix.CreateScale (1.0f));
this.maneuverPrograde = new Bilboard (maneuverPrograde, Matrix.CreateScale (1.0f));
this.targetPrograde = new Bilboard (targetPrograde, Matrix.CreateScale (1.0f));
this.targetRetrograde = new Bilboard (targetRetrograde, Matrix.CreateScale (1.0f));
texture = tex;
radius = Radius;
graphicd = graphics;
effect = new BasicEffect(graphicd);
nvertices = res * res; // 90 vertices in a circle, 90 circles in a sphere
nindices = res * res * 6;
vbuffer = new VertexBuffer(graphics, typeof(VertexPositionNormalTexture), nvertices, BufferUsage.WriteOnly);
ibuffer = new IndexBuffer(graphics, IndexElementSize.SixteenBits, nindices, BufferUsage.WriteOnly);
createspherevertices();
createindices();
vbuffer.SetData<VertexPositionNormalTexture>(vertices);
ibuffer.SetData<short>(indices);
effect.TextureEnabled = true;
effect.LightingEnabled = true;
rotQuat = Quaternion.Identity;
}
示例12: HeightMappedTerrain
public HeightMappedTerrain(Texture2D heightmap, float cellsize, float height, Texture2D basetex, float textile, Vector3 lightdir, GraphicsDevice device, ContentManager content)
{
baseTexture = basetex;
textureTiling = textile;
lightDirection = lightdir;
heightMap = heightmap;
width = heightmap.Width;
length = heightMap.Height;
cellSize = cellsize;
this.height = height;
GraphicsDevice = device;
effect = content.Load<Effect>("TerrainEffect");
nVertices = width * length;
nIndices = (width - 1) * (length - 1) * 6;
vertexBuffer = new VertexBuffer(device, typeof(VertexPositionNormalTexture), nVertices, BufferUsage.WriteOnly);
indexBuffer = new IndexBuffer(device, IndexElementSize.ThirtyTwoBits, nIndices, BufferUsage.WriteOnly);
extractHeightData();
createVertexData();
createIndexData();
createNormalData();
vertexBuffer.SetData<VertexPositionNormalTexture>(vertices);
indexBuffer.SetData<int>(indices);
}
示例13: 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
);
}
示例14: 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);
}
示例15: SetUpIndices
private void SetUpIndices() {
short[] Indices = new short[ 3 ];
Indices[ 0 ] = 0;
Indices[ 1 ] = 2;
Indices[ 2 ] = 1;
indexBuffer = new IndexBuffer( Editor.graphics.GraphicsDevice, sizeof( short ) * Indices.Length, BufferUsage.None, IndexElementSize.SixteenBits );
indexBuffer.SetData<short>( Indices );
}