aboutsummaryrefslogtreecommitdiffstats
path: root/src/glx/dri_common.c
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2011-12-01 13:52:53 -0800
committerIan Romanick <[email protected]>2012-01-02 12:41:45 -0800
commitb45f77dc4c9662a774c19db764bb8f95c4f61073 (patch)
treeb9739261379d37f9d274b3de8429bb5be58ea8d7 /src/glx/dri_common.c
parent4c7898cb13528ede00c7524849de4aeac81a6ac3 (diff)
glx/dri: Add utility function dri2_convert_glx_attribs
This converts all of the GLX data from glXCreateContextAttribsARB to the values expected by the DRI driver interfaces. Signed-off-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glx/dri_common.c')
-rw-r--r--src/glx/dri_common.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c
index 1482b88bd93..5d50aa92e53 100644
--- a/src/glx/dri_common.c
+++ b/src/glx/dri_common.c
@@ -419,4 +419,106 @@ driReleaseDrawables(struct glx_context *gc)
}
+_X_HIDDEN bool
+dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
+ unsigned *major_ver, unsigned *minor_ver,
+ uint32_t *flags, unsigned *api, unsigned *error)
+{
+ unsigned i;
+ bool got_profile = false;
+ uint32_t profile;
+ int render_type = GLX_RGBA_TYPE;
+
+ if (num_attribs == 0)
+ return true;
+
+ /* This is actually an internal error, but what the heck.
+ */
+ if (attribs == NULL) {
+ *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
+ return false;
+ }
+
+ *major_ver = 1;
+ *minor_ver = 0;
+
+ for (i = 0; i < num_attribs; i++) {
+ switch (attribs[i * 2]) {
+ case GLX_CONTEXT_MAJOR_VERSION_ARB:
+ *major_ver = attribs[i * 2 + 1];
+ break;
+ case GLX_CONTEXT_MINOR_VERSION_ARB:
+ *minor_ver = attribs[i * 2 + 1];
+ break;
+ case GLX_CONTEXT_FLAGS_ARB:
+ *flags = attribs[i * 2 + 1];
+ break;
+ case GLX_CONTEXT_PROFILE_MASK_ARB:
+ profile = attribs[i * 2 + 1];
+ got_profile = true;
+ break;
+ case GLX_RENDER_TYPE:
+ render_type = attribs[i * 2 + 1];
+ break;
+ default:
+ /* If an unknown attribute is received, fail.
+ */
+ *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
+ return false;
+ }
+ }
+
+ *api = __DRI_API_OPENGL;
+ if (!got_profile) {
+ if (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
+ *api = __DRI_API_OPENGL_CORE;
+ } else {
+ switch (profile) {
+ case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
+ /* There are no profiles before OpenGL 3.2. The
+ * GLX_ARB_create_context_profile spec says:
+ *
+ * "If the requested OpenGL version is less than 3.2,
+ * GLX_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality
+ * of the context is determined solely by the requested version."
+ */
+ *api = (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
+ ? __DRI_API_OPENGL_CORE : __DRI_API_OPENGL;
+ break;
+ case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
+ *api = __DRI_API_OPENGL;
+ break;
+ default:
+ *error = __DRI_CTX_ERROR_BAD_API;
+ return false;
+ }
+ }
+
+ /* Unknown flag value.
+ */
+ if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE)) {
+ *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
+ return false;
+ }
+
+ /* There are no forward-compatible contexts before OpenGL 3.0. The
+ * GLX_ARB_create_context spec says:
+ *
+ * "Forward-compatible contexts are defined only for OpenGL versions
+ * 3.0 and later."
+ */
+ if (*major_ver < 3 && (*flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
+ *error = __DRI_CTX_ERROR_BAD_FLAG;
+ return false;
+ }
+
+ if (*major_ver >= 3 && render_type == GLX_COLOR_INDEX_TYPE) {
+ *error = __DRI_CTX_ERROR_BAD_FLAG;
+ return false;
+ }
+
+ *error = __DRI_CTX_ERROR_SUCCESS;
+ return true;
+}
+
#endif /* GLX_DIRECT_RENDERING */