Skip to content

Commit

Permalink
glx: correctly handle ARB_create_context lack/presence
Browse files Browse the repository at this point in the history
Earlier commit loosened the check of ARB_create_context, for OpenGL 3.2 and
earlier.

Although the commit did not fully consider that the extension is required for
 - all context attributes (missing robustness), and
 - GLES* profiles

As a result, any GL robustness or GLES* context would result in a GL one,
w/o the robustness flag, being created.

Update and sync both attribute validation and runtime check.

Issue: waffle-gl/waffle#50
Fixes: e7f0314 ("glx: Don't use ARB_create_context with pre 3.2 contexts")
Cc: Jose Fonseca <[email protected]>
Cc: Chad Versace <[email protected]>
Signed-off-by: Emil Velikov <[email protected]>
  • Loading branch information
evelikov committed Jan 13, 2020
1 parent 1ded029 commit b8a39e6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
45 changes: 26 additions & 19 deletions src/waffle/glx/glx_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,44 @@ glx_config_check_context_attrs(struct glx_display *dpy,
assert(wcore_config_attrs_version_ge(attrs, 30));
}

if (attrs->context_debug && !dpy->ARB_create_context) {
if (!dpy->ARB_create_context &&
glx_context_needs_arb_create_context(attrs)) {
const char *gl = "";
const char *fwd_compat = "";
const char *debug = "";
const char *robust = "";

// XXX: Keep in sync with glx_context_needs_arb_create_context()
if (attrs->context_api != WAFFLE_CONTEXT_OPENGL)
gl = " - a OpenGL ES* context\n";
else if (wcore_config_attrs_version_ge(attrs, 32))
gl = " - a OpenGL 3.2+ context\n";

if (attrs->context_forward_compatible)
fwd_compat = " - a forward-compatible context\n";

if (attrs->context_debug)
debug = " - a debug context\n";

if (attrs->context_robust)
robust = " - a robust access context\n";

wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
"GLX_ARB_create_context is required in order to "
"request a debug context");
"GLX_ARB_create_context is required to create:\n"
"%s%s%s%s", gl, fwd_compat, debug, robust);
return false;
}

if (attrs->context_robust && !dpy->ARB_create_context_robustness) {
wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
"GLX_ARB_create_context_robustness is required in order to "
"GLX_ARB_create_context_robustness is required to "
"request a robust access context");
return false;
}

switch (attrs->context_api) {
case WAFFLE_CONTEXT_OPENGL:
if (glx_context_needs_arb_create_context(attrs) &&
!dpy->ARB_create_context) {
wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
"GLX_ARB_create_context is required in order to "
"request an OpenGL version greater or equal than 3.2");
return false;
}
else if (wcore_config_attrs_version_ge(attrs, 32) && !dpy->ARB_create_context_profile) {
if (wcore_config_attrs_version_ge(attrs, 32) && !dpy->ARB_create_context_profile) {
wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
"GLX_ARB_create_context_profile is required "
"to create a context with version >= 3.2");
Expand All @@ -94,13 +108,6 @@ glx_config_check_context_attrs(struct glx_display *dpy,
attrs->context_profile == WAFFLE_CONTEXT_COMPATIBILITY_PROFILE);
}

if (attrs->context_forward_compatible && !dpy->ARB_create_context) {
wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
"GLX_ARB_create_context is required in order to "
"request a forward-compatible context");
return false;
}

return true;

case WAFFLE_CONTEXT_OPENGL_ES1:
Expand Down
15 changes: 5 additions & 10 deletions src/waffle/glx/glx_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,15 @@ glx_context_create_native(struct glx_config *config,
{
GLXContext ctx;
GLXContext real_share_ctx = share_ctx ? share_ctx->glx : NULL;
const struct wcore_config_attrs *attrs = &config->wcore.attrs;
struct glx_display *dpy = glx_display(config->wcore.display);
struct glx_platform *platform = glx_platform(dpy->wcore.platform);

// Use ARB_create_context when we have
// - OpenGL version 1.0, or
// - OpenGL version 3.2 or greater, or
// - OpenGL with fwd_compat, or
// - Debug context
//
// The first one of the four is optional, the remainder hard requirement
// for the use of ARB_create_context.
// Optionally use ARB_create_context for OpenGL 1.0, if available.
if (dpy->ARB_create_context &&
(wcore_config_attrs_version_eq(&config->wcore.attrs, 10) ||
glx_context_needs_arb_create_context(&config->wcore.attrs))) {
(glx_context_needs_arb_create_context(attrs) ||
(attrs->context_api == WAFFLE_CONTEXT_OPENGL &&
wcore_config_attrs_version_eq(attrs, 10)))) {
bool ok;

// Choose a large size to prevent accidental overflow.
Expand Down
20 changes: 17 additions & 3 deletions src/waffle/glx/glx_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,30 @@ union waffle_native_context*
glx_context_get_native(struct wcore_context *wc_self);


// XXX: Keep in sync with glx_config_check_context_attrs()
static inline bool
glx_context_needs_arb_create_context(const struct wcore_config_attrs *attrs)
{
if (attrs->context_api == WAFFLE_CONTEXT_OPENGL &&
(wcore_config_attrs_version_ge(attrs, 32) ||
attrs->context_forward_compatible))
// Any of the following require the ARB extension, since the data is
// passed as attributes.

// Using any GLES* profile,
if (attrs->context_api != WAFFLE_CONTEXT_OPENGL)
return true;

// explicitly requesting OpenGL version (>=3.2),
if (wcore_config_attrs_version_ge(attrs, 32))
return true;

// ... or any of the context flags.
if (attrs->context_forward_compatible)
return true;

if (attrs->context_debug)
return true;

if (attrs->context_robust)
return true;

return false;
}

0 comments on commit b8a39e6

Please sign in to comment.