protected override void RecognizeUInt(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveIndex> lastIndexIdList, uint primitiveRestartIndex) { int length = oneIndexBufferPtr.Length; unsafe { var array = (uint *)pointer.ToPointer(); long nearestRestartIndex = -1; uint i = 0; while (i < length && array[i] == primitiveRestartIndex) { nearestRestartIndex = i; i++; } for (i = i + 1; i < length; i++) { var value = array[i]; if (value == primitiveRestartIndex) { nearestRestartIndex = i; } else if (value == lastVertexId && array[i - 1] != primitiveRestartIndex && (i - nearestRestartIndex) % 2 == 0) { var item = new RecognizedPrimitiveIndex(lastVertexId, i); item.IndexIdList.Add(array[i - 1]); item.IndexIdList.Add(value); lastIndexIdList.Add(item); } } } }
protected override void RecognizeByte(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveIndex> lastIndexIdList) { int length = oneIndexBufferPtr.Length; unsafe { var array = (byte *)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 RecognizedPrimitiveIndex(lastVertexId, i); item.IndexIdList.Add(array[i - 3]); item.IndexIdList.Add(array[i - 2]); item.IndexIdList.Add(array[i - 1]); item.IndexIdList.Add(value); lastIndexIdList.Add(item); } } } }
protected override void RecognizeUInt(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex) { int length = oneIndexBufferPtr.Length; unsafe { var array = (uint *)pointer.ToPointer(); long nearestRestartIndex = -1; uint i = 0; while (i < length && array[i] == primitiveRestartIndex) { nearestRestartIndex = i; i++; } for (i = i + 2; i < length; i++) { var value = array[i]; if (value == primitiveRestartIndex) { // try the loop back line. nearestRestartIndex = i; } else if (value == lastVertexId && array[i - 1] != primitiveRestartIndex && array[i - 2] != primitiveRestartIndex ) { var item = new RecognizedPrimitiveInfo(i, array[i - 2], array[i - 1], lastVertexId); primitiveInfoList.Add(item); } } } }
/// <summary> /// 识别出以<paramref name="lastVertexId"/>结尾的图元。 /// </summary> /// <param name="lastVertexId"></param> /// <param name="pointer"></param> /// <param name="oneIndexBufferPtr"></param> /// <returns></returns> public List <RecognizedPrimitiveInfo> Recognize( uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr) { var lastIndexIdList = new List <RecognizedPrimitiveInfo>(); switch (oneIndexBufferPtr.Type) { case IndexElementType.UByte: RecognizeByte(lastVertexId, pointer, oneIndexBufferPtr, lastIndexIdList); break; case IndexElementType.UShort: RecognizeUShort(lastVertexId, pointer, oneIndexBufferPtr, lastIndexIdList); break; case IndexElementType.UInt: RecognizeUInt(lastVertexId, pointer, oneIndexBufferPtr, lastIndexIdList); break; default: throw new NotImplementedException(); } return(lastIndexIdList); }
internal override uint[] Search(RenderEventArgs arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer <uint>(DrawMode.Lines, BufferUsage.StaticDraw)) { buffer.Alloc(6); unsafe { var array = (uint *)buffer.Header.ToPointer(); array[0] = lastVertexId - 2; array[1] = lastVertexId - 0; array[2] = lastVertexId - 4; array[3] = lastVertexId - 2; array[4] = lastVertexId - 0; array[5] = lastVertexId - 4; } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); indexBufferPtr.Dispose(); if (id + 4 == lastVertexId) { return(new uint[] { id + 4, id, }); } else { return(new uint[] { id - 2, id, }); } }
protected override void RecognizeUInt(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveInfo> primitiveInfoList) { int length = oneIndexBufferPtr.Length; unsafe { var array = (uint *)pointer.ToPointer(); for (uint i = 1; i < length; i++) { var value = array[i]; if (value == lastVertexId) { var item = new RecognizedPrimitiveInfo(i, array[i - 1], lastVertexId); primitiveInfoList.Add(item); } } if (array[0] == lastVertexId && length > 1) { var item = new RecognizedPrimitiveInfo(0, array[length - 1], lastVertexId); primitiveInfoList.Add(item); } } }
public PrimitiveRestartSwitch(OneIndexBufferPtr indexBufferPtr) : base(OpenGL.GL_PRIMITIVE_RESTART, true) { if (indexBufferPtr == null) { throw new ArgumentException(); } switch (indexBufferPtr.Type) { case IndexElementType.UnsignedByte: this.RestartIndex = byte.MaxValue; break; case IndexElementType.UnsignedShort: this.RestartIndex = ushort.MaxValue; break; case IndexElementType.UnsignedInt: this.RestartIndex = uint.MaxValue; break; default: break; } }
internal override uint[] Search(RenderEventArgs arg, int x, int y, RecognizedPrimitiveIndex lastIndexId, OneIndexRenderer modernRenderer) { List <uint> indexList = lastIndexId.IndexIdList; if (indexList.Count < 3) { throw new ArgumentException(); } OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer <uint>(DrawMode.LineLoop, BufferUsage.StaticDraw)) { buffer.Create(indexList.Count); unsafe { var array = (uint *)buffer.Header.ToPointer(); for (int i = 0; i < indexList.Count; i++) { array[i] = indexList[i]; } } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); indexBufferPtr.Dispose(); if (id == indexList[0]) { return(new uint[] { indexList[indexList.Count - 1], id, }); } else { uint[] result = null; for (int i = 1; i < indexList.Count; i++) { if (id == indexList[i]) { result = new uint[] { indexList[i - 1], indexList[i], }; break; } } if (result != null) { return(result); } else { throw new Exception("This should not happen!"); } } }
protected override void RecognizeUShort(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveIndex> lastIndexIdList) { int length = oneIndexBufferPtr.Length; unsafe { var array = (ushort *)pointer.ToPointer(); for (uint i = 1; i < length; i++) { var value = array[i]; if (value == lastVertexId) { var item = new RecognizedPrimitiveIndex(lastVertexId, i); item.IndexIdList.Add(array[i - 1]); item.IndexIdList.Add(value); lastIndexIdList.Add(item); } } if (array[0] == lastVertexId && length > 1) { var item = new RecognizedPrimitiveIndex(lastVertexId, 0); item.IndexIdList.Add(array[length - 1]); item.IndexIdList.Add(lastVertexId); lastIndexIdList.Add(item); } } }
/// <summary> /// 识别出以<paramref name="lastVertexId"/>结尾的图元。 /// <para>识别过程中要考虑排除PrimitiveRestartIndex</para> /// </summary> /// <param name="lastVertexId"></param> /// <param name="pointer"></param> /// <param name="oneIndexBufferPtr"></param> /// <param name="primitiveRestartIndex"></param> /// <returns></returns> public List <RecognizedPrimitiveIndex> Recognize( uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, uint primitiveRestartIndex) { var lastIndexIdList = new List <RecognizedPrimitiveIndex>(); if (lastVertexId != primitiveRestartIndex) { switch (oneIndexBufferPtr.Type) { case IndexElementType.UnsignedByte: RecognizeByte(lastVertexId, pointer, oneIndexBufferPtr, lastIndexIdList, primitiveRestartIndex); break; case IndexElementType.UnsighedShort: RecognizeUShort(lastVertexId, pointer, oneIndexBufferPtr, lastIndexIdList, primitiveRestartIndex); break; case IndexElementType.UnsignedInt: RecognizeUInt(lastVertexId, pointer, oneIndexBufferPtr, lastIndexIdList, primitiveRestartIndex); break; default: throw new NotImplementedException(); } } return(lastIndexIdList); }
internal override uint Search(RenderEventArgs arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.Points, BufferUsage.StaticDraw)) { buffer.Create(3); unsafe { var array = (uint *)buffer.Header.ToPointer(); array[0] = 0; array[1] = lastVertexId - 1; array[2] = lastVertexId - 0; } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, arg.CanvasRect.Height - y - 1); indexBufferPtr.Dispose(); if (0 == id || lastVertexId - 1 == id || lastVertexId - 0 == id) { return(id); } else { throw new Exception("This should not happen!"); } }
internal override uint Search(RenderEventArgs arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer <uint>(DrawMode.Points, BufferUsage.StaticDraw)) { buffer.Alloc(4); unsafe { var array = (uint *)buffer.Header.ToPointer(); array[0] = lastVertexId - 0; array[1] = lastVertexId - 1; array[2] = lastVertexId - 2; array[3] = lastVertexId - 3; } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); indexBufferPtr.Dispose(); if (lastVertexId - 3 <= id && id <= lastVertexId - 0) { return(id); } else { throw new Exception("This should not happen!"); } }
private uint Pick(RenderEventArgs arg, OneIndexBufferPtr twoPrimitivesIndexBufferPtr, int x, int y) { Render4InnerPicking(arg, twoPrimitivesIndexBufferPtr); uint pickedIndex = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); return(pickedIndex); }
internal override uint[] Search(RenderEventArgs arg, int x, int y, RecognizedPrimitiveIndex lastIndexId, OneIndexRenderer modernRenderer) { List <uint> indexList = lastIndexId.IndexIdList; if (indexList.Count != 4) { throw new ArgumentException(); } OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer <uint>(DrawMode.Lines, BufferUsage.StaticDraw)) { buffer.Create(8); unsafe { var array = (uint *)buffer.Header.ToPointer(); array[0] = indexList[0]; array[1] = indexList[1]; array[2] = indexList[1]; array[3] = indexList[2]; array[4] = indexList[2]; array[5] = indexList[3]; array[6] = indexList[3]; array[7] = indexList[0]; } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); indexBufferPtr.Dispose(); if (id == indexList[1]) { return(new uint[] { indexList[0], indexList[1], }); } else if (id == indexList[2]) { return(new uint[] { indexList[1], indexList[2], }); } else if (id == indexList[3]) { return(new uint[] { indexList[2], indexList[3], }); } else if (id == indexList[0]) { return(new uint[] { indexList[2], indexList[0], }); } else { throw new Exception("This should not happen!"); } }
internal override uint[] Search(RenderEventArgs arg, int x, int y, RecognizedPrimitiveInfo primitiveInfo, OneIndexRenderer modernRenderer) { uint[] indexList = primitiveInfo.VertexIds; if (indexList.Length != 3) { throw new ArgumentException(); } //if (indexList[0] == indexList[1]) { return new uint[] { indexList[0], indexList[2], }; } //else if (indexList[0] == indexList[2]) { return new uint[] { indexList[0], indexList[1], }; } //else if (indexList[1] == indexList[2]) { return new uint[] { indexList[1], indexList[0], }; } OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.Lines, BufferUsage.StaticDraw)) { buffer.Create(6); unsafe { var array = (uint *)buffer.Header.ToPointer(); array[0] = indexList[0]; array[1] = indexList[1]; array[2] = indexList[1]; array[3] = indexList[2]; array[4] = indexList[2]; array[5] = indexList[0]; } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, arg.CanvasRect.Height - y - 1); indexBufferPtr.Dispose(); if (id == indexList[1]) { return(new uint[] { indexList[0], indexList[1], }); } else if (id == indexList[2]) { return(new uint[] { indexList[1], indexList[2], }); } else if (id == indexList[0]) { return(new uint[] { indexList[2], indexList[0], }); } else { throw new Exception("This should not happen!"); } }
//protected override UnmanagedArrayBase CreateElements(int elementCount) //{ // UnmanagedArrayBase result = null; // switch (this.Type) // { // case IndexElementType.UnsignedByte: // result = new UnmanagedArray<byte>(elementCount); // break; // case IndexElementType.UnsignedShort: // result = new UnmanagedArray<ushort>(elementCount); // break; // case IndexElementType.UnsignedInt: // result = new UnmanagedArray<uint>(elementCount); // break; // default: // throw new NotImplementedException(); // } // return result; //} protected override VertexBufferPtr Upload2GPU() { uint[] buffers = new uint[1]; GL.GetDelegateFor <GL.glGenBuffers>()(1, buffers); GL.GetDelegateFor <GL.glBindBuffer>()(GL.GL_ELEMENT_ARRAY_BUFFER, buffers[0]); GL.GetDelegateFor <GL.glBufferData>()(GL.GL_ELEMENT_ARRAY_BUFFER, this.ByteLength, this.Header, (uint)this.Usage); OneIndexBufferPtr bufferPtr = new OneIndexBufferPtr( buffers[0], this.Mode, this.ElementCount, this.Type, this.Length, this.ByteLength); return(bufferPtr); }
//protected override UnmanagedArrayBase CreateElements(int elementCount) //{ // UnmanagedArrayBase result = null; // switch (this.Type) // { // case IndexElementType.UnsignedByte: // result = new UnmanagedArray<byte>(elementCount); // break; // case IndexElementType.UnsignedShort: // result = new UnmanagedArray<ushort>(elementCount); // break; // case IndexElementType.UnsignedInt: // result = new UnmanagedArray<uint>(elementCount); // break; // default: // throw new NotImplementedException(); // } // return result; //} protected override BufferPtr Upload2GPU() { uint[] buffers = new uint[1]; glGenBuffers(1, buffers); glBindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, buffers[0]); glBufferData(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.ByteLength, this.Header, (uint)this.Usage); glBindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, 0); OneIndexBufferPtr bufferPtr = new OneIndexBufferPtr( buffers[0], this.Mode, 0, this.ElementCount, this.Type, this.Length, this.ByteLength); return(bufferPtr); }
protected override void RecognizeByte(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveIndex> lastIndexIdList, uint primitiveRestartIndex) { int length = oneIndexBufferPtr.Length; unsafe { var array = (byte *)pointer.ToPointer(); long nearestRestartIndex = -1; uint i = 0; while (i < length && array[i] == primitiveRestartIndex) { nearestRestartIndex = i; i++; } for (i = i + 1; i < length; i++) { var value = array[i]; if (value == primitiveRestartIndex) { // try the loop back line. if (array[nearestRestartIndex + 1] == lastVertexId && array[i - 1] != primitiveRestartIndex && nearestRestartIndex + 1 < i - 1) { var item = new RecognizedPrimitiveIndex(lastVertexId, (uint)(nearestRestartIndex + 1)); item.IndexIdList.Add(value); item.IndexIdList.Add(lastVertexId); lastIndexIdList.Add(item); } nearestRestartIndex = i; } else if (value == lastVertexId && array[i - 1] != primitiveRestartIndex) { var item = new RecognizedPrimitiveIndex(lastVertexId, i); item.IndexIdList.Add(array[i - 1]); item.IndexIdList.Add(value); lastIndexIdList.Add(item); } } if (array[nearestRestartIndex + 1] == lastVertexId && array[length - 1] != primitiveRestartIndex && nearestRestartIndex + 1 < length - 1) { var item = new RecognizedPrimitiveIndex(lastVertexId, (uint)(nearestRestartIndex + 1)); item.IndexIdList.Add(array[length - 1]); item.IndexIdList.Add(lastVertexId); lastIndexIdList.Add(item); } } }
/// <summary> /// /// </summary> protected override IndexBufferPtr Upload2GPU() { uint[] buffers = new uint[1]; glGenBuffers(1, buffers); const uint target = OpenGL.GL_ELEMENT_ARRAY_BUFFER; glBindBuffer(target, buffers[0]); glBufferData(target, this.ByteLength, this.Header, (uint)this.Usage); glBindBuffer(target, 0); var bufferPtr = new OneIndexBufferPtr( buffers[0], this.Mode, this.Type, this.Length, this.ByteLength); return(bufferPtr); }
internal override uint[] Search(RenderEventArgs arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer <uint>(DrawMode.Lines, BufferUsage.StaticDraw)) { buffer.Create(8); unsafe { var array = (uint *)buffer.Header.ToPointer(); array[0] = lastVertexId - 0; array[1] = lastVertexId - 2; array[2] = lastVertexId - 2; array[3] = lastVertexId - 3; array[4] = lastVertexId - 3; array[5] = lastVertexId - 1; array[6] = lastVertexId - 1; array[7] = lastVertexId - 0; } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); indexBufferPtr.Dispose(); if (id + 2 == lastVertexId) { return(new uint[] { lastVertexId - 0, lastVertexId - 2, }); } else if (id + 3 == lastVertexId) { return(new uint[] { lastVertexId - 2, lastVertexId - 3 }); } else if (id + 1 == lastVertexId) { return(new uint[] { lastVertexId - 3, lastVertexId - 1, }); } else if (id + 0 == lastVertexId) { return(new uint[] { lastVertexId - 1, lastVertexId - 0, }); } else { throw new Exception("This should not happen!"); } }
protected override void RecognizeUShort(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex) { int length = oneIndexBufferPtr.Length; unsafe { var array = (ushort *)pointer.ToPointer(); for (uint i = 0; i < length; i++) { var value = array[i]; if (value == lastVertexId) { var item = new RecognizedPrimitiveInfo(i, value); primitiveInfoList.Add(item); } } } }
internal override uint Search(RenderEventArgs arg, int x, int y, RecognizedPrimitiveIndex lastIndexId, OneIndexRenderer modernRenderer) { List <uint> indexList = lastIndexId.IndexIdList; if (indexList.Count < 3) { throw new ArgumentException(); } OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer <uint>(DrawMode.Points, BufferUsage.StaticDraw)) { buffer.Alloc(indexList.Count); unsafe { var array = (uint *)buffer.Header.ToPointer(); for (int i = 0; i < indexList.Count; i++) { array[i] = indexList[i]; } } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); indexBufferPtr.Dispose(); if (id != uint.MaxValue) { return(id); } else { throw new Exception("This should not happen!"); } }
protected override void RecognizeByte(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveIndex> lastIndexIdList) { int length = oneIndexBufferPtr.Length; unsafe { var array = (byte *)pointer.ToPointer(); for (uint i = 0; i < length; i++) { var value = array[i]; if (value == lastVertexId) { var item = new RecognizedPrimitiveIndex(lastVertexId, i); item.IndexIdList.Add(value); lastIndexIdList.Add(item); } } } }
protected override void RecognizeByte(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveInfo> primitiveInfoList) { int length = oneIndexBufferPtr.Length; unsafe { var array = (byte *)pointer.ToPointer(); uint i = 0; for (i = i + 2; i < length; i++) { var value = array[i]; if (value == lastVertexId) { var item = new RecognizedPrimitiveInfo(i, array[i - 2], array[i - 1], lastVertexId); primitiveInfoList.Add(item); } } } }
internal override uint Search(RenderEventArgs arg, int x, int y, RecognizedPrimitiveInfo primitiveInfo, OneIndexRenderer modernRenderer) { uint[] indexList = primitiveInfo.VertexIds; if (indexList.Length < 3) { throw new ArgumentException(); } OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.Points, BufferUsage.StaticDraw)) { buffer.Create(indexList.Length); unsafe { var array = (uint *)buffer.Header.ToPointer(); for (int i = 0; i < indexList.Length; i++) { array[i] = indexList[i]; } } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, arg.CanvasRect.Height - y - 1); indexBufferPtr.Dispose(); if (id != uint.MaxValue) { return(id); } else { throw new Exception("This should not happen!"); } }
protected override void RecognizeUInt(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveInfo> primitiveInfoList) { int length = oneIndexBufferPtr.Length; 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); } } } }
/// <summary> /// 在三角形图元中拾取指定位置的Line /// </summary> /// <param name="arg">渲染参数</param> /// <param name="x">指定位置</param> /// <param name="y">指定位置</param> /// <param name="lastVertexId">三角形图元的最后一个顶点</param> /// <param name="modernRenderer">目标Renderer</param> /// <returns></returns> internal override uint[] Search(RenderEventArgs arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { // 创建临时索引 OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer <uint>(DrawMode.Lines, BufferUsage.StaticDraw)) { buffer.Create(6); unsafe { var array = (uint *)buffer.Header.ToPointer(); array[0] = lastVertexId - 1; array[1] = lastVertexId - 0; array[2] = lastVertexId - 2; array[3] = lastVertexId - 1; array[4] = lastVertexId - 0; array[5] = lastVertexId - 2; } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } // 用临时索引渲染此三角形图元(仅渲染此三角形图元) modernRenderer.Render4InnerPicking(arg, indexBufferPtr); // id是拾取到的Line的Last Vertex Id uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); indexBufferPtr.Dispose(); // 对比临时索引,找到那个Line if (id + 2 == lastVertexId) { return(new uint[] { id + 2, id, }); } else { return(new uint[] { id - 1, id, }); } }
/// <summary> /// 在三角形图元中拾取指定位置的Point /// </summary> /// <param name="arg">渲染参数</param> /// <param name="x">指定位置</param> /// <param name="y">指定位置</param> /// <param name="lastVertexId">三角形图元的最后一个顶点</param> /// <param name="modernRenderer">目标Renderer</param> /// <returns></returns> internal override uint Search(RenderEventArgs arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { // 创建临时索引 OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer <uint>(DrawMode.Points, BufferUsage.StaticDraw)) { buffer.Create(3); unsafe { var array = (uint *)buffer.Header.ToPointer(); array[0] = lastVertexId - 0; array[1] = lastVertexId - 1; array[2] = lastVertexId - 2; } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } // 用临时索引渲染此三角形图元(仅渲染此三角形图元) modernRenderer.Render4InnerPicking(arg, indexBufferPtr); // id是拾取到的Line的Last Vertex Id uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); indexBufferPtr.Dispose(); // 对比临时索引,找到那个Line if (lastVertexId - 2 <= id && id <= lastVertexId - 0) { return(id); } else { throw new Exception("This should not happen!"); } }
/// <summary> /// 将共享点前移,然后重新渲染、拾取 /// </summary> /// <param name="recognizedPrimitiveIndex0"></param> /// <param name="recognizedPrimitiveIndex1"></param> /// <param name="drawMode"></param> /// <param name="oneIndexBufferPtr"></param> /// <param name="lastIndex0"></param> /// <param name="lastIndex1"></param> private void AssembleIndexBuffer( RecognizedPrimitiveIndex recognizedPrimitiveIndex0, RecognizedPrimitiveIndex recognizedPrimitiveIndex1, DrawMode drawMode, out OneIndexBufferPtr oneIndexBufferPtr, out uint lastIndex0, out uint lastIndex1) { List <uint> indexArray = ArrangeIndexes( recognizedPrimitiveIndex0, recognizedPrimitiveIndex1, drawMode, out lastIndex0, out lastIndex1); if (indexArray.Count != recognizedPrimitiveIndex0.IndexIdList.Count + 1 + recognizedPrimitiveIndex1.IndexIdList.Count) { throw new Exception(); } using (var indexBuffer = new OneIndexBuffer <uint>(drawMode, BufferUsage.StaticDraw)) { indexBuffer.Create( recognizedPrimitiveIndex0.IndexIdList.Count + 1 + recognizedPrimitiveIndex1.IndexIdList.Count); unsafe { var array = (uint *)indexBuffer.Header.ToPointer(); for (int i = 0; i < indexArray.Count; i++) { array[i] = indexArray[i]; } } oneIndexBufferPtr = indexBuffer.GetBufferPtr() as OneIndexBufferPtr; } }
protected abstract void RecognizeByte(uint lastVertexId, IntPtr pointer, OneIndexBufferPtr oneIndexBufferPtr, List <RecognizedPrimitiveIndex> lastIndexIdList, uint primitiveRestartIndex);