コード例 #1
0
        /// <summary>
        /// 在三角形图元中拾取指定位置的Point
        /// </summary>
        /// <param name="arg">渲染参数</param>
        /// <param name="lastVertexId">三角形图元的最后一个顶点</param>
        /// <param name="picker">目标Renderer</param>
        /// <returns></returns>
        internal override uint Search(PickingEventArgs arg, uint lastVertexId, DrawArraysPicker picker)
        {
            // 创建临时索引
            IndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 3, BufferUsage.StaticDraw);

            unsafe
            {
                var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = lastVertexId - 0;
                array[1] = lastVertexId - 1;
                array[2] = lastVertexId - 2;
                buffer.UnmapBuffer();
            }
            var cmd = new DrawElementsCmd(buffer, DrawMode.Points);

            // 用临时索引渲染此三角形图元(仅渲染此三角形图元)
            picker.Node.Render4InnerPicking(arg, IndexAccessMode.ByFrame, cmd);
            // id是拾取到的Line的Last Vertex Id
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            // 对比临时索引,找到那个Line
            if (lastVertexId - 2 <= id && id <= lastVertexId - 0)
            {
                return(id);
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
コード例 #2
0
        /// <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, 4, BufferUsage.StaticDraw);

            unsafe
            {
                var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = lastVertexId - 0;
                array[1] = lastVertexId - 1;
                array[2] = lastVertexId - 2;
                array[3] = lastVertexId - 3;
                buffer.UnmapBuffer();
            }
            var cmd = new DrawElementsCmd(buffer, DrawMode.Points);

            picker.Node.Render4InnerPicking(arg, ControlMode.ByFrame, cmd);
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            if (lastVertexId - 3 <= id && id <= lastVertexId - 0)
            {
                return(id);
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
コード例 #3
0
        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 + 1; 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)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 1], lastVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
コード例 #4
0
        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 + 1; i < length; i++)
                {
                    var value = array[i];
                    if (value == primitiveRestartIndex)
                    {
                        nearestRestartIndex = i;
                    }
                    else if (((i - 1 - nearestRestartIndex) % 2 == 0) &&
                             (value == flatColorVertexId) &&
                             (array[i - 1] != primitiveRestartIndex))
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 1], flatColorVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
コード例 #5
0
        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();
                for (uint i = 1; i < length; i++)
                {
                    var value = array[i];
                    if (value == flatColorVertexId)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 1], flatColorVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
                if (array[0] == flatColorVertexId &&
                    length > 1)
                {
                    var item = new RecognizedPrimitiveInfo(0, array[length - 1], flatColorVertexId);
                    primitiveInfoList.Add(item);
                }
            }
            indexBuffer.UnmapBuffer();
        }
コード例 #6
0
        private IndexBuffer GetBufferInUInt(int length)
        {
            IndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, length, BufferUsage.StaticDraw);

            unsafe {
                IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly);
                var    array   = (uint *)pointer;
                for (int i = 0; i < model.indexes.Length; i++)
                {
                    array[i] = model.indexes[i];
                }
                buffer.UnmapBuffer();
            }
            return(buffer);
        }
コード例 #7
0
        protected override void RecognizeUShort(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 = (ushort *)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] == flatColorVertexId &&
                            array[i - 1] != primitiveRestartIndex &&
                            nearestRestartIndex + 1 < i - 1)
                        {
                            var item = new RecognizedPrimitiveInfo((uint)(nearestRestartIndex + 1), value, flatColorVertexId);
                            primitiveInfoList.Add(item);
                        }
                        nearestRestartIndex = i;
                    }
                    else if (value == flatColorVertexId &&
                             array[i - 1] != primitiveRestartIndex)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 1], flatColorVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
                if (array[nearestRestartIndex + 1] == flatColorVertexId &&
                    array[length - 1] != primitiveRestartIndex &&
                    nearestRestartIndex + 1 < length - 1)
                {
                    var item = new RecognizedPrimitiveInfo((uint)(nearestRestartIndex + 1), array[length - 1], flatColorVertexId);
                    primitiveInfoList.Add(item);
                }
            }
            indexBuffer.UnmapBuffer();
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="flatColorVertexId"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint[] Search(PickingEventArgs arg,
                                        uint flatColorVertexId, DrawArraysPicker picker)
        {
            IndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 8, BufferUsage.StaticDraw);

            unsafe
            {
                var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = flatColorVertexId - 0; array[1] = flatColorVertexId - 2;
                array[2] = flatColorVertexId - 2; array[3] = flatColorVertexId - 3;
                array[4] = flatColorVertexId - 3; array[5] = flatColorVertexId - 1;
                array[6] = flatColorVertexId - 1; array[7] = flatColorVertexId - 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 + 2 == flatColorVertexId)
            {
                return(new uint[] { flatColorVertexId - 0, flatColorVertexId - 2, });
            }
            else if (id + 3 == flatColorVertexId)
            {
                return(new uint[] { flatColorVertexId - 2, flatColorVertexId - 3 });
            }
            else if (id + 1 == flatColorVertexId)
            {
                return(new uint[] { flatColorVertexId - 3, flatColorVertexId - 1, });
            }
            else if (id + 0 == flatColorVertexId)
            {
                return(new uint[] { flatColorVertexId - 1, flatColorVertexId - 0, });
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
コード例 #9
0
        protected override void RecognizeUShort(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 = (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);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
コード例 #10
0
        protected override void RecognizeByte(uint singleNodeVertexId, 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 + 4; i < length; i += 6)
                {
                    var value = array[i];
                    if (value == singleNodeVertexId)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 4], array[i - 2], singleNodeVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
コード例 #11
0
        protected override void RecognizeUShort(uint flatColorVertexId, 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 += 4)
                {
                    var value = array[i];
                    if (value == flatColorVertexId)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 1], flatColorVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
コード例 #12
0
        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);
        }
コード例 #13
0
ファイル: QuadsRecognizer.cs プロジェクト: jamescnxm/CSharpGL
        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();
                uint i     = 0;
                for (i = i + 3; i < length; i++)
                {
                    var value = array[i];
                    if (value == lastVertexId &&
                        (i - 3) % 4 == 0)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 3], array[i - 2], array[i - 1], lastVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
コード例 #14
0
        protected override void RecognizeByte(uint lastVertexId, 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();
                //long nearestRestartIndex = -1;
                uint i = 0;
                for (i = i + 2; i < length; i += 3)
                {
                    var value = array[i];
                    if (value == lastVertexId)
                    //&& (i - nearestRestartIndex) % 3 == 0)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 2], array[i - 1], lastVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }