gl_basic: Clean up usage errors

Add new function usage_error_printf() to simply emission of usage
errors.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
core: Fix typo in error message

s/must WAFFLE_NONE/must be WAFFLE_NONE/

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
gl_basic: Replace tabs with spaces

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
gl_basic: Replace positional args with --long-opts

For example,
  gl_basic glx gl 3.2
becomes
  gl_basic --platform=glx --api=gl --version=3.2

To accomplish this, replace handrolled argument parsing with getopt.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
examples: Fix example Makefile to use C99

The Makefile doesn't work with GCC because the example programs require
-std=c99, but GCC defaults to -std=gnu89.
man: Document new attrib WAFFLE_CONTEXT_FORWARD_COMPATIBLE

The new attribute isn't implemented yet, but I like to commit
documentations before implementation. This attribute selects
a foward-compatible context.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
core: Define wcore_enum_to_string()

A later patch needs to translate enums to strings to emit a useful error
message. Since it's bad manners to internally call public API, we need
a private variant of waffle_enum_to_string().

Redefine waffle_enum_to_string() in terms of wcore_enum_to_string().

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
core: Support WAFFLE_CONTEXT_FORWARD_COMPATIBLE

This adds support only to core waffle. That is, this patch makes aware
only wcore_config_attrs_parse() and wcore_enum_to_string().

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
core: Add unittests for WAFFLE_CONTEXT_FORWARD_COMPATIBLE

Add the following unittests.

wcore_config_attrs.forward_compat_gles1_emits_bad_attribute
wcore_config_attrs.forward_compat_gles2_emits_bad_attribute
wcore_config_attrs.forward_compat_gles3_emits_bad_attribute
wcore_config_attrs.forward_compat_gl_emits_bad_attribute
wcore_config_attrs.forward_compat_gl10_emits_bad_attribute
wcore_config_attrs.forward_compat_gl21_emits_bad_attribute
wcore_config_attrs.forward_compat_gl30
wcore_config_attrs.forward_compat_gl32
wcore_config_attrs.forward_compat_gl41
wcore_config_attrs.forward_compat_gl30_dont_care
wcore_config_attrs.forward_compat_gl30_bad_value

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
core: Fix type of wcore_config_attrs::sample_buffers

It should be bool, not int32_t. This fix is needed to prevent the next
patch from breaking the build.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
core: Fix fatal typo s/ACCUM_BUFFERS/ACCUM_BUFFER/

Luckily, the build has not been broken because the typo'd enum name was
used only by the preprocessor's stringify operator (#).

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
core: Refactor how to parse bool config attribs

There exist two codepaths in wcore_config_attrs.c for parsing bool
attributes.  Coalesce them into new function parse_bool().

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
examples/gl_basic: Add support for forward-compatible contexts

Add new command line argument, --forward-compatible. If set and the
created context is not forward-compatible, then gl_basic fails.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
cgl: Handle WAFFLE_CONTEXT_FORWARD_COMPATIBLE

As of 2013-09-16 and up to Mac OS 10.8 Mountain Lion, CGL doesn't allow
creation of forward-compatible contexts. Emit WAFFLE_ERROR_BAD_ATTRIBUTE
if the user requests one.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
glx: Support creation of foward-compatible contexts

If the waffle_config has WAFFLE_CONTEXT_FORWARD_COMPATIBLE=true,
then try to create a forward-compatible GLXContext.

Validated with ``gl_basic --platform=glx --api=gl --version=30
--forward-compatible`` on Mesa 9.3.0-devel (git-24765c5) with Intel
Ivybridge.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
egl: Support creation of foward-compatible contexts

If the waffle_config has WAFFLE_CONTEXT_FORWARD_COMPATIBLE=true,
then try to create a forward-compatible EGLContext.

Validated with ``gl_basic --platform=wayland --api=gl --version=30
--forward-compatible`` on Mesa 9.3.0-devel (git-24765c5).

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
tests/gl_basic: Give gl_basic_draw() a default argument list

By using default function arguments, we avoid updating every call to
gl_basic_draw() when adding new tests. This will make it easier to add
tests for forward-compatible contexts.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
tests/gl_basic: Replace .expect_unsupported with .expect_error

If gl_basic_draw was called with .expect_unsupported=true, then the test
passed only if waffle_config_choose() emitted
WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM. Future tests will need to also
check for WAFFLE_ERROR_BAD_ATTRIBUTE, so let's generalize by replacing
the .expect_unsupported with .expect_error.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
tests/gl_basic: Add tests for forward-compatible contexts

Add the following tests. Tests marked with '*' were verified with
Mesa 9.3.0-devel (git-24765c5).

cgl_gl_fwdcompat_bad_attribute

for platform in [glx, wayland, x11_egl]:
    ${platform}_gl21_fwdcompat_bad_attribute *
    ${platform}_gl30_fwdcompat *
    ${platform}_gl31_fwdcompat *
    ${platform}_gl32_core_fwdcompat
    ${platform}_gles1_fwdcompat_bad_attribute *
    ${platform}_gles2_fwdcompat_bad_attribute *
    ${platform}_gles3_fwdcompat_bad_attribute *

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Merge branch 'forward-compatible-contexts'