mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
graphicscommand: Refactoring
This commit is contained in:
parent
d22026d366
commit
fe79bb27af
6
image.go
6
image.go
@ -384,10 +384,6 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha
|
|||||||
|
|
||||||
mode := driver.CompositeMode(options.CompositeMode)
|
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 imgw, imgh int
|
||||||
var imgs [graphics.ShaderImageNum]*buffered.Image
|
var imgs [graphics.ShaderImageNum]*buffered.Image
|
||||||
for i, img := range options.Images {
|
for i, img := range options.Images {
|
||||||
@ -419,7 +415,7 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha
|
|||||||
is := make([]uint16, len(indices))
|
is := make([]uint16, len(indices))
|
||||||
copy(is, 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.
|
// SubImage returns an image representing the portion of the image p visible through r.
|
||||||
|
@ -424,12 +424,6 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error {
|
|||||||
imgs[i] = src.image.ID()
|
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.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)
|
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)
|
||||||
|
@ -298,10 +298,14 @@ func (g *Graphics) DrawShader(dst driver.ImageID, srcs [graphics.ShaderImageNum]
|
|||||||
}
|
}
|
||||||
g.context.blendFunc(mode)
|
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 {
|
for k, v := range uniforms {
|
||||||
us[k].name = fmt.Sprintf("U%d", k)
|
us[k+1].name = fmt.Sprintf("U%d", k+1)
|
||||||
us[k].value = v
|
us[k+1].value = v
|
||||||
}
|
}
|
||||||
|
|
||||||
var ts [graphics.ShaderImageNum]textureVariable
|
var ts [graphics.ShaderImageNum]textureVariable
|
||||||
|
Loading…
Reference in New Issue
Block a user