summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorChad Versace <chad.versace@linux.intel.com>2013-09-18 20:14:16 -0700
committerChad Versace <chad.versace@linux.intel.com>2013-09-18 23:23:44 -0700
commit3ad77c648b3157d36977d0e7d56dc0c3af14aafb (patch)
treea1f43ffe14adce903088f94a184ad9cd3991bfc4 /examples
parentd6d169fb4a2330182516da2c2f7dfd201b5fd5e7 (diff)
examples/gl_basic: Add option to resize window between colors
Add option --resize-window, which enlargens the window between each draw call. Validated on: - CGL, Mac OS 10.7 - Wayland under Weston Resizing causes the glReadPixels check to fail on GLX and X/EGL under Gnome Shell. This nicely exposes someone's bug, but whose? Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/gl_basic.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/examples/gl_basic.c b/examples/gl_basic.c
index 5812f1c..3c8445a 100644
--- a/examples/gl_basic.c
+++ b/examples/gl_basic.c
@@ -62,6 +62,7 @@ static const char *usage_message =
" [--profile=core|compat|none]\n"
" [--forward-compatible]\n"
" [--debug]\n"
+ " [--resize-window]\n"
"\n"
"examples:\n"
" gl_basic --platform=glx --api=gl\n"
@@ -77,6 +78,9 @@ static const char *usage_message =
"\n"
" --debug\n"
" Create a debug context.\n"
+ "\n"
+ " --resize-window\n"
+ " Resize the window between each draw call.\n"
;
enum {
@@ -86,6 +90,7 @@ enum {
OPT_PROFILE,
OPT_DEBUG,
OPT_FORWARD_COMPATIBLE,
+ OPT_RESIZE_WINDOW,
};
static const struct option get_opts[] = {
@@ -95,6 +100,7 @@ static const struct option get_opts[] = {
{ .name = "profile", .has_arg = required_argument, .val = OPT_PROFILE },
{ .name = "debug", .has_arg = no_argument, .val = OPT_DEBUG },
{ .name = "forward-compatible", .has_arg = no_argument, .val = OPT_FORWARD_COMPATIBLE },
+ { .name = "resize-window", .has_arg = no_argument, .val = OPT_RESIZE_WINDOW },
{ 0 },
};
@@ -188,6 +194,7 @@ static void (*glClear)(GLbitfield mask);
static void (*glGetIntegerv)(GLenum pname, GLint *params);
static void (*glReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid* data);
+static void (*glViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
/// @}
/// @defgroup Parsing Options
@@ -208,6 +215,8 @@ struct options {
bool context_forward_compatible;
bool context_debug;
+ bool resize_window;
+
/// @brief One of `WAFFLE_DL_*`.
int dl;
};
@@ -326,6 +335,9 @@ parse_args(int argc, char *argv[], struct options *opts)
case OPT_DEBUG:
opts->context_debug = true;
break;
+ case OPT_RESIZE_WINDOW:
+ opts->resize_window = true;
+ break;
default:
abort();
loop_get_opt = false;
@@ -365,10 +377,12 @@ error_unrecognized_arg:
/// @}
static bool
-draw(struct waffle_window *window)
+draw(struct waffle_window *window, bool resize)
{
bool ok;
unsigned char *colors;
+ int width = WINDOW_WIDTH;
+ int height = WINDOW_HEIGHT;
static const struct timespec sleep_time = {
// 0.5 sec
@@ -384,27 +398,41 @@ draw(struct waffle_window *window)
case 3: abort(); break;
}
+ if (resize) {
+ width = (i + 2) * 40;
+ height = width;
+ waffle_window_resize(window, width, height);
+ glViewport(0, 0, width, height);
+ }
+
glClear(GL_COLOR_BUFFER_BIT);
- colors = calloc(WINDOW_WIDTH * WINDOW_HEIGHT * 4, sizeof(*colors));
+ colors = calloc(width * height * 4, sizeof(*colors));
glReadPixels(0, 0,
- WINDOW_WIDTH, WINDOW_HEIGHT,
+ width, height,
GL_RGBA, GL_UNSIGNED_BYTE,
colors);
- for (int j = 0; j < WINDOW_WIDTH * WINDOW_HEIGHT * 4; j += 4) {
+ for (int j = 0; j < width * height * 4; j += 4) {
if ((colors[j] != (i == 0 ? 0xff : 0)) ||
(colors[j+1] != (i == 1 ? 0xff : 0)) ||
(colors[j+2] != (i == 2 ? 0xff : 0)) ||
(colors[j+3] != 0xff)) {
- free(colors);
- gl_basic_error("glReadPixels returned unexpected result");
+ fprintf(stderr, "glReadPixels returned unexpected result\n");
+ break;
}
}
free(colors);
+ if (i == 0) {
+ ok = waffle_window_show(window);
+ if (!ok)
+ return false;
+ }
+
ok = waffle_window_swap_buffers(window);
if (!ok)
return false;
+
nanosleep(&sleep_time, NULL);
}
@@ -524,6 +552,10 @@ main(int argc, char **argv)
if (!glReadPixels)
error_get_gl_symbol("glReadPixels");
+ glViewport = waffle_dl_sym(opts.dl, "glViewport");
+ if (!glViewport)
+ error_get_gl_symbol("glViewport");
+
i = 0;
config_attrib_list[i++] = WAFFLE_CONTEXT_API;
config_attrib_list[i++] = opts.context_api;
@@ -572,10 +604,6 @@ main(int argc, char **argv)
if (!window)
error_waffle();
- ok = waffle_window_show(window);
- if (!ok)
- error_waffle();
-
ok = waffle_make_current(dpy, window, ctx);
if (!ok)
error_waffle();
@@ -595,7 +623,7 @@ main(int argc, char **argv)
gl_basic_error("context is not a debug context");
}
- ok = draw(window);
+ ok = draw(window, opts.resize_window);
if (!ok)
error_waffle();