mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 00:16:15 +00:00
ui/app/internal/gl: move single channel format detection to context
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -18,6 +18,8 @@ type caps struct {
|
||||
// floatTriple holds the settings for floating point
|
||||
// textures.
|
||||
floatTriple textureTriple
|
||||
// Single channel alpha textures.
|
||||
alphaTriple textureTriple
|
||||
}
|
||||
|
||||
// textureTriple holds the type settings for
|
||||
@@ -57,10 +59,20 @@ func newContext(glctx gl.Context) (*context, error) {
|
||||
EXT_disjoint_timer_query: strings.Contains(exts, "GL_EXT_disjoint_timer_query"),
|
||||
srgbMode: srgbMode,
|
||||
floatTriple: floatTriple,
|
||||
alphaTriple: alphaTripleFor(ver),
|
||||
}
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
func alphaTripleFor(ver [2]int) textureTriple {
|
||||
intf, f := gl.R8, gl.Enum(gl.RED)
|
||||
if ver[0] < 3 {
|
||||
// R8, RED not supported on OpenGL ES 2.0.
|
||||
intf, f = gl.LUMINANCE, gl.Enum(gl.LUMINANCE)
|
||||
}
|
||||
return textureTriple{intf, f, gl.UNSIGNED_BYTE}
|
||||
}
|
||||
|
||||
func floatTripleFor(ver [2]int, exts string) (textureTriple, error) {
|
||||
switch {
|
||||
case ver[0] >= 3:
|
||||
|
||||
@@ -376,13 +376,8 @@ func loadLUT(ctx *context, lut *image.Gray) (gl.Texture, error) {
|
||||
if lut.Stride != lut.Bounds().Dx() {
|
||||
panic("unsupported LUT stride")
|
||||
}
|
||||
ver, _ := gl.ParseGLVersion(ctx.GetString(gl.VERSION))
|
||||
intf, f := gl.R8, gl.RED
|
||||
if ver[0] < 3 {
|
||||
// R8, RED not supported on OpenGL ES 2.0.
|
||||
intf, f = gl.LUMINANCE, gl.LUMINANCE
|
||||
}
|
||||
ctx.TexImage2D(gl.TEXTURE_2D, 0, intf, lut.Bounds().Dx(), lut.Bounds().Dy(), gl.Enum(f), gl.UNSIGNED_BYTE, lut.Pix)
|
||||
tt := ctx.caps.alphaTriple
|
||||
ctx.TexImage2D(gl.TEXTURE_2D, 0, tt.internalFormat, lut.Bounds().Dx(), lut.Bounds().Dy(), tt.format, tt.typ, lut.Pix)
|
||||
ctx.PixelStorei(gl.UNPACK_ALIGNMENT, 4)
|
||||
return tex, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user