コード例 #1
0
        Drawing3d.PrimIdObj[,] ReadPickingBuffer(int x, int y, int w, int h)
        {
            uint[,] Pixels = new uint[w, h];
            Drawing3d.PrimIdObj[,] Result = new Drawing3d.PrimIdObj[w, h];
            ShaderKind Save = Device.ShaderKind;

            Device.ShaderKind = ShaderKind.SmallShader;
            SnapBuffer.ReadPixel(x, y, Pixels);

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    Result[i, j].Object = (short)(Pixels[i, j] & 0XFFFF);
                    if (Result[i, j].Object != 0)
                    {
                    }
                    Result[i, j].PrimId = (short)(Pixels[i, j] >> 16);
                    if (Result[i, j].PrimId != 0)
                    {
                    }
                }
            }
            Device.ShaderKind = Save;
            return(Result);
        }
コード例 #2
0
        //public void ReorgSnapBuffer()
        //{
        //    if (SnapMesh != null)
        //        for (int i = 0; i < SnapMesh.Progs.Count; i++)
        //        {
        //            Mesh M = SnapMesh.Progs[i] as Mesh;
        //            if (M != null)
        //            {
        //                SnapItem S = M.SnapItem;
        //                M.ObjectNumber = StoredSnapItems.IndexOf(S);
        //            }
        //            SnapBufferDirty = true;
        //        }
        //}
        public void RefreshSnapBuffer()
        {
            if (!Device.SnapEnable)
            {
                return;
            }
            //    if ((SnapKind == Snap.Static) && (SnapMesh == null))
            {
                SnapMesh = CompileSnapBuffer();
            }


            //GL.Disable(EnableCap.Blend);
            //if (PickingShader == null)
            //{
            //    PickingShader = new GLShader(PickingFragmentShader, PickingVertexShader);
            //    PickingShader.CompileAndLink();

            //    OpenGlDevice.CheckError();


            //}

            CurrentObjectIndex = PickingShader.GetVarHandle("TheObject");



            GLShader Save = Device.Shader;

            Device.Shader = PickingShader;
            RenderKind SaveRenderKind = Device.RenderKind;

            Device.RenderKind = RenderKind.SnapBuffer;
            if (!RegisterLocked)
            {
                StoredSnapItems.Clear();
                StoredSnapItems.Add(null);
            }


            SnapBuffer.Init((int)Device.ViewPort.Width, (int)Device.ViewPort.Height);

            SnapBuffer.EnableWriting();

            if (SnapMesh != null)
            {
                Device.Selector.FastRefresh = true;
                System.Diagnostics.Stopwatch SW = new System.Diagnostics.Stopwatch();
                SW.Start();
                SnapMesh.Paint(Device);
                SW.Stop();
                Device.Selector.FastRefresh = false;
            }
            else
            {
                Device.OnPaint();
            }
            SnapBuffer.DisableWriting();

            Device.RenderKind = SaveRenderKind;
            SnapBufferDirty   = false;
            ObjectBuffer      = ReadPickingBuffer(0, 0, (int)Device.ViewPort.Width, (int)Device.ViewPort.Height);
            // GL.Enable(EnableCap.Blend);
            Device.Shader = Save;
            CreateSnapList();
        }