Skip to content

Commit

Permalink
wgl: 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: 03fdde4 ("wgl: 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-work authored and evelikov committed Jan 13, 2020
1 parent b8a39e6 commit 6d096c0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
43 changes: 25 additions & 18 deletions src/waffle/wgl/wgl_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,31 @@ wgl_config_check_context_attrs(struct wgl_display *dpy,
assert(wcore_config_attrs_version_ge(attrs, 30));
}

if (attrs->context_debug && !dpy->ARB_create_context) {
if (!dpy->ARB_create_context &&
wgl_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,
"WGL_ARB_create_context is required in order to "
"request a debug context");
"WGL_ARB_create_context is required to create:\n"
"%s%s%s%s", gl, fwd_compat, debug, robust);
return false;
}

Expand All @@ -81,14 +102,7 @@ wgl_config_check_context_attrs(struct wgl_display *dpy,

switch (attrs->context_api) {
case WAFFLE_CONTEXT_OPENGL:
if (wgl_context_needs_arb_create_context(attrs) &&
!dpy->ARB_create_context) {
wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
"WGL_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,
"WGL_ARB_create_context_profile is required "
"to create a context with version >= 3.2");
Expand All @@ -99,13 +113,6 @@ wgl_config_check_context_attrs(struct wgl_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,
"WGL_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/wgl/wgl_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,15 @@ wgl_context_create_native(struct wgl_config *config,
struct wgl_context *share_ctx)
{
struct wgl_display *dpy = wgl_display(config->wcore.display);
const struct wcore_config_attrs *attrs = &config->wcore.attrs;
HGLRC real_share_ctx = share_ctx ? share_ctx->hglrc : NULL;
HGLRC hglrc;

// 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) ||
wgl_context_needs_arb_create_context(&config->wcore.attrs))) {
(wgl_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/wgl/wgl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,30 @@ wgl_context_create(struct wcore_platform *wc_plat,
bool
wgl_context_destroy(struct wcore_context *wc_self);

// XXX: Keep in sync with wgl_config_check_context_attrs()
static inline bool
wgl_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 6d096c0

Please sign in to comment.