private void UpdateVB(int num, void *ptr) { if (_vertexBufferData == null || _vertexBufferData.Length < num) { _vertexBufferData = new Vertex[num + 200]; if (_vertexBuffer != null) { _vertexBuffer.Dispose(); } _vertexBuffer = _inputDataProcessor.CreateDynamicBuffer(_vertexBufferData.Length); } fixed(Vertex *dest = _vertexBufferData) { Buffer.MemoryCopy(ptr, dest, Marshal.SizeOf <Vertex>() * _vertexBufferData.Length, Marshal.SizeOf <Vertex>() * num); } _vertexBuffer.Update(_vertexBufferData); }
public Sprite(LightDevice device) { _device = device; device.AddComponent(this); _pipeline = device.CompilePipeline(InputTopology.Triangle, ShaderSource.FromString(PipelineCode, ShaderType.Vertex | ShaderType.Pixel)); _pipeline.SetBlender(Blender.AlphaBlender); _vertexProcessor = _pipeline.CreateVertexDataProcessor <Vertex>(); _array = new[] { new Vertex { TexCoord = new Vector4(0, 0, 0, 0), Position = new Vector4(0, 0, 0, 0) }, new Vertex { TexCoord = new Vector4(1, 0, 0, 0), Position = new Vector4(1, 0, 0, 0) }, new Vertex { TexCoord = new Vector4(0, 1, 0, 0), Position = new Vector4(0, 1, 0, 0) }, new Vertex { TexCoord = new Vector4(0, 1, 0, 0), Position = new Vector4(0, 1, 0, 0) }, new Vertex { TexCoord = new Vector4(1, 0, 0, 0), Position = new Vector4(1, 0, 0, 0) }, new Vertex { TexCoord = new Vector4(1, 1, 0, 0), Position = new Vector4(1, 1, 0, 0) }, }; _buffer = _vertexProcessor.CreateDynamicBuffer(6); _constant = _pipeline.CreateConstantBuffer <VSConstant>(); _pipeline.SetConstant(ShaderType.Vertex, 0, _constant); }
public VertexBuffer CreateDynamic(int size) { return(_inputProcessor.CreateDynamicBuffer(size)); }