graphicsdriver: Change indexOffsetInBytes -> indexOffset at DrawElements

This commit is contained in:
Hajime Hoshi 2018-11-11 23:51:16 +09:00
parent b2b51fb1bf
commit 575af7e416
3 changed files with 15 additions and 15 deletions

View File

@ -30,7 +30,7 @@ import (
type command interface { type command interface {
fmt.Stringer fmt.Stringer
Exec(indexOffsetInBytes int) error Exec(indexOffset int) error
NumVertices() int NumVertices() int
NumIndices() int NumIndices() int
AddNumVertices(n int) AddNumVertices(n int)
@ -172,19 +172,19 @@ func (q *commandQueue) Flush() {
es = es[ne:] es = es[ne:]
vs = vs[nv:] vs = vs[nv:]
} }
indexOffsetInBytes := 0 indexOffset := 0
for _, c := range q.commands[:nc] { for _, c := range q.commands[:nc] {
if err := c.Exec(indexOffsetInBytes); err != nil { if err := c.Exec(indexOffset); err != nil {
q.err = err q.err = err
return return
} }
if recordLog() { if recordLog() {
fmt.Printf("%s\n", c) fmt.Printf("%s\n", c)
} }
// TODO: indexOffsetInBytes should be reset if the command type is different // TODO: indexOffset should be reset if the command type is different
// from the previous one. This fix is needed when another drawing command is // from the previous one. This fix is needed when another drawing command is
// introduced than drawImageCommand. // introduced than drawImageCommand.
indexOffsetInBytes += c.NumIndices() * 2 // 2 is uint16 size in bytes indexOffset += c.NumIndices()
} }
if 0 < nc { if 0 < nc {
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS). // Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
@ -225,7 +225,7 @@ func (c *drawImageCommand) String() string {
} }
// Exec executes the drawImageCommand. // Exec executes the drawImageCommand.
func (c *drawImageCommand) Exec(indexOffsetInBytes int) error { func (c *drawImageCommand) Exec(indexOffset int) error {
// TODO: Is it ok not to bind any framebuffer here? // TODO: Is it ok not to bind any framebuffer here?
if c.nindices == 0 { if c.nindices == 0 {
return nil return nil
@ -236,7 +236,7 @@ func (c *drawImageCommand) Exec(indexOffsetInBytes int) error {
if err := driver().UseProgram(c.mode, c.color, c.filter); err != nil { if err := driver().UseProgram(c.mode, c.color, c.filter); err != nil {
return err return err
} }
driver().DrawElements(c.nindices, indexOffsetInBytes) driver().DrawElements(c.nindices, indexOffset)
return nil return nil
} }
@ -292,7 +292,7 @@ func (c *replacePixelsCommand) String() string {
} }
// Exec executes the replacePixelsCommand. // Exec executes the replacePixelsCommand.
func (c *replacePixelsCommand) Exec(indexOffsetInBytes int) error { func (c *replacePixelsCommand) Exec(indexOffset int) error {
c.dst.image.ReplacePixels(c.pixels, c.x, c.y, c.width, c.height) c.dst.image.ReplacePixels(c.pixels, c.x, c.y, c.width, c.height)
return nil return nil
} }
@ -321,7 +321,7 @@ type pixelsCommand struct {
} }
// Exec executes a pixelsCommand. // Exec executes a pixelsCommand.
func (c *pixelsCommand) Exec(indexOffsetInBytes int) error { func (c *pixelsCommand) Exec(indexOffset int) error {
p, err := c.img.image.Pixels() p, err := c.img.image.Pixels()
if err != nil { if err != nil {
return err return err
@ -362,7 +362,7 @@ func (c *disposeCommand) String() string {
} }
// Exec executes the disposeCommand. // Exec executes the disposeCommand.
func (c *disposeCommand) Exec(indexOffsetInBytes int) error { func (c *disposeCommand) Exec(indexOffset int) error {
c.target.image.Delete() c.target.image.Delete()
return nil return nil
} }
@ -397,7 +397,7 @@ func (c *newImageCommand) String() string {
} }
// Exec executes a newImageCommand. // Exec executes a newImageCommand.
func (c *newImageCommand) Exec(indexOffsetInBytes int) error { func (c *newImageCommand) Exec(indexOffset int) error {
i, err := driver().NewImage(c.width, c.height) i, err := driver().NewImage(c.width, c.height)
if err != nil { if err != nil {
return err return err
@ -436,7 +436,7 @@ func (c *newScreenFramebufferImageCommand) String() string {
} }
// Exec executes a newScreenFramebufferImageCommand. // Exec executes a newScreenFramebufferImageCommand.
func (c *newScreenFramebufferImageCommand) Exec(indexOffsetInBytes int) error { func (c *newScreenFramebufferImageCommand) Exec(indexOffset int) error {
c.result.image = driver().NewScreenFramebufferImage(c.width, c.height) c.result.image = driver().NewScreenFramebufferImage(c.width, c.height)
return nil return nil
} }

View File

@ -21,7 +21,7 @@ import (
type GraphicsDriver interface { type GraphicsDriver interface {
BufferSubData(vertices []float32, indices []uint16) BufferSubData(vertices []float32, indices []uint16)
DrawElements(len int, offsetInBytes int) DrawElements(indexLen int, indexOffset int)
Flush() Flush()
MaxImageSize() int MaxImageSize() int
NewImage(width, height int) (Image, error) NewImage(width, height int) (Image, error)

View File

@ -95,8 +95,8 @@ func (d *Driver) UseProgram(mode graphics.CompositeMode, colorM *affine.ColorM,
return d.useProgram(mode, colorM, filter) return d.useProgram(mode, colorM, filter)
} }
func (d *Driver) DrawElements(len int, offsetInBytes int) { func (d *Driver) DrawElements(len int, offset int) {
d.context.drawElements(len, offsetInBytes) d.context.drawElements(len, offset*2) // 2 is uint16 size in bytes
// glFlush() might be necessary at least on MacBook Pro (a smilar problem at #419), // glFlush() might be necessary at least on MacBook Pro (a smilar problem at #419),
// but basically this pass the tests (esp. TestImageTooManyFill). // but basically this pass the tests (esp. TestImageTooManyFill).
// As glFlush() causes performance problems, this should be avoided as much as possible. // As glFlush() causes performance problems, this should be avoided as much as possible.