00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <windows.h>
00012 #include <gl/gl.h>
00013 #include <gl/glu.h>
00014
00015 #include "arb_multisample.h"
00016
00017
00018 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
00019 #define WGL_SAMPLES_ARB 0x2042
00020
00021 bool arbMultisampleSupported = false;
00022 int arbMultisampleFormat = 0;
00023
00024
00025 bool WGLisExtensionSupported(const char *extension)
00026 {
00027 const size_t extlen = strlen(extension);
00028 const char *supported = NULL;
00029
00030
00031 PROC wglGetExtString = wglGetProcAddress("wglGetExtensionsStringARB");
00032
00033 if (wglGetExtString)
00034 supported = ((char*(__stdcall*)(HDC))wglGetExtString)(wglGetCurrentDC());
00035
00036
00037 if (supported == NULL)
00038 supported = (char*)glGetString(GL_EXTENSIONS);
00039
00040
00041 if (supported == NULL)
00042 return false;
00043
00044
00045 for (const char* p = supported; ; p++)
00046 {
00047
00048 p = strstr(p, extension);
00049
00050 if (p == NULL)
00051 return false;
00052
00053
00054
00055
00056
00057
00058
00059 if ((p==supported || p[-1]==' ') && (p[extlen]=='\0' || p[extlen]==' '))
00060 return true;
00061 }
00062 }
00063
00064
00065 bool InitMultisample(HINSTANCE hInstance,HWND hWnd,PIXELFORMATDESCRIPTOR pfd)
00066 {
00067
00068 if (!WGLisExtensionSupported("WGL_ARB_multisample"))
00069 {
00070 arbMultisampleSupported=false;
00071 return false;
00072 }
00073
00074
00075 PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
00076 if (!wglChoosePixelFormatARB)
00077 {
00078 arbMultisampleSupported=false;
00079 return false;
00080 }
00081
00082
00083 HDC hDC = GetDC(hWnd);
00084
00085 int pixelFormat;
00086 int valid;
00087 UINT numFormats;
00088 float fAttributes[] = {0,0};
00089
00090
00091
00092
00093
00094
00095 int iAttributes[] =
00096 {
00097 WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
00098 WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
00099 WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
00100 WGL_COLOR_BITS_ARB,24,
00101 WGL_ALPHA_BITS_ARB,8,
00102 WGL_DEPTH_BITS_ARB,16,
00103 WGL_STENCIL_BITS_ARB,0,
00104 WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
00105 WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
00106 WGL_SAMPLES_ARB,4,
00107 0,0
00108 };
00109
00110
00111 valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
00112
00113
00114 if (valid && numFormats >= 1)
00115 {
00116 arbMultisampleSupported = true;
00117 arbMultisampleFormat = pixelFormat;
00118 return arbMultisampleSupported;
00119 }
00120
00121
00122 iAttributes[19] = 2;
00123 valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
00124 if (valid && numFormats >= 1)
00125 {
00126 arbMultisampleSupported = true;
00127 arbMultisampleFormat = pixelFormat;
00128 return arbMultisampleSupported;
00129 }
00130
00131
00132 return arbMultisampleSupported;
00133 }