本文整理汇总了C#中VertexBuffer.Lock方法的典型用法代码示例。如果您正苦于以下问题:C# VertexBuffer.Lock方法的具体用法?C# VertexBuffer.Lock怎么用?C# VertexBuffer.Lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VertexBuffer
的用法示例。
在下文中一共展示了VertexBuffer.Lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VertexContainer
public void VertexContainer( object sender, EventArgs e )
{
Device dev = (Device)sender ;
// Set culling so we're not rendering the back of our triangle
dev.RenderState.CullMode = Cull.CounterClockwise ;
// Turn off D3D lighting, since we are providing our own vertex colors
dev.RenderState.Lighting = false ;
// Create an instance of ready-made DirectX VertexBuffer
vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored),
3, dev, 0, CustomVertex.PositionColored.Format, Pool.Default);
// Lock our buffer so nothing gets changed while we are reading the data
GraphicsStream GraphixStream = vertexBuffer.Lock( 0, 0, 0 );
CustomVertex.PositionColored[] VerticeArray = new CustomVertex.PositionColored[3];
VerticeArray[0].Position = new Vector3( -0.5f, 0.5f, 0 ); // top right Vertice
VerticeArray[0].Color = System.Drawing.Color.Yellow.ToArgb();
VerticeArray[1].Position = new Vector3( 0.5f, -0.5f, 0 ); // bottom right
VerticeArray[1].Color = System.Drawing.Color.Orange.ToArgb();
VerticeArray[2].Position = new Vector3( -0.5f, -0.5f, 0 ); // bottom left
VerticeArray[2].Color = System.Drawing.Color.Red.ToArgb();
GraphixStream.Write(VerticeArray);
vertexBuffer.Unlock();
}
示例2: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var form = new Form1();
var panel = form.SplitContainer.Panel1;
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, panel.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
{
BackBufferWidth = panel.ClientSize.Width,
BackBufferHeight = panel.ClientSize.Height
});
var vertices = new VertexBuffer(device, 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
vertices.Lock(0, 0, LockFlags.None).WriteRange(new[] {
new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector4(400.0f, 100.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector4(650.0f, 500.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(150.0f, 500.0f, 0.5f, 1.0f) }
});
vertices.Unlock();
var vertices2 = new VertexBuffer(device, 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
vertices2.Lock(0, 0, LockFlags.None).WriteRange(new[] {
new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector4(300.0f, 100.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector4(550.0f, 500.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(050.0f, 500.0f, 0.5f, 1.0f) }
});
vertices2.Unlock();
var vertexElems = new[] {
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
};
var vertexDecl = new VertexDeclaration(device, vertexElems);
MessagePump.Run(form, () =>
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
device.BeginScene();
device.SetStreamSource(0, vertices, 0, 20);
device.VertexDeclaration = vertexDecl;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
device.SetStreamSource(0, vertices2, 0, 20);
device.VertexDeclaration = vertexDecl;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
device.EndScene();
device.Present();
});
foreach (var item in ObjectTable.Objects)
item.Dispose();
}
示例3: Background
// constructor
public Background(Device device, float width, float height)
{
this.device = device;
// Load the background texture image
backgroundT = TextureLoader.FromFile(device, "../../mars.bmp");
// Create a vertex buffer for the background image we will draw
backgroundV = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), // Type
4, // How many
device, // What device
0, // No special usage
CustomVertex.PositionColoredTextured.Format,
Pool.Managed);
// Fill the vertex buffer with the corners of a rectangle that covers
// the entire playing surface.
GraphicsStream stm = backgroundV.Lock(0, 0, 0); // Lock the background vertex list
int clr = Color.Transparent.ToArgb();
stm.Write(new CustomVertex.PositionColoredTextured(0, 0, 0, clr, 0, 1));
stm.Write(new CustomVertex.PositionColoredTextured(0, height, 0, clr, 0, 0));
stm.Write(new CustomVertex.PositionColoredTextured(width, height, 0, clr, 1, 0));
stm.Write(new CustomVertex.PositionColoredTextured(width, 0, 0, clr, 1, 1));
backgroundV.Unlock();
}
示例4: CreateTextures
public bool CreateTextures()
{
CustomVertex[] verts;
try {
string textureFile;
// Load the textures, named from "walk1.bmp" to "walk10.bmp"
for(int i=1; i<=10; i++) {
textureFile = Application.StartupPath + @"\..\..\Images\walk" + i.ToString() + ".bmp";
textures[i-1] = TextureLoader.FromFile(device, textureFile);
}
// Define the vertex buffer to hold our custom vertices
vertBuffer = new VertexBuffer(typeof(CustomVertex),
numVerts, device, Usage.WriteOnly, customVertexFlags, Pool.Default);
// Locks the memory, which will return the array to be filled
verts = vertBuffer.Lock(0, 0) as CustomVertex[];
// Defines the vertices
SquareVertices(verts);
// Unlock the buffer, which will save our vertex information to the device
vertBuffer.Unlock();
return true;
}
catch {
return false;
}
}
示例5: OnCreateDevice
public void OnCreateDevice(object sender, EventArgs e )
{
Device dev = (Device)sender;
vertexBuffer =
new VertexBuffer(typeof(CustomVertex.TransformedColored ),
3, dev, 0, CustomVertex.TransformedColored.Format,
Pool.Default ) ;
GraphicsStream stm = vertexBuffer.Lock( 0, 0, 0 ) ;
CustomVertex.TransformedColored[ ] verts = new CustomVertex.TransformedColored[ 3 ] ;
verts[0].X = 150 ;
verts[0].Y = 50 ;
verts[0].Z = 0.5f ;
verts[0].Rhw = 1 ;
verts[0].Color = System.Drawing.Color.Aqua.ToArgb ( ) ;
verts[1].X = 250 ;
verts[1].Y = 250 ;
verts[1].Z = 0.5f ;
verts[1].Rhw = 1 ;
verts[1].Color = System.Drawing.Color.Brown.ToArgb ( ) ;
verts[2].X = 50 ;
verts[2].Y = 250 ;
verts[2].Z = 0.5f ;
verts[2].Rhw = 1 ;
verts[2].Color = System.Drawing.Color.LightPink.ToArgb ( ) ;
stm.Write ( verts ) ;
vertexBuffer.Unlock ( ) ;
}
示例6: CreateParticles
public Result CreateParticles()
{
try {
ReleaseCom(_vb);
_vb = new VertexBuffer(_device, _hm.Size.X * _hm.Size.Y * Particle.Size, Usage.Dynamic | Usage.Points | Usage.WriteOnly, Particle.FVF, Pool.Default);
var ds = _vb.Lock(0, 0, LockFlags.Discard);
for (var y = 0; y < _hm.Size.Y; y++) {
for (var x = 0; x < _hm.Size.X; x++) {
var prc = _hm[x + y * _hm.Size.X] / _hm.MaxHeight;
//Debug.Print("prc: {0}", prc);
var red = prc;
var green = 1.0f - prc;
bool contains = false;
if (Editor != null) {
contains = x >= Editor.SelectionRect.Left && x <= Editor.SelectionRect.Right && y >= Editor.SelectionRect.Top && y <= Editor.SelectionRect.Bottom;
}
var v = new Particle {
Position = new Vector3(x, _hm[x + y * _hm.Size.X], -y),
Color = (ShowSelection && contains) ? new Color4(1.0f, 0, 0, 1.0f).ToArgb() : new Color4(1.0f, red, green, 0.0f).ToArgb()
};
ds.Write(v);
}
}
_vb.Unlock();
} catch (Exception ex) {
Debug.Print("Error in {0} - {1}\n{2}", ex.TargetSite, ex.Message, ex.StackTrace);
return ResultCode.Failure;
}
return ResultCode.Success;
}
示例7: OnResourceLoad
protected override void OnResourceLoad() {
vertexBuffer = new VertexBuffer(
Context9.Device,
3 * Marshal.SizeOf( typeof( ColoredVertex ) ),
Usage.WriteOnly,
VertexFormat.None,
Pool.Managed
);
var stream = vertexBuffer.Lock( 0, 0, LockFlags.None );
stream.WriteRange( new[] {
new ColoredVertex( new Vector3(0.0f, 0.5f, 0.5f), Color.Red.ToArgb() ),
new ColoredVertex( new Vector3(0.5f, -0.5f, 0.5f), Color.Blue.ToArgb() ),
new ColoredVertex( new Vector3(-0.5f, -0.5f, 0.5f), Color.Green.ToArgb() ),
} );
vertexBuffer.Unlock();
// Since this sample does not use any lights, disable lighting (otherwise the
// triangle will appear flat black).
Context9.Device.SetRenderState( RenderState.Lighting, false );
vertexDecl = new VertexDeclaration(Context9.Device, new[] {
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 12, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
});
}
示例8: setCollisionBox
// Default 값
public void setCollisionBox()
{
if (null != m_CollisionBox)
{
m_CollisionBox.Dispose();
}
m_CollisionBox = new VertexBuffer(typeof(CustomVertex.PositionColored), 8,
m_device, 0, CustomVertex.PositionColored.Format, Pool.Default);
CustomVertex.PositionColored[] posColoredVerts = new CustomVertex.PositionColored[8];
for (int i = 0; i < posColoredVerts.Length; ++i )
{
posColoredVerts[i].Position = new Vector3(0, 0, 0);
posColoredVerts[i].Color = System.Drawing.Color.Black.ToArgb();
}
GraphicsStream gstm = m_CollisionBox.Lock(0, 0, LockFlags.None);
gstm.Write(posColoredVerts);
m_CollisionBox.Unlock();
// indexedBuffer
m_IndexBuffer = new IndexBuffer(m_device, 12 * 2 * 2, Usage.WriteOnly, Pool.Managed, true);
GraphicsStream idstm = m_IndexBuffer.Lock(0, 0, LockFlags.None);
idstm.Write(m_IndexedBufferOrder);
m_IndexBuffer.Unlock();
}
示例9: FromScene
public static Model FromScene(Scene scene, Device device)
{
VertexDeclaration vertexDeclaration = new VertexDeclaration(device,
VertexPositionNormalTexture.VertexElements);
Model result = new Model(scene, device, vertexDeclaration);
foreach (Mesh mesh in scene.Meshes)
{
VertexBuffer vertexBuffer = new VertexBuffer(device,
mesh.Positions.Count * VertexPositionNormalTexture.SizeInBytes,
Usage.WriteOnly, VertexFormat.None, Pool.Default);
DataStream vertexDataStream = vertexBuffer.Lock(0,
mesh.Positions.Count * VertexPositionNormalTexture.SizeInBytes,
LockFlags.None);
VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[mesh.Positions.Count];
for (int i = 0; i < vertices.Length; ++i)
vertices[i] = new VertexPositionNormalTexture(mesh.Positions[i], (mesh.Normals.Count > i) ? mesh.Normals[i] : Vector3D.Zero, Point2D.Zero);
vertexDataStream.WriteRange(vertices);
vertexBuffer.Unlock();
IndexBuffer indexBuffer = new IndexBuffer(device, mesh.Indices.Count * sizeof(int),
Usage.WriteOnly, Pool.Default, false);
DataStream indexDataStream = indexBuffer.Lock(0, mesh.Indices.Count * sizeof(int), LockFlags.None);
indexDataStream.WriteRange(mesh.Indices.ToArray());
indexBuffer.Unlock();
ModelMesh modelMesh = new ModelMesh(mesh, device, vertexBuffer,
mesh.Positions.Count, indexBuffer, mesh.PrimitiveCount,
Matrix3D.Identity, mesh.Material);
result.Meshes.Add(modelMesh);
}
return result;
}
示例10: InitGraphicsResource
void InitGraphicsResource()
{
vertexBuffer = new VertexBuffer(SlimMMDXCore.Instance.Device, verticesSource.Length * Marshal.SizeOf(typeof(VertexPNmTx)), Usage.Dynamic, VertexFormat.None, Pool.Default);
DataStream stream = vertexBuffer.Lock(0, 0, LockFlags.None);
stream.WriteRange(verticesSource);
vertexBuffer.Unlock();
vertexDec = new VertexDeclaration(SlimMMDXCore.Instance.Device, VertexPNmTx.VertexElements);
}
示例11: CreateAxisSphere
private void CreateAxisSphere(ref VertexBuffer vBuffer, Vector3 dir, int clr)
{
double angle = Math.PI * ((360 / (double)orbitLineSz) / 180);
vBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), orbitLineSz + 1, device, Usage.None,
CustomVertex.PositionOnly.Format, Pool.Managed);
CustomVertex.PositionColored[] verts = (CustomVertex.PositionColored[])vBuffer.Lock(0, LockFlags.None);
double currentAngle = 0;
int vIdx = 0;
if (dir.X > 0)
{
for (int i = 0; i < orbitLineSz + 1; i++)
{
float x = scale * (float)Math.Cos(currentAngle);
float y = scale * (float)Math.Sin(currentAngle);
verts[vIdx].Color = clr;
verts[vIdx++].Position = new Vector3(0, x, y);
currentAngle += angle;
}
}
else if (dir.Y > 0)
{
for (int i = 0; i < orbitLineSz + 1; i++)
{
float x = scale * (float)Math.Cos(currentAngle);
float y = scale * (float)Math.Sin(currentAngle);
verts[vIdx].Color = clr;
verts[vIdx++].Position = new Vector3(x, 0, y);
currentAngle += angle;
}
}
else if (dir.Z > 0)
{
for (int i = 0; i < orbitLineSz + 1; i++)
{
float x = scale * (float)Math.Cos(currentAngle);
float y = scale * (float)Math.Sin(currentAngle);
verts[vIdx].Color = clr;
verts[vIdx++].Position = new Vector3(x, y, 0);
currentAngle += angle;
}
}
vBuffer.Unlock();
}
示例12: draw
public void draw(Vector3 cameraLocation, Vector3 cameraRotation, Device device)
{
Material initialMaterial = device.Material;
if (particleList.Count > 0)
{
sortParticles(particleList, 0, particleList.Count - 1, cameraLocation);
}
device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.SetTexture(0, particleTexture);
foreach (ParticleData particle in particleList)
{
device.Transform.World =
Matrix.RotationYawPitchRoll(cameraRotation.X, cameraRotation.Y, cameraRotation.Z) *
Matrix.Translation(particle.location);
Material material = device.Material;
Color diffuse = material.Diffuse;
material.Diffuse = particle.modColor;
material.Emissive = Color.White;
device.Material = material;
VertexBuffer buffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, device, 0, CustomVertex.PositionNormalTextured.Format, Pool.Default);
CustomVertex.PositionTextured[] vertices = (CustomVertex.PositionTextured[])buffer.Lock(0, 0);
float particleRadius = particle.size / 2;
vertices[0] = new CustomVertex.PositionTextured(new Vector3(-particleRadius, -particleRadius, 0f), 0, 1); // bottom right
vertices[1] = new CustomVertex.PositionTextured(new Vector3(-particleRadius, particleRadius, 0f), 0, 0); // top right
vertices[2] = new CustomVertex.PositionTextured(new Vector3(particleRadius, -particleRadius, 0f), 1, 1); // bottom left
vertices[3] = new CustomVertex.PositionTextured(new Vector3(particleRadius, particleRadius, 0), 1, 0); // top left
buffer.Unlock();
device.VertexFormat = CustomVertex.PositionTextured.Format;
device.SetStreamSource(0, buffer, 0);
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
}
device.RenderState.AlphaBlendEnable = false;
device.Material = initialMaterial;
}
示例13: BuildRings
private void BuildRings()
{
detailCount = 40;
ringClrs = new int[] { Color.Red.ToArgb(), Color.Green.ToArgb(), Color.Blue.ToArgb() };
vBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), (detailCount + 1) * 3,
gDevice, Usage.WriteOnly, CustomVertex.PositionColored.Format,
Pool.Managed);
CustomVertex.PositionColored[] verts = (CustomVertex.PositionColored[])vBuffer.Lock(0, LockFlags.None);
Vector2[] points;
CircleHelper.CalcCirclePointsCCW(detailCount + 1, 1, new Vector2(), out points);
BuildRingOnX(verts, (detailCount + 1) * 0, ringClrs[0], points);
BuildRingOnY(verts, (detailCount + 1) * 1, ringClrs[1], points);
BuildRingOnZ(verts, (detailCount + 1) * 2, ringClrs[2], points);
vBuffer.Unlock();
}
示例14: OnPlotterAttached
public override void OnPlotterAttached(Plotter plotter)
{
base.OnPlotterAttached(plotter);
//effect = SlimDX.Direct3D9.Effect.FromStream(Device, GetType().Assembly.GetManifestResourceStream("Microsoft.Research.DynamicDataDisplay.DirectX2D.VectorFieldConvolution.ConvolutionShader.fx"), ShaderFlags.None);
float size = .9f;
vertices = new VertexBuffer(Device, 2 * 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Default);
vertices.Lock(0, 0, LockFlags.None).WriteRange(new[] {
new VertexPosition4Color() { Color = Color.Red.ToArgb(), Position = new Vector4(0.0f, 0.0f, 0.5f, 1.0f) },
new VertexPosition4Color() { Color = Color.Blue.ToArgb(), Position = new Vector4(size, 0.0f, 0.5f, 1.0f) },
new VertexPosition4Color() { Color = Color.Green.ToArgb(), Position = new Vector4(size, size, 0.5f, 1.0f) },
new VertexPosition4Color() { Color = Color.Green.ToArgb(), Position = new Vector4(size, size, 0.5f, 1.0f) },
new VertexPosition4Color() { Color = Color.Green.ToArgb(), Position = new Vector4(0.0f, size, 0.5f, 1.0f) },
new VertexPosition4Color() { Color = Color.Green.ToArgb(), Position = new Vector4(0.0f, 0.0f, 0.5f, 1.0f) }
});
vertices.Unlock();
}
示例15: Init
public void Init(Device device)
{
this.device = device;
vBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 6, device, Usage.None, CustomVertex.PositionColored.Format, Pool.Managed);
CustomVertex.PositionColored[] verts = (CustomVertex.PositionColored[])vBuffer.Lock(0, LockFlags.None);
verts[0].Color = verts[1].Color = Color.Red.ToArgb();
verts[1].Position = new Vector3(1, 0, 0);
verts[2].Color = verts[3].Color = Color.Green.ToArgb();
verts[3].Position = new Vector3(0, 1, 0);
verts[4].Color = verts[5].Color = Color.Blue.ToArgb();
verts[5].Position = new Vector3(0, 0, 1);
vBuffer.Unlock();
}