mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/driver: Refactoring: Merge two Draw* functions
This commit is contained in:
parent
b9d52c0267
commit
e9b6237f61
@ -51,18 +51,13 @@ type Graphics interface {
|
||||
|
||||
NewShader(program *shaderir.Program) (Shader, error)
|
||||
|
||||
// Draw draws an image onto another image.
|
||||
//
|
||||
// TODO: Merge this into DrawShader.
|
||||
Draw(dst, src ImageID, indexLen int, indexOffset int, mode CompositeMode, colorM *affine.ColorM, filter Filter, address Address, dstRegion, srcRegion Region) error
|
||||
|
||||
// DrawShader draws the shader.
|
||||
// DrawTriangles draws an image onto another image with the given parameters.
|
||||
//
|
||||
// uniforms represents a colletion of uniform variables. The values must be one of these types:
|
||||
//
|
||||
// * float32
|
||||
// * []float32
|
||||
DrawShader(dst ImageID, srcs [graphics.ShaderImageNum]ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader ShaderID, indexLen int, indexOffset int, dstRegion, srcRegion Region, mode CompositeMode, uniforms []interface{}) error
|
||||
DrawTriangles(dst ImageID, srcs [graphics.ShaderImageNum]ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader ShaderID, indexLen int, indexOffset int, mode CompositeMode, colorM *affine.ColorM, filter Filter, address Address, dstRegion, srcRegion Region, uniforms []interface{}) error
|
||||
}
|
||||
|
||||
// GraphicsNotReady represents that the graphics driver is not ready for recovering from the context lost.
|
||||
|
@ -413,8 +413,10 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var shaderID driver.ShaderID = driver.InvalidShaderID
|
||||
var imgs [graphics.ShaderImageNum]driver.ImageID
|
||||
if c.shader != nil {
|
||||
var imgs [graphics.ShaderImageNum]driver.ImageID
|
||||
shaderID = c.shader.shader.ID()
|
||||
for i, src := range c.srcs {
|
||||
if src == nil {
|
||||
imgs[i] = driver.InvalidImageID
|
||||
@ -422,10 +424,11 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error {
|
||||
}
|
||||
imgs[i] = src.image.ID()
|
||||
}
|
||||
|
||||
return theGraphicsDriver.DrawShader(c.dst.image.ID(), imgs, c.offsets, c.shader.shader.ID(), c.nindices, indexOffset, c.dstRegion, c.srcRegion, c.mode, c.uniforms)
|
||||
} else {
|
||||
imgs[0] = c.srcs[0].image.ID()
|
||||
}
|
||||
return theGraphicsDriver.Draw(c.dst.image.ID(), c.srcs[0].image.ID(), c.nindices, indexOffset, c.mode, c.color, c.filter, c.address, c.dstRegion, c.srcRegion)
|
||||
|
||||
return theGraphicsDriver.DrawTriangles(c.dst.image.ID(), imgs, c.offsets, shaderID, c.nindices, indexOffset, c.mode, c.color, c.filter, c.address, c.dstRegion, c.srcRegion, c.uniforms)
|
||||
}
|
||||
|
||||
func (c *drawTrianglesCommand) NumVertices() int {
|
||||
|
@ -684,7 +684,14 @@ func (g *Graphics) draw(rps mtl.RenderPipelineState, dst *Image, dstRegion drive
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Graphics) Draw(dstID, srcID driver.ImageID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region) error {
|
||||
func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderImageNum]driver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, uniforms []interface{}) error {
|
||||
if shader == driver.InvalidShaderID {
|
||||
return g.drawTrianglesWithDefaultShader(dstID, srcIDs[0], indexLen, indexOffset, mode, colorM, filter, address, dstRegion, srcRegion)
|
||||
}
|
||||
return g.drawTrianglesWithShader(dstID, srcIDs, offsets, shader, indexLen, indexOffset, mode, dstRegion, srcRegion, uniforms)
|
||||
}
|
||||
|
||||
func (g *Graphics) drawTrianglesWithDefaultShader(dstID, srcID driver.ImageID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region) error {
|
||||
dst := g.images[dstID]
|
||||
|
||||
srcs := [graphics.ShaderImageNum]*Image{g.images[srcID]}
|
||||
@ -930,7 +937,7 @@ func (i *Image) ReplacePixels(args []*driver.ReplacePixelsArgs) {
|
||||
bce.EndEncoding()
|
||||
}
|
||||
|
||||
func (g *Graphics) DrawShader(dstID driver.ImageID, srcIDs [graphics.ShaderImageNum]driver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader driver.ShaderID, indexLen int, indexOffset int, dstRegion, srcRegion driver.Region, mode driver.CompositeMode, uniforms []interface{}) error {
|
||||
func (g *Graphics) drawTrianglesWithShader(dstID driver.ImageID, srcIDs [graphics.ShaderImageNum]driver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, dstRegion, srcRegion driver.Region, uniforms []interface{}) error {
|
||||
dst := g.images[dstID]
|
||||
|
||||
var srcs [graphics.ShaderImageNum]*Image
|
||||
|
@ -142,7 +142,14 @@ func (g *Graphics) SetVertices(vertices []float32, indices []uint16) {
|
||||
g.context.elementArrayBufferSubData(indices)
|
||||
}
|
||||
|
||||
func (g *Graphics) Draw(dst, src driver.ImageID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region) error {
|
||||
func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderImageNum]driver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, uniforms []interface{}) error {
|
||||
if shader == driver.InvalidShaderID {
|
||||
return g.drawTrianglesWithDefaultShader(dstID, srcIDs[0], indexLen, indexOffset, mode, colorM, filter, address, dstRegion, srcRegion)
|
||||
}
|
||||
return g.drawTrianglesWithShader(dstID, srcIDs, offsets, shader, indexLen, indexOffset, mode, dstRegion, srcRegion, uniforms)
|
||||
}
|
||||
|
||||
func (g *Graphics) drawTrianglesWithDefaultShader(dst, src driver.ImageID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region) error {
|
||||
destination := g.images[dst]
|
||||
source := g.images[src]
|
||||
|
||||
@ -289,7 +296,7 @@ func (g *Graphics) removeShader(shader *Shader) {
|
||||
delete(g.shaders, shader.id)
|
||||
}
|
||||
|
||||
func (g *Graphics) DrawShader(dst driver.ImageID, srcs [graphics.ShaderImageNum]driver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader driver.ShaderID, indexLen int, indexOffset int, dstRegion, srcRegion driver.Region, mode driver.CompositeMode, uniforms []interface{}) error {
|
||||
func (g *Graphics) drawTrianglesWithShader(dst driver.ImageID, srcs [graphics.ShaderImageNum]driver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, dstRegion, srcRegion driver.Region, uniforms []interface{}) error {
|
||||
d := g.images[dst]
|
||||
s := g.shaders[shader]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user