internal/mipmap: refactoring: add a fast path

This commit is contained in:
Hajime Hoshi 2024-10-27 01:04:00 +09:00
parent 00fade9dcf
commit dc41960d3b

View File

@ -83,9 +83,21 @@ func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Mipmap, verti
return return
} }
level := 0 // Use the fast path if mipmap is not used.
if !canSkipMipmap && srcs[0] != nil && canUseMipmap(srcs[0].imageType) { if canSkipMipmap || srcs[0] == nil || !canUseMipmap(srcs[0].imageType) {
level = math.MaxInt32 var imgs [graphics.ShaderSrcImageCount]*buffered.Image
for i, src := range srcs {
if src == nil {
continue
}
imgs[i] = src.orig
}
m.orig.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, fillRule, hint)
m.markDirty()
return
}
level := math.MaxInt32
for i := 0; i < len(indices); i += 3 { for i := 0; i < len(indices); i += 3 {
idx0 := indices[i] idx0 := indices[i]
idx1 := indices[i+1] idx1 := indices[i+1]
@ -115,7 +127,6 @@ func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Mipmap, verti
if level == math.MaxInt32 { if level == math.MaxInt32 {
panic("mipmap: level must be calculated at least once but not") panic("mipmap: level must be calculated at least once but not")
} }
}
var imgs [graphics.ShaderSrcImageCount]*buffered.Image var imgs [graphics.ShaderSrcImageCount]*buffered.Image
for i, src := range srcs { for i, src := range srcs {