private static void InitFunctions() { if (glGenBuffersARB == null) { glGenBuffersARB = (glGenBuffersARBHandler)WGL.GetProc <glGenBuffersARBHandler>("glGenBuffersARB"); } if (glBufferDataARB == null) { glBufferDataARB = (glBufferDataARBHandler)WGL.GetProc <glBufferDataARBHandler>("glBufferDataARB"); } if (glDeleteBuffersARB == null) { glDeleteBuffersARB = (glDeleteBuffersARBHandler)WGL.GetProc <glDeleteBuffersARBHandler>("glDeleteBuffersARB"); } if (glBindBufferARB == null) { glBindBufferARB = (glBindBufferARBHandler)WGL.GetProc <glBindBufferARBHandler>("glBindBufferARB"); } if (glMapBufferARB == null) { glMapBufferARB = (glMapBufferARBHandler)WGL.GetProc <glMapBufferARBHandler>("glMapBufferARB"); } if (glUnmapBufferARB == null) { glUnmapBufferARB = (glUnmapBufferARBHandler)WGL.GetProc <glUnmapBufferARBHandler>("glUnmapBufferARB"); } if (glBufferSubDataARB == null) { glBufferSubDataARB = (glBufferSubDataARBHandler)WGL.GetProc <glBufferSubDataARBHandler>("glBufferSubDataARB"); } }
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); }