graphicsdriver: Merge UseProgram and DrawElements into Draw

This commit is contained in:
Hajime Hoshi 2018-11-11 23:53:23 +09:00
parent 575af7e416
commit 846a719d6c
3 changed files with 8 additions and 10 deletions

View File

@ -233,10 +233,9 @@ func (c *drawImageCommand) Exec(indexOffset int) error {
c.dst.image.SetAsDestination()
c.src.image.SetAsSource()
if err := driver().UseProgram(c.mode, c.color, c.filter); err != nil {
if err := driver().Draw(c.nindices, indexOffset, c.mode, c.color, c.filter); err != nil {
return err
}
driver().DrawElements(c.nindices, indexOffset)
return nil
}

View File

@ -21,13 +21,12 @@ import (
type GraphicsDriver interface {
BufferSubData(vertices []float32, indices []uint16)
DrawElements(indexLen int, indexOffset int)
Flush()
MaxImageSize() int
NewImage(width, height int) (Image, error)
NewScreenFramebufferImage(width, height int) Image
Reset() error
UseProgram(mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter) error
Draw(indexLen int, indexOffset int, mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter) error
}
type Image interface {

View File

@ -91,16 +91,16 @@ func (d *Driver) BufferSubData(vertices []float32, indices []uint16) {
d.context.elementArrayBufferSubData(indices)
}
func (d *Driver) UseProgram(mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter) error {
return d.useProgram(mode, colorM, filter)
}
func (d *Driver) DrawElements(len int, offset int) {
d.context.drawElements(len, offset*2) // 2 is uint16 size in bytes
func (d *Driver) Draw(indexLen int, indexOffset int, mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter) error {
if err := d.useProgram(mode, colorM, filter); err != nil {
return err
}
d.context.drawElements(indexLen, indexOffset*2) // 2 is uint16 size in bytes
// glFlush() might be necessary at least on MacBook Pro (a smilar problem at #419),
// but basically this pass the tests (esp. TestImageTooManyFill).
// As glFlush() causes performance problems, this should be avoided as much as possible.
// Let's wait and see, and file a new issue when this problem is newly found.
return nil
}
func (d *Driver) Flush() {