diff options
author | Dave Airlie <airlied@redhat.com> | 2011-03-16 09:06:49 +1000 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2011-03-16 09:06:49 +1000 |
commit | 9fca3c206b52726ac1425b05ebd356608ed96ca3 (patch) | |
tree | 8159d7c5dbbff598240f10692ab09a2a08095f7a | |
parent | 36e099de35e51e252f6ba64d7b08d1e05a80e9e0 (diff) |
-rw-r--r-- | tests/glx/CMakeLists.gl.txt | 1 | ||||
-rw-r--r-- | tests/glx/glx-create-context.c | 161 |
2 files changed, 162 insertions, 0 deletions
diff --git a/tests/glx/CMakeLists.gl.txt b/tests/glx/CMakeLists.gl.txt index b3b590bb5..d17b3e0d0 100644 --- a/tests/glx/CMakeLists.gl.txt +++ b/tests/glx/CMakeLists.gl.txt @@ -17,6 +17,7 @@ link_libraries ( IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") add_executable (glx-shader-sharing glx-shader-sharing.c) + add_executable (glx-create-context glx-create-context.c) add_executable (glx-destroycontext-1 glx-destroycontext-1.c) add_executable (glx-destroycontext-2 glx-destroycontext-2.c) add_executable (glx-multithread glx-multithread.c) diff --git a/tests/glx/glx-create-context.c b/tests/glx/glx-create-context.c new file mode 100644 index 000000000..332087da2 --- /dev/null +++ b/tests/glx/glx-create-context.c @@ -0,0 +1,161 @@ +/* + * Copyright © 2011 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Dave Airlie + * + */ + +/** + * @file glx-create_context.c + */ +#include "glxew.h" + +#include "piglit-util.h" +#include "piglit-glx-util.h" + +int piglit_width = 70, piglit_height = 30; +static Display *dpy; +static Window win; +static XVisualInfo *visinfo; +static GLXFBConfig fb_config; + +enum piglit_result +draw(Display *dpy) +{ + int pass = 1; + GLXContext ctx, myctx; + char *str; + int attrib[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + None + }; + GLXFBConfig *configs; + int nconfigs; + int context_attribs[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 3, + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB | GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, + None + }; + + /* create old fashioned context just for show */ + ctx = piglit_get_glx_context(dpy, visinfo); + glXMakeCurrent(dpy, win, ctx); + + glewInit(); + + configs = glXChooseFBConfig(dpy, DefaultScreen(dpy), + attrib, &nconfigs); + assert(nconfigs > 0); + fb_config = configs[nconfigs-1]; + XFree(configs); + + str = glGetString(GL_VERSION); + + printf("%s\n", str ? str : "none"); + glXMakeContextCurrent(dpy, None, None, None); + glXDestroyContext(dpy, ctx); + + /* 2.1 */ + ctx = glXCreateContextAttribsARB(dpy, fb_config, NULL, true, context_attribs); + if (!ctx) { + printf("failed to create context\n"); + pass = 0; + }; + + fprintf(stderr,"gl error is %d\n", glGetError()); + if (!glXMakeCurrent(dpy, win, ctx)) + printf("failed to make current %d %x\n", glGetError(), ctx); + + str = glGetString(GL_VERSION); + + myctx = glXGetCurrentContext(); + + printf("%x %x %s\n", ctx, myctx, str ? str : "none"); + + glXMakeContextCurrent(dpy, None, None, None); + glXDestroyContext(dpy, ctx); + + /* 3.0 */ + context_attribs[1] = 3; + context_attribs[3] = 0; + ctx = glXCreateContextAttribsARB(dpy, fb_config, NULL, true, context_attribs); + if (!ctx) { + printf("failed to create context\n"); + pass = 0; + }; + + if (!glXMakeCurrent(dpy, win, ctx)) + printf("failed to make current\n"); + str = glGetString(GL_VERSION); + + printf("%s\n", str ? str : "none"); + glXDestroyContext(dpy, ctx); + + /* 3.1 */ + context_attribs[3] = 1; + ctx = glXCreateContextAttribsARB(dpy, fb_config, NULL, true, context_attribs); + if (!ctx) { + printf("failed to create context\n"); + pass = 0; + }; + + if (!glXMakeCurrent(dpy, win, ctx)) + printf("failed to make current %d\n", glGetError()); + + glXDestroyContext(dpy, ctx); + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +int +main(int argc, char **argv) +{ + int i; + + + for(i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "-auto")) + piglit_automatic = 1; + else + fprintf(stderr, "Unknown option: %s\n", argv[i]); + } + + dpy = XOpenDisplay(NULL); + if (dpy == NULL) { + fprintf(stderr, "couldn't open display\n"); + piglit_report_result(PIGLIT_FAILURE); + } + + visinfo = piglit_get_glx_visual(dpy); + win = piglit_get_glx_window(dpy, visinfo); + + piglit_require_glx_extension(dpy, "GLX_ARB_create_context"); + + piglit_glx_event_loop(dpy, draw); + + return 0; +} |