static bool try_get_context_id(GLXContext ctx, enum context_mode mode) { bool pass = true; GLXContextID id = glXGetContextIDEXT(ctx); XSync(dpy, 0); if (mode != invalid && id == None) { fprintf(stderr, "Could not get context ID for %s context.\n", context_mode_name(mode)); pass = false; } else if (mode == invalid && id != None) { fprintf(stderr, "Got a context ID for %s context.\n", context_mode_name(mode)); pass = false; } /* The glXGetContextIDEXT man page says: * * "GLXBadContext is generated if ctx does not refer to a valid * context." * * However, glXGetContextIDEXT doesn't take a Display. If the context * is invalid and no context is current, it is impossible for * glXGetContextIDEXT to get a Display. Without a Display, it is * impossible to generate a protocol error! */ pass = validate_glx_error_code(Success, -1) && pass; return pass; }
static bool try_render_type(int type) { const int attribs[] = { GLX_RENDER_TYPE, type, None }; GLXContext ctx; bool pass = true; ctx = glXCreateContextAttribsARB(dpy, fbconfig, NULL, True, attribs); XSync(dpy, 0); if (ctx != NULL) { fprintf(stderr, "Created OpenGL context with invalid render-type " "0x%08x, but this should have failed.\n", type); glXDestroyContext(dpy, ctx); pass = false; } /* The GLX_ARB_create_context spec says: * * "* If attribute GLX_RENDER_TYPE does not describe a valid * rendering type, BadValue is generated." */ if (!validate_glx_error_code(BadValue, -1)) { if (ctx == NULL) fprintf(stderr, "Render type = 0x%08x\n", type); pass = false; } return pass; }
static bool try_query(GLXContext ctx, int attribute, const char *attribute_string, int expected_error, int expected_value) { bool pass = true; int value = 0xDEADBEEF; int err; err = glXQueryContextInfoEXT(dpy, ctx, attribute, &value); XSync(dpy, 0); if (err != expected_error) { fprintf(stderr, "Query of %s had error %d, but %d was expected.\n", attribute_string, err, expected_error); pass = false; } /* There is no way in GLX_SGIX_fbconfig to get an XID from a * GLXFBConfig. As a result, there's no way to verify * glXQueryContextInfoEXT has returned the correct value. The * required functionality was not added until GLX 1.3. */ if (attribute != GLX_FBCONFIG_ID_SGIX) { if (expected_error != Success) expected_value = 0xDEADBEEF; if (value != expected_value) { fprintf(stderr, "Query of %s had value %d, but %d was " "expected.\n", attribute_string, value, expected_value); pass = false; } } else { if (value == 0xDEADBEEF) { fprintf(stderr, "Query of %s did not set a value.\n", attribute_string); pass = false; } } /* No GLX protocol error should be generated. */ pass = validate_glx_error_code(Success, -1) && pass; return pass; }
bool try_import_context(GLXContextID id, enum context_mode mode) { const int expected_glx_error = (mode == invalid) ? GLXBadContext : -1; bool pass = true; GLXContext ctx = glXImportContextEXT(dpy, id); XSync(dpy, 0); switch (mode) { case direct_rendering: if (ctx != NULL) { fprintf(stderr, "Could import direct-rendering context, " "but should have failed.\n"); pass = false; } break; case indirect_rendering: if (ctx == NULL) { fprintf(stderr, "Could not import indirect-rendering context, " "but should have succeeded.\n"); pass = false; } break; case invalid: if (ctx != NULL) { fprintf(stderr, "Could import invalid context (0x%08x), " "but should have failed.\n", (int) id); pass = false; } break; } assert(mode != invalid || expected_glx_error != -1); pass = validate_glx_error_code(Success, expected_glx_error) && pass; if (!pass) fprintf(stderr, "Context ID = 0x%08x.\n", (int) id); if (ctx != NULL) glXFreeContextEXT(dpy, ctx); return pass; }
static bool try_attribute(int attribute) { /* If the attribute is GLX_CONTEXT_CORE_PROFILE_BIT_ARB, use a valid * value for that attribute. This ensures that the attribute is * rejected for the correct reason. */ const int attribs[] = { attribute, (attribute == GLX_CONTEXT_PROFILE_MASK_ARB) ? GLX_CONTEXT_CORE_PROFILE_BIT_ARB : 0, None }; GLXContext ctx; bool pass = true; ctx = glXCreateContextAttribsARB(dpy, fbconfig, NULL, True, attribs); XSync(dpy, 0); if (ctx != NULL) { fprintf(stderr, "Created OpenGL context with invalud attribute " "0x%08x, but this should have failed.\n", attribute); glXDestroyContext(dpy, ctx); pass = false; } /* The GLX_ARB_create_context spec says: * * "* If an attribute or attribute value in <attrib_list> is not * recognized (including unrecognized bits in bitmask * attributes), BadValue is generated." */ if (!validate_glx_error_code(BadValue, -1)) { fprintf(stderr, "Attribute = 0x%08x\n", attribute); pass = false; } return pass; }
static bool try_profile(int profile) { const int attribs[] = { GLX_CONTEXT_PROFILE_MASK_ARB, profile, None }; GLXContext ctx; bool pass = true; ctx = glXCreateContextAttribsARB(dpy, fbconfig, NULL, True, attribs); XSync(dpy, 0); if (ctx != NULL) { fprintf(stderr, "Created OpenGL context with invalid profile " "0x%08x, but this should have failed.\n", profile); glXDestroyContext(dpy, ctx); pass = false; } /* The GLX_ARB_create_context_profile spec says: * * "* If attribute GLX_CONTEXT_PROFILE_MASK_ARB has no bits set; * has any bits set other than GLX_CONTEXT_CORE_PROFILE_BIT_ARB * and GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; has more than * one of these bits set; or if the implementation does not * support the requested profile, then GLXBadProfileARB is * generated." */ if (!validate_glx_error_code(Success, GLXBadProfileARB)) { fprintf(stderr, "Profile = 0x%08x\n", profile); pass = false; } return pass; }
int main(int argc, char **argv) { static const int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 2, GLX_CONTEXT_MINOR_VERSION_ARB, 0, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT, None }; bool pass = true; GLXContext ctx; GLX_ARB_create_context_setup(); piglit_require_glx_extension(dpy, "GLX_ARB_create_context_profile"); piglit_require_glx_extension(dpy, "GLX_EXT_create_context_es2_profile"); /* The GLX_EXT_create_context_es2_profile doesn't say anything about * indirect-rendering contexts for ES2. However, there is no protocol * defined, so it seems impossible that this could ever work. */ ctx = glXCreateContextAttribsARB(dpy, fbconfig, NULL, False, attribs); XSync(dpy, 0); if (ctx != NULL) { PFNGLGETSHADERPRECISIONFORMATPROC func; GLint r[] = { ~0, ~0 }; GLint p = ~0; /* Try to call an ES2 function that does not exist in desktop * OpenGL or have GLX protocol defined. If this works, then * we'll assume the implementation is using some magic * protocol for ES2. If it doesn't work, then the test fails. */ func = (PFNGLGETSHADERPRECISIONFORMATPROC) glXGetProcAddress((const GLubyte *) "glGetShaderPrecisionFormat"); if (func == NULL) { fprintf(stderr, "Indirect rendering OpenGL ES 2.0 context was " "created, but could not get\n" "function address for " "glGetShaderPrecisionFormat.\n"); pass = false; goto done; } if (!glXMakeCurrent(dpy, glxWin, ctx)) { fprintf(stderr, "Indirect rendering OpenGL ES 2.0 " "context was created, but\n" "it could not be made current.\n"); pass = false; goto done; } (*func)(GL_VERTEX_SHADER, GL_MEDIUM_FLOAT, r, &p); if (r[0] < 14 || r[1] < 14 || p < 10) { fprintf(stderr, "Indirect rendering OpenGL ES 2.0 " "context was created, but\n" "glGetShaderPrecisionFormat produced " "incorrect results.\n"); pass = false; } } else { /* The GLX_ARB_create_context_profile spec says: * * "* If <config> does not support compatible OpenGL * contexts providing the requested API major and minor * version, forward-compatible flag, and debug context * flag, GLXBadFBConfig is generated." */ if (!validate_glx_error_code(Success, GLXBadFBConfig)) pass = false; } done: if (ctx != NULL) { glXMakeCurrent(dpy, None, NULL); glXDestroyContext(dpy, ctx); } GLX_ARB_create_context_teardown(); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); return 0; }