ui/app: split extension string before matching

Avoids false matches for extensions whose names are substrings of
other extensions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-05-11 13:13:56 +02:00
parent c6863581e0
commit f1c87417bd
2 changed files with 27 additions and 9 deletions
+11 -2
View File
@@ -176,6 +176,15 @@ func (c *context) MakeCurrent() error {
return nil
}
func hasExtension(exts []string, ext string) bool {
for _, e := range exts {
if ext == e {
return true
}
}
return false
}
func createContext(disp _EGLNativeDisplayType) (*eglContext, error) {
eglDisp := eglGetDisplay(disp)
if eglDisp == 0 {
@@ -186,8 +195,8 @@ func createContext(disp _EGLNativeDisplayType) (*eglContext, error) {
return nil, fmt.Errorf("eglInitialize failed: 0x%x", eglGetError())
}
// sRGB framebuffer support on EGL 1.5 or if EGL_KHR_gl_colorspace is supported.
exts := eglQueryString(eglDisp, _EGL_EXTENSIONS)
srgb := minor >= 5 || strings.Contains(exts, "EGL_KHR_gl_colorspace")
exts := strings.Split(eglQueryString(eglDisp, _EGL_EXTENSIONS), " ")
srgb := minor >= 5 || hasExtension(exts, "EGL_KHR_gl_colorspace")
attribs := []_EGLint{
_EGL_RENDERABLE_TYPE, _EGL_OPENGL_ES2_BIT,
_EGL_SURFACE_TYPE, _EGL_WINDOW_BIT,
+16 -7
View File
@@ -34,7 +34,7 @@ func newContext(glctx gl.Context) (*context, error) {
ctx := &context{
Functions: glctx.Functions(),
}
exts := ctx.GetString(gl.EXTENSIONS)
exts := strings.Split(ctx.GetString(gl.EXTENSIONS), " ")
glVer := ctx.GetString(gl.VERSION)
ver, err := gl.ParseGLVersion(glVer)
if err != nil {
@@ -49,7 +49,7 @@ func newContext(glctx gl.Context) (*context, error) {
return nil, err
}
ctx.caps = caps{
EXT_disjoint_timer_query: strings.Contains(exts, "GL_EXT_disjoint_timer_query"),
EXT_disjoint_timer_query: hasExtension(exts, "GL_EXT_disjoint_timer_query"),
floatTriple: floatTriple,
alphaTriple: alphaTripleFor(ver),
srgbaTriple: srgbaTriple,
@@ -57,11 +57,11 @@ func newContext(glctx gl.Context) (*context, error) {
return ctx, nil
}
func srgbaTripleFor(ver [2]int, exts string) (textureTriple, error) {
func srgbaTripleFor(ver [2]int, exts []string) (textureTriple, error) {
switch {
case ver[0] >= 3:
return textureTriple{gl.SRGB8_ALPHA8, gl.Enum(gl.RGBA), gl.Enum(gl.UNSIGNED_BYTE)}, nil
case strings.Contains(exts, "GL_EXT_sRGB"):
case hasExtension(exts, "GL_EXT_sRGB"):
return textureTriple{gl.SRGB_ALPHA_EXT, gl.Enum(gl.SRGB_ALPHA_EXT), gl.Enum(gl.UNSIGNED_BYTE)}, nil
default:
return textureTriple{}, errors.New("no sRGB texture formats found")
@@ -77,15 +77,24 @@ func alphaTripleFor(ver [2]int) textureTriple {
return textureTriple{intf, f, gl.UNSIGNED_BYTE}
}
func floatTripleFor(ver [2]int, exts string) (textureTriple, error) {
func floatTripleFor(ver [2]int, exts []string) (textureTriple, error) {
switch {
case ver[0] >= 3:
return textureTriple{gl.R16F, gl.Enum(gl.RED), gl.Enum(gl.HALF_FLOAT)}, nil
case strings.Contains(exts, "GL_OES_texture_half_float"):
case hasExtension(exts, "GL_OES_texture_half_float") || hasExtension(exts, "EXT_color_buffer_half_float"):
return textureTriple{gl.RGBA, gl.Enum(gl.RGBA), gl.Enum(gl.HALF_FLOAT_OES)}, nil
case strings.Contains(exts, "GL_OES_texture_float"):
case hasExtension(exts, "GL_OES_texture_float") || hasExtension(exts, "GL_EXT_color_buffer_float"):
return textureTriple{gl.RGBA, gl.Enum(gl.RGBA), gl.Enum(gl.FLOAT)}, nil
default:
return textureTriple{}, errors.New("floating point texture not supported")
}
}
func hasExtension(exts []string, ext string) bool {
for _, e := range exts {
if ext == e {
return true
}
}
return false
}