protected override void RecognizeUShort(uint singleNodeVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList) { IndexBuffer indexBuffer = cmd.IndexBufferObject; int length = indexBuffer.Length; IntPtr pointer = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly); unsafe { var array = (ushort *)pointer.ToPointer(); uint i = 0; for (i = i + 2; i < length; i++) { var value = array[i]; if (value == singleNodeVertexId) { var item = new RecognizedPrimitiveInfo(i, array[0], array[i - 1], singleNodeVertexId); primitiveInfoList.Add(item); } } } indexBuffer.UnmapBuffer(); }
protected override void RecognizeByte(uint flatColorVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList) { IndexBuffer indexBuffer = cmd.IndexBufferObject; int length = indexBuffer.Length; IntPtr pointer = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly); unsafe { var array = (byte *)pointer.ToPointer(); uint i = 0; for (i = i + 3; i < length; i += 4) { var value = array[i]; if (value == flatColorVertexId) { var item = new RecognizedPrimitiveInfo(i, array[i - 3], array[i - 2], array[i - 1], flatColorVertexId); primitiveInfoList.Add(item); } } } indexBuffer.UnmapBuffer(); }
protected override void RecognizeByte(uint lastVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex) { IndexBuffer indexBuffer = cmd.IndexBufferObject; int length = indexBuffer.Length; IntPtr pointer = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly); unsafe { var array = (byte *)pointer.ToPointer(); long nearestRestartIndex = -1; uint i = 0; while (i < length && array[i] == primitiveRestartIndex) { nearestRestartIndex = i; i++; } for (i = i + 4; i < length; i++) { var value = array[i]; if (value == primitiveRestartIndex) { nearestRestartIndex = i; } else if ( array[i + 1] != primitiveRestartIndex && value == lastVertexId && array[i - 1] != primitiveRestartIndex && array[i - 2] != primitiveRestartIndex && array[i - 3] != primitiveRestartIndex && array[i - 4] != primitiveRestartIndex && (i - 4 - nearestRestartIndex) % 6 == 0) { var item = new RecognizedPrimitiveInfo(i, array[i - 4], array[i - 2], lastVertexId); primitiveInfoList.Add(item); } } } indexBuffer.UnmapBuffer(); }
private IndexBuffer GetBufferInBytes(int length) { IndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UByte, length, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (byte *)pointer; for (int i = 0; i < model.indexes.Length; i++) { if (model.indexes[i] == uint.MaxValue) { array[i] = byte.MaxValue; } else { array[i] = (byte)model.indexes[i]; } } buffer.UnmapBuffer(); } return(buffer); }
/// <summary> /// /// </summary> /// <param name="arg"></param> /// <param name="lastVertexId"></param> /// <param name="picker"></param> /// <returns></returns> internal override uint[] Search(PickingEventArgs arg, uint lastVertexId, DrawArraysPicker picker) { IndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 6, BufferUsage.StaticDraw); unsafe { var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly); array[0] = 0; array[1] = lastVertexId - 1; array[2] = lastVertexId - 1; array[3] = lastVertexId - 0; array[4] = lastVertexId - 0; array[5] = 0; buffer.UnmapBuffer(); } var cmd = new DrawElementsCmd(buffer, DrawMode.Lines); picker.Node.Render4InnerPicking(arg, IndexAccessMode.ByFrame, cmd); uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y); buffer.Dispose(); if (id + 1 == lastVertexId) { return(new uint[] { 0, lastVertexId - 1, }); } else if (id == lastVertexId) { return(new uint[] { lastVertexId - 1, lastVertexId - 0, }); } else if (id == 0) { return(new uint[] { lastVertexId - 0, 0, }); } else { throw new Exception("This should not happen!"); } }
protected override void RecognizeUInt(uint lastVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList) { IndexBuffer indexBuffer = cmd.IndexBufferObject; int length = indexBuffer.Length; IntPtr pointer = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly); unsafe { var array = (uint *)pointer.ToPointer(); long nearestRestartIndex = -1; uint i = 0; for (i = i + 3; i < length; i++) { var value = array[i]; if (value == lastVertexId && (i - nearestRestartIndex) % 4 == 0) { var item = new RecognizedPrimitiveInfo(i, array[i - 3], array[i - 2], array[i - 1], lastVertexId); primitiveInfoList.Add(item); } } } indexBuffer.UnmapBuffer(); }
protected override void RecognizeUInt(uint flatColorVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex) { IndexBuffer indexBuffer = cmd.IndexBufferObject; int length = indexBuffer.Length; IntPtr pointer = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly); unsafe { var array = (uint *)pointer.ToPointer(); long nearestRestartIndex = -1; uint i = 0; while (i < length && array[i] == primitiveRestartIndex) { nearestRestartIndex = i; i++; } for (i = i + 3; i < length; i++) { var value = array[i]; if (value == primitiveRestartIndex) { // try the loop back line. nearestRestartIndex = i; } else if (value == flatColorVertexId && array[i - 1] != primitiveRestartIndex && array[i - 3] != primitiveRestartIndex && array[i - 2] != primitiveRestartIndex ) { var item = new RecognizedPrimitiveInfo(i, array[i - 2], array[i - 3], array[i - 1], flatColorVertexId); primitiveInfoList.Add(item); } } } indexBuffer.UnmapBuffer(); }