internal/restorable: remove unnecessary functions and variables around shaders

Updates #805
This commit is contained in:
Hajime Hoshi 2024-01-09 03:01:08 +09:00
parent 8169253a57
commit 4f3e00ec3a
4 changed files with 18 additions and 31 deletions

View File

@ -376,7 +376,7 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
vertices[i+2] += oxf vertices[i+2] += oxf
vertices[i+3] += oyf vertices[i+3] += oyf
} }
if shader.ensureShader().Unit() == shaderir.Texels { if shader.ir.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

@ -73,6 +73,12 @@ func (s *Shader) deallocate() {
} }
var ( var (
NearestFilterShader = &Shader{shader: restorable.NearestFilterShader} NearestFilterShader = &Shader{
LinearFilterShader = &Shader{shader: restorable.LinearFilterShader} shader: restorable.NearestFilterShader,
ir: restorable.LinearFilterShaderIR,
}
LinearFilterShader = &Shader{
shader: restorable.LinearFilterShader,
ir: restorable.LinearFilterShaderIR,
}
) )

View File

@ -22,14 +22,12 @@ import (
// images is a set of Image objects. // images is a set of Image objects.
type images struct { type images struct {
images map[*Image]struct{} images map[*Image]struct{}
shaders map[*Shader]struct{}
} }
// theImages represents the images for the current process. // theImages represents the images for the current process.
var theImages = &images{ var theImages = &images{
images: map[*Image]struct{}{}, images: map[*Image]struct{}{},
shaders: map[*Shader]struct{}{},
} }
func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error { func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
@ -64,19 +62,11 @@ func (i *images) add(img *Image) {
i.images[img] = struct{}{} i.images[img] = struct{}{}
} }
func (i *images) addShader(shader *Shader) {
i.shaders[shader] = struct{}{}
}
// remove removes img from the images. // remove removes img from the images.
func (i *images) remove(img *Image) { func (i *images) remove(img *Image) {
delete(i.images, img) delete(i.images, img)
} }
func (i *images) removeShader(shader *Shader) {
delete(i.shaders, shader)
}
var graphicsDriverInitialized bool var graphicsDriverInitialized bool
// InitializeGraphicsDriverState initializes the graphics driver state. // InitializeGraphicsDriverState initializes the graphics driver state.

View File

@ -27,37 +27,26 @@ import (
type Shader struct { type Shader struct {
shader *graphicscommand.Shader shader *graphicscommand.Shader
ir *shaderir.Program
} }
func NewShader(ir *shaderir.Program) *Shader { func NewShader(ir *shaderir.Program) *Shader {
s := &Shader{ s := &Shader{
shader: graphicscommand.NewShader(ir), shader: graphicscommand.NewShader(ir),
ir: ir,
} }
theImages.addShader(s)
return s return s
} }
func (s *Shader) Dispose() { func (s *Shader) Dispose() {
theImages.removeShader(s)
s.shader.Dispose() s.shader.Dispose()
s.shader = nil s.shader = nil
s.ir = nil
}
func (s *Shader) restore() {
s.shader = graphicscommand.NewShader(s.ir)
}
func (s *Shader) Unit() shaderir.Unit {
return s.ir.Unit
} }
var ( var (
NearestFilterShader *Shader NearestFilterShader *Shader
LinearFilterShader *Shader NearestFilterShaderIR *shaderir.Program
clearShader *Shader LinearFilterShader *Shader
LinearFilterShaderIR *shaderir.Program
clearShader *Shader
) )
func init() { func init() {
@ -96,7 +85,9 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
if err := wg.Wait(); err != nil { if err := wg.Wait(); err != nil {
panic(err) panic(err)
} }
NearestFilterShaderIR = nearestIR
NearestFilterShader = NewShader(nearestIR) NearestFilterShader = NewShader(nearestIR)
LinearFilterShaderIR = linearIR
LinearFilterShader = NewShader(linearIR) LinearFilterShader = NewShader(linearIR)
clearShader = NewShader(clearIR) clearShader = NewShader(clearIR)
} }