ui/app/internal/gpu: move sRGBA feature detection to context

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-05-04 15:50:10 +02:00
parent fd9eb029c8
commit 51482b6493
2 changed files with 17 additions and 31 deletions
+15 -22
View File
@@ -14,12 +14,12 @@ type context struct {
type caps struct {
EXT_disjoint_timer_query bool
srgbMode srgbMode
// floatTriple holds the settings for floating point
// textures.
floatTriple textureTriple
// Single channel alpha textures.
alphaTriple textureTriple
srgbaTriple textureTriple
}
// textureTriple holds the type settings for
@@ -30,13 +30,6 @@ type textureTriple struct {
typ gl.Enum
}
type srgbMode uint8
const (
srgbES3 srgbMode = iota
srgbEXT
)
func newContext(glctx gl.Context) (*context, error) {
ctx := &context{
Functions: glctx.Functions(),
@@ -47,23 +40,34 @@ func newContext(glctx gl.Context) (*context, error) {
if err != nil {
return nil, err
}
srgbMode, err := srgbModeFor(ver, exts)
floatTriple, err := floatTripleFor(ver, exts)
if err != nil {
return nil, err
}
floatTriple, err := floatTripleFor(ver, exts)
srgbaTriple, err := srgbaTripleFor(ver, exts)
if err != nil {
return nil, err
}
ctx.caps = caps{
EXT_disjoint_timer_query: strings.Contains(exts, "GL_EXT_disjoint_timer_query"),
srgbMode: srgbMode,
floatTriple: floatTriple,
alphaTriple: alphaTripleFor(ver),
srgbaTriple: srgbaTriple,
}
return ctx, nil
}
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"):
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")
}
}
func alphaTripleFor(ver [2]int) textureTriple {
intf, f := gl.R8, gl.Enum(gl.RED)
if ver[0] < 3 {
@@ -85,14 +89,3 @@ func floatTripleFor(ver [2]int, exts string) (textureTriple, error) {
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")
}
}
+2 -9
View File
@@ -859,15 +859,8 @@ func (r *renderer) uploadTexture(img image.Image) {
default:
pixels = copyImage(img, b).Pix
}
var internal int
var format gl.Enum
switch r.ctx.caps.srgbMode {
case srgbES3:
internal, format = gl.SRGB8_ALPHA8, gl.RGBA
case srgbEXT:
internal, format = gl.SRGB_ALPHA_EXT, gl.SRGB_ALPHA_EXT
}
r.ctx.TexImage2D(gl.TEXTURE_2D, 0, internal, w, h, format, gl.UNSIGNED_BYTE, pixels)
tt := r.ctx.caps.srgbaTriple
r.ctx.TexImage2D(gl.TEXTURE_2D, 0, tt.internalFormat, w, h, tt.format, tt.typ, pixels)
}