private PrimitiveRestartState GetPrimitiveRestartState(OneIndexBuffer indexBuffer) { PrimitiveRestartState result = null; switch (indexBuffer.ElementType) { case IndexBufferElementType.UByte: if (this.ubyteRestartIndexState == null) { this.ubyteRestartIndexState = new PrimitiveRestartState(indexBuffer.ElementType); } result = this.ubyteRestartIndexState; break; case IndexBufferElementType.UShort: if (this.ushortRestartIndexState == null) { this.ushortRestartIndexState = new PrimitiveRestartState(indexBuffer.ElementType); } result = this.ushortRestartIndexState; break; case IndexBufferElementType.UInt: if (this.uintRestartIndexState == null) { this.uintRestartIndexState = new PrimitiveRestartState(indexBuffer.ElementType); } result = this.uintRestartIndexState; break; default: throw new NotImplementedException(); } return result; }
protected override void RecognizeByte(uint lastVertexId, IntPtr pointer, OneIndexBuffer oneIndexBuffer, List<RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex) { int length = oneIndexBuffer.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 + 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[nearestRestartIndex + 1] != primitiveRestartIndex && nearestRestartIndex + 2 < i) { var item = new RecognizedPrimitiveInfo(i, array[nearestRestartIndex + 1], array[i - 1], lastVertexId); primitiveInfoList.Add(item); } } } }
public unsafe IndexBuffer GetIndexBuffer() { if (this.indexBuffer != null) { return(this.indexBuffer); } int vertexCount = (faceCount * 2 + 2) * (this.pipeline.Count - 1); int length = vertexCount + (this.pipeline.Count - 1); OneIndexBuffer buffer = CSharpGL.Buffer.Create(IndexBufferElementType.UInt, length, DrawMode.QuadStrip, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (uint *)pointer.ToPointer(); uint positionIndex = 0; for (int i = 0; i < buffer.Length; i++) { if (i % (faceCount * 2 + 2 + 1) == (faceCount * 2 + 2)) { array[i] = uint.MaxValue;//分割各个圆柱体 } else { array[i] = positionIndex++; } } this.indexBuffer = buffer; } return(this.indexBuffer); }
protected override void RecognizeUInt(uint lastVertexId, IntPtr pointer, OneIndexBuffer oneIndexBuffer, List<RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex) { int length = oneIndexBuffer.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 RecognizedPrimitiveInfo(i, array[i - 1], lastVertexId); primitiveInfoList.Add(item); } } } }
/// <summary> /// 识别出以<paramref name="lastVertexId"/>结尾的图元。 /// <para>识别过程中要考虑排除PrimitiveRestartIndex</para> /// </summary> /// <param name="lastVertexId"></param> /// <param name="pointer"></param> /// <param name="oneIndexBuffer"></param> /// <param name="primitiveRestartIndex"></param> /// <returns></returns> public List<RecognizedPrimitiveInfo> Recognize( uint lastVertexId, IntPtr pointer, OneIndexBuffer oneIndexBuffer, uint primitiveRestartIndex) { var lastIndexIdList = new List<RecognizedPrimitiveInfo>(); if (lastVertexId != primitiveRestartIndex) { switch (oneIndexBuffer.ElementType) { case IndexBufferElementType.UByte: RecognizeByte(lastVertexId, pointer, oneIndexBuffer, lastIndexIdList, primitiveRestartIndex); break; case IndexBufferElementType.UShort: RecognizeUShort(lastVertexId, pointer, oneIndexBuffer, lastIndexIdList, primitiveRestartIndex); break; case IndexBufferElementType.UInt: RecognizeUInt(lastVertexId, pointer, oneIndexBuffer, lastIndexIdList, primitiveRestartIndex); break; default: throw new NotImplementedException(); } } return lastIndexIdList; }
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!"); } }
public IndexBufferPtr GetIndexBufferPtr() { if (indexBufferPtr == null) { using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.TriangleStrip, BufferUsage.StaticDraw)) { buffer.Create(this.SideLength * (this.SideLength - 1) * 2); unsafe { var pointer = (uint *)buffer.Header.ToPointer(); for (int k = 0; k < this.SideLength - 1; k++) { for (int i = 0; i < this.SideLength; i++) { if (k % 2 == 0) { pointer[(i + k * this.SideLength) * 2 + 0] = (uint)(i + (k + 1) * this.SideLength); pointer[(i + k * this.SideLength) * 2 + 1] = (uint)(i + (k + 0) * this.SideLength); } else { pointer[(i + k * this.SideLength) * 2 + 0] = (uint)(this.SideLength - 1 - i + (k + 0) * this.SideLength); pointer[(i + k * this.SideLength) * 2 + 1] = (uint)(this.SideLength - 1 - i + (k + 1) * this.SideLength); } } } } indexBufferPtr = buffer.GetBufferPtr(); } } return(indexBufferPtr); }
public IndexBuffer GetIndexBuffer() { if (this.indexBuffer == null) { int length = this.SideLength * (this.SideLength - 1) * 2; OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, length, DrawMode.TriangleStrip, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (uint *)pointer; for (int k = 0; k < this.SideLength - 1; k++) { for (int i = 0; i < this.SideLength; i++) { if (k % 2 == 0) { array[(i + k * this.SideLength) * 2 + 0] = (uint)(i + (k + 1) * this.SideLength); array[(i + k * this.SideLength) * 2 + 1] = (uint)(i + (k + 0) * this.SideLength); } else { array[(i + k * this.SideLength) * 2 + 0] = (uint)(this.SideLength - 1 - i + (k + 0) * this.SideLength); array[(i + k * this.SideLength) * 2 + 1] = (uint)(this.SideLength - 1 - i + (k + 1) * this.SideLength); } } } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } return(this.indexBuffer); }
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!"); } }
internal override uint[] Search(RenderEventArg arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { OneIndexBufferPtr indexBufferPtr = null; using (var buffer = new OneIndexBuffer<uint>(DrawMode.Lines, BufferUsage.StaticDraw)) { buffer.Alloc(8); 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 - 3; array[5] = lastVertexId - 2; array[6] = lastVertexId - 0; array[7] = lastVertexId - 3; } indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr; } modernRenderer.Render4InnerPicking(arg, indexBufferPtr); uint id = ColorCodedPicking.ReadPixel(x, y, arg.CanvasRect.Height); indexBufferPtr.Dispose(); if (id + 3 == lastVertexId) { return new uint[] { id + 3, id, }; } else { return new uint[] { id - 1, id, }; } }
internal override uint[] Search(RenderEventArg 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.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 == 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, OneIndexBuffer oneIndexBuffer, List<RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex) { int length = oneIndexBuffer.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); } } } }
public IndexBufferPtr GetIndex() { using (var indexBuffer = new OneIndexBuffer <uint>(DrawMode.TriangleStrip, BufferUsage.StaticDraw)) { indexBuffer.Alloc(indexes.Length); unsafe { uint *indexArray = (uint *)indexBuffer.FirstElement(); for (int i = 0; i < indexes.Length; i++) { indexArray[i] = indexes[i]; } } return(indexBuffer.GetBufferPtr() as IndexBufferPtr); } }
public IndexBufferPtr GetIndex() { using (var buffer = new OneIndexBuffer <uint>( DrawMode.LineStrip, BufferUsage.StaticDraw)) { buffer.Alloc(model.Indexes.Length); unsafe { var array = (uint *)buffer.FirstElement(); for (int i = 0; i < model.Indexes.Length; i++) { array[i] = model.Indexes[i]; } } return(buffer.GetBufferPtr() as IndexBufferPtr); } }
protected override void RecognizeByte(uint lastVertexId, IntPtr pointer, OneIndexBuffer oneIndexBuffer, List<RecognizedPrimitiveInfo> primitiveInfoList) { int length = oneIndexBuffer.Length; unsafe { var array = (byte*)pointer.ToPointer(); uint i = 0; for (i = i + 3; i < length; i++) { var value = array[i]; if (value == lastVertexId) { var item = new RecognizedPrimitiveInfo(i, array[i - 2], array[i - 3], array[i - 1], lastVertexId); primitiveInfoList.Add(item); } } } }
/// <summary> /// Creates a <see cref="OneIndexBuffer"/> object directly in server side(GPU) without initializing its value. /// </summary> /// <param name="type"></param> /// <param name="length">How many indexes are there?(How many uint/ushort/bytes?)</param> /// <param name="mode"></param> /// <param name="usage"></param> /// <returns></returns> public static OneIndexBuffer Create(IndexBufferElementType type, int length, DrawMode mode, BufferUsage usage) { if (glGenBuffers == null) { glGenBuffers = OpenGL.GetDelegateFor<OpenGL.glGenBuffers>(); } if (glBindBuffer == null) { glBindBuffer = OpenGL.GetDelegateFor<OpenGL.glBindBuffer>(); } if (glBufferData == null) { glBufferData = OpenGL.GetDelegateFor<OpenGL.glBufferData>(); } int byteLength = GetSize(type) * length; uint[] buffers = new uint[1]; glGenBuffers(1, buffers); const uint target = OpenGL.GL_ELEMENT_ARRAY_BUFFER; glBindBuffer(target, buffers[0]); glBufferData(target, byteLength, IntPtr.Zero, (uint)usage); glBindBuffer(target, 0); var buffer = new OneIndexBuffer( buffers[0], mode, type, length, byteLength); return buffer; }
protected override void RecognizeUInt(uint lastVertexId, IntPtr pointer, OneIndexBuffer oneIndexBuffer, List<RecognizedPrimitiveInfo> primitiveInfoList) { int length = oneIndexBuffer.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); } } } }
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(); } //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<uint>(DrawMode.Lines, BufferUsage.StaticDraw)) { buffer.Alloc(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, 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[0]) { return new uint[] { indexList[2], indexList[0], }; } else { throw new Exception("This should not happen!"); } }
public IndexBufferPtr GetIndexBufferPtr() { if (indexBufferPtr == null) { using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.Triangles, BufferUsage.StaticDraw)) { buffer.Create(xy_indices.Length); unsafe { var array = (uint *)buffer.Header.ToPointer(); for (int i = 0; i < xy_indices.Length; i++) { array[i] = xy_indices[i]; } } indexBufferPtr = buffer.GetBufferPtr(); } } return(indexBufferPtr); }
public IndexBufferPtr GetIndexBufferPtr() { if (indexBufferPtr == null) { using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.Triangles, BufferUsage.StaticDraw)) { buffer.Create(3 * 3); unsafe { var array = (uint *)buffer.Header.ToPointer(); array[0] = 0; array[1] = 1; array[2] = 3; array[3] = 0; array[4] = 3; array[5] = 2; array[6] = 1; array[7] = 3; array[8] = 2; } indexBufferPtr = buffer.GetBufferPtr(); } } return(indexBufferPtr); }
public override IndexBuffer GetIndexBuffer() { if (this.indexBuffer == null) { int dimSize = this.DataSource.DimenSize; int length = dimSize * 2 * (Marshal.SizeOf(typeof(HalfHexahedronIndex)) / sizeof(uint)); OneIndexBuffer buffer = CSharpGL.GLBuffer.Create(IndexBufferElementType.UInt, length, DrawMode.QuadStrip, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (HalfHexahedronIndex *)pointer; for (int gridIndex = 0; gridIndex < dimSize; gridIndex++) { array[gridIndex * 2].dot0 = (uint)(8 * gridIndex + 6); array[gridIndex * 2].dot1 = (uint)(8 * gridIndex + 2); array[gridIndex * 2].dot2 = (uint)(8 * gridIndex + 7); array[gridIndex * 2].dot3 = (uint)(8 * gridIndex + 3); array[gridIndex * 2].dot4 = (uint)(8 * gridIndex + 4); array[gridIndex * 2].dot5 = (uint)(8 * gridIndex + 0); array[gridIndex * 2].dot6 = (uint)(8 * gridIndex + 5); array[gridIndex * 2].dot7 = (uint)(8 * gridIndex + 1); array[gridIndex * 2].restartIndex = uint.MaxValue; array[gridIndex * 2 + 1].dot0 = (uint)(8 * gridIndex + 3); array[gridIndex * 2 + 1].dot1 = (uint)(8 * gridIndex + 0); array[gridIndex * 2 + 1].dot2 = (uint)(8 * gridIndex + 2); array[gridIndex * 2 + 1].dot3 = (uint)(8 * gridIndex + 1); array[gridIndex * 2 + 1].dot4 = (uint)(8 * gridIndex + 6); array[gridIndex * 2 + 1].dot5 = (uint)(8 * gridIndex + 5); array[gridIndex * 2 + 1].dot6 = (uint)(8 * gridIndex + 7); array[gridIndex * 2 + 1].dot7 = (uint)(8 * gridIndex + 4); array[gridIndex * 2 + 1].restartIndex = uint.MaxValue; } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } return(this.indexBuffer); }
public IndexBuffer GetIndexBuffer() { if (this.indexBuffer == null) { int uCount = GetUCount(interval); int vCount = GetVCount(interval); int length = (uCount + 1) * vCount + (vCount + 1 + 1) * uCount; OneIndexBuffer buffer = CSharpGL.Buffer.Create(IndexBufferElementType.UInt, length, DrawMode.LineStrip, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (uint *)pointer; int index = 0; // vertical lines. for (int i = 0; i < vCount; i++) { for (int j = 0; j < uCount; j++) { array[index++] = (uint)(i + j * vCount); } array[index++] = uint.MaxValue;// primitive restart index. } // horizontal lines. for (int i = 0; i < uCount; i++) { for (int j = 0; j < vCount; j++) { array[index++] = (uint)(j + i * vCount); } array[index++] = (uint)(0 + i * vCount); array[index++] = uint.MaxValue;// primitive restart index. } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } return(this.indexBuffer); }
public IndexBufferPtr GetIndex() { if (indexBufferPtr == null) { using (var buffer = new OneIndexBuffer <uint>(DrawMode.Triangles, BufferUsage.StaticDraw)) { buffer.Alloc(indices.Length); unsafe { var array = (uint *)buffer.Header.ToPointer(); for (int i = 0; i < indices.Length; i++) { array[i] = indices[i]; } } indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr; } } return(indexBufferPtr); }
/// <summary> /// /// </summary> /// <returns></returns> public IndexBufferPtr GetIndexBufferPtr() { if (indexBufferPtr == null) { using (var buffer = new OneIndexBuffer(IndexElementType.UByte, DrawMode.Triangles, BufferUsage.StaticDraw)) { buffer.Create(TetrahedronModel.index.Length); unsafe { var array = (byte *)buffer.Header.ToPointer(); for (int i = 0; i < TetrahedronModel.index.Length; i++) { array[i] = TetrahedronModel.index[i]; } } indexBufferPtr = buffer.GetBufferPtr(); } } return(indexBufferPtr); }
/// <summary> /// /// </summary> /// <returns></returns> public IndexBufferPtr GetIndexBufferPtr() { if (indexBufferPtr == null) { using (var buffer = new OneIndexBuffer(IndexElementType.UShort, DrawMode.Triangles, BufferUsage.StaticDraw)) { ushort[] faces = model.GetFaces(); buffer.Create(faces.Length); unsafe { var array = (ushort *)buffer.Header.ToPointer(); for (int i = 0; i < faces.Length; i++) { array[i] = (ushort)(faces[i] - 1); } } indexBufferPtr = buffer.GetBufferPtr(); } } return(indexBufferPtr); }
public IndexBufferPtr GetIndexBufferRenderer() { using (var buffer = new OneIndexBuffer <uint>(DrawMode.Triangles, BufferUsage.StaticDraw)) { buffer.Alloc(faces.Count * 3); unsafe { uint *array = (uint *)buffer.FirstElement(); for (int i = 0; i < faces.Count; i++) { //TODO: 用ushort类型的IndexBuffer就会引发系统错误,为什么? //array[i * 3 + 0] = (ushort)(faces[i].Item1 - 1); //array[i * 3 + 1] = (ushort)(faces[i].Item2 - 1); //array[i * 3 + 2] = (ushort)(faces[i].Item3 - 1); array[i * 3 + 0] = (uint)(faces[i].Item1 - 1); array[i * 3 + 1] = (uint)(faces[i].Item2 - 1); array[i * 3 + 2] = (uint)(faces[i].Item3 - 1); } } return(buffer.GetBufferPtr() as IndexBufferPointerBase); } }
/// <summary> /// /// </summary> /// <param name="arg"></param> /// <param name="twoPrimitivesIndexBuffer"></param> /// <param name="x">mouse position(Left Down is (0, 0)).</param> /// <param name="y">mouse position(Left Down is (0, 0)).</param> /// <returns></returns> private uint Pick(RenderEventArgs arg, OneIndexBuffer twoPrimitivesIndexBuffer, int x, int y) { Render4InnerPicking(arg, twoPrimitivesIndexBuffer); uint pickedIndex = ColorCodedPicking.ReadStageVertexId(x, y); return pickedIndex; }
/// <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.Alloc( 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 RecognizeUInt(uint lastVertexId, IntPtr pointer, OneIndexBuffer oneIndexBuffer, List<RecognizedPrimitiveInfo> primitiveInfoList);
protected abstract void RecognizeUShort(uint lastVertexId, IntPtr pointer, OneIndexBuffer oneIndexBuffer, List<RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex);
public IndexBufferPtr GetIndex() { if (indexBufferPtr == null) { if (model.positions.Length < byte.MaxValue) { using (var buffer = new OneIndexBuffer <byte>(DrawMode.TriangleStrip, BufferUsage.StaticDraw)) { buffer.Alloc(model.indexes.Length); unsafe { var indexArray = (byte *)buffer.Header.ToPointer(); for (int i = 0; i < model.indexes.Length; i++) { if (model.indexes[i] == uint.MaxValue) { indexArray[i] = byte.MaxValue; } else { indexArray[i] = (byte)model.indexes[i]; } } } indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr; } } else if (model.positions.Length < ushort.MaxValue) { using (var buffer = new OneIndexBuffer <ushort>(DrawMode.TriangleStrip, BufferUsage.StaticDraw)) { buffer.Alloc(model.indexes.Length); unsafe { var indexArray = (ushort *)buffer.Header.ToPointer(); for (int i = 0; i < model.indexes.Length; i++) { if (model.indexes[i] == uint.MaxValue) { indexArray[i] = ushort.MaxValue; } else { indexArray[i] = (ushort)model.indexes[i]; } } } indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr; } } else { using (var buffer = new OneIndexBuffer <uint>(DrawMode.TriangleStrip, BufferUsage.StaticDraw)) { buffer.Alloc(model.indexes.Length); unsafe { var indexArray = (uint *)buffer.Header.ToPointer(); for (int i = 0; i < model.indexes.Length; i++) { indexArray[i] = model.indexes[i]; } } indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr; } } } return(indexBufferPtr); }
/// <summary> /// 将共享点前移,然后重新渲染、拾取 /// </summary> /// <param name="recognizedPrimitiveIndex0"></param> /// <param name="recognizedPrimitiveIndex1"></param> /// <param name="drawMode"></param> /// <param name="oneIndexBuffer"></param> /// <param name="lastIndex0"></param> /// <param name="lastIndex1"></param> private void AssembleIndexBuffer( RecognizedPrimitiveInfo recognizedPrimitiveIndex0, RecognizedPrimitiveInfo recognizedPrimitiveIndex1, DrawMode drawMode, out OneIndexBuffer oneIndexBuffer, out uint lastIndex0, out uint lastIndex1) { List<uint> indexArray = ArrangeIndexes( recognizedPrimitiveIndex0, recognizedPrimitiveIndex1, drawMode, out lastIndex0, out lastIndex1); if (indexArray.Count != recognizedPrimitiveIndex0.VertexIds.Length + 1 + recognizedPrimitiveIndex1.VertexIds.Length) { throw new Exception(string.Format("index array[{0}] not same length with [recognized primitive1 index length{1}] + [1] + recognized primitive2 index length[{2}]", recognizedPrimitiveIndex0.VertexIds.Length, recognizedPrimitiveIndex1.VertexIds.Length)); } oneIndexBuffer = indexArray.ToArray().GenIndexBuffer(drawMode, BufferUsage.StaticDraw); //oneIndexBuffer = Buffer.Create(IndexElementType.UInt, // recognizedPrimitiveIndex0.VertexIds.Length // + 1 // + recognizedPrimitiveIndex1.VertexIds.Length, // drawMode, BufferUsage.StaticDraw); //unsafe //{ // var array = (uint*)oneIndexBuffer.MapBuffer(MapBufferAccess.WriteOnly); // for (int i = 0; i < indexArray.Count; i++) // { // array[i] = indexArray[i]; // } // oneIndexBuffer.UnmapBuffer(); //} }
public IndexBufferPtr GetIndex() { if (indexBufferPtr == null) { if (model.positions.Length < byte.MaxValue) { using (var buffer = new OneIndexBuffer<byte>(DrawMode.TriangleStrip, BufferUsage.StaticDraw)) { buffer.Alloc(model.indexes.Length); unsafe { var indexArray = (byte*)buffer.Header.ToPointer(); for (int i = 0; i < model.indexes.Length; i++) { if (model.indexes[i] == uint.MaxValue) { indexArray[i] = byte.MaxValue; } else { indexArray[i] = (byte)model.indexes[i]; } } } indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr; } } else if (model.positions.Length < ushort.MaxValue) { using (var buffer = new OneIndexBuffer<ushort>(DrawMode.TriangleStrip, BufferUsage.StaticDraw)) { buffer.Alloc(model.indexes.Length); unsafe { var indexArray = (ushort*)buffer.Header.ToPointer(); for (int i = 0; i < model.indexes.Length; i++) { if (model.indexes[i] == uint.MaxValue) { indexArray[i] = ushort.MaxValue; } else { indexArray[i] = (ushort)model.indexes[i]; } } } indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr; } } else { using (var buffer = new OneIndexBuffer<uint>(DrawMode.TriangleStrip, BufferUsage.StaticDraw)) { buffer.Alloc(model.indexes.Length); unsafe { var indexArray = (uint*)buffer.Header.ToPointer(); for (int i = 0; i < model.indexes.Length; i++) { indexArray[i] = model.indexes[i]; } } indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr; } } } return indexBufferPtr; }