本文整理汇总了C#中IndexBuffer.Allocate方法的典型用法代码示例。如果您正苦于以下问题:C# IndexBuffer.Allocate方法的具体用法?C# IndexBuffer.Allocate怎么用?C# IndexBuffer.Allocate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IndexBuffer
的用法示例。
在下文中一共展示了IndexBuffer.Allocate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
protected override void Build()
{
vb = new VertexBuffer<Vector3>(Vector3.Descriptor);
vb.Allocate(8);
ib = new IndexBuffer<ushort>();
ib.Allocate(4 * 6);
vb[0] = new Vector3(-0.5f, -0.5f, -0.5f);
vb[1] = new Vector3(0.5f, -0.5f, -0.5f);
vb[2] = new Vector3(0.5f, 0.5f, -0.5f);
vb[3] = new Vector3(-0.5f, 0.5f, -0.5f);
vb[4] = new Vector3(-0.5f, -0.5f, 0.5f);
vb[5] = new Vector3(0.5f, -0.5f, 0.5f);
vb[6] = new Vector3(0.5f, 0.5f, 0.5f);
vb[7] = new Vector3(-0.5f, 0.5f, 0.5f);
ib[0] = 0;
ib[1] = 1;
ib[2] = 2;
ib[3] = 3;
ib[4] = 4;
ib[5] = 0;
ib[6] = 3;
ib[7] = 7;
ib[8] = 5;
ib[9] = 4;
ib[10] = 7;
ib[11] = 6;
ib[12] = 1;
ib[13] = 5;
ib[14] = 6;
ib[15] = 2;
ib[16] = 6;
ib[17] = 7;
ib[18] = 3;
ib[19] = 2;
ib[20] = 0;
ib[21] = 4;
ib[22] = 5;
ib[23] = 1;
vb.BufferData(VboUsage.GL_STATIC_DRAW);
ib.BufferData(VboUsage.GL_STATIC_DRAW);
// Client data is no longer needed. Free it!
vb.FreeClientData();
ib.FreeClientData();
}
示例2: TerrainBlock
internal TerrainBlock(int x_start, int y_start, int x_count, int y_count, BoundingBox box, int subdivision, Terrain owner)
{
bounds = box;
if (subdivision < owner.Subdivisions)
{
x_count /= 2;
y_count /= 2;
Vector3 new_size = box.Size / 2;
new_size.y = box.Size.y;
float offset = box.Size.x / 4;
children = new List<TerrainBlock>();
children.Add(new TerrainBlock(x_start, y_start, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, offset) }, subdivision + 1, owner));
children.Add(new TerrainBlock(x_start + x_count, y_start, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, offset) }, subdivision + 1, owner));
children.Add(new TerrainBlock(x_start + x_count, y_start + y_count, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, -offset) }, subdivision + 1, owner));
children.Add(new TerrainBlock(x_start, y_start + y_count, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, -offset) }, subdivision + 1, owner));
}
else
{
ib = new IndexBuffer<int>();
ib.Allocate(6 * (x_count) * (y_count));
int index = 0;
for (int i = 0; i < y_count; i++)
{
for (int j = 0; j < x_count; j++)
{
int i1 = (y_start + i) * owner.heightmap.Width + x_start + j;
int i2 = (y_start + i) * owner.heightmap.Width + x_start + j + 1;
int i3 = (y_start + i + 1) * owner.heightmap.Width + x_start + j + 1;
int i4 = (y_start + i + 1) * owner.heightmap.Width + x_start + j;
ib[index++] = i1;
ib[index++] = i3;
ib[index++] = i2;
ib[index++] = i1;
ib[index++] = i4;
ib[index++] = i3;
}
}
ib.BufferData(VboUsage.GL_STATIC_DRAW);
ib.FreeClientData();
}
}
示例3: InitializeGraphics
public void InitializeGraphics()
{
if(mat == null)
owner.Resources.Load("shaders\\Grid", out mat);
if (vb == null)
{
vb = new VertexBuffer<VertexPositionColor>(VertexPositionColor.Descriptor);
vb.Allocate(8);
}
if (ib == null)
{
ib = new IndexBuffer<uint>();
ib.Allocate(24);
ib[0] = 0;
ib[1] = 1;
ib[2] = 1;
ib[3] = 2;
ib[4] = 2;
ib[5] = 3;
ib[6] = 3;
ib[7] = 0;
ib[8] = 4;
ib[9] = 5;
ib[10] = 5;
ib[11] = 6;
ib[12] = 6;
ib[13] = 7;
ib[14] = 4;
ib[15] = 0;
ib[16] = 4;
ib[17] = 1;
ib[18] = 5;
ib[19] = 2;
ib[20] = 6;
ib[21] = 3;
ib[22] = 7;
ib.BufferData(VboUsage.GL_STATIC_DRAW);
}
if (points != null)
{
for (int i = 0; i < 8; i++)
{
vb[i] = new VertexPositionColor() { Position = points[i], Color = Colors.Yellow };
}
}
vb.BufferData(VboUsage.GL_DYNAMIC_DRAW);
}
示例4: Build
public override Model Build()
{
Model ret = new Model();
var w2 = width / 2;
var h2 = height / 2;
var d2 = depth / 2;
ret.VertexBuffer = new VertexBuffer<VertexPositionTexCoordNormal>(VertexPositionTexCoordNormal.Descriptor);
ret.VertexBuffer.Allocate(24);
var vb = ret.VertexBuffer;
var ib = new IndexBuffer<uint>();
//ib.Allocate(36);
Vector3[] pos = new Vector3[8];
pos[0] = new Vector3(-w2, h2, d2);
pos[1] = new Vector3(w2, h2, d2);
pos[2] = new Vector3(w2, h2, -d2);
pos[3] = new Vector3(-w2, h2, -d2);
pos[4] = new Vector3(-w2, -h2, d2);
pos[5] = new Vector3(w2, -h2, d2);
pos[6] = new Vector3(w2, -h2, -d2);
pos[7] = new Vector3(-w2, -h2, -d2);
ret.Parts.Add(
new ModelPart()
{
IndexBuffer = ib
}
);
vb[0] = new VertexPositionTexCoordNormal()
{
Position = pos[0],
Normal = Vector3.Up,
TexCoord = new Vector2(0, 0)
};
vb[1] = new VertexPositionTexCoordNormal()
{
Position = pos[1],
Normal = Vector3.Up,
TexCoord = new Vector2(1, 0)
};
vb[2] = new VertexPositionTexCoordNormal()
{
Position = pos[2],
Normal = Vector3.Up,
TexCoord = new Vector2(1, 1)
};
vb[3] = new VertexPositionTexCoordNormal()
{
Position = pos[3],
Normal = Vector3.Up,
TexCoord = new Vector2(0, 1)
};
vb[4] = new VertexPositionTexCoordNormal()
{
Position = pos[7],
Normal = Vector3.Down,
TexCoord = new Vector2(0, 0)
};
vb[5] = new VertexPositionTexCoordNormal()
{
Position = pos[6],
Normal = Vector3.Down,
TexCoord = new Vector2(1, 0)
};
vb[6] = new VertexPositionTexCoordNormal()
{
Position = pos[5],
Normal = Vector3.Down,
TexCoord = new Vector2(1, 1)
};
vb[7] = new VertexPositionTexCoordNormal()
{
Position = pos[4],
Normal = Vector3.Down,
TexCoord = new Vector2(0, 1)
};
vb[8] = new VertexPositionTexCoordNormal()
{
Position = pos[4],
Normal = Vector3.North,
TexCoord = new Vector2(0, 0)
};
vb[9] = new VertexPositionTexCoordNormal()
{
Position = pos[5],
Normal = Vector3.North,
TexCoord = new Vector2(0, 0)
};
//.........这里部分代码省略.........