本文整理汇总了C#中System.Buffer类的典型用法代码示例。如果您正苦于以下问题:C# Buffer类的具体用法?C# Buffer怎么用?C# Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Buffer类属于System命名空间,在下文中一共展示了Buffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Make
public static Buffer Make(byte[] buffer)
{
Buffer b = new Buffer();
b.buf = buffer;
b.bytesize = (uint)buffer.Length;
return b;
}
示例2: BufferPool
public BufferPool()
{
for (int i = 0; i < PoolSize; i++)
{
pool[i] = new Buffer(this, BufferLength);
}
}
示例3: ParticleSystem
public ParticleSystem(GraphicsDevice device, ContentManager content)
{
this.device = device;
// Create vertex buffer used to spawn new particles
this.particleStart = Buffer.Vertex.New<ParticleVertex>(device, MAX_NEW);
// Create vertex buffers to use for updating and drawing the particles alternatively
var vbFlags = BufferFlags.VertexBuffer | BufferFlags.StreamOutput;
this.particleDrawFrom = Buffer.New<ParticleVertex>(device, MAX_PARTICLES, vbFlags);
this.particleStreamTo = Buffer.New<ParticleVertex>(device, MAX_PARTICLES, vbFlags);
this.layout = VertexInputLayout.FromBuffer(0, this.particleStreamTo);
this.effect = content.Load<Effect>("ParticleEffect");
this.texture = content.Load<Texture2D>("Dot");
this.viewParameter = effect.Parameters["_view"];
this.projParameter = effect.Parameters["_proj"];
this.lookAtMatrixParameter = effect.Parameters["_lookAtMatrix"];
this.elapsedSecondsParameter = effect.Parameters["_elapsedSeconds"];
this.camDirParameter = effect.Parameters["_camDir"];
this.gravityParameter = effect.Parameters["_gravity"];
this.textureParameter = effect.Parameters["_texture"];
this.samplerParameter = effect.Parameters["_sampler"];
this.updatePass = effect.Techniques["UpdateTeq"].Passes[0];
this.renderPass = effect.Techniques["RenderTeq"].Passes[0];
}
示例4: ReadOne
private void ReadOne(Buffer buffer, LowLevelTcpConnection connection)
{
connection.ReadAsync(buffer.Segment.Array, buffer.Segment.Offset, buffer.Segment.Count,
readBytes =>
{
var readSegment = new ArraySegment<byte>(buffer.Segment.Array, 0, buffer.Segment.Offset + readBytes);
int headersSize;
var headers = TryParse(readSegment, out headersSize);
if (headers != null)
{
FixBuffer(buffer.Segment.Array, headersSize, buffer.Segment.Offset + readBytes);
StartHttp(headers, buffer.Segment.Array, connection);
}
else
{
ReadOne(new Buffer()
{
Segment =
new ArraySegment<byte>(buffer.Segment.Array,
buffer.Segment.Offset + readBytes,
buffer.Segment.Count - readBytes),
}, connection);
}
});
}
示例5: DoInitialize
protected override void DoInitialize()
{
{
// particleSimulator-fountain.comp is also OK.
var shaderCode = new ShaderCode(File.ReadAllText(@"shaders\ParticleSimulatorRenderer\particleSimulator.comp"), ShaderType.ComputeShader);
this.computeProgram = shaderCode.CreateProgram();
}
{
Buffer buffer = this.positionBuffer;
Texture texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
texture.Initialize();
this.positionTexture = texture;
}
{
Buffer buffer = this.velocityBuffer;
Texture texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
texture.Initialize();
this.velocityTexture = texture;
}
{
const int length = 64;
UniformBuffer buffer = UniformBuffer.Create(typeof(vec4), length, BufferUsage.DynamicCopy);
buffer.Bind();
OpenGL.BindBufferBase((BindBufferBaseTarget)BufferTarget.UniformBuffer, 0, buffer.BufferId);
buffer.Unbind();
this.attractorBuffer = buffer;
OpenGL.CheckError();
}
}
示例6: Minimap
public Minimap(Device device, DeviceContext dc, int minimapWidth, int minimapHeight, Terrain terrain, CameraBase viewCam) {
_dc = dc;
_minimapViewport = new Viewport(0, 0, minimapWidth, minimapHeight);
CreateMinimapTextureViews(device, minimapWidth, minimapHeight);
_terrain = terrain;
SetupOrthoCamera();
_viewCam = viewCam;
// frustum vb will contain four corners of view frustum, with first vertex repeated as the last
var vbd = new BufferDescription(
VertexPC.Stride * 5,
ResourceUsage.Dynamic,
BindFlags.VertexBuffer,
CpuAccessFlags.Write,
ResourceOptionFlags.None,
0
);
_frustumVB = new Buffer(device, vbd);
_edgePlanes = new[] {
new Plane(1, 0, 0, -_terrain.Width / 2),
new Plane(-1, 0, 0, _terrain.Width / 2),
new Plane(0, 1, 0, -_terrain.Depth / 2),
new Plane(0, -1, 0, _terrain.Depth / 2)
};
ScreenPosition = new Vector2(0.25f, 0.75f);
Size = new Vector2(0.25f, 0.25f);
}
示例7: SegmentRenderer
public SegmentRenderer()
{
m_program = TriangleProgram.Instance;
m_instances = new List<SegmentInstance>();
m_vao = new VertexArray();
GL.BindVertexArray(m_vao);
GL.UseProgram(m_program);
m_bufferSprite = new Buffer<SegmentData>();
m_bufferTriangle = new Buffer<Vector3>();
m_program.Position.SetValue(m_bufferSprite.GetView<Vector3>("Position"));
m_program.Color.SetValue(m_bufferSprite.GetView<Color4ub>("Color"));
//m_program.Position.SetDivisor(1);
// m_program.Normal.SetValue(m_bufferSprite.GetView<Vector3>("Normal"));
//// m_program.Normal.SetDivisor(1);
// m_program.Transform.SetValue(m_bufferSprite.GetView<Matrix4>("Transform"));
// //m_program.Transform.SetDivisor(1);
// m_program.TextureOrigin.SetValue(m_bufferSprite.GetView<Vector2>("TextureOrigin"));
// //m_program.TextureOrigin.SetDivisor(1);
// m_program.TextureTarget.SetValue(m_bufferSprite.GetView<Vector2>("TextureTarget"));
//m_program.TextureTarget.SetDivisor(1);
GL.BindVertexArray(null);
m_isDirty = true;
}
示例8: Insert
public static bool Insert(Buffer dest, Buffer source)
{
if (dest.BitsLeft() < source.BitsLeft())
return false;
Bitstream.Buffer tmp = new Bitstream.Buffer();
Copy(tmp, source);
while (tmp.BitsLeft() > 0)
{
if (tmp.bitpos > 0)
{
uint bits = (uint)(8 - tmp.bitpos);
if (bits > tmp.BitsLeft())
{
bits = tmp.BitsLeft();
}
Bitstream.PutBits(dest, bits, Bitstream.ReadBits(tmp, bits));
}
if (tmp.BitsLeft() > 32)
Bitstream.PutBits(dest, 32, Bitstream.ReadBits(tmp, 32));
uint left = tmp.BitsLeft();
if (left >= 8)
{
Bitstream.PutBits(dest, 8, Bitstream.ReadBits(tmp, 8));
}
else if (left > 0)
{
Bitstream.PutBits(dest, left, Bitstream.ReadBits(tmp, left));
}
}
return true;
}
示例9: ConsoleViewModel
public ConsoleViewModel(
ISyncThingManager syncThingManager,
IConfigurationProvider configurationProvider)
{
this.syncThingManager = syncThingManager;
this.LogMessages = new Queue<string>();
// Display log messages 100ms after the previous message, or every 500ms if they're arriving thick and fast
this.logMessagesBuffer = new Buffer<string>(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(500));
this.logMessagesBuffer.Delivered += (o, e) =>
{
foreach (var message in e.Items)
{
this.LogMessages.Enqueue(message);
if (this.LogMessages.Count > maxLogMessages)
this.LogMessages.Dequeue();
}
this.NotifyOfPropertyChange(() => this.LogMessages);
};
this.syncThingManager.MessageLogged += (o, e) =>
{
this.logMessagesBuffer.Add(e.LogMessage);
};
}
示例10: Skybox
public Skybox(GraphicsDevice device)
{
float x = 0.525731f;
float z = 0.850651f;
var vertices = new SkyboxVertex[12]
{
new SkyboxVertex(-x, 0f, z), new SkyboxVertex(x, 0f, z),
new SkyboxVertex(-x, 0f, -z), new SkyboxVertex(x, 0f, -z),
new SkyboxVertex(0f, z, x), new SkyboxVertex(0f, z, -x),
new SkyboxVertex(0f, -z, x), new SkyboxVertex(0f, -z, -x),
new SkyboxVertex(z, x, 0f), new SkyboxVertex(-z, x, 0f),
new SkyboxVertex(z, -x, 0f), new SkyboxVertex(-z, -x, 0f),
};
var indices = new int[60]
{
1,4,0, 4,9,0, 4,5,9, 8,5,4, 1,8,4,
1,10,8, 10,3,8, 8,3,5, 3,2,5, 3,7,2,
3,10,7, 10,6,7, 6,11,7, 6,0,11, 6,1,0,
10,1,6, 11,0,9, 2,11,9, 5,2,9, 11,2,7
};
vertexBuffer = Buffer<SkyboxVertex>.New(device, vertices, BufferFlags.VertexBuffer);
indexBuffer = Buffer<int>.New(device, indices, BufferFlags.IndexBuffer);
skyboxEffect = EffectLoader.Load(@"Graphics/Shaders/Skybox.fx");
skyboxTex = Texture2D.Load(device, @"G:\Users\Athrun\Documents\Stratum\trunk\src\Stratum\WorldEngine\Earth\milkyWay.tif");
}
示例11: Read_file
private void Read_file(string filename, Action<Buffer> continueWith) {
using (var fileStream = File.Open(filename, FileMode.Open, FileAccess.Read)) {
var buffer = new Buffer();
buffer.LengthUsed = fileStream.Read(buffer.Content, 0, buffer.Content.Length);
continueWith(buffer);
}
}
示例12: MyModel
public MyModel(Project1Game game, VertexPositionColor[] shapeArray, String textureName)
{
this.vertices = Buffer.Vertex.New(game.GraphicsDevice, shapeArray);
this.inputLayout = VertexInputLayout.New<VertexPositionColor>(0);
vertexStride = Utilities.SizeOf<VertexPositionColor>();
modelType = ModelType.Colored;
}
示例13: Process
public void Process(Buffer buffer) {
if (first) {
first = false;
First_Buffer(buffer);
}
All_Buffers(buffer);
}
示例14: Worker
public Worker(int threadCount, int blockLength, IHash hasher, FileStream stream)
{
mainThread = Thread.CurrentThread;
this.threadCount = threadCount;
this.stream = stream;
this.hasher = hasher;
this.blockLength = blockLength;
threads = new List<Thread>(threadCount);
for (int i = 0; i < threadCount; ++i)
{
var b = new Buffer();
b.raw = new byte[blockLength];
bufferQueue.AddToQueue(b);
}
blockCount = stream.Length / blockLength;
if (stream.Length % blockLength != 0)
{
blockCount++;
}
Console.CancelKeyPress += new ConsoleCancelEventHandler(Cancel);
}
示例15: OnLoad
private void OnLoad(object sender, EventArgs e)
{
// initialize shader (load sources, create/compile/link shader program, error checking)
// when using the factory method the shader sources are retrieved from the ShaderSourceAttributes
_program = ProgramFactory.Create<ExampleProgram>();
// this program will be used all the time so just activate it once and for all
_program.Use();
// create vertices for a triangle
var vertices = new[] { new Vector3(-1,-1,0), new Vector3(1,-1,0), new Vector3(0,1,0) };
// create buffer object and upload vertex data
_vbo = new Buffer<Vector3>();
_vbo.Init(BufferTarget.ArrayBuffer, vertices);
// create and bind a vertex array
_vao = new VertexArray();
_vao.Bind();
// set up binding of the shader variable to the buffer object
_vao.BindAttribute(_program.InPosition, _vbo);
// set camera position
Camera.DefaultState.Position = new Vector3(0,0,3);
Camera.ResetToDefault();
// set a nice clear color
GL.ClearColor(Color.MidnightBlue);
}