internal/restorable: integrate Shader.Dispose into internal/atlas

Updates #805
This commit is contained in:
Hajime Hoshi 2024-01-13 18:38:36 +09:00
parent 2a465c2d0b
commit bfa2c460a2
3 changed files with 6 additions and 10 deletions

View File

@ -68,7 +68,8 @@ func (s *Shader) deallocate() {
if s.shader == nil { if s.shader == nil {
return return
} }
s.shader.Dispose() s.shader.Shader.Dispose()
s.shader.Shader = nil
s.shader = nil s.shader = nil
} }

View File

@ -91,7 +91,7 @@ func quadVertices(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, cr, cg, cb, ca float32
func clearImage(i *graphicscommand.Image, region image.Rectangle) { func clearImage(i *graphicscommand.Image, region image.Rectangle) {
vs := quadVertices(float32(region.Min.X), float32(region.Min.Y), float32(region.Max.X), float32(region.Max.Y), 0, 0, 0, 0, 0, 0, 0, 0) vs := quadVertices(float32(region.Min.X), float32(region.Min.Y), float32(region.Max.X), float32(region.Max.Y), 0, 0, 0, 0, 0, 0, 0, 0)
is := graphics.QuadIndices() is := graphics.QuadIndices()
i.DrawTriangles([graphics.ShaderImageCount]*graphicscommand.Image{}, vs, is, graphicsdriver.BlendClear, region, [graphics.ShaderImageCount]image.Rectangle{}, clearShader.shader, nil, graphicsdriver.FillAll) i.DrawTriangles([graphics.ShaderImageCount]*graphicscommand.Image{}, vs, is, graphicsdriver.BlendClear, region, [graphics.ShaderImageCount]image.Rectangle{}, clearShader.Shader, nil, graphicsdriver.FillAll)
} }
// ClearPixels clears the specified region by WritePixels. // ClearPixels clears the specified region by WritePixels.
@ -141,5 +141,5 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
} }
imgs[i] = src.Image imgs[i] = src.Image
} }
i.Image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.shader, uniforms, fillRule) i.Image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.Shader, uniforms, fillRule)
} }

View File

@ -26,21 +26,16 @@ import (
) )
type Shader struct { type Shader struct {
shader *graphicscommand.Shader Shader *graphicscommand.Shader
} }
func NewShader(ir *shaderir.Program) *Shader { func NewShader(ir *shaderir.Program) *Shader {
s := &Shader{ s := &Shader{
shader: graphicscommand.NewShader(ir), Shader: graphicscommand.NewShader(ir),
} }
return s return s
} }
func (s *Shader) Dispose() {
s.shader.Dispose()
s.shader = nil
}
var ( var (
NearestFilterShader *Shader NearestFilterShader *Shader
NearestFilterShaderIR *shaderir.Program NearestFilterShaderIR *shaderir.Program