ui/app/internal/gpu: implement OpenGL ES 2 float fbo fallbacks

Also applicable to WebGL.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-05-04 14:29:37 +02:00
parent d118bd5a88
commit f5fa968038
3 changed files with 46 additions and 10 deletions
+40 -6
View File
@@ -1,6 +1,7 @@
package gpu
import (
"errors"
"strings"
"gioui.org/ui/app/internal/gl"
@@ -14,6 +15,17 @@ type context struct {
type caps struct {
EXT_disjoint_timer_query bool
srgbMode srgbMode
// floatTriple holds the settings for floating point
// textures.
floatTriple textureTriple
}
// textureTriple holds the type settings for
// a TexImage2D call.
type textureTriple struct {
internalFormat int
format gl.Enum
typ gl.Enum
}
type srgbMode uint8
@@ -33,20 +45,42 @@ func newContext(glctx gl.Context) (*context, error) {
if err != nil {
return nil, err
}
srgbMode, err := srgbModeFor(ver, exts)
if err != nil {
return nil, err
}
floatTriple, err := floatTripleFor(ver, exts)
if err != nil {
return nil, err
}
ctx.caps = caps{
EXT_disjoint_timer_query: strings.Contains(exts, "GL_EXT_disjoint_timer_query"),
srgbMode: srgbModeFor(ver, exts),
srgbMode: srgbMode,
floatTriple: floatTriple,
}
return ctx, nil
}
func srgbModeFor(ver [2]int, exts string) srgbMode {
func floatTripleFor(ver [2]int, exts string) (textureTriple, error) {
switch {
case ver[0] >= 3:
return srgbES3
case strings.Contains(exts, "EXT_sRGB"):
return srgbEXT
return textureTriple{gl.R16F, gl.Enum(gl.RED), gl.Enum(gl.HALF_FLOAT)}, nil
case strings.Contains(exts, "GL_OES_texture_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"):
return textureTriple{gl.RGBA, gl.Enum(gl.RGBA), gl.Enum(gl.FLOAT)}, nil
default:
panic("neither OpenGL ES 3 nor EXT_sRGB is supported")
return textureTriple{}, errors.New("floating point texture not supported")
}
}
func srgbModeFor(ver [2]int, exts string) (srgbMode, error) {
switch {
case ver[0] >= 3:
return srgbES3, nil
case strings.Contains(exts, "EXT_sRGB"):
return srgbEXT, nil
default:
return 0, errors.New("neither OpenGL ES 3 nor EXT_sRGB is supported")
}
}