graphicscommand: Refactoring

This commit is contained in:
Hajime Hoshi 2020-07-18 23:25:16 +09:00
parent d22026d366
commit fe79bb27af
3 changed files with 8 additions and 14 deletions

View File

@ -384,10 +384,6 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha
mode := driver.CompositeMode(options.CompositeMode)
// The first uniform variable is Internal_ViewportSize.
// The actual value is set at graphicscommand package.
us := append([]interface{}{[]float32{0, 0}}, options.Uniforms...)
var imgw, imgh int
var imgs [graphics.ShaderImageNum]*buffered.Image
for i, img := range options.Images {
@ -419,7 +415,7 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha
is := make([]uint16, len(indices))
copy(is, indices)
i.buffered.DrawTriangles(imgs, vs, is, nil, mode, driver.FilterNearest, driver.AddressUnsafe, driver.Region{}, shader.shader, us)
i.buffered.DrawTriangles(imgs, vs, is, nil, mode, driver.FilterNearest, driver.AddressUnsafe, driver.Region{}, shader.shader, options.Uniforms)
}
// SubImage returns an image representing the portion of the image p visible through r.

View File

@ -424,12 +424,6 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error {
imgs[i] = src.image.ID()
}
// The last uniform variables are added at /shader.go and represents a viewport size.
w, h := c.dst.InternalSize()
viewport := c.uniforms[0].([]float32)
viewport[0] = float32(w)
viewport[1] = float32(h)
return theGraphicsDriver.DrawShader(c.dst.image.ID(), imgs, c.shader.shader.ID(), c.nindices, indexOffset, c.mode, c.uniforms)
}
return theGraphicsDriver.Draw(c.dst.image.ID(), c.srcs[0].image.ID(), c.nindices, indexOffset, c.mode, c.color, c.filter, c.address, c.sourceRegion)

View File

@ -298,10 +298,14 @@ func (g *Graphics) DrawShader(dst driver.ImageID, srcs [graphics.ShaderImageNum]
}
g.context.blendFunc(mode)
us := make([]uniformVariable, len(uniforms))
us := make([]uniformVariable, 1+len(uniforms))
vw := graphics.InternalImageSize(d.width)
vh := graphics.InternalImageSize(d.height)
us[0].name = "U0"
us[0].value = []float32{float32(vw), float32(vh)}
for k, v := range uniforms {
us[k].name = fmt.Sprintf("U%d", k)
us[k].value = v
us[k+1].name = fmt.Sprintf("U%d", k+1)
us[k+1].value = v
}
var ts [graphics.ShaderImageNum]textureVariable