48 #include <private/qgl_p.h> 60 const int *piAttributes,
63 const int *piAttribList,
64 const float *pfAttribFList,
68 #ifndef WGL_ARB_multisample 69 #define WGL_SAMPLE_BUFFERS_ARB 0x2041 70 #define WGL_SAMPLES_ARB 0x2042 73 #ifndef WGL_ARB_pixel_format 74 #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 75 #define WGL_DRAW_TO_WINDOW_ARB 0x2001 76 #define WGL_DRAW_TO_BITMAP_ARB 0x2002 77 #define WGL_ACCELERATION_ARB 0x2003 78 #define WGL_NEED_PALETTE_ARB 0x2004 79 #define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 80 #define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 81 #define WGL_SWAP_METHOD_ARB 0x2007 82 #define WGL_NUMBER_OVERLAYS_ARB 0x2008 83 #define WGL_NUMBER_UNDERLAYS_ARB 0x2009 84 #define WGL_TRANSPARENT_ARB 0x200A 85 #define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 86 #define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 87 #define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 88 #define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A 89 #define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B 90 #define WGL_SHARE_DEPTH_ARB 0x200C 91 #define WGL_SHARE_STENCIL_ARB 0x200D 92 #define WGL_SHARE_ACCUM_ARB 0x200E 93 #define WGL_SUPPORT_GDI_ARB 0x200F 94 #define WGL_SUPPORT_OPENGL_ARB 0x2010 95 #define WGL_DOUBLE_BUFFER_ARB 0x2011 96 #define WGL_STEREO_ARB 0x2012 97 #define WGL_PIXEL_TYPE_ARB 0x2013 98 #define WGL_COLOR_BITS_ARB 0x2014 99 #define WGL_RED_BITS_ARB 0x2015 100 #define WGL_RED_SHIFT_ARB 0x2016 101 #define WGL_GREEN_BITS_ARB 0x2017 102 #define WGL_GREEN_SHIFT_ARB 0x2018 103 #define WGL_BLUE_BITS_ARB 0x2019 104 #define WGL_BLUE_SHIFT_ARB 0x201A 105 #define WGL_ALPHA_BITS_ARB 0x201B 106 #define WGL_ALPHA_SHIFT_ARB 0x201C 107 #define WGL_ACCUM_BITS_ARB 0x201D 108 #define WGL_ACCUM_RED_BITS_ARB 0x201E 109 #define WGL_ACCUM_GREEN_BITS_ARB 0x201F 110 #define WGL_ACCUM_BLUE_BITS_ARB 0x2020 111 #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 112 #define WGL_DEPTH_BITS_ARB 0x2022 113 #define WGL_STENCIL_BITS_ARB 0x2023 114 #define WGL_AUX_BUFFERS_ARB 0x2024 115 #define WGL_NO_ACCELERATION_ARB 0x2025 116 #define WGL_GENERIC_ACCELERATION_ARB 0x2026 117 #define WGL_FULL_ACCELERATION_ARB 0x2027 118 #define WGL_SWAP_EXCHANGE_ARB 0x2028 119 #define WGL_SWAP_COPY_ARB 0x2029 120 #define WGL_SWAP_UNDEFINED_ARB 0x202A 121 #define WGL_TYPE_RGBA_ARB 0x202B 122 #define WGL_TYPE_COLORINDEX_ARB 0x202C 125 #ifndef WGL_ARB_create_context 126 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 127 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 128 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 129 #define WGL_CONTEXT_FLAGS_ARB 0x2094 130 #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 131 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 132 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002 133 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x0001 134 #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x0002 136 #define ERROR_INVALID_VERSION_ARB 0x2095 137 #define ERROR_INVALID_PROFILE_ARB 0x2096 140 #ifndef GL_VERSION_3_2 141 #define GL_CONTEXT_PROFILE_MASK 0x9126 142 #define GL_MAJOR_VERSION 0x821B 143 #define GL_MINOR_VERSION 0x821C 144 #define GL_NUM_EXTENSIONS 0x821D 145 #define GL_CONTEXT_FLAGS 0x821E 146 #define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001 195 void resize(
int newSize);
197 int find(
QRgb color)
const;
198 int findNearest(
QRgb color)
const;
201 void setEntry(
int idx,
QRgb color,
uint flags = 0,
quint8 context = 0);
203 const QRgb* colors()
const;
245 return d->colorArray.size();
275 if (newSize < 0 || newSize >
d->maxSize) {
276 qWarning(
"QGLCmap::resize(): size out of range");
279 int oldSize = size();
282 d->colorArray.resize(newSize);
283 d->allocArray.resize(newSize);
284 d->contextArray.resize(newSize);
285 if (newSize > oldSize) {
286 memset(
d->allocArray.data() + oldSize, 0, newSize - oldSize);
287 memset(
d->contextArray.data() + oldSize, 0, newSize - oldSize);
295 if (it !=
d->colorMap.end())
303 int idx = find(color);
306 int mapSize = size();
307 int mindist = 200000;
310 int b =
qBlue(color);
311 int rx, gx, bx, dist;
312 for (
int i=0; i < mapSize; i++) {
315 QRgb ci =
d->colorArray[i];
319 dist = rx*rx + gx*gx + bx*bx;
320 if (dist < mindist) {
335 int idx = find(color);
339 int mapSize =
d->colorArray.size();
355 d->colorArray[newIdx] = color;
361 d->colorMap.insert(color, newIdx);
363 d->contextArray[newIdx] = context;
370 if (idx < 0 || idx >=
d->maxSize) {
371 qWarning(
"QGLCmap::set(): Index out of range");
375 int mapSize = size();
376 if (idx >= mapSize) {
380 d->colorArray[idx] = color;
386 d->colorMap.insert(color, idx);
388 d->contextArray[idx] = context;
394 return d->colorArray.data();
409 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
411 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
412 (
char*) &lpMsgBuf, 0, 0);
413 qWarning(
"%s : %s failed: %s", method, func, lpMsgBuf);
440 static bool checkDone =
false;
441 static bool hasOl =
false;
445 HDC display_dc = GetDC(0);
446 int pfiMax = DescribePixelFormat(display_dc, 0, 0, NULL);
447 PIXELFORMATDESCRIPTOR pfd;
448 for (
int pfi = 1; pfi <= pfiMax; pfi++) {
449 DescribePixelFormat(display_dc, pfi,
sizeof(PIXELFORMATDESCRIPTOR), &pfd);
450 if ((pfd.bReserved & 0x0f) && (pfd.dwFlags & PFD_SUPPORT_OPENGL)) {
452 LAYERPLANEDESCRIPTOR lpd;
453 wglDescribeLayerPlane(display_dc, pfi, 1,
454 sizeof(LAYERPLANEDESCRIPTOR), &lpd);
455 if (lpd.dwFlags & LPD_SUPPORT_OPENGL) {
461 ReleaseDC(0, display_dc);
473 const uchar map_3_to_8[8] = {
474 0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
476 const uchar map_2_to_8[4] = {
479 const uchar map_1_to_8[2] = {
488 res = map_1_to_8[val];
492 res = map_2_to_8[val];
496 res = map_3_to_8[val];
507 if ((pfd->iPixelType != PFD_TYPE_RGBA) ||
508 !(pfd->dwFlags & PFD_NEED_PALETTE) ||
509 (pfd->cColorBits != 8))
511 int numEntries = 1 << pfd->cColorBits;
513 for (
int i = 0; i < numEntries; i++) {
517 pal[i] =
qRgb(r, g, b);
520 const int syscol_indices[12] = {
521 3, 24, 27, 64, 67, 88, 173, 181, 236, 247, 164, 91
524 const uint syscols[20] = {
525 0x000000, 0x800000, 0x008000, 0x808000, 0x000080, 0x800080,
526 0x008080, 0xc0c0c0, 0xc0dcc0, 0xa6caf0, 0xfffbf0, 0xa0a0a4,
527 0x808080, 0xff0000, 0x00ff00, 0xffff00, 0x0000ff, 0xff00ff,
531 if ((pfd->cColorBits == 8) &&
532 (pfd->cRedBits == 3) && (pfd->cRedShift == 0) &&
533 (pfd->cGreenBits == 3) && (pfd->cGreenShift == 3) &&
534 (pfd->cBlueBits == 2) && (pfd->cBlueShift == 6)) {
535 for (
int j = 0 ; j < 12 ; j++)
536 pal[syscol_indices[j]] =
QRgb(syscols[j+1]);
549 fmt.
setRgba(pfd->iPixelType == PFD_TYPE_RGBA);
562 fmt.
setStereo(pfd->dwFlags & PFD_STEREO);
564 !(pfd->dwFlags & PFD_GENERIC_FORMAT));
592 if (has_sample_buffers) {
599 if (wglGetPixelFormatAttribivARB
600 && wglGetPixelFormatAttribivARB(hdc, pfi, 0, i,
627 if (has_sample_buffers) {
634 qDebug() <<
"values for pfi:" << pfi;
677 d->dmy_id = CreateWindow((
const wchar_t *)windowClassName.
utf16(),
681 d->dmy_pdc = GetDC(
d->dmy_id);
682 PIXELFORMATDESCRIPTOR dmy_pfd;
683 memset(&dmy_pfd, 0,
sizeof(PIXELFORMATDESCRIPTOR));
684 dmy_pfd.nSize =
sizeof(PIXELFORMATDESCRIPTOR);
685 dmy_pfd.nVersion = 1;
686 dmy_pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
687 dmy_pfd.iPixelType = PFD_TYPE_RGBA;
688 if (!directRendering)
689 dmy_pfd.dwFlags |= PFD_GENERIC_FORMAT;
691 int dmy_pf = ChoosePixelFormat(
d->dmy_pdc, &dmy_pfd);
692 SetPixelFormat(
d->dmy_pdc, dmy_pf, &dmy_pfd);
693 d->dmy_rc = wglCreateContext(
d->dmy_pdc);
694 d->old_dc = wglGetCurrentDC();
695 d->old_context = wglGetCurrentContext();
696 wglMakeCurrent(
d->dmy_pdc,
d->dmy_rc);
701 wglMakeCurrent(
d->dmy_pdc, 0);
702 wglDeleteContext(
d->dmy_rc);
703 ReleaseDC(
d->dmy_id,
d->dmy_pdc);
704 DestroyWindow(
d->dmy_id);
705 if (
d->old_dc &&
d->old_context)
706 wglMakeCurrent(
d->old_dc,
d->old_context);
713 typedef HGLRC (
APIENTRYP PFNWGLCREATECONTEXTATTRIBSARB)(HDC, HGLRC,
const int *);
714 PFNWGLCREATECONTEXTATTRIBSARB wglCreateContextAttribsARB =
715 (PFNWGLCREATECONTEXTATTRIBSARB) wglGetProcAddress(
"wglCreateContextAttribsARB");
716 if (wglCreateContextAttribsARB) {
722 attributes[attribIndex++] = major;
724 attributes[attribIndex++] = minor;
731 if ((major == 3 && minor >= 2) || major > 3) {
744 qWarning(
"QGLContext::chooseContext(): Context profile not supported.");
754 attributes[attribIndex++] = 0;
755 d->
rc = wglCreateContextAttribsARB(hdc, shareContext && shareContext->
valid 756 ? shareContext->
rc : 0, attributes);
765 if (d->
rc && shareContext && shareContext->
valid)
774 if (!(s && s[0] >=
'0' && s[0] <=
'9' && s[1] ==
'.' && s[2] >=
'0' && s[2] <=
'9')) {
776 qWarning(
"QGLContext::chooseContext(): OpenGL version string is null.");
778 qWarning(
"QGLContext::chooseContext(): Unexpected OpenGL version string format.");
779 glFormat.setVersion(0, 0);
785 int major = s[0] -
'0';
786 int minor = s[2] -
'0';
787 glFormat.setVersion(major, minor);
794 if (major > 3 || minor >= 2)
834 if (deviceIsPixmap()) {
835 if (
d->glFormat.plane())
838 HDC display_dc = GetDC(0);
839 myDc =
d->hbitmap_hdc = CreateCompatibleDC(display_dc);
843 memset(&bmi, 0,
sizeof(bmi));
844 bmi.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
845 bmi.bmiHeader.biWidth = px->
width();
846 bmi.bmiHeader.biHeight = px->
height();
847 bmi.bmiHeader.biPlanes = 1;
848 bmi.bmiHeader.biBitCount = 32;
849 bmi.bmiHeader.biCompression = BI_RGB;
850 d->hbitmap = CreateDIBSection(display_dc, &bmi, DIB_RGB_COLORS, 0, 0, 0);
851 SelectObject(myDc,
d->hbitmap);
852 ReleaseDC(0, display_dc);
854 widget =
static_cast<QWidget *
>(
d->paintDevice);
856 myDc = GetDC(
d->win);
865 qWarning(
"QGLContext::chooseContext(): Paint device cannot be null");
870 if (
d->glFormat.plane()) {
871 d->pixelFormatId = ((
QGLWidget*)
d->paintDevice)->context()->d_func()->pixelFormatId;
872 if (!
d->pixelFormatId) {
873 qWarning(
"QGLContext::chooseContext(): Cannot create overlay context for invalid widget");
879 qwglError(
"QGLContext::chooseContext()",
"CreateLayerContext");
884 LAYERPLANEDESCRIPTOR lpfd;
885 wglDescribeLayerPlane(myDc,
d->pixelFormatId,
d->glFormat.plane(),
sizeof(LAYERPLANEDESCRIPTOR), &lpfd);
886 d->glFormat.setDoubleBuffer(lpfd.dwFlags & LPD_DOUBLEBUFFER);
887 d->glFormat.setDepth(lpfd.cDepthBits);
888 d->glFormat.setRgba(lpfd.iPixelType == PFD_TYPE_RGBA);
889 if (
d->glFormat.rgba()) {
890 if (
d->glFormat.redBufferSize() != -1)
891 d->glFormat.setRedBufferSize(lpfd.cRedBits);
892 if (
d->glFormat.greenBufferSize() != -1)
893 d->glFormat.setGreenBufferSize(lpfd.cGreenBits);
894 if (
d->glFormat.blueBufferSize() != -1)
895 d->glFormat.setBlueBufferSize(lpfd.cBlueBits);
897 d->glFormat.setAlpha(lpfd.cAlphaBits);
898 d->glFormat.setAccum(lpfd.cAccumBits);
899 d->glFormat.setStencil(lpfd.cStencilBits);
900 d->glFormat.setStereo(lpfd.dwFlags & LPD_STEREO);
901 d->glFormat.setDirectRendering(
false);
902 if (
d->glFormat.depth())
903 d->glFormat.setDepthBufferSize(lpfd.cDepthBits);
904 if (
d->glFormat.alpha())
905 d->glFormat.setAlphaBufferSize(lpfd.cAlphaBits);
906 if (
d->glFormat.accum())
907 d->glFormat.setAccumBufferSize(lpfd.cAccumRedBits);
908 if (
d->glFormat.stencil())
909 d->glFormat.setStencilBufferSize(lpfd.cStencilBits);
911 if (
d->glFormat.rgba()) {
912 if (lpfd.dwFlags & LPD_TRANSPARENT)
913 d->transpColor =
QColor(lpfd.crTransparent & 0xff,
914 (lpfd.crTransparent >> 8) & 0xff,
915 (lpfd.crTransparent >> 16) & 0xff);
917 d->transpColor =
QColor(0, 0, 0);
920 if (lpfd.dwFlags & LPD_TRANSPARENT)
925 d->cmap =
new QGLCmap(1 << lpfd.cColorBits);
926 d->cmap->setEntry(lpfd.crTransparent,
qRgb(1, 2, 3));
929 PIXELFORMATDESCRIPTOR pfd;
930 PIXELFORMATDESCRIPTOR realPfd;
931 d->pixelFormatId = choosePixelFormat(&pfd, myDc);
932 if (
d->pixelFormatId == 0) {
933 qwglError(
"QGLContext::chooseContext()",
"ChoosePixelFormat");
938 bool overlayRequested =
d->glFormat.hasOverlay();
939 DescribePixelFormat(myDc,
d->pixelFormatId,
sizeof(PIXELFORMATDESCRIPTOR), &realPfd);
941 if (!deviceIsPixmap() && wglGetProcAddress(
"wglGetPixelFormatAttribivARB"))
946 d->glFormat.setOverlay(
d->glFormat.hasOverlay() && overlayRequested);
948 if (deviceIsPixmap() && !(realPfd.dwFlags & PFD_DRAW_TO_BITMAP)) {
949 qWarning(
"QGLContext::chooseContext(): Failed to get pixmap rendering context.");
954 if (deviceIsPixmap() &&
955 (((
QPixmap*)
d->paintDevice)->depth() != realPfd.cColorBits)) {
956 qWarning(
"QGLContext::chooseContext(): Failed to get pixmap rendering context of suitable depth.");
961 if (!SetPixelFormat(myDc,
d->pixelFormatId, &realPfd)) {
962 qwglError(
"QGLContext::chooseContext()",
"SetPixelFormat");
968 qwglError(
"QGLContext::chooseContext()",
"wglCreateContext");
973 if(!deviceIsPixmap()) {
978 ((
QGLWidget*)
d->paintDevice)->setColormap(cmap);
986 wglMakeCurrent(myDc,
d->rc);
988 d->updateFormatVersion();
990 typedef BOOL (
APIENTRYP PFNWGLSWAPINTERVALEXT) (
int interval);
991 typedef int (
APIENTRYP PFNWGLGETSWAPINTERVALEXT) (void);
992 PFNWGLSWAPINTERVALEXT wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXT) wglGetProcAddress(
"wglSwapIntervalEXT");
993 PFNWGLGETSWAPINTERVALEXT wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXT) wglGetProcAddress(
"wglGetSwapIntervalEXT");
994 if (wglSwapIntervalEXT && wglGetSwapIntervalEXT) {
995 if (
d->reqFormat.swapInterval() != -1)
996 wglSwapIntervalEXT(
d->reqFormat.swapInterval());
997 d->glFormat.setSwapInterval(wglGetSwapIntervalEXT());
1001 ReleaseDC(
d->win, myDc);
1009 return (((!a) && (!b)) || (a && b));
1029 if (!deviceIsPixmap() && wglChoosePixelFormatARB) {
1031 int pixelFormat = 0;
1032 uint numFormats = 0;
1036 if (
d->glFormat.directRendering())
1041 iAttributes[i++] =
TRUE;
1043 iAttributes[i++] =
TRUE;
1045 iAttributes[i++] = 24;
1047 iAttributes[i++] =
d->glFormat.doubleBuffer();
1048 if (
d->glFormat.stereo()) {
1050 iAttributes[i++] =
TRUE;
1052 if (
d->glFormat.depth()) {
1054 iAttributes[i++] =
d->glFormat.depthBufferSize() == -1 ? 24 :
d->glFormat.depthBufferSize();
1057 if (
d->glFormat.rgba()) {
1059 if (
d->glFormat.redBufferSize() != -1) {
1061 iAttributes[i++] =
d->glFormat.redBufferSize();
1063 if (
d->glFormat.greenBufferSize() != -1) {
1065 iAttributes[i++] =
d->glFormat.greenBufferSize();
1067 if (
d->glFormat.blueBufferSize() != -1) {
1069 iAttributes[i++] =
d->glFormat.blueBufferSize();
1074 if (
d->glFormat.alpha()) {
1076 iAttributes[i++] =
d->glFormat.alphaBufferSize() == -1 ? 8 :
d->glFormat.alphaBufferSize();
1078 if (
d->glFormat.accum()) {
1080 iAttributes[i++] =
d->glFormat.accumBufferSize() == -1 ? 16 :
d->glFormat.accumBufferSize();
1082 if (
d->glFormat.stencil()) {
1084 iAttributes[i++] =
d->glFormat.stencilBufferSize() == -1 ? 8 :
d->glFormat.stencilBufferSize();
1086 if (
d->glFormat.hasOverlay()) {
1088 iAttributes[i++] = 1;
1092 if (trySampleBuffers &&
d->glFormat.sampleBuffers()) {
1094 iAttributes[i++] =
TRUE;
1097 iAttributes[i++] =
d->glFormat.samples() == -1 ? 4 :
d->glFormat.samples();
1102 valid = wglChoosePixelFormatARB(pdc, iAttributes.
constData(), 0, 1,
1103 &pixelFormat, &numFormats);
1104 if (trySampleBuffers && (!valid || numFormats < 1) &&
d->glFormat.sampleBuffers())
1105 iAttributes[si] /= 2;
1108 }
while ((!valid || numFormats < 1) && iAttributes[si] > 1);
1109 chosenPfi = pixelFormat;
1113 int pmDepth = deviceIsPixmap() ? ((
QPixmap*)
d->paintDevice)->depth() : 0;
1114 PIXELFORMATDESCRIPTOR* p = (PIXELFORMATDESCRIPTOR*)dummyPfd;
1115 memset(p, 0,
sizeof(PIXELFORMATDESCRIPTOR));
1116 p->nSize =
sizeof(PIXELFORMATDESCRIPTOR);
1118 p->dwFlags = PFD_SUPPORT_OPENGL;
1119 if (deviceIsPixmap())
1120 p->dwFlags |= PFD_DRAW_TO_BITMAP;
1122 p->dwFlags |= PFD_DRAW_TO_WINDOW;
1123 if (!
d->glFormat.directRendering())
1124 p->dwFlags |= PFD_GENERIC_FORMAT;
1125 if (
d->glFormat.doubleBuffer() && !deviceIsPixmap())
1126 p->dwFlags |= PFD_DOUBLEBUFFER;
1127 if (
d->glFormat.stereo())
1128 p->dwFlags |= PFD_STEREO;
1129 if (
d->glFormat.depth())
1130 p->cDepthBits =
d->glFormat.depthBufferSize() == -1 ? 32 :
d->glFormat.depthBufferSize();
1132 p->dwFlags |= PFD_DEPTH_DONTCARE;
1133 if (
d->glFormat.rgba()) {
1134 p->iPixelType = PFD_TYPE_RGBA;
1135 if (
d->glFormat.redBufferSize() != -1)
1136 p->cRedBits =
d->glFormat.redBufferSize();
1137 if (
d->glFormat.greenBufferSize() != -1)
1138 p->cGreenBits =
d->glFormat.greenBufferSize();
1139 if (
d->glFormat.blueBufferSize() != -1)
1140 p->cBlueBits =
d->glFormat.blueBufferSize();
1141 if (deviceIsPixmap())
1142 p->cColorBits = pmDepth;
1146 p->iPixelType = PFD_TYPE_COLORINDEX;
1149 if (
d->glFormat.alpha())
1150 p->cAlphaBits =
d->glFormat.alphaBufferSize() == -1 ? 8 :
d->glFormat.alphaBufferSize();
1151 if (
d->glFormat.accum()) {
1152 p->cAccumRedBits = p->cAccumGreenBits = p->cAccumBlueBits = p->cAccumAlphaBits =
1153 d->glFormat.accumBufferSize() == -1 ? 16 :
d->glFormat.accumBufferSize();
1155 if (
d->glFormat.stencil())
1156 p->cStencilBits =
d->glFormat.stencilBufferSize() == -1 ? 8 :
d->glFormat.stencilBufferSize();
1157 p->iLayerType = PFD_MAIN_PLANE;
1158 chosenPfi = ChoosePixelFormat(pdc, p);
1166 bool doSearch = chosenPfi <= 0;
1167 PIXELFORMATDESCRIPTOR pfd;
1170 DescribePixelFormat(pdc, chosenPfi,
sizeof(PIXELFORMATDESCRIPTOR),
1173 if (
d->glFormat.hasOverlay() && !fmt.
hasOverlay())
1177 else if (deviceIsPixmap() && (!(pfd.dwFlags & PFD_DRAW_TO_BITMAP) ||
1178 pfd.cColorBits != pmDepth))
1180 else if (!deviceIsPixmap() && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))
1187 int pfiMax = DescribePixelFormat(pdc, 0, 0, NULL);
1190 for (
int pfi = 1; pfi <= pfiMax; pfi++) {
1191 DescribePixelFormat(pdc, pfi,
sizeof(PIXELFORMATDESCRIPTOR), &pfd);
1192 if (!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
1194 if (deviceIsPixmap() && (!(pfd.dwFlags & PFD_DRAW_TO_BITMAP) ||
1195 pfd.cColorBits != pmDepth))
1197 if (!deviceIsPixmap() && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))
1201 if (
d->glFormat.hasOverlay() && !fmt.
hasOverlay())
1204 int score = pfd.cColorBits;
1206 score += pfd.cDepthBits;
1208 score += pfd.cAlphaBits;
1210 score += pfd.cAccumBits;
1212 score += pfd.cStencilBits;
1221 if (score > bestScore) {
1228 chosenPfi = bestPfi;
1252 wglDeleteContext(
d->rc);
1254 if (
d->win &&
d->dc)
1255 ReleaseDC(
d->win,
d->dc);
1256 if (deviceIsPixmap()) {
1257 DeleteDC(
d->hbitmap_hdc);
1258 DeleteObject(
d->hbitmap);
1265 d->pixelFormatId = 0;
1271 d->initDone =
false;
1284 if (
d->rc == wglGetCurrentContext() || !
d->valid)
1288 d->dc = GetDC(
d->win);
1291 qwglError(
"QGLContext::makeCurrent()",
"GetDC()");
1294 }
else if (deviceIsPixmap()) {
1295 d->dc =
d->hbitmap_hdc;
1300 SelectPalette(
d->dc, hpal,
FALSE);
1301 RealizePalette(
d->dc);
1303 if (
d->glFormat.plane()) {
1304 wglRealizeLayerPalette(
d->dc,
d->glFormat.plane(),
TRUE);
1307 if (wglMakeCurrent(
d->dc,
d->rc)) {
1310 qwglError(
"QGLContext::makeCurrent()",
"wglMakeCurrent");
1318 wglMakeCurrent(0, 0);
1320 if (deviceIsPixmap() &&
d->hbitmap) {
1324 if (
d->win &&
d->dc) {
1325 ReleaseDC(
d->win,
d->dc);
1334 if (
d->dc &&
d->glFormat.doubleBuffer() && !deviceIsPixmap()) {
1335 if (
d->glFormat.plane())
1336 wglSwapLayerBuffers(
d->dc, WGL_SWAP_OVERLAY1);
1338 if (
d->glFormat.hasOverlay())
1339 wglSwapLayerBuffers(
d->dc, WGL_SWAP_MAIN_PLANE);
1349 return d_func()->transpColor;
1359 int idx =
d->cmap->find(c.
rgb());
1362 if (
d->dc &&
d->glFormat.plane()) {
1363 idx =
d->cmap->allocate(c.
rgb());
1366 wglSetLayerPaletteEntries(
d->dc,
d->glFormat.plane(), idx, 1, &r);
1367 wglRealizeLayerPalette(
d->dc,
d->glFormat.plane(),
TRUE);
1371 return d->cmap->findNearest(c.
rgb());
1374 return cmap.
pixel(c) & 0x00ffffff;
1382 HDC display_dc = GetDC(0);
1383 HDC tmp_dc = CreateCompatibleDC(display_dc);
1384 HGDIOBJ old_font = SelectObject(tmp_dc, fnt.
handle());
1386 ReleaseDC(0, display_dc);
1388 if (!wglUseFontBitmaps(tmp_dc, 0, 256, listBase))
1389 qWarning(
"QGLContext::generateFontDisplayLists: Could not generate display lists for font '%s'", fnt.
family().
toLatin1().
data());
1391 SelectObject(tmp_dc, old_font);
1397 return (
void *)wglGetProcAddress(proc.
toLatin1());
1408 initContext(ctx, shareWidget);
1410 if (q->isValid() && q->context()->format().hasOverlay()) {
1412 if (!olcx->create(shareWidget ? shareWidget->
overlayContext() : 0)) {
1415 glcx->d_func()->glFormat.setOverlay(
false);
1430 for (
int i = 0; i < cols.
size(); i++) {
1432 pe.peRed =
qRed(color);
1433 pe.peGreen =
qGreen(color);
1434 pe.peBlue =
qBlue(color);
1437 SetPaletteEntries(cmap, i, 1, &pe);
1446 HDC hdc = GetDC(q->winId());
1447 SelectPalette(hdc, (HPALETTE)
cmap.handle(),
TRUE);
1449 RealizePalette(hdc);
1450 ReleaseDC(q->winId(), hdc);
1465 if (!
d->glcx->initialized())
1467 resizeGL(width(), height());
1469 makeOverlayCurrent();
1470 resizeOverlayGL(width(), height());
1477 return d_func()->olcx;
1485 d->olcx->makeCurrent();
1486 if (!
d->olcx->initialized()) {
1487 initializeOverlayGL();
1488 d->olcx->setInitialized(
true);
1498 makeOverlayCurrent();
1500 if (
d->olcx->format().doubleBuffer()) {
1502 d->olcx->swapBuffers();
1513 bool deleteOldContext)
1517 qWarning(
"QGLWidget::setContext: Cannot set null context");
1521 qWarning(
"QGLWidget::setContext: Context must refer to this widget");
1526 d->glcx->doneCurrent();
1530 bool doShow =
false;
1531 if (oldcx && oldcx->d_func()->win == winId() && !
d->glcx->deviceIsPixmap()) {
1535 doShow = isVisible();
1537 QPoint pos = geometry().topLeft();
1538 setParent(pW, windowFlags());
1542 if (!
d->glcx->isValid()) {
1543 bool wasSharing = shareContext || (oldcx && oldcx->
isSharing());
1544 d->glcx->create(shareContext ? shareContext : oldcx);
1549 d->glcx->d_ptr->sharing =
false;
1552 if (deleteOldContext)
1568 if (
cmap.handle()) {
1569 HDC hdc = GetDC(q->winId());
1570 SelectPalette(hdc, (HPALETTE) GetStockObject(DEFAULT_PALETTE),
FALSE);
1571 DeleteObject((HPALETTE)
cmap.handle());
1572 ReleaseDC(q->winId(), hdc);
1580 return d_func()->cmap;
1588 if (
d->cmap.handle()) {
1589 d->updateColormap();
1591 LOGPALETTE *lpal = (LOGPALETTE *) malloc(
sizeof(LOGPALETTE)
1592 +c.
size()*
sizeof(PALETTEENTRY));
1593 lpal->palVersion = 0x300;
1594 lpal->palNumEntries = c.
size();
1595 d->cmap.setHandle(CreatePalette(lpal));
1597 d->updateColormap();
The QColor class provides colors based on RGB, HSV or CMYK values.
virtual void swapBuffers() const
Swaps the screen contents with an off-screen buffer.
void updateFormatVersion()
const T * constData() const
static QColormap instance(int screen=-1)
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
#define QT_END_NAMESPACE
This macro expands to.
#define WGL_CONTEXT_FLAGS_ARB
int width() const
Returns the width of the pixmap.
static uchar qgl_rgb_palette_comp(int idx, uint nbits, uint shift)
char * data()
Returns a pointer to the data stored in the byte array.
static void setCurrentContext(QGLContext *context)
#define it(className, varName)
int size() const
Returns the number of colorcells in the colormap.
void setEntry(int idx, QRgb color, uint flags=0, quint8 context=0)
static QPixmap fromWinHBITMAP(HBITMAP hbitmap, HBitmapFormat format=NoAlpha)
Win32 only: Returns a QPixmap that is equivalent to the given bitmap.
#define WGL_TYPE_RGBA_ARB
QColor overlayTransparentColor() const
If this context is a valid context in an overlay plane, returns the plane's transparent color...
void * getProcAddress(const QString &proc) const
Returns a function pointer to the GL extension function passed in proc.
long ASN1_INTEGER_get ASN1_INTEGER * a
#define WGL_CONTEXT_MINOR_VERSION_ARB
The QString class provides a Unicode character string.
#define WGL_DRAW_TO_WINDOW_ARB
HFONT handle() const
Returns the window system handle to the font, for low-level access.
static void removeShare(const QGLContext *context)
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
int allocate(QRgb color, uint flags=0, quint8 context=0)
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Q_CORE_EXPORT void qDebug(const char *,...)
int find(QRgb color) const
QPlatformGLContext * context
#define WGL_GREEN_BITS_ARB
#define QT_BEGIN_NAMESPACE
This macro expands to.
void generateFontDisplayLists(const QFont &fnt, int listBase)
Generates a set of 256 display lists for the 256 first characters in the font font.
QVector< quint8 > contextArray
The QGLContext class encapsulates an OpenGL rendering context.
#define WGL_TYPE_COLORINDEX_ARB
void setEntries(int count, const QRgb *colors, int base=0)
Set an array of cells in this colormap.
#define WGL_SAMPLE_BUFFERS_ARB
The QResizeEvent class contains event parameters for resize events.
Q_CORE_EXPORT void qWarning(const char *,...)
static QRgb * qgl_create_rgb_palette(const PIXELFORMATDESCRIPTOR *pfd)
#define FALSE
Synonym for false.
QPaintDevice * device() const
Returns the paint device set for this context.
static QGLFormat pfdToQGLFormat(const PIXELFORMATDESCRIPTOR *pfd)
#define WGL_NO_ACCELERATION_ARB
bool(APIENTRY * PFNWGLCHOOSEPIXELFORMATARB)(HDC hdc, const int *piAttribList, const float *pfAttribFList, uint nMaxFormats, int *piFormats, UINT *nNumFormats)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
bool deviceIsPixmap() const
Returns true if the paint device of this context is a pixmap; otherwise returns false.
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
The QGLColormap class is used for installing custom colormaps into a QGLWidget.
uint pixel(const QColor &color) const
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB
int findNearest(QRgb color) const
#define WGL_BLUE_BITS_ARB
#define GL_CONTEXT_PROFILE_MASK
virtual int choosePixelFormat(void *pfd, HDC pdc)
Win32 only: This virtual function chooses a pixel format that matches the OpenGL format.
static bool qLogEq(bool a, bool b)
QGLFormat pfiToQGLFormat(HDC hdc, int pfi)
#define TRUE
Synonym for true.
QRgb entryRgb(int idx) const
Returns the QRgb value in the colorcell with index idx.
void qwglError(const char *method, const char *func)
void reset()
Resets the context and makes it invalid.
virtual bool chooseContext(const QGLContext *shareContext=0)
This semi-internal function is called by create().
#define WGL_DEPTH_BITS_ARB
static void qStoreColors(HPALETTE cmap, const QGLColormap &cols)
const QRgb * colors() const
static bool qgl_create_context(HDC hdc, QGLContextPrivate *d, QGLContextPrivate *shareContext)
bool isSharing() const
Returns true if this context is sharing its GL context with another QGLContext, otherwise false is re...
The QFont class specifies a font used for drawing text.
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
QString family() const
Returns the requested font family name, i.e.
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
virtual void doneCurrent()
Makes no GL context the current context.
The QPoint class defines a point in the plane using integer precision.
Q_GUI_EXPORT const QString qt_getRegisteredWndClass()
if(void) toggleToolbarShown
#define WGL_ACCUM_BITS_ARB
virtual void makeCurrent()
Makes this context the current OpenGL rendering context.
QGLTemporaryContext(bool directRendering=true, QWidget *parent=0)
static Extensions glExtensions()
The QPixmap class is an off-screen image representation that can be used as a paint device...
QVector< quint8 > allocArray
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
uint colorIndex(const QColor &c) const
Returns a colormap index for the color c, in ColorIndex mode.
#define WGL_DOUBLE_BUFFER_ARB
int height() const
Returns the height of the pixmap.
Q_CORE_EXPORT HINSTANCE qWinAppInst()
#define WGL_CONTEXT_LAYER_PLANE_ARB
bool(APIENTRY * PFNWGLGETPIXELFORMATATTRIBIVARB)(HDC hdc, int iPixelFormat, int iLayerPlane, uint nAttributes, const int *piAttributes, int *piValues)
#define WGL_ACCELERATION_ARB
#define WGL_COLOR_BITS_ARB
#define WGL_STENCIL_BITS_ARB
static const KeyPair *const end
#define WGL_CONTEXT_PROFILE_MASK_ARB
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QGLCmap & operator=(const QGLCmap &map)
#define WGL_CONTEXT_MAJOR_VERSION_ARB
#define WGL_SUPPORT_OPENGL_ARB
QRgb rgb() const
Returns the RGB value of the color.
#define WGL_PIXEL_TYPE_ARB
#define WGL_ALPHA_BITS_ARB
QMap< uint, int > colorMap
#define WGL_FULL_ACCELERATION_ARB
#define WGL_NUMBER_OVERLAYS_ARB
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
void qErrnoWarning(const char *msg,...)
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.
QVector< uint > colorArray