本文整理汇总了C#中VertexBuffer.Unlock方法的典型用法代码示例。如果您正苦于以下问题:C# VertexBuffer.Unlock方法的具体用法?C# VertexBuffer.Unlock怎么用?C# VertexBuffer.Unlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VertexBuffer
的用法示例。
在下文中一共展示了VertexBuffer.Unlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 ( ) ;
}
示例2: 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;
}
示例3: 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();
}
示例4: 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();
}
示例5: 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
});
}
示例6: 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;
}
示例7: 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;
}
}
示例8: 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);
}
示例9: 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();
}
示例10: 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();
}
示例11: 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();
}
示例12: 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();
}
示例13: CreateTextures
public bool CreateTextures()
{
CustomVertex[] verts;
try {
for(int i=1; i<=10; i++) {
textures[i-1] = TextureLoader.FromFile(device, [email protected]"\..\..\Images\Walk"+i.ToString()+".bmp");
}
vertBuffer = new VertexBuffer(typeof(CustomVertex), numVerts,
device, Usage.WriteOnly, customVertex, Pool.Default);
verts = vertBuffer.Lock(0, 0) as CustomVertex[];
SquareVertices(verts);
vertBuffer.Unlock();
return true;
}
catch {
return false;
}
}
示例14: draw
public void draw(Vector3 cameraRotation, Device device)
{
device.SetTexture(0, particleTexture);
device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
device.TextureState[0].AlphaArgument0 = TextureArgument.Current;
device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
device.TextureState[0].AlphaArgument2 = TextureArgument.TextureColor;
device.TextureState[0].ColorArgument0 = TextureArgument.Current;
device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
device.TextureState[0].ColorArgument2 = TextureArgument.TextureColor;
device.TextureState[0].ColorOperation = TextureOperation.Modulate;
Material material = device.Material;
Color diffuse = material.Diffuse;
material.Diffuse = fade;
material.Emissive = Color.White;
device.Material = material;
foreach (ParticleData particle in particleList)
{
device.Transform.World =
Matrix.RotationYawPitchRoll(cameraRotation.X, cameraRotation.Y, cameraRotation.Z) *
Matrix.Translation(particle.location);
VertexBuffer buffer = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 4, device, 0, CustomVertex.PositionNormalTextured.Format, Pool.Default);
CustomVertex.PositionNormalTextured[] vertices = (CustomVertex.PositionNormalTextured[])buffer.Lock(0, 0);
float particleRadius = particle.size / 2;
vertices[0] = new CustomVertex.PositionNormalTextured(new Vector3(-particleRadius, -particleRadius, 0f), new Vector3(0, 1, 0), 0, 1); // bottom right
vertices[1] = new CustomVertex.PositionNormalTextured(new Vector3(-particleRadius, particleRadius, 0f), new Vector3(0, 1, 0), 0, 0); // top right
vertices[2] = new CustomVertex.PositionNormalTextured(new Vector3(particleRadius, -particleRadius, 0f), new Vector3(0, 1, 0), 1, 1); // bottom left
vertices[3] = new CustomVertex.PositionNormalTextured(new Vector3(particleRadius, particleRadius, 0), new Vector3(0, 1, 0), 1, 0); // top left
buffer.Unlock();
device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
device.SetStreamSource(0, buffer, 0);
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
}
}
示例15: Form1
public Form1()
{
InitializeComponent();
GenericVolumeScene volumeScene = new GenericVolumeScene(new IVolume[] {
//new BoxVolume(new Vector3(), 50, 50, 50)
//new BoxVolume(new Vector3(70, 0 , 0), 30, 30, 30)
//new Metaball(new Vector3(0, 0, 0), 15f),
//new Metaball(new Vector3(110, 0, 0), 10f),
//new Metaball(new Vector3(75, 75, 0), 8f)
});
//pictureBox1.Image = IsosurfaceGenerator2D.GenerateBitmapSurface(pictureBox1.Width, pictureBox1.Height, 1.0f, 1.0f, volumeScene);
PresentParameters pParams = new PresentParameters();
//pParams.EnableAutoDepthStencil = true;
pParams.Windowed = true;
pParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this.pictureBox1, CreateFlags.SoftwareVertexProcessing/*.HardwareVertexProcessing*/, pParams);
device.RenderState.Lighting = false;
//Vector3[] points = IsosurfaceGenerator3D.GenerateSimplePointField(volumeScene, new Vector3(), 400, 20);
Vector3[] points;
int[] triangles;
Color[] colors;
IsosurfaceGenerator3D.GenerateSimpleMesh(volumeScene, new Vector3(), 400, 30, false, out triangles, out points, out colors);
vBuffer = new VertexBuffer(typeof(CustomVertex.PositionOnly), triangles.Length, device, Usage.None, CustomVertex.PositionOnly.Format, Pool.Managed);
CustomVertex.PositionOnly[] vertices = (CustomVertex.PositionOnly[])vBuffer.Lock(0, LockFlags.None);
for (int vIdx = 0; vIdx < triangles.Length; vIdx++)
{
vertices[vIdx].Position = points[triangles[vIdx]];
}
vBuffer.Unlock();
numPoints = triangles.Length;
numTris = numPoints / 3;
}