internal/atlas: reduce the access to (*restorable.Shader).Unit

This commit is contained in:
Hajime Hoshi 2024-10-27 00:46:03 +09:00
parent 2437ad8248
commit 00fade9dcf
2 changed files with 11 additions and 3 deletions

View File

@ -405,7 +405,7 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertice
vertices[i+2] += oxf vertices[i+2] += oxf
vertices[i+3] += oyf vertices[i+3] += oyf
} }
if shader.ensureShader().Unit() == shaderir.Texels { if shader.unit == shaderir.Texels {
sw, sh := srcs[0].backend.restorable.InternalSize() sw, sh := srcs[0].backend.restorable.InternalSize()
swf, shf := float32(sw), float32(sh) swf, shf := float32(sw), float32(sh)
for i := 0; i < n; i += graphics.VertexFloatCount { for i := 0; i < n; i += graphics.VertexFloatCount {

View File

@ -24,6 +24,7 @@ import (
type Shader struct { type Shader struct {
ir *shaderir.Program ir *shaderir.Program
shader *restorable.Shader shader *restorable.Shader
unit shaderir.Unit
name string name string
} }
@ -32,6 +33,7 @@ func NewShader(ir *shaderir.Program, name string) *Shader {
return &Shader{ return &Shader{
ir: ir, ir: ir,
name: name, name: name,
unit: ir.Unit,
} }
} }
@ -77,6 +79,12 @@ func (s *Shader) deallocate() {
} }
var ( var (
NearestFilterShader = &Shader{shader: restorable.NearestFilterShader} NearestFilterShader = &Shader{
LinearFilterShader = &Shader{shader: restorable.LinearFilterShader} shader: restorable.NearestFilterShader,
unit: restorable.NearestFilterShader.Unit(),
}
LinearFilterShader = &Shader{
shader: restorable.LinearFilterShader,
unit: restorable.LinearFilterShader.Unit(),
}
) )