graphics: Reduce the usage of InternalImageSize

This commit is contained in:
Hajime Hoshi 2020-08-08 16:01:33 +09:00
parent ad3a8bca7f
commit b4046a795e
2 changed files with 5 additions and 7 deletions

View File

@ -117,6 +117,9 @@ func (i *Image) Dispose() {
} }
func (i *Image) InternalSize() (int, int) { func (i *Image) InternalSize() (int, int) {
if i.screen {
return i.width, i.height
}
if i.internalWidth == 0 { if i.internalWidth == 0 {
i.internalWidth = graphics.InternalImageSize(i.width) i.internalWidth = graphics.InternalImageSize(i.width)
} }

View File

@ -154,8 +154,6 @@ func (g *Graphics) SetVertices(vertices []float32, indices []uint16) {
} }
func (g *Graphics) Draw(dst, src driver.ImageID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address, sourceRegion driver.Region) error { func (g *Graphics) Draw(dst, src driver.ImageID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address, sourceRegion driver.Region) error {
// TODO: Use sourceRegion.
destination := g.images[dst] destination := g.images[dst]
source := g.images[src] source := g.images[src]
@ -206,9 +204,7 @@ func (g *Graphics) Draw(dst, src driver.ImageID, indexLen int, indexOffset int,
} }
if filter != driver.FilterNearest { if filter != driver.FilterNearest {
srcW, srcH := source.width, source.height sw, sh := source.framebufferSize()
sw := graphics.InternalImageSize(srcW)
sh := graphics.InternalImageSize(srcH)
uniforms = append(uniforms, uniformVariable{ uniforms = append(uniforms, uniformVariable{
name: "source_size", name: "source_size",
value: []float32{float32(sw), float32(sh)}, value: []float32{float32(sw), float32(sh)},
@ -305,8 +301,7 @@ func (g *Graphics) DrawShader(dst driver.ImageID, srcs [graphics.ShaderImageNum]
g.context.blendFunc(mode) g.context.blendFunc(mode)
us := make([]uniformVariable, graphics.PreservedUniformVariablesNum+len(uniforms)) us := make([]uniformVariable, graphics.PreservedUniformVariablesNum+len(uniforms))
vw := graphics.InternalImageSize(d.width) vw, vh := d.framebufferSize()
vh := graphics.InternalImageSize(d.height)
us[0].name = "U0" us[0].name = "U0"
us[0].value = []float32{float32(vw), float32(vh)} us[0].value = []float32{float32(vw), float32(vh)}
us[0].typ = s.ir.Uniforms[0] us[0].typ = s.ir.Uniforms[0]