private void When_increasing_file_size_using_Seek_followed_by_write_it_must_fail() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(512)) .IncludingBinaryFile(path, BufferFactory.Create(32)) .Build(); using (IFileStream stream = fileSystem.File.OpenWrite(path)) { byte[] buffer = BufferFactory.Create(64); stream.Write(buffer, 0, buffer.Length); stream.Seek(1280, SeekOrigin.Begin); // Act // ReSharper disable once AccessToDisposedClosure Action action = () => stream.WriteByte(0x33); // Assert action.Should().ThrowExactly <IOException>().WithMessage("There is not enough space on the disk."); AssertFreeSpaceOnDrive(fileSystem, "C:", 448); } AssertFileSize(fileSystem, path, 64); }
public QuadRenderer(IRenderer renderer) { mesh = new Mesh(); var vertexFormat = new VertexFormat(); position = vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); texcoord = vertexFormat.Add(new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2)); color = vertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 0, 4)); // Some gfx cards fail to show last vertex right if texcoord is set to have 3 components vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.StaticDraw); indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedInt, BufferUsageHint.StaticDraw); mesh.VertexBufferRange = vertexBufferRange = vertexBuffer.CreateVertexBufferRange(); indexBufferRange = mesh.FindOrCreateIndexBufferRange( MeshMode.PolygonFill, indexBuffer, BeginMode.Triangles ); vertexWriter = new VertexBufferWriter(mesh.VertexBufferRange); indexWriter = new IndexBufferWriter(indexBufferRange); }
private void When_moving_file_to_other_drive_it_must_fail() { // Arrange const string sourcePath = @"C:\source.txt"; const string targetPath = @"D:\target.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(sourcePath, BufferFactory.Create(768)) .IncludingVolume("D:", new FakeVolumeInfoBuilder() .OfCapacity(16384) .WithFreeSpace(512)) .Build(); // Act Action action = () => fileSystem.File.Move(sourcePath, targetPath); // Assert action.Should().ThrowExactly <IOException>().WithMessage("There is not enough space on the disk."); // Assert AssertFreeSpaceOnDrive(fileSystem, "C:", 3328); AssertFileSize(fileSystem, sourcePath, 768); AssertFreeSpaceOnDrive(fileSystem, "D:", 512); fileSystem.File.Exists(targetPath).Should().BeFalse(); }
private void When_unlocking_bytes_in_stream_it_must_not_raise_events() { // Arrange const string directoryToWatch = @"c:\some"; string filePath = Path.Combine(directoryToWatch, "file.txt"); FakeFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingBinaryFile(filePath, BufferFactory.Create(4096)) .Build(); using (IFileStream stream = fileSystem.File.Open(filePath, FileMode.Open)) { stream.Lock(0, 256); using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch)) { watcher.NotifyFilter = TestNotifyFilters.All; watcher.IncludeSubdirectories = true; using (var listener = new FileSystemWatcherEventListener(watcher)) { // Act stream.Unlock(0, 256); watcher.FinishAndWaitForFlushed(MaxTestDurationInMilliseconds); // Assert listener.EventsCollected.Should().BeEmpty(); } } } }
public TextBuffer(FontStyle fontStyle) { this.fontStyle = fontStyle; mesh = new Mesh.Mesh(); var vertexFormat = new VertexFormat(); vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); vertexFormat.Add(new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2)); vertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 0, 3)); vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.DynamicDraw); indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedInt, BufferUsageHint.StaticDraw); mesh.VertexBufferRange = vertexBuffer.CreateVertexBufferRange(); var indexBufferRange = mesh.FindOrCreateIndexBufferRange( MeshMode.PolygonFill, indexBuffer, BeginMode.Triangles ); vertexWriter = new VertexBufferWriter(mesh.VertexBufferRange); indexWriter = new IndexBufferWriter(indexBufferRange); }
private void When_moving_file_to_other_drive_it_must_succeed() { // Arrange const string sourcePath = @"C:\source.txt"; const string targetPath = @"D:\target.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(sourcePath, BufferFactory.Create(768)) .IncludingVolume("D:", new FakeVolumeInfoBuilder() .OfCapacity(16384) .WithFreeSpace(6144)) .Build(); // Act fileSystem.File.Move(sourcePath, targetPath); // Assert IDriveInfo driveInfoC = fileSystem.ConstructDriveInfo("C:"); driveInfoC.AvailableFreeSpace.Should().Be(4096); IDriveInfo driveInfoD = fileSystem.ConstructDriveInfo("D:"); driveInfoD.AvailableFreeSpace.Should().Be(5376); }
//private BufferRange indexBufferRange; protected override void InitializeService() { //basic = materialManager["Basic"]; basic = materialManager.MakeMaterial("Basic"); Image terrainImage = new Image("res/images/terrain.png"); // \todo support material textures basic.Textures["t_surface_color"] = materialManager.Textures["terrain"] = new TextureGL(terrainImage); blockTypes[BlockType.Grass] = new BlockType(0, 0, 2, 0, 3, 0, 3, 0, 3, 0, 3, 0); blockTypes[BlockType.Stone] = new BlockType(1, 0); blockTypes[BlockType.Dirt] = new BlockType(2, 0); blockTypes[BlockType.Cobblestone] = new BlockType(0, 1); blockTypes[BlockType.Bedrock] = new BlockType(1, 1); blockTypes[BlockType.Wood] = new BlockType(5, 1, 5, 1, 4, 1, 4, 1, 4, 1, 4, 1); blockTypes[BlockType.Sand] = new BlockType(2, 1); // 0, 0 grass (in gray) // 1, 0 stone // 2, 0 dirt // 3, 0 grass left, right, front, back // 4, 0 wooden planks // 5, 0 stone slab sides // 6, 0 stone slab top, bottom // 7, 0 brick // 8, 0 tnt sides // 9, 0 tnt top // 10, 0 tnt bottom // 11, 0 spider web // 12, 0 red flower // 13, 0 yellow flower // 14, 0 water? // 15, 0 sapling // 0, 1 cobble stone // 1, 1 bedrock // 2, 1 sand // 3, 1 gravel // 4, 1 log sidem // 5, 1 log top, bottom // 6, 1 iron block // 7, 1 gold block // 8, 1 diamond block // 9, 1 chest top, bottom // 10, 1 chest front, left, right // 11, 1 chest back // 12, 1 var vertexFormat = new VertexFormat(); position = vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); texcoord = vertexFormat.Add(new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2)); //color = vertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Byte, 0, 4, true)); color = vertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 0, 4)); // Some gfx cards fail to show last vertex right if texcoord is set to have 3 components vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.StaticDraw); indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedInt, BufferUsageHint.StaticDraw); }
public NinePatch(NinePatchStyle style) { this.style = style; //mesh = new Mesh.Mesh(BufferUsageHint.DynamicDraw); mesh = new RenderStack.Mesh.Mesh(); VertexFormat vertexFormat = new VertexFormat(); vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); vertexFormat.Add(new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2)); // \todo Allocate vertex buffers form from UI BufferPool and use double buffered Buffers // \todo Share one index buffer among all UI components that have the same index buffer //Buffer vertexBuffer = BufferPool.Instance.GetVertexBuffer(vertexFormat, BufferUsageHint.DynamicDraw); //Buffer indexBuffer = BufferPool.Instance.GetIndexBuffer(DrawElementsType.UnsignedShort, BufferUsageHint.StaticDraw); vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.DynamicDraw); indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedShort, BufferUsageHint.StaticDraw); mesh.VertexBufferRange = vertexBuffer.CreateVertexBufferRange(); IBufferRange indexBufferRange = mesh.FindOrCreateIndexBufferRange( MeshMode.PolygonFill, indexBuffer, BeginMode.Triangles ); var writer = new IndexBufferWriter(indexBufferRange); vertexWriter = new VertexBufferWriter(mesh.VertexBufferRange); // 12 13 14 15 // // 8 9 10 11 // // 4 5 6 7 // // 0 1 2 3 writer.BeginEdit(); writer.Quad(4, 5, 1, 0); writer.CurrentIndex += 6; writer.Quad(5, 6, 2, 1); writer.CurrentIndex += 6; writer.Quad(6, 7, 3, 2); writer.CurrentIndex += 6; writer.Quad(8, 9, 5, 4); writer.CurrentIndex += 6; writer.Quad(9, 10, 6, 5); writer.CurrentIndex += 6; writer.Quad(10, 11, 7, 6); writer.CurrentIndex += 6; writer.Quad(12, 13, 9, 8); writer.CurrentIndex += 6; writer.Quad(13, 14, 10, 9); writer.CurrentIndex += 6; writer.Quad(14, 15, 11, 10); writer.CurrentIndex += 6; writer.EndEdit(); // \bug //indexBuffer.UpdateAll(); }
static Quad() { var vertices = new float[] { 1f, -1f, 1f, 1f, -1f, -1f, -1f, 1f }; instance = new Quad { vbo = BufferFactory.Create <ArrayBuffer>(sizeof(float) * (uint)vertices.Length, vertices, BufferUsage.StaticDraw) }; }
static Triangle() { float[] vertices = { .0f, 1f, -1f, -1f, 1f, -1f }; instance = new Triangle { vbo = BufferFactory.Create <ArrayBuffer>(sizeof(float) * (uint)vertices.Length, vertices, OpenGL.BufferUsage.StaticDraw) }; }
private void When_writing_to_new_file_it_must_succeed() { // Arrange IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .Build(); // Act fileSystem.File.WriteAllBytes(@"C:\file.txt", BufferFactory.Create(1024)); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(3072); }
public static ReadOnlySequence<byte> GetSequence(byte[] _dataUtf8, int segmentSize) { int numberOfSegments = _dataUtf8.Length / segmentSize + 1; byte[][] buffers = new byte[numberOfSegments][]; for (int j = 0; j < numberOfSegments - 1; j++) { buffers[j] = new byte[segmentSize]; Array.Copy(_dataUtf8, j * segmentSize, buffers[j], 0, segmentSize); } int remaining = _dataUtf8.Length % segmentSize; buffers[numberOfSegments - 1] = new byte[remaining]; Array.Copy(_dataUtf8, _dataUtf8.Length - remaining, buffers[numberOfSegments - 1], 0, remaining); return BufferFactory.Create(buffers); }
public static BulletBatch Create() { var program = CreateProgram(); var timeUniform = program.GetUniform <FloatUniform>("uTime"); var scaleUniform = program.GetUniform <FloatUniform>("uScale"); var vbo = Quad.VertexBuffer; var ivbo = BufferFactory.Create <ArrayBuffer>((uint)Marshal.SizeOf <Position>() * MAX_BULLETS, null, BufferUsage.StreamDraw); var vao = CreateVertexArray(); return(new BulletBatch(vao, ivbo, program, timeUniform, scaleUniform)); ShaderProgram CreateProgram() { using (var vertexShader = ShaderFactory <VertexShader> .FromSource(Resources.BulletVertex)) using (var fragShader = ShaderFactory <FragmentShader> .FromSource(Resources.BulletFrag)) { return(ShaderProgram.LinkShaders(vertexShader, fragShader)); } } VertexArray CreateVertexArray() { var newVao = VertexArray.Create(); using (var vaoBinding = newVao.BindVertexArray()) { using (var vboBinding = vbo.BindBuffer()) { var positionAttribute = new Vec2Attribute(0u); vaoBinding.SetAttributePointer(positionAttribute, 0, 0); vaoBinding.EnableAttribute(positionAttribute); } using (var ivboBinding = ivbo.BindBuffer()) { var offsetAttribute = new Vec2Attribute(1u); vaoBinding.SetAttributePointer(offsetAttribute, 0, 0); vaoBinding.EnableAttribute(offsetAttribute); vaoBinding.SetAttributeDivisor(offsetAttribute, 1); } } return(newVao); } }
private void When_encrypting_file_it_must_succeed() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(path, BufferFactory.Create(1024)) .Build(); // Act fileSystem.File.Encrypt(path); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(3072); }
private void When_decreasing_file_size_using_overwrite_it_must_succeed() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(path, BufferFactory.Create(1024)) .Build(); // Act fileSystem.File.WriteAllBytes(path, BufferFactory.Create(256)); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(3840); }
private void When_writing_to_file_it_must_fail() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(512)) .Build(); // Act Action action = () => fileSystem.File.WriteAllBytes(path, BufferFactory.Create(1024)); // Assert action.Should().ThrowExactly <IOException>().WithMessage("There is not enough space on the disk."); AssertFileSize(fileSystem, path, 0); AssertFreeSpaceOnDrive(fileSystem, "C:", 512); }
private void When_renaming_directory_it_must_succeed() { // Arrange IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(@"c:\source\src.txt", BufferFactory.Create(64)) .IncludingBinaryFile(@"c:\source\nested\src.txt", BufferFactory.Create(256)) .IncludingDirectory(@"c:\source\subfolder") .Build(); // Act fileSystem.Directory.Move(@"C:\source", @"C:\target"); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(3776); }
private void When_copying_file_to_same_drive_it_must_succeed() { // Arrange const string sourcePath = @"C:\source.txt"; const string targetPath = @"C:\target.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(sourcePath, BufferFactory.Create(768)) .Build(); // Act fileSystem.File.Copy(sourcePath, targetPath); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(2560); }
private void When_writing_to_new_file_with_DeleteOnClose_it_must_succeed() { // Arrange IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .Build(); // Act using (IFileStream stream = fileSystem.File.Create(@"C:\file.txt", options: FileOptions.DeleteOnClose)) { byte[] buffer = BufferFactory.Create(1024); stream.Write(buffer, 0, buffer.Length); } // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(4096); }
private void When_async_appending_to_stream_it_must_raise_events(NotifyFilters filters, [NotNull] string expectedText) { // Arrange const string directoryToWatch = @"c:\some"; const string containerDirectoryName = "Container"; const string fileNameToWrite = "file.txt"; string pathToFileToWrite = Path.Combine(directoryToWatch, containerDirectoryName, fileNameToWrite); FakeFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingBinaryFile(pathToFileToWrite, BufferFactory.Create(1024)) .Build(); var buffer = new byte[512]; using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch)) { watcher.NotifyFilter = filters; watcher.IncludeSubdirectories = true; using (var listener = new FileSystemWatcherEventListener(watcher)) { using (IFileStream stream = fileSystem.File.Open(pathToFileToWrite, FileMode.Open, FileAccess.ReadWrite)) { stream.Seek(0, SeekOrigin.End); // Act Task task = stream.WriteAsync(buffer, 0, buffer.Length); task.Wait(); } watcher.FinishAndWaitForFlushed(MaxTestDurationInMilliseconds); // Assert string text = string.Join(Environment.NewLine, listener.GetEventsCollectedAsText()); text.Should().Be(expectedText); } } }
private void When_moving_position_past_end_of_file_it_must_not_allocate_disk_space() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(512)) .IncludingBinaryFile(path, BufferFactory.Create(32)) .Build(); using (IFileStream stream = fileSystem.File.Open(path, FileMode.Open)) { // Act stream.Position = 1024; // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(480); } }
private void When_replacing_file_without_backup_it_must_succeed() { // Arrange const string sourcePath = @"C:\source.txt"; const string targetPath = @"C:\target.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(2112)) .IncludingBinaryFile(sourcePath, BufferFactory.Create(768)) .IncludingBinaryFile(targetPath, BufferFactory.Create(1280)) .Build(); // Act fileSystem.File.Replace(sourcePath, targetPath, null); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(1344); }
private void When_increasing_file_size_using_SetLength_it_must_succeed() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(path, BufferFactory.Create(1024)) .Build(); using (IFileStream stream = fileSystem.File.OpenWrite(path)) { // Act stream.SetLength(1280); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(2816); } }
protected override void InitializeService() { if ( (RenderStack.Graphics.Configuration.canUseGeometryShaders) && (RenderStack.Graphics.Configuration.glslVersion >= 330) ) { material = new Material("", renderer.Programs["WideLine"], renderer.MaterialUB); } else { material = new Material("", renderer.Programs["ColorFill"], renderer.MaterialUB); } LineWidth = 1.0f; mesh = new Mesh(); var vertexFormat = new VertexFormat(); position = vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); edgeColor = vertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 1, 4)); vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.DynamicDraw); indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedInt, BufferUsageHint.DynamicDraw); mesh.VertexBufferRange = vertexBufferRange = vertexBuffer.CreateVertexBufferRange(); indexBufferRange = mesh.FindOrCreateIndexBufferRange( MeshMode.EdgeLines, indexBuffer, BeginMode.Lines ); vertexWriter = new VertexBufferWriter(mesh.VertexBufferRange); indexWriter = new IndexBufferWriter(indexBufferRange); }
private void When_copying_over_existing_file_to_same_drive_it_must_fail() { // Arrange const string sourcePath = @"C:\source.txt"; const string targetPath = @"C:\target.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(1024)) .IncludingBinaryFile(sourcePath, BufferFactory.Create(768)) .IncludingEmptyFile(targetPath) .Build(); // Act Action action = () => fileSystem.File.Copy(sourcePath, targetPath, true); // Assert action.Should().ThrowExactly <IOException>().WithMessage("There is not enough space on the disk."); AssertFreeSpaceOnDrive(fileSystem, "C:", 256); AssertFileSize(fileSystem, sourcePath, 768); fileSystem.File.Exists(targetPath).Should().BeTrue(); }
internal static ShipBatch Create() { ShaderProgram program; using (var vertexShader = ShaderFactory.FromSource <VertexShader>(Resources.BulletVertex)) using (var fragmentShader = ShaderFactory.FromSource <FragmentShader>(Resources.ShipFrag)) { program = ShaderProgram.LinkShaders(vertexShader, fragmentShader); } var timeUniform = program.GetUniform <FloatUniform>("uTime"); var scaleUniform = program.GetUniform <FloatUniform>("uScale"); var ivbo = BufferFactory.Create <ArrayBuffer>((uint)Marshal.SizeOf <Position>() * MAX_SHIPS, null, BufferUsage.StreamDraw); var vbo = Triangle.VertexBuffer; var vertexArray = VertexArray.Create(); using (var vaoBinding = vertexArray.BindVertexArray()) { using (var vboBinding = vbo.BindBuffer()) { var positionAttribute = new Vec2Attribute(0u); vaoBinding.SetAttributePointer(positionAttribute, 0, 0); vaoBinding.EnableAttribute(positionAttribute); } using (var ivboBinding = ivbo.BindBuffer()) { var offsetAttribute = new Vec2Attribute(1u); vaoBinding.SetAttributePointer(offsetAttribute, 0, 0); Gl.VertexAttribDivisor(offsetAttribute.Index, 1u); vaoBinding.EnableAttribute(offsetAttribute); } } return(new ShipBatch(program, ivbo, vertexArray, timeUniform, scaleUniform)); }
public CurveTube(ICurve curve) { this.curve = curve; PointMesh = new Mesh(); LineMesh = new Mesh(); Line2Mesh = new Mesh(); TubeMesh = new Mesh(); var positionColor = new VertexFormat(); // pointMesh, lineMesh, line2Mesh var tubeVertexFormat = new VertexFormat(); positionColor.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); positionColor.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 0, 4)); tubeVertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3)); tubeVertexFormat.Add(new Attribute(VertexUsage.Tangent, VertexAttribPointerType.Float, 0, 3)); tubeVertexFormat.Add(new Attribute(VertexUsage.Normal, VertexAttribPointerType.Float, 0, 3)); tubeVertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 0, 4)); tubeVertexFormat.Add(new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 1, 1)); tubeVertexFormat.Add(new Attribute(VertexUsage.Id, VertexAttribPointerType.UnsignedInt, 0, 1)); // Could perhaps use BufferPool var positionColorVertexBuffer = BufferFactory.Create(positionColor, BufferUsageHint.DynamicDraw); var tubeVertexBuffer = BufferFactory.Create(tubeVertexFormat, BufferUsageHint.DynamicDraw); var indexBuffer = BufferFactory.Create(DrawElementsType.UnsignedInt, BufferUsageHint.DynamicDraw); PointMesh.VertexBufferRange = positionColorVertexBuffer.CreateVertexBufferRange(); LineMesh.VertexBufferRange = positionColorVertexBuffer.CreateVertexBufferRange(); Line2Mesh.VertexBufferRange = positionColorVertexBuffer.CreateVertexBufferRange(); TubeMesh.VertexBufferRange = tubeVertexBuffer.CreateVertexBufferRange(); var pointIndexBuffer = PointMesh.FindOrCreateIndexBufferRange( MeshMode.CornerPoints, indexBuffer, BeginMode.Points ); var lineIndexBuffer = LineMesh.FindOrCreateIndexBufferRange( MeshMode.EdgeLines, indexBuffer, BeginMode.Lines ); var line2IndexBuffer = Line2Mesh.FindOrCreateIndexBufferRange( MeshMode.EdgeLines, indexBuffer, BeginMode.Lines ); var tubeIndexBuffer = TubeMesh.FindOrCreateIndexBufferRange( MeshMode.PolygonFill, indexBuffer, BeginMode.Triangles ); tubeVertexWriter = new VertexBufferWriter(TubeMesh.VertexBufferRange); tubeIndexWriter = new IndexBufferWriter(tubeIndexBuffer); pointVertexWriter = new VertexBufferWriter(PointMesh.VertexBufferRange); pointIndexWriter = new IndexBufferWriter(pointIndexBuffer); lineVertexWriter = new VertexBufferWriter(LineMesh.VertexBufferRange); lineIndexWriter = new IndexBufferWriter(lineIndexBuffer); line2VertexWriter = new VertexBufferWriter(Line2Mesh.VertexBufferRange); line2IndexWriter = new IndexBufferWriter(line2IndexBuffer); UpdateIndexBuffers(); }