static private int GetAAPixelFormat(ref int samples)
        {
            PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR();

            pfd.nSize      = (ushort)Marshal.SizeOf(typeof(PIXELFORMATDESCRIPTOR));
            pfd.nVersion   = 1;
            pfd.dwFlags    = PixelFlag.PFD_DRAW_TO_WINDOW | PixelFlag.PFD_SUPPORT_OPENGL | PixelFlag.PFD_DOUBLEBUFFER;
            pfd.iPixelType = PixelType.PFD_TYPE_RGBA;
            pfd.cColorBits = 32;

            IntPtr dummyHWnd = GDI.CreateWindowEx(0, s_dummyClass, "", GDI.WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
            IntPtr dummyHDc  = GDI.GetDC(dummyHWnd);

            int dummyPF = GDI.ChoosePixelFormat(dummyHDc, ref pfd);

            GDI.SetPixelFormat(dummyHDc, dummyPF, ref pfd);

            IntPtr dummyHRc = WGL.wglCreateContext(dummyHDc);

            WGL.wglMakeCurrent(dummyHDc, dummyHRc);

            int[] iattrs = new int[] {
                WGL.WGL_DRAW_TO_WINDOW_ARB, 1,
                WGL.WGL_ACCELERATION_ARB, WGL.WGL_FULL_ACCELERATION_ARB,
                WGL.WGL_COLOR_BITS_ARB, 24,
                WGL.WGL_ALPHA_BITS_ARB, 8,
                WGL.WGL_DEPTH_BITS_ARB, 24,
                WGL.WGL_STENCIL_BITS_ARB, 8,
                WGL.WGL_DOUBLE_BUFFER_ARB, 1,
                WGL.WGL_SAMPLE_BUFFERS_ARB, 1,
                WGL.WGL_SAMPLES_ARB, 0,
                0, 0
            };

            WGL.wglChoosePixelFormatARBHandler wglChoosePixelFormatARB = (WGL.wglChoosePixelFormatARBHandler)WGL.GetProc <WGL.wglChoosePixelFormatARBHandler>("wglChoosePixelFormatARB");

            int pixelFormat = 0;

            if (wglChoosePixelFormatARB != null)
            {
                int reqSamples;
                for (reqSamples = samples; reqSamples > 0; reqSamples /= 2)
                {
                    iattrs[17] = reqSamples;

                    int[] pixelFormats = new int[16];
                    int   numFormats;

                    unsafe
                    {
                        fixed(int *pPixelFormats = pixelFormats)
                        {
                            fixed(int *pIAttrs = iattrs)
                            {
                                int success = wglChoosePixelFormatARB(
                                    dummyHDc,
                                    pIAttrs, (float *)0, 16,
                                    pPixelFormats, &numFormats);

                                if (success != 0 && numFormats > 0)
                                {
                                    pixelFormat = pixelFormats[0];
                                    samples     = reqSamples;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                samples     = 1;
                pixelFormat = GDI.ChoosePixelFormat(dummyHDc, ref pfd);
            }

            WGL.wglMakeCurrent(dummyHDc, dummyHRc);
            WGL.wglDeleteContext(dummyHRc);
            GDI.ReleaseDC(dummyHWnd, dummyHDc);
            GDI.DestroyWindow(dummyHWnd);

            return(pixelFormat);
        }
示例#2
0
        protected void OnScroll(ScrollEventArgs se)
        {
            bool hasViewChanged = false;

            if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll)
            {
                GDI.SCROLLINFO si = new GDI.SCROLLINFO();
                si.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(GDI.SCROLLINFO));
                si.fMask  = (int)(GDI.ScrollInfoMask.SIF_TRACKPOS | GDI.ScrollInfoMask.SIF_PAGE | GDI.ScrollInfoMask.SIF_POS);
                GDI.GetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_HORZ, ref si);

                switch (se.Type)
                {
                case ScrollEventType.LargeDecrement:
                    m_view = new RectD(m_view.Left - m_view.Width, m_view.Top, m_view.Right - m_view.Width, m_view.Bottom);
                    break;

                case ScrollEventType.LargeIncrement:
                    m_view = new RectD(m_view.Left + m_view.Width, m_view.Top, m_view.Right + m_view.Width, m_view.Bottom);
                    break;

                case ScrollEventType.SmallDecrement:
                    m_view = new RectD(m_view.Left - m_view.Width * 0.1f, m_view.Top, m_view.Right - m_view.Width * 0.1f, m_view.Bottom);
                    break;

                case ScrollEventType.SmallIncrement:
                    m_view = new RectD(m_view.Left + m_view.Width * 0.1f, m_view.Top, m_view.Right + m_view.Width * 0.1f, m_view.Bottom);
                    break;

                case ScrollEventType.ThumbTrack:
                {
                    double tp = si.nTrackPos / ScrollScale * m_physExtents.Width + m_physExtents.Left;
                    m_view = new RectD(tp, m_view.Top, tp + m_view.Width, m_view.Bottom);
                }
                break;
                }

                ClampView();
                UpdateScroll();
                Invalidate();

                hasViewChanged = true;
            }
            else if (se.ScrollOrientation == ScrollOrientation.VerticalScroll)
            {
                GDI.SCROLLINFO si = new GDI.SCROLLINFO();
                si.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(GDI.SCROLLINFO));
                si.fMask  = (int)(GDI.ScrollInfoMask.SIF_TRACKPOS | GDI.ScrollInfoMask.SIF_PAGE | GDI.ScrollInfoMask.SIF_POS);
                GDI.GetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_VERT, ref si);

                switch (se.Type)
                {
                case ScrollEventType.LargeDecrement:
                    m_view = new RectD(m_view.Left, m_view.Top - m_view.Height, m_view.Right, m_view.Bottom - m_view.Height);
                    break;

                case ScrollEventType.LargeIncrement:
                    m_view = new RectD(m_view.Left, m_view.Top + m_view.Height, m_view.Right, m_view.Bottom + m_view.Height);
                    break;

                case ScrollEventType.SmallDecrement:
                    m_view = new RectD(m_view.Left, m_view.Top - m_view.Height * 0.1f, m_view.Right, m_view.Bottom - m_view.Height * 0.1f);
                    break;

                case ScrollEventType.SmallIncrement:
                    m_view = new RectD(m_view.Left, m_view.Top + m_view.Height * 0.1f, m_view.Right, m_view.Bottom + m_view.Height * 0.1f);
                    break;

                case ScrollEventType.ThumbTrack:
                {
                    double tp = si.nTrackPos / ScrollScale * m_physExtents.Height + m_physExtents.Top;
                    m_view = new RectD(m_view.Left, tp, m_view.Right, tp + m_view.Height);
                }
                break;
                }

                ClampView();
                UpdateScroll();
                Invalidate();

                hasViewChanged = true;
            }

            if (hasViewChanged)
            {
                OnViewChanged();
            }
        }