Changeset 846 for trunk/src/opengl/qgl_win.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/opengl/qgl_win.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 123 123 #endif 124 124 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 135 // Error codes returned by GetLastError(). 136 #define ERROR_INVALID_VERSION_ARB 0x2095 137 #define ERROR_INVALID_PROFILE_ARB 0x2096 138 #endif 139 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 147 #endif 148 125 149 QT_BEGIN_NAMESPACE 126 150 … … 683 707 } 684 708 709 static bool qgl_create_context(HDC hdc, QGLContextPrivate *d, QGLContextPrivate *shareContext) 710 { 711 d->rc = 0; 712 713 typedef HGLRC (APIENTRYP PFNWGLCREATECONTEXTATTRIBSARB)(HDC, HGLRC, const int *); 714 PFNWGLCREATECONTEXTATTRIBSARB wglCreateContextAttribsARB = 715 (PFNWGLCREATECONTEXTATTRIBSARB) wglGetProcAddress("wglCreateContextAttribsARB"); 716 if (wglCreateContextAttribsARB) { 717 int attributes[11]; 718 int attribIndex = 0; 719 const int major = d->reqFormat.majorVersion(); 720 const int minor = d->reqFormat.minorVersion(); 721 attributes[attribIndex++] = WGL_CONTEXT_MAJOR_VERSION_ARB; 722 attributes[attribIndex++] = major; 723 attributes[attribIndex++] = WGL_CONTEXT_MINOR_VERSION_ARB; 724 attributes[attribIndex++] = minor; 725 726 if (major >= 3 && !d->reqFormat.testOption(QGL::DeprecatedFunctions)) { 727 attributes[attribIndex++] = WGL_CONTEXT_FLAGS_ARB; 728 attributes[attribIndex++] = WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; 729 } 730 731 if ((major == 3 && minor >= 2) || major > 3) { 732 switch (d->reqFormat.profile()) { 733 case QGLFormat::NoProfile: 734 break; 735 case QGLFormat::CoreProfile: 736 attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB; 737 attributes[attribIndex++] = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; 738 break; 739 case QGLFormat::CompatibilityProfile: 740 attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB; 741 attributes[attribIndex++] = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; 742 break; 743 default: 744 qWarning("QGLContext::chooseContext(): Context profile not supported."); 745 return false; 746 } 747 } 748 749 if (d->reqFormat.plane() != 0) { 750 attributes[attribIndex++] = WGL_CONTEXT_LAYER_PLANE_ARB; 751 attributes[attribIndex++] = d->reqFormat.plane(); 752 } 753 754 attributes[attribIndex++] = 0; // Terminate list. 755 d->rc = wglCreateContextAttribsARB(hdc, shareContext && shareContext->valid 756 ? shareContext->rc : 0, attributes); 757 if (d->rc) { 758 if (shareContext) 759 shareContext->sharing = d->sharing = true; 760 return true; 761 } 762 } 763 764 d->rc = wglCreateLayerContext(hdc, d->reqFormat.plane()); 765 if (d->rc && shareContext && shareContext->valid) 766 shareContext->sharing = d->sharing = wglShareLists(shareContext->rc, d->rc); 767 return d->rc != 0; 768 } 769 770 void QGLContextPrivate::updateFormatVersion() 771 { 772 const GLubyte *s = glGetString(GL_VERSION); 773 774 if (!(s && s[0] >= '0' && s[0] <= '9' && s[1] == '.' && s[2] >= '0' && s[2] <= '9')) { 775 if (!s) 776 qWarning("QGLContext::chooseContext(): OpenGL version string is null."); 777 else 778 qWarning("QGLContext::chooseContext(): Unexpected OpenGL version string format."); 779 glFormat.setVersion(0, 0); 780 glFormat.setProfile(QGLFormat::NoProfile); 781 glFormat.setOption(QGL::DeprecatedFunctions); 782 return; 783 } 784 785 int major = s[0] - '0'; 786 int minor = s[2] - '0'; 787 glFormat.setVersion(major, minor); 788 789 if (major < 3) { 790 glFormat.setProfile(QGLFormat::NoProfile); 791 glFormat.setOption(QGL::DeprecatedFunctions); 792 } else { 793 GLint value = 0; 794 if (major > 3 || minor >= 2) 795 glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value); 796 797 switch (value) { 798 case WGL_CONTEXT_CORE_PROFILE_BIT_ARB: 799 glFormat.setProfile(QGLFormat::CoreProfile); 800 break; 801 case WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB: 802 glFormat.setProfile(QGLFormat::CompatibilityProfile); 803 break; 804 default: 805 glFormat.setProfile(QGLFormat::NoProfile); 806 break; 807 } 808 809 glGetIntegerv(GL_CONTEXT_FLAGS, &value); 810 if (value & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) 811 glFormat.setOption(QGL::NoDeprecatedFunctions); 812 else 813 glFormat.setOption(QGL::DeprecatedFunctions); 814 } 815 } 816 685 817 bool QGLContext::chooseContext(const QGLContext* shareContext) 686 818 { 819 QGLContextPrivate *share = shareContext ? const_cast<QGLContext *>(shareContext)->d_func() : 0; 820 687 821 Q_D(QGLContext); 688 822 // workaround for matrox driver: … … 742 876 } 743 877 744 d->rc = wglCreateLayerContext(myDc, d->glFormat.plane()); 745 if (!d->rc) { 878 if (!qgl_create_context(myDc, d, share)) { 746 879 qwglError("QGLContext::chooseContext()", "CreateLayerContext"); 747 880 result = false; … … 793 926 d->cmap->setEntry(lpfd.crTransparent, qRgb(1, 2, 3));//, QGLCmap::Reserved); 794 927 } 795 796 if (shareContext && shareContext->isValid()) { 797 QGLContext *share = const_cast<QGLContext *>(shareContext); 798 d->sharing = (wglShareLists(shareContext->d_func()->rc, d->rc) != 0); 799 share->d_func()->sharing = d->sharing; 800 } 801 802 goto end; 803 } 804 { 928 } else { 805 929 PIXELFORMATDESCRIPTOR pfd; 806 930 PIXELFORMATDESCRIPTOR realPfd; … … 841 965 } 842 966 843 if (! (d->rc = wglCreateLayerContext(myDc, 0))) {967 if (!qgl_create_context(myDc, d, share)) { 844 968 qwglError("QGLContext::chooseContext()", "wglCreateContext"); 845 969 result = false; 846 970 goto end; 847 }848 849 if (shareContext && shareContext->isValid()) {850 d->sharing = (wglShareLists(shareContext->d_func()->rc, d->rc) != 0);851 const_cast<QGLContext *>(shareContext)->d_func()->sharing = d->sharing;852 971 } 853 972 … … 866 985 // vblanking 867 986 wglMakeCurrent(myDc, d->rc); 987 if (d->rc) 988 d->updateFormatVersion(); 989 868 990 typedef BOOL (APIENTRYP PFNWGLSWAPINTERVALEXT) (int interval); 869 991 typedef int (APIENTRYP PFNWGLGETSWAPINTERVALEXT) (void); … … 921 1043 iAttributes[i++] = TRUE; 922 1044 iAttributes[i++] = WGL_COLOR_BITS_ARB; 923 iAttributes[i++] = 32;1045 iAttributes[i++] = 24; 924 1046 iAttributes[i++] = WGL_DOUBLE_BUFFER_ARB; 925 1047 iAttributes[i++] = d->glFormat.doubleBuffer(); … … 1159 1281 { 1160 1282 Q_D(QGLContext); 1161 if (d->rc == wglGetCurrentContext() || !d->valid) 1283 if (d->rc == wglGetCurrentContext() || !d->valid) // already current 1162 1284 return; 1285 1163 1286 if (d->win) { 1164 1287 d->dc = GetDC(d->win);
Note:
See TracChangeset
for help on using the changeset viewer.