int main(int argc, char **argv)
{
	static const EGLint attribs[] = {
		EGL_NONE
	};
	const char *version_string;
	int major;
	int minor;

	if (!EGL_KHR_create_context_setup(EGL_OPENGL_ES_BIT)) {
		fprintf(stderr, "ES 1 not available.\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	/* The EGL 1.4 spec says:
	 *
	 *     "attrib list may be NULL or empty (first attribute is EGL_NONE),
	 *     in which case all the attributes assume their default values"
	 *
	 * Specify an empty attrib_list and expect to receive an ES 1.x context.
	 */
	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);
	if (ctx == EGL_NO_CONTEXT) {
		fprintf(stderr, "eglCreateContext() failed\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx)) {
		fprintf(stderr, "eglMakeCurrent() failed\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	piglit_dispatch_default_init(PIGLIT_DISPATCH_ES1);

	version_string = (char *) glGetString(GL_VERSION);

	if (!parse_version_string(version_string, &major, &minor)) {
		fprintf(stderr,
			"Unable to parse GL version string: %s\n",
			version_string);
		piglit_report_result(PIGLIT_FAIL);
	}

	if (major != 1 || (minor != 0 && minor != 1)) {
		fprintf(stderr,
			"Unexpected GLES version: %s\n"
			"Expected ES 1.0 or ES 1.1.\n",
			version_string);
		piglit_report_result(PIGLIT_FAIL);
	}

	eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
	eglDestroyContext(egl_dpy, ctx);

	EGL_KHR_create_context_teardown();

	piglit_report_result(PIGLIT_PASS);

	return EXIT_SUCCESS;
}
예제 #2
0
enum piglit_result
draw(Display *dpy)
{
	bool pass = true;
	float green[] = {0.0, 1.0, 0.0, 0.0};
	GLXContext ctx;

	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, win, ctx);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	/* Clear to green */
	glClearColor(0.0, 1.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Noop */
	glXSwapBuffers(dpy, win);

	/* We want to actually catch any X error that leaks through as
	 * a result of glXSwapBuffers() before we go saying "pass" or
	 * "fail".
	 */
	XSync(dpy, False);

	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
예제 #3
0
void
piglit_oml_sync_control_test_run(bool fullscreen, enum piglit_result (*draw)(Display *dpy))
{
	Display *dpy;
	GLXContext ctx;

	dpy = XOpenDisplay(NULL);
	if (dpy == NULL) {
		fprintf(stderr, "couldn't open display\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	piglit_require_glx_extension(dpy, "GLX_OML_sync_control");
	piglit_glx_get_all_proc_addresses(procs, ARRAY_SIZE(procs));

	visinfo = piglit_get_glx_visual(dpy);
	if (fullscreen)
		win = piglit_get_glx_window_fullscreen(dpy, visinfo);
	else
		win = piglit_get_glx_window(dpy, visinfo);
	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, win, ctx);

	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	XMapWindow(dpy, win);

	piglit_glx_event_loop(dpy, draw);
}
예제 #4
0
enum piglit_result
draw(Display *dpy)
{
	GLboolean pass = GL_TRUE;
	float green[] = {0.0, 1.0, 0.0, 0.0};
	GLXContext ctx;

	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, win, ctx);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
	glClearColor(1.0, 0.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glXDestroyContext(dpy, ctx);

	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, win, ctx);

	glClearColor(0.0, 1.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	pass &= piglit_probe_pixel_rgb(1, 1, green);

	glXSwapBuffers(dpy, win);

	/* Free our resources when we're done. */
	glXMakeCurrent(dpy, None, NULL);
	glXDestroyContext(dpy, ctx);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
예제 #5
0
enum piglit_result
draw(Display *dpy)
{
	GLboolean pass = GL_TRUE;
	float green[] = {0.0, 1.0, 0.0, 1.0};
	float gray[] = {0.5, 0.5, 0.5, 1.0};
	pthread_t thread1, thread2;
	void *retval;
	int ret;

	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, win, ctx);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	piglit_require_glx_extension(dpy, "MESA_multithread_makecurrent");

	/* Clear background to gray */
	glClearColor(0.5, 0.5, 0.5, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	pthread_mutex_init(&mutex, NULL);

	glFlush();
	/* Now, spawn some threads that do some drawing, both with this
	 * context
	 */
	pthread_create(&thread1, NULL, thread1_func, NULL);
	pthread_create(&thread2, NULL, thread2_func, NULL);

	ret = pthread_join(thread1, &retval);
	assert(ret == 0);
	ret = pthread_join(thread2, &retval);
	assert(ret == 0);

	pthread_mutex_destroy(&mutex);
	glFlush();

	pass &= piglit_probe_rect_rgba( 0, 10, 10, 10, gray);
	pass &= piglit_probe_rect_rgba(10, 10, 10, 10, green);
	pass &= piglit_probe_rect_rgba(20, 10, 10, 10, gray);
	pass &= piglit_probe_rect_rgba(30, 10, 10, 10, green);
	pass &= piglit_probe_rect_rgba(40, 10, 10, 10, gray);
	pass &= piglit_probe_rect_rgba(50, 10, 10, 10, green);
	pass &= piglit_probe_rect_rgba(60, 10, 10, 10, gray);

	pass &= piglit_probe_rect_rgba(0, 0, piglit_width, 10, gray);
	pass &= piglit_probe_rect_rgba(0, 20, piglit_width, 10, gray);

	glXSwapBuffers(dpy, win);

	glXMakeCurrent(dpy, None, None);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
예제 #6
0
enum piglit_result
draw(Display *dpy)
{
	GLXContext ctx;
	bool pass = true;
	unsigned int age;
	int i;
	static GLfloat colors[5][4] = {
		{1.0, 0.0, 0.0, 1.0},
		{0.0, 1.0, 0.0, 1.0},
		{0.0, 0.0, 1.0, 1.0},
		{1.0, 0.0, 1.0, 1.0},
		{0.0, 1.0, 1.0, 1.0}
	};

	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, window, ctx);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	glXQueryDrawable(dpy, window, GLX_BACK_BUFFER_AGE_EXT, &age);
	if (age != 0) {
		fprintf(stderr, "Initial age was %d, should be 0\n", age);
		pass = false;
	}

	for (i = 0; i < 5; i++) {
		glClearColor(colors[i][0],
			     colors[i][1],
			     colors[i][2],
			     colors[i][3]);
		glClear(GL_COLOR_BUFFER_BIT);
		glXSwapBuffers(dpy, window);

		glXQueryDrawable(dpy, window, GLX_BACK_BUFFER_AGE_EXT, &age);
		printf("Frame %d: age %d\n", i + 1, age);

		if (age > 0) {
			int color_i = i - (age - 1);
			if (color_i < 0) {
				fprintf(stderr, "too old\n");
				pass = false;
			} else {
				pass = piglit_probe_rect_rgba(0, 0,
							      piglit_width,
							      piglit_height,
							      colors[color_i])
					&& pass;
			}
		}
	}

	glXMakeCurrent(dpy, None, NULL);
	glXDestroyContext(dpy, ctx);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
int
main(int argc, char **argv)
{
	GLenum internal_format = 0;

	EGLDisplay dpy;
	EGLContext ctx;
	bool ok;

	/* Strip common piglit args. */
	piglit_strip_arg(&argc, argv, "-fbo");
	piglit_strip_arg(&argc, argv, "-auto");

	if (argc == 2) {
		if (streq(argv[1], "GL_RGBA")) {
			internal_format = GL_RGBA;
		} else if (streq(argv[1], "GL_DEPTH_COMPONENT24")) {
			internal_format = GL_DEPTH_COMPONENT24;
		}
	}

	if (internal_format == 0)
		usage_error();

	dpy = create_display();
	ctx = create_context(dpy);

	ok = eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
	if (!ok) {
		piglit_loge("failed to make context current without surface");
		piglit_report_result(PIGLIT_FAIL);
	}

	piglit_dispatch_default_init(PIGLIT_DISPATCH_ES2);

	if (!piglit_is_extension_supported("GL_OES_EGL_image")) {
		piglit_loge("context does not support GL_OES_EGL_image");
		piglit_report_result(PIGLIT_SKIP);
	}

	switch (internal_format) {
	case GL_RGBA:
		test_rgba(dpy, ctx);
		break;
	case GL_DEPTH_COMPONENT24:
		test_depth24(dpy, ctx);
		break;
	default:
		break;
	}

	/* unreachable */
	abort();
}
예제 #8
0
enum piglit_result
draw(Display *dpy, GLXFBConfig config)
{
	int dbits;
	float green[3] = {0.0, 1.0, 0.0};
	float blue[3] = {0.0, 0.0, 1.0};
	float *left, *right;
	bool pass = true;

	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
	glXGetFBConfigAttrib(dpy, config, GLX_DEPTH_SIZE, &dbits);

	piglit_ortho_projection(piglit_width, piglit_height, false);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_ALWAYS);

	/* Set half the FB to depth 0, half to 1, and everything blue */
	glColor3fv(blue);
	piglit_draw_rect_z(1.0,
			   0, 0,
			   piglit_width / 2, piglit_height);
	piglit_draw_rect_z(0.0,
			   piglit_width / 2, 0,
			   piglit_width, piglit_height);

	/* Now draw a rect trying to set just the 1 values to green. */
	glColor3fv(green);
	glDepthFunc(GL_LESS);
	piglit_draw_rect_z(0.5,
			   0, 0, piglit_width, piglit_height);

	/* If there was a depth buffer, then we get half the window
	 * set to green.  Otherwise, the depth test always passes
	 * and the whole thing should have been set green.
	 */
	if (dbits) {
		left = blue;
		right = green;
	} else {
		left = green;
		right = green;
	}

	pass = pass && piglit_probe_rect_rgb(0, 0,
					     piglit_width / 2, piglit_height,
					     left);
	pass = pass && piglit_probe_rect_rgb(piglit_width / 2, 0,
					     piglit_width - piglit_width / 2,
					     piglit_height,
					     right);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
예제 #9
0
enum piglit_result
draw(Display *dpy)
{
    pthread_t draw_thread, load_thread;
    void *draw_ret, *load_ret;
    int ret, i;
    GLXContext my_ctx;

    my_ctx = piglit_get_glx_context_share(dpy, visinfo, NULL);
    draw_ctx = piglit_get_glx_context_share(dpy, visinfo, my_ctx);
    load_ctx = piglit_get_glx_context_share(dpy, visinfo, my_ctx);

    ret = glXMakeCurrent(dpy, draw_win, my_ctx);
    assert(ret);
    piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

    glEnable(GL_TEXTURE_2D);

    for (i = 0; i < ARRAY_SIZE(texture); ++i) {
        glGenTextures(1, &texture[i].id);
        texture[i].color = -1;
        texture[i].user = NONE;
        glBindTexture(GL_TEXTURE_2D, texture[i].id);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
        GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
        GL_NEAREST);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height,
        0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    }
    texture[0].user = DRAW;
    texture[1].user = LOAD;

    pthread_mutex_init(&mutex, NULL);

    pthread_create(&draw_thread, NULL, draw_func, NULL);
    pthread_create(&load_thread, NULL, load_func, NULL);

    ret = pthread_join(draw_thread, &draw_ret);
    assert(ret == 0);
    ret = pthread_join(load_thread, &load_ret);
    assert(ret == 0);

    pthread_mutex_destroy(&mutex);

    glXDestroyContext(dpy, load_ctx);
    glXDestroyContext(dpy, draw_ctx);
    glXDestroyContext(dpy, my_ctx);

    return draw_ret && load_ret ? PIGLIT_PASS : PIGLIT_FAIL;
}
예제 #10
0
int
main(int argc, char **argv)
{
	Pixmap p;
	GLXPixmap g;
	GLXContext ctx;

	dpy = XOpenDisplay(NULL);
	if (dpy == NULL) {
		fprintf(stderr, "couldn't open display\n");
		piglit_report_result(PIGLIT_FAIL);
	}

        piglit_glx_get_error(dpy, NULL);
	piglit_require_glx_version(dpy, 1, 3);

	visinfo = piglit_get_glx_visual(dpy);
	p = XCreatePixmap(dpy, DefaultRootWindow(dpy), piglit_width,
			  piglit_height, visinfo->depth);

	g = glXCreateGLXPixmap(dpy, visinfo, p);

	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, g, ctx);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	/* Clear to green */
	glClearColor(0.0, 1.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Noop */
	XSetErrorHandler(handler);
	glXSwapBuffers(dpy, p);

	/* We want to actually catch any X error that leaks through as
	 * a result of glXSwapBuffers() before we go saying "pass" or
	 * "fail".
	 */
	XSync(dpy, False);

	glXDestroyPixmap(dpy, g);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);

	return 0;
}
static void *
thread_func(void *arg)
{
	Display *dpy;
	XVisualInfo *visinfo;
	Window win;
	unsigned i;

	dpy = piglit_get_glx_display();
	visinfo = piglit_get_glx_visual(dpy);
	win = piglit_get_glx_window(dpy, visinfo);

	for (i = 0; i < 100; ++i) {
		GLXContext ctx;
		GLuint vert_shader, frag_shader;
		GLuint program;

		ctx = piglit_get_glx_context(dpy, visinfo);
		glXMakeCurrent(dpy, win, ctx);

		/* Ok, not nice but should be safe due to all threads working
		 * on the same type of context.
                 */
		pthread_mutex_lock(&mutex);
		piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
		pthread_mutex_unlock(&mutex);

		vert_shader = piglit_compile_shader_text(GL_VERTEX_SHADER, vert_shader_text);
		piglit_check_gl_error(GL_NO_ERROR);

		frag_shader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag_shader_text);
		piglit_check_gl_error(GL_NO_ERROR);

		program = piglit_link_simple_program(vert_shader, frag_shader);
		piglit_check_gl_error(GL_NO_ERROR);

		glUseProgram(program);
		piglit_check_gl_error(GL_NO_ERROR);

		glXDestroyContext(dpy, ctx);
	}

	return NULL;
}
예제 #12
0
enum piglit_result
draw(Display *dpy)
{
	GLboolean pass = GL_TRUE;
	float green[] = {0.0, 1.0, 0.0, 0.0};
	pthread_t thread1, thread2;
	void *retval;
	int ret;
	int x1 = 10, x2 = 30;
	GLXContext ctx;

	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, win, ctx);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	/* Clear background to gray */
	glClearColor(0.5, 0.5, 0.5, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glFinish();

	pthread_mutex_init(&mutex, NULL);
	/* Now, spawn some threads that do some drawing, both with this
	 * context
	 */
	pthread_create(&thread1, NULL, thread_func, &x1);
	pthread_create(&thread2, NULL, thread_func, &x2);

	ret = pthread_join(thread1, &retval);
	assert(ret == 0);
	ret = pthread_join(thread2, &retval);
	assert(ret == 0);

	pthread_mutex_destroy(&mutex);

	pass &= piglit_probe_pixel_rgb(15, 15, green);
	pass &= piglit_probe_pixel_rgb(35, 15, green);

	glXSwapBuffers(dpy, win);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
int
main(int argc, char **argv)
{
	XVisualInfo *visinfo;
	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_FAIL);
	}
	visinfo = piglit_get_glx_visual(dpy);

	win = piglit_get_glx_window(dpy, visinfo);
	XMapWindow(dpy, win);

	for (i = 0; i < num_contexts; i++) {
		ctx[i] = piglit_get_glx_context(dpy, visinfo);
	}

	glXMakeCurrent(dpy, win, ctx[0]);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	piglit_glx_event_loop(dpy, draw);

	XFree(visinfo);
	glXDestroyWindow(dpy, win);
	for (i = 0; i < num_contexts; i++) {
		glXDestroyContext(dpy, ctx[i]);
	}

	return 0;
}
예제 #14
0
enum piglit_result
draw(Display *dpy)
{
	GLXContext ctx;
	GLboolean pass = GL_TRUE;
	static float red[]   = {1.0, 0.0, 0.0, 0.0};
	static float green[] = {0.0, 1.0, 0.0, 0.0};

	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, win_one, ctx);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	glClearColor(1.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glXSwapBuffers(dpy, win_one);

	glClearColor(0.0, 1.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	CopySubBuffer(dpy, win_one,
		      piglit_width / 4,
		      piglit_height / 4,
		      piglit_width / 2,
		      piglit_height / 2);

	glReadBuffer(GL_FRONT);

	pass &= piglit_probe_rect_rgb(0, 0, piglit_width / 4, piglit_height / 4,
				      red);
	pass &= piglit_probe_rect_rgb(piglit_width / 4, piglit_width / 4,
				      piglit_width / 2, piglit_height / 2,
				      green);

	glXMakeCurrent(dpy, None, NULL);
	glXDestroyContext(dpy, ctx);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
예제 #15
0
int
main(int argc, char **argv)
{
   Display *dpy;
   XVisualInfo *visinfo;
   int i;

   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-auto") == 0) {
         piglit_automatic = 1;
         break;
      }
   }

   dpy = XOpenDisplay(NULL);
   if (!dpy) {
      fprintf(stderr, "Failed to open display\n");
      piglit_report_result(PIGLIT_FAIL);
   }

   visinfo = piglit_get_glx_visual(dpy);
   Windows[0] = piglit_get_glx_window(dpy, visinfo);
   Windows[1] = piglit_get_glx_window(dpy, visinfo);

   XMapWindow(dpy, Windows[0]);
   XMapWindow(dpy, Windows[1]);

   ctx = piglit_get_glx_context(dpy, visinfo);

   glXMakeCurrent(dpy, Windows[0], ctx);
   piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

   piglit_glx_event_loop(dpy, draw);

   return 0;
}
void
piglit_init(int argc, char **argv)
{
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
}
예제 #17
0
int main(int argc, char **argv)
{
	static const int attribs[] = {
		GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
		None
	};
	GLXContext ctx;
	const char *version_string;
	int major;
	int minor;

	GLX_ARB_create_context_setup();

	/* The GLX_ARB_create_context spec says:
	 *
	 *     "The default values for GLX_CONTEXT_MAJOR_VERSION_ARB and
	 *     GLX_CONTEXT_MINOR_VERSION_ARB are 1 and 0 respectively. In this
	 *     case, implementations will typically return the most recent
	 *     version of OpenGL they support which is backwards compatible
	 *     with OpenGL 1.0 (e.g. 3.0, 3.1 + GL_ARB_compatibility, or 3.2
	 *     compatibility profile)."
	 *
	 * Request an OpenGL 2.0 context by explicitly setting the major
	 * version to 2 and leaving the major version at the default value of
	 * 0.  The Linux OpenGL ABI only requires OpenGL 1.2, so this might
	 * fail to create a context.
	 */
	ctx = glXCreateContextAttribsARB(dpy, fbconfig, NULL, True, attribs);
	if (ctx == NULL) {
		printf("Unable to create an OpenGL 2.0 context.\n");
		goto done;
	}

	glXMakeContextCurrent(dpy, glxWin, glxWin, ctx);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	version_string = (char *) glGetString(GL_VERSION);

	if (!parse_version_string(version_string, &major, &minor)) {
		fprintf(stderr,
			"Unable to parse GL version string: %s\n",
			version_string);
		piglit_report_result(PIGLIT_FAIL);
	}

	if (major < 2 || (major == 2 && minor < 0)) {
		fprintf(stderr,
			"GL version too low: %s\n"
			"Expected 2.0 or greater.\n",
			version_string);
		piglit_report_result(PIGLIT_FAIL);
	}

	glXMakeContextCurrent(dpy, None, None, None);
	glXDestroyContext(dpy, ctx);

done:
	GLX_ARB_create_context_teardown();

	piglit_report_result(PIGLIT_PASS);
	return 0;
}
예제 #18
0
static bool
make_context_current_singlepass(struct piglit_wfl_framework *wfl_fw,
                                const struct piglit_gl_test_config *test_config,
                                enum context_flavor flavor,
                                const int32_t partial_config_attrib_list[])
{
	bool ok;
	int32_t *attrib_list = NULL;
	char ctx_desc[1024];

	assert(wfl_fw->config == NULL);
	assert(wfl_fw->context == NULL);
	assert(wfl_fw->window == NULL);

	parse_test_config(test_config, flavor, ctx_desc, sizeof(ctx_desc),
			  partial_config_attrib_list, &attrib_list);
	assert(attrib_list);
	wfl_fw->config = waffle_config_choose(wfl_fw->display, attrib_list);
	free(attrib_list);
	if (!wfl_fw->config) {
		wfl_log_error("waffle_config_choose");
		fprintf(stderr, "piglit: error: Failed to create "
			"waffle_config for %s\n", ctx_desc);
		goto fail;
	}

	wfl_fw->context = waffle_context_create(wfl_fw->config, NULL);
	if (!wfl_fw->context) {
		wfl_log_error("waffle_context_create");
		fprintf(stderr, "piglit: error: Failed to create "
			"waffle_context for %s\n", ctx_desc);
		goto fail;
	}

	wfl_fw->window = wfl_checked_window_create(wfl_fw->config,
	                                           test_config->window_width,
	                                           test_config->window_height);

	wfl_checked_make_current(wfl_fw->display,
	                         wfl_fw->window,
	                         wfl_fw->context);

#ifdef PIGLIT_USE_OPENGL
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
#elif defined(PIGLIT_USE_OPENGL_ES1)
	piglit_dispatch_default_init(PIGLIT_DISPATCH_ES1);
#elif defined(PIGLIT_USE_OPENGL_ES2) || defined(PIGLIT_USE_OPENGL_ES3)
	piglit_dispatch_default_init(PIGLIT_DISPATCH_ES2);
#else
#	error
#endif

	ok = check_gl_version(test_config, flavor, ctx_desc);
	if (!ok)
	   goto fail;

	ok = special_case_gl31(wfl_fw, test_config, flavor, ctx_desc,
			       partial_config_attrib_list);
	if (!ok)
		goto fail;

	return true;

fail:
	waffle_make_current(wfl_fw->display, NULL, NULL);
	waffle_window_destroy(wfl_fw->window);
	waffle_context_destroy(wfl_fw->context);
	waffle_config_destroy(wfl_fw->config);

	wfl_fw->window = NULL;
	wfl_fw->context = NULL;
	wfl_fw->config = NULL;

	piglit_gl_reinitialize_extensions();

	return false;
}
예제 #19
0
static void
try_debug_flag(EGLenum context_api, EGLenum context_bit)
{
	GLint actual_flags = 0;
	piglit_dispatch_api dispatch_api;

	EGLint attribs[64];
	int i = 0;

	if (!EGL_KHR_create_context_setup(context_bit))
		piglit_report_result(PIGLIT_SKIP);

	if (!piglit_egl_bind_api(context_api))
		piglit_report_result(PIGLIT_SKIP);

        attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
        attribs[i++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;

        switch (context_bit) {
        case EGL_OPENGL_BIT:
           break;
        case EGL_OPENGL_ES_BIT:
              attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
              attribs[i++] = 1;
              break;
        case EGL_OPENGL_ES2_BIT:
              attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
              attribs[i++] = 2;
              break;
        case EGL_OPENGL_ES3_BIT_KHR:
           attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
           attribs[i++] = 3;
           break;
        default:
           assert(0);
           break;
        }

        attribs[i++] = EGL_NONE;

	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);
	if (!ctx) {
		if (piglit_check_egl_error(EGL_BAD_MATCH)) {
			piglit_report_result(PIGLIT_SKIP);
		} else {
			piglit_report_result(PIGLIT_FAIL);
		}
	}

	if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx)) {
		fprintf(stderr, "eglMakeCurrent() failed\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	switch (context_bit) {
	case EGL_OPENGL_BIT:
		dispatch_api = PIGLIT_DISPATCH_GL;
		break;
	case EGL_OPENGL_ES_BIT:
		/* Piglit doesn't yet have ES1 dispatch, so just initialize
		 * with ES2 dispatch. This should be safe because the only
		 * GL functions called by this test are glGetString() and
		 * glGetIntegerv().
		 */
		dispatch_api = PIGLIT_DISPATCH_ES2;
		break;
	case EGL_OPENGL_ES2_BIT:
	case EGL_OPENGL_ES3_BIT_KHR:
		dispatch_api = PIGLIT_DISPATCH_ES2;
		break;
	default:
		dispatch_api = 0;
		assert(0);
		break;
	}

	piglit_dispatch_default_init(dispatch_api);

	switch (context_bit) {
	case EGL_OPENGL_BIT:
		if (piglit_get_gl_version() < 31 &&
		    !piglit_is_extension_supported("GL_KHR_debug")) {
			fprintf(stderr, "In OpenGL, either OpenGL 3.1 or "
				"GL_KHR_debug is required to query "
				"GL_CONTEXT_FLAGS\n");
			piglit_report_result(PIGLIT_SKIP);
		}
		break;
	case EGL_OPENGL_ES_BIT:
	case EGL_OPENGL_ES2_BIT:
	case EGL_OPENGL_ES3_BIT_KHR:
		if (!piglit_is_extension_supported("GL_KHR_debug")) {
			fprintf(stderr, "In OpenGL ES, GL_KHR_debug is "
				"required to query GL_CONTEXT_FLAGS\n");
			piglit_report_result(PIGLIT_SKIP);
		}
		break;
	default:
		assert(0);
		break;
	}

	glGetIntegerv(GL_CONTEXT_FLAGS, &actual_flags);

	if (!piglit_check_gl_error(GL_NO_ERROR)) {
		fprintf(stderr, "glGetIntegerv(GL_CONTEXT_FLAGS) failed\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	/* Verify that this is actually a debug context. */
	if (!(actual_flags & GL_CONTEXT_FLAG_DEBUG_BIT)) {
		fprintf(stderr,
			"GL_CONTEXT_FLAGS=0x%x does not contain "
			"GL_CONTEXT_FLAG_DEBUG_BIT=0x%x\n",
			actual_flags, GL_CONTEXT_FLAG_DEBUG_BIT);
		piglit_report_result(PIGLIT_FAIL);
	}

	eglDestroyContext(egl_dpy, ctx);
	EGL_KHR_create_context_teardown();

	piglit_report_result(PIGLIT_PASS);
}
static void
init_glut(void)
{
	const struct piglit_gl_test_config *test_config = glut_fw.gl_fw.test_config;
	char *argv[] = {"piglit"};
	int argc = 1;
	unsigned flags = GLUT_RGB;

	if (test_config->window_visual & PIGLIT_GL_VISUAL_RGBA)
		flags |= GLUT_ALPHA;
	if (test_config->window_visual & PIGLIT_GL_VISUAL_DEPTH)
		flags |= GLUT_DEPTH;
	if (test_config->window_visual & PIGLIT_GL_VISUAL_STENCIL)
		flags |= GLUT_STENCIL;
	if (test_config->window_visual & PIGLIT_GL_VISUAL_ACCUM)
		flags |= GLUT_ACCUM;

	if (test_config->window_visual & PIGLIT_GL_VISUAL_DOUBLE)
		flags |= GLUT_DOUBLE;
	else
		flags |= GLUT_SINGLE;

	/*
	 * MacOSX GLUT.
	 *
	 * This will request a core profile.  It will always return the highest
	 * version supported.
	 *
	 * See:
	 * /System/Library/Frameworks/GLUT.framework/Headers/glut.h
	 * https://developer.apple.com/opengl/capabilities/
	 */
#if GLUT_MACOSX_IMPLEMENTATION >= 4
	if (test_config->supports_gl_core_version >= 31) {
		flags |= GLUT_3_2_CORE_PROFILE;
	}
#endif

	glutInit(&argc, argv);
	glutInitWindowPosition(0, 0);
	glutInitWindowSize(test_config->window_width,
	                   test_config->window_height);
	glutInitDisplayMode(flags);

	/*
	 * FreeGLUT
	 */
#ifdef PIGLIT_USE_GLUT_INIT_ERROR_FUNC
	glutInitErrorFunc(error_func);
#else
	(void)error_func;
#endif
#ifdef GLUT_CORE_PROFILE
	if (test_config->supports_gl_core_version) {
		glutInitContextVersion(test_config->supports_gl_core_version / 10,
				       test_config->supports_gl_core_version % 10);
		if (test_config->supports_gl_core_version >= 32) {
			glutInitContextProfile(GLUT_CORE_PROFILE);
		}
	} else {
		glutInitContextVersion(test_config->supports_gl_compat_version / 10,
				       test_config->supports_gl_compat_version % 10);
		if (test_config->supports_gl_compat_version >= 32) {
			glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);
		}
	}

	int context_flags = 0;
	/* There are no 3.1 core profiles -- the closest is 3.1 context without
	 * ARB_compatibility or a 3.2 core context --, and setting
	 * forward-compatible flag should ensure we don't get a 3.1 context w/
	 * ARB_compatibility.
	 */
	if (test_config->require_forward_compatible_context ||
	    test_config->supports_gl_core_version == 31) {
		context_flags |= GLUT_FORWARD_COMPATIBLE;
	}
	if (test_config->require_debug_context) {
		context_flags |= GLUT_DEBUG;
	}
	if (context_flags) {
		glutInitContextFlags(context_flags);
	}
#endif

	glut_fw.window = glutCreateWindow("Piglit");

	glutDisplayFunc(display);
	glutReshapeFunc(default_reshape_func);
	glutKeyboardFunc(piglit_escape_exit_key);

#ifdef PIGLIT_USE_OPENGL
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
#endif
}
예제 #21
0
int
main(int argc, char **argv)
{
    Pixmap p;
    GLXPixmap g;
    static const float green_alpha_zero[4] = {0.0, 1.0, 0.0, 0.0};
    static const float green_alpha_one[4] = {0.0, 1.0, 0.0, 1.0};
    GLXContext ctx;
    bool pass;
    GLint alpha_bits;

    dpy = XOpenDisplay(NULL);
    if (dpy == NULL) {
        fprintf(stderr, "couldn't open display\n");
        piglit_report_result(PIGLIT_FAIL);
    }

    piglit_glx_get_error(dpy, NULL);
    piglit_require_glx_version(dpy, 1, 3);

    visinfo = piglit_get_glx_visual(dpy);
    p = XCreatePixmap(dpy, DefaultRootWindow(dpy), piglit_width,
                      piglit_height, visinfo->depth);

    g = glXCreateGLXPixmap(dpy, visinfo, p);

    ctx = piglit_get_glx_context(dpy, visinfo);
    glXMakeCurrent(dpy, g, ctx);
    piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

    /* Clear to green */
    glClearColor(0.0, 1.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);

    /* Noop */
    glXSwapBuffers(dpy, g);

    /* We want to actually catch any X error that leaks through as
     * a result of glXSwapBuffers() before we go saying "pass" or
     * "fail".
     */
    XSync(dpy, False);

    /* If the visual has no alpha, then the GL spec requires that 1.0 be
     * read back.  Otherwise, we should read back the 0.0 that we wrote.
     */
    glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
    if (alpha_bits == 0) {
        pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
                                      green_alpha_one);
    } else {
        pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
                                      green_alpha_zero);
    }

    glXDestroyPixmap(dpy, g);

    piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);

    return 0;
}
int main(int argc, char **argv)
{
	EGLint attribs[] = {
		EGL_CONTEXT_MAJOR_VERSION_KHR, 2,
		EGL_NONE
	};
	const char *version_string;
	int major;
	int minor;

	if (!EGL_KHR_create_context_setup(EGL_OPENGL_BIT)) {
		fprintf(stderr, "Desktop GL not available.\n");
		piglit_report_result(PIGLIT_SKIP);
	}
	eglBindAPI(EGL_OPENGL_API);

	/* The EGL_KHR_create_context spec says:
	 *
	 *    "Typically, the implementation will return the most recent
	 *     version of OpenGL it supports which is backwards compatible
	 *     with the requested version."
	 *
	 *     "The default values for EGL_CONTEXT_MAJOR_VERSION_KHR and
	 *     EGL_CONTEXT_MINOR_VERSION_KHR are 1 and 0 respectively."
	 *
	 * Request an OpenGL 2.0 context by explicitly setting the major
	 * version to 2 and leaving the major version at the default value of
	 * 0.  The Linux OpenGL ABI only requires OpenGL 1.2, so this might
	 * fail to create a context.
	 */
	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);
	if (ctx == EGL_NO_CONTEXT) {
		fprintf(stderr, "eglCreateContext() failed with "
				"EGL_CONTEXT_MAJOR_VERSION_KHR=%d. skipping "
				"test.\n", attribs[1]);
		piglit_report_result(PIGLIT_SKIP);
	}

	if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx)) {
		fprintf(stderr, "eglMakeCurrent() failed\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	version_string = (char *) glGetString(GL_VERSION);

	if (!parse_version_string(version_string, &major, &minor)) {
		fprintf(stderr,
			"Unable to parse GL version string: %s\n",
			version_string);
		piglit_report_result(PIGLIT_FAIL);
	}

	if ((major == 2 && (minor < 0 || minor > 1)) ||
	    (major == 3 && (minor != 0)) ||
	    (major < 2 || major > 3)) {
		fprintf(stderr,
			"Unexpected GL version: %s\n"
			"Expected GL 2.0, 2.1, or 3.0.\n",
			version_string);
		piglit_report_result(PIGLIT_FAIL);
	}

	eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
	eglDestroyContext(egl_dpy, ctx);

	EGL_KHR_create_context_teardown();

	piglit_report_result(PIGLIT_PASS);

	return EXIT_SUCCESS;
}
예제 #23
0
static enum piglit_result
check_flavor(int requested_version, enum gl_api requested_api)
{
	static bool is_dispatch_init = false;

	enum piglit_result result = PIGLIT_PASS;
	int i;

	const char *api_name = NULL;
	const char *profile_name = "";

	EGLint context_attribs[64];
	EGLContext ctx = 0;

	EGLenum requested_client_type = 0;
	EGLint actual_client_type = 0;
	int actual_version = 0;
	GLint actual_profile = 0;

	switch (requested_api) {
	case API_GL_COMPAT:
		requested_client_type = EGL_OPENGL_API;
		api_name = "OpenGL";
		if (requested_version >= 32)
			profile_name = "compatibility ";
		break;
	case API_GL_CORE:
		requested_client_type = EGL_OPENGL_API;
		api_name = "OpenGL";
		if (requested_version >= 32)
			profile_name = "core ";
		break;
	case API_GLES1:
	case API_GLES2:
	case API_GLES3:
		requested_client_type = EGL_OPENGL_ES_API;
		api_name = "OpenGL ES";
		break;
	default:
		assert(0);
		break;
	}

	printf("info: request an %s %d.%d %scontext\n",
	       api_name,
	       requested_version / 10,
	       requested_version % 10,
	       profile_name);

	if (!eglBindAPI(requested_client_type)) {
		/* Assume the driver doesn't support the requested API. */
		result = PIGLIT_SKIP;
		goto cleanup;
	}

	i = 0;
	context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
	context_attribs[i++] = requested_version / 10;
	context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR;
	context_attribs[i++] = requested_version % 10;
	if (requested_api == API_GL_CORE) {
		context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
		context_attribs[i++] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
	} else if (requested_api == API_GL_COMPAT) {
		context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
		context_attribs[i++] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
	}
	context_attribs[i++] = EGL_NONE;

	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, context_attribs);

	if (ctx == NULL) {
		printf("%s", "info: context creation failed\n");
		if (eglGetError() != EGL_SUCCESS) {
			result = PIGLIT_SKIP;
		} else {
			printf("%s", "error: eglCreateContext failed but "
			       "the EGL error is EGL_SUCCESS\n");
			result = PIGLIT_FAIL;
		}

		goto cleanup;
	}

	if (!piglit_check_egl_error(EGL_SUCCESS)) {
		result = PIGLIT_FAIL;
		goto cleanup;
	}

	if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE,
			    EGL_NO_SURFACE, ctx)) {
		printf("%s", "error: failed to make context current\n");
		goto fail;
	}

	if (!is_dispatch_init) {
		/* We must postpone initialization of piglit-dispatch until
		 * a context is current.
		 */
		piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
		is_dispatch_init = true;
	}

	if (!eglQueryContext(egl_dpy, ctx,
			     EGL_CONTEXT_CLIENT_TYPE, &actual_client_type)) {
		printf("%s", "error: eglQueryContext(EGL_CONTEXT_CLIENT_TYPE) "
		       "failed\n");
		goto fail;
	}

	if (actual_client_type != requested_client_type) {
		printf("error: requested a context with EGL_CONTEXT_CLIENT_TYPE=0x%x "
		       "but received one with EGL_CONTEXT_CLIENT_TYPE=0x%x.\n",
		       requested_client_type,
		       actual_client_type);
		goto fail;
	}

	actual_version = get_gl_version();

	if (actual_version < requested_version) {
		printf("error: requested context version %d.%d but received "
		       "version %d.%d\n",
		       requested_version / 10, requested_version % 10,
		       actual_version / 10, actual_version % 10);
		goto fail;
	}

	if (requested_api == API_GL_CORE ||
	    (requested_api == API_GL_COMPAT && requested_version >= 32)) {
		my_glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &actual_profile);
		if (!piglit_check_gl_error(GL_NO_ERROR)) {
			printf("%s", "error: glGetIntegerv(GL_CONTEXT_PROFILE_MASK)"
			       "failed\n");
			goto fail;
		}
	}

	if (requested_api == API_GL_CORE) {
		assert(requested_version >= 32);
		if (actual_profile != EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) {
			printf("error: requested an OpenGL %d.%d core context, "
			       "but received a context whose profile "
			       "mask is 0x%x.\n",
			       requested_version / 10, requested_version % 10,
			       actual_profile);
			goto fail;
		}
	} else if (requested_api == API_GL_COMPAT && requested_version >= 32) {
		if (actual_profile != EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR) {
			printf("error: requested an OpenGL %d.%d compatibility context, "
			       "but received a context whose profile "
			       "mask is 0x%x.\n",
			       requested_version / 10, requested_version % 10,
			       actual_profile);
			goto fail;
		}
	} else if (requested_api == API_GLES1) {
		if (actual_version > 11) {
			printf("error: requested an OpenGL ES %d.%d context, "
			       "but received %d.%d context.\n",
			       requested_version / 10, requested_version % 10,
			       actual_version / 10, actual_version % 10);
			goto fail;
		}
	} else if (requested_api == API_GLES2) {
		/* Nothing special to check. */
	}

	result = PIGLIT_PASS;
	goto cleanup;

fail:
	result = PIGLIT_FAIL;
	goto cleanup;

cleanup:
	/* We must unbind the context here due to a subtle requirement in the
	 * EGL 1.4 spec published on 2011-04-06. The call to eglMakeCurrent at
	 * the top of this function may attempt to bind a context whose api
	 * differs from the api of the current context. Yet, according to the
	 * EGL spec, it is illegal to bind a GL context to a surface if an ES
	 * context is currently bound to it, and vice versa.
	 *
	 * A future revision of the EGL 1.4 spec will fix this non-intuitive
	 * requirement.
	 */
	if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
			    EGL_NO_CONTEXT)) {
		printf("%s", "error: failed to unbind any current context\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	switch (result) {
	case PIGLIT_PASS:
		printf("%s", "info: pass\n");
		break;
	case PIGLIT_FAIL:
		printf("%s", "info: fail\n");
		break;
	case PIGLIT_SKIP:
		printf("%s", "info: skip\n");
		break;
	case PIGLIT_WARN:
	default:
		assert(0);
		break;
	}

	return result;
}
예제 #24
0
int main(int argc, char **argv)
{
	EGLint attribs[] = {
		EGL_CONTEXT_MAJOR_VERSION_KHR, 1,
		EGL_NONE
	};
	const char *version_string;
	int major;
	int minor;

	if (!EGL_KHR_create_context_setup(EGL_OPENGL_ES_BIT)) {
		attribs[1] = 2;
		if (!EGL_KHR_create_context_setup(EGL_OPENGL_ES2_BIT)) {
			fprintf(stderr, "ES 2 not available.\n");
			piglit_report_result(PIGLIT_SKIP);
		}
	}

	/* The EGL_KHR_create_context spec says:
	 *
	 *     "The default values for EGL_CONTEXT_MAJOR_VERSION_KHR and
	 *     EGL_CONTEXT_MINOR_VERSION_KHR are 1 and 0 respectively."
	 *
	 * Request an OpenGL ES 1.x or 2.0 context by explicitly setting the
	 * major version and leaving the minor version at the default value of
	 * 0.
	 *
	 * The EGLConfig's EGL_RENDERABLE_TYPE and the attribute list's
	 * EGL_CONTEXT_MAJOR_VERSION_KHR have been chosen so that the driver
	 * is required to succeed at context creation.
	 */
	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);
	if (ctx == EGL_NO_CONTEXT) {
		fprintf(stderr, "eglCreateContext() failed\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx)) {
		fprintf(stderr, "eglMakeCurrent() failed\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	if (attribs[1] == 1) {
		/* FINISHME: Use PIGLIT_DISPATCH_ES1 when implemented. */
		piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
	} else if (attribs[1] == 2) {
		piglit_dispatch_default_init(PIGLIT_DISPATCH_ES2);
	}

	version_string = (char *) glGetString(GL_VERSION);

	if (!parse_version_string(version_string, &major, &minor)) {
		fprintf(stderr,
			"Unable to parse GL version string: %s\n",
			version_string);
		piglit_report_result(PIGLIT_FAIL);
	}

	if (!version_is_valid_for_context(attribs[1], major, minor)) {
		fprintf(stderr,
			"Unexpected GLES version: %s\n"
			"Expected ES %s.\n",
			version_string,
			attribs[1] == 1 ? "1.0 or 1.1" : "2.0 or 3.0");
		piglit_report_result(PIGLIT_FAIL);
	}

	eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
	eglDestroyContext(egl_dpy, ctx);

	EGL_KHR_create_context_teardown();

	piglit_report_result(PIGLIT_PASS);

	return EXIT_SUCCESS;
}
void
piglit_init(int argc, char **argv)
{
	piglit_require_extension("GL_ARB_direct_state_access");
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
}
예제 #26
0
int main(int argc, char**argv)
{
	XVisualInfo *visinfo;
	GLXContext ctx;
	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_FAIL);
	}

	visinfo = piglit_get_glx_visual(dpy);
	ctx = piglit_get_glx_context(dpy, visinfo);
	win = piglit_get_glx_window(dpy, visinfo);
	XFree(visinfo);

	glXMakeCurrent(dpy, win, ctx);

	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	if (piglit_automatic)
		piglit_glx_set_no_input();

	XMapWindow(dpy, win);

	piglit_require_glx_extension(dpy, "GLX_EXT_texture_from_pixmap");
	if (!piglit_is_extension_supported("GL_ARB_texture_env_combine")) {
		fprintf(stderr, "Test requires GL_ARB_texture_env_combine\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	pglXBindTexImageEXT = (PFNGLXBINDTEXIMAGEEXTPROC)
		glXGetProcAddress((GLubyte *)"glXBindTexImageEXT");
	pglXReleaseTexImageEXT = (PFNGLXRELEASETEXIMAGEEXTPROC)
		glXGetProcAddress((GLubyte *)"glXReleaseTexImageEXT");
	if (pglXBindTexImageEXT == NULL || pglXReleaseTexImageEXT == NULL) {
		fprintf(stderr, "Couldn't get TFP functions\n");
		piglit_report_result(PIGLIT_FAIL);
		exit(1);
	}

	init();

	if (!piglit_automatic) {
		printf("Left rectangle (RGB) should be green on the top and\n"
		       "red on the bottom.  The right rectangle (RGBA) should\n"
		       "be the same, but darker on the right half.\n");
		printf("Press Escape to quit\n");
	}

	piglit_glx_event_loop(dpy, draw);

	return 0;
}
예제 #27
0
/**
 * Create OpenGL ES 2.0 context, make it current, and verify that it supports
 * GL_OES_EGL_sync.
 */
static enum piglit_result
init_context(EGLDisplay dpy, EGLContext *out_ctx)
{
	enum piglit_result result = PIGLIT_PASS;
	bool ok = false;
	EGLConfig config = 0;
	EGLint num_configs = 0;
	EGLContext ctx = 0;

	/* Create OpenGL ES 2.0 or backwards-compatible context. */
	static const EGLint config_attribs[] = {
		EGL_RED_SIZE,		EGL_DONT_CARE,
		EGL_GREEN_SIZE,		EGL_DONT_CARE,
		EGL_BLUE_SIZE,		EGL_DONT_CARE,
		EGL_ALPHA_SIZE,		EGL_DONT_CARE,
		EGL_DEPTH_SIZE, 	EGL_DONT_CARE,
		EGL_STENCIL_SIZE, 	EGL_DONT_CARE,
		EGL_RENDERABLE_TYPE, 	EGL_OPENGL_ES2_BIT
				        | EGL_OPENGL_ES3_BIT_KHR,
		EGL_NONE,
	};

	static const EGLint context_attribs[] = {
		EGL_CONTEXT_CLIENT_VERSION, 2,
		EGL_NONE,
	};

	ok = eglChooseConfig(dpy, config_attribs, &config, 1,
			     &num_configs);
	if (!ok || !config || num_configs == 0) {
		EGLint egl_error = eglGetError();
		piglit_loge("failed to get EGLConfig: %s(0x%x)",
			  piglit_get_egl_error_name(egl_error), egl_error);
		result = PIGLIT_SKIP;
		goto error;
	}

	ok = piglit_egl_bind_api(EGL_OPENGL_ES_API);
	if (!ok) {
		piglit_loge("failed to bind EGL_OPENGL_ES_API");
		result = PIGLIT_FAIL;
		goto error;

	}

	ctx = eglCreateContext(dpy, config, EGL_NO_CONTEXT, context_attribs);
	if (!ctx) {
		EGLint egl_error = eglGetError();
		piglit_loge("failed to create EGLContext: %s(0x%x)",
			  piglit_get_egl_error_name(egl_error), egl_error);
		result = PIGLIT_FAIL;
		goto error;
	}

	ok = eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
	if (!ok) {
		/* Skip, don't fail. Assume the context doesn't support
		 * GL_OES_surfaceless_context or equivalent.
		 */
		piglit_loge("failed to make context current without surface");
		result = PIGLIT_SKIP;
		goto error;
	}

	piglit_dispatch_default_init(PIGLIT_DISPATCH_ES2);

	/* From the EGL_KHR_fence_sync spec:
	 *
	 *     Each client API which supports fence commands indicates this
	 *     support in the form of a client API extension. If the
	 *     GL_OES_EGL_sync extension is supported by OpenGL ES (either
	 *     version 1.x or 2.0), a fence sync object may be created when the
	 *     currently bound API is OpenGL ES.
	 */
	if (!piglit_is_extension_supported("GL_OES_EGL_sync")) {
		piglit_loge("context does not support GL_OES_EGL_sync; "
			  "skipping test");
		result = PIGLIT_SKIP;
		goto error;
	}

	*out_ctx = ctx;
	return result;

error:
	if (ctx) {
		eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
			       EGL_NO_CONTEXT);
		eglDestroyContext(dpy, ctx);
	}
	return result;
}
예제 #28
0
static bool
init_gl(struct piglit_wfl_framework *wfl_fw)
{
#ifdef PIGLIT_USE_OPENGL_ES1
	return false;
#else
	const struct piglit_gl_test_config *test_config = wfl_fw->gl_fw.test_config;

	GLuint tex, depth = 0;
	GLenum status;

#ifdef PIGLIT_USE_OPENGL
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	if (piglit_get_gl_version() < 20)
		return false;
#endif

	glGenFramebuffers(1, &piglit_winsys_fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
		     piglit_width, piglit_height, 0,
		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glFramebufferTexture2D(GL_FRAMEBUFFER,
			       GL_COLOR_ATTACHMENT0,
			       GL_TEXTURE_2D,
			       tex,
			       0);

	if (test_config->window_visual & (PIGLIT_GL_VISUAL_DEPTH |
					  PIGLIT_GL_VISUAL_STENCIL)) {
		/* Create a combined depth+stencil texture and attach it
		 * to the depth and stencil attachment points.
		 */
		glGenTextures(1, &depth);
		glBindTexture(GL_TEXTURE_2D, depth);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL,
			     piglit_width, piglit_height, 0,
			     GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
		glFramebufferTexture2D(GL_FRAMEBUFFER,
				       GL_DEPTH_ATTACHMENT,
				       GL_TEXTURE_2D,
				       depth,
				       0);
		glFramebufferTexture2D(GL_FRAMEBUFFER,
				       GL_STENCIL_ATTACHMENT,
				       GL_TEXTURE_2D,
				       depth,
				       0);
	}

	glBindTexture(GL_TEXTURE_2D, 0);

	status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (status != GL_FRAMEBUFFER_COMPLETE) {
		fprintf(stderr,
			"framebuffer status is incomplete, falling"
			"back to winsys\n");
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glDeleteTextures(1, &depth);
		glDeleteTextures(1, &tex);
		return false;
	}

	return true;
#endif
}