70 delete ctx; |
70 delete ctx; |
71 ctx = 0; |
71 ctx = 0; |
72 return false; |
72 return false; |
73 } |
73 } |
74 |
74 |
|
75 // Find the shared context. |
|
76 QEglContext *shareContext = 0; |
|
77 if (shareWidget && shareWidget->d_func()->glcx) |
|
78 shareContext = shareWidget->d_func()->glcx->d_func()->eglContext; |
|
79 |
75 // Choose an appropriate configuration. We use the best format |
80 // Choose an appropriate configuration. We use the best format |
76 // we can find, even if it is greater than the requested format. |
81 // we can find, even if it is greater than the requested format. |
77 // We try for a pbuffer that is capable of texture rendering if possible. |
82 // We try for a pbuffer that is capable of texture rendering if possible. |
78 QEglProperties configProps; |
83 textureFormat = EGL_NONE; |
79 qt_egl_set_format(configProps, QInternal::Pbuffer, f); |
84 if (shareContext) { |
80 configProps.setRenderableType(ctx->api()); |
85 // Use the same configuration as the widget we are sharing with. |
81 bool ok = false; |
86 ctx->setConfig(shareContext->config()); |
82 #if QGL_RENDER_TEXTURE |
87 #if QGL_RENDER_TEXTURE |
83 textureFormat = EGL_TEXTURE_RGBA; |
88 EGLint value = EGL_FALSE; |
84 configProps.setValue(EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE); |
89 if (ctx->configAttrib(EGL_BIND_TO_TEXTURE_RGBA, &value) && value) |
85 ok = ctx->chooseConfig(configProps, QEgl::BestPixelFormat); |
90 textureFormat = EGL_TEXTURE_RGBA; |
86 if (!ok) { |
91 else if (ctx->configAttrib(EGL_BIND_TO_TEXTURE_RGB, &value) && value) |
87 // Try again with RGB texture rendering. |
92 textureFormat = EGL_TEXTURE_RGB; |
88 textureFormat = EGL_TEXTURE_RGB; |
93 #endif |
89 configProps.removeValue(EGL_BIND_TO_TEXTURE_RGBA); |
94 } else { |
90 configProps.setValue(EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE); |
95 QEglProperties configProps; |
|
96 qt_egl_set_format(configProps, QInternal::Pbuffer, f); |
|
97 configProps.setRenderableType(ctx->api()); |
|
98 bool ok = false; |
|
99 #if QGL_RENDER_TEXTURE |
|
100 textureFormat = EGL_TEXTURE_RGBA; |
|
101 configProps.setValue(EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE); |
91 ok = ctx->chooseConfig(configProps, QEgl::BestPixelFormat); |
102 ok = ctx->chooseConfig(configProps, QEgl::BestPixelFormat); |
92 if (!ok) { |
103 if (!ok) { |
93 // One last try for a pbuffer with no texture rendering. |
104 // Try again with RGB texture rendering. |
94 configProps.removeValue(EGL_BIND_TO_TEXTURE_RGB); |
105 textureFormat = EGL_TEXTURE_RGB; |
95 textureFormat = EGL_NONE; |
106 configProps.removeValue(EGL_BIND_TO_TEXTURE_RGBA); |
|
107 configProps.setValue(EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE); |
|
108 ok = ctx->chooseConfig(configProps, QEgl::BestPixelFormat); |
|
109 if (!ok) { |
|
110 // One last try for a pbuffer with no texture rendering. |
|
111 configProps.removeValue(EGL_BIND_TO_TEXTURE_RGB); |
|
112 textureFormat = EGL_NONE; |
|
113 } |
96 } |
114 } |
97 } |
115 #endif |
98 #else |
116 if (!ok) { |
99 textureFormat = EGL_NONE; |
117 if (!ctx->chooseConfig(configProps, QEgl::BestPixelFormat)) { |
100 #endif |
118 delete ctx; |
101 if (!ok) { |
119 ctx = 0; |
102 if (!ctx->chooseConfig(configProps, QEgl::BestPixelFormat)) { |
120 return false; |
103 delete ctx; |
121 } |
104 ctx = 0; |
|
105 return false; |
|
106 } |
122 } |
107 } |
123 } |
108 |
124 |
109 // Retrieve the actual format properties. |
125 // Retrieve the actual format properties. |
110 qt_egl_update_format(*ctx, format); |
126 qt_egl_update_format(*ctx, format); |