graphicscommand: Reduce calling InternalWidth/InternalHeight

This commit is contained in:
Hajime Hoshi 2019-09-28 23:03:11 +09:00
parent 74f1e5519f
commit f873b66267
2 changed files with 16 additions and 7 deletions

View File

@ -158,7 +158,8 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst, src *Image, vertices []f
}
n := len(vertices) / graphics.VertexFloatNum
q.appendVertices(vertices, float32(graphics.InternalImageSize(src.width)), float32(graphics.InternalImageSize(src.height)))
iw, ih := src.InternalSize()
q.appendVertices(vertices, float32(iw), float32(ih))
q.appendIndices(indices, uint16(q.nextIndex))
q.nextIndex += n
q.tmpNumIndices += len(indices)

View File

@ -40,6 +40,8 @@ type Image struct {
image driver.Image
width int
height int
internalWidth int
internalHeight int
screen bool
id int
@ -96,7 +98,13 @@ func (i *Image) Dispose() {
}
func (i *Image) InternalSize() (int, int) {
return graphics.InternalImageSize(i.width), graphics.InternalImageSize(i.height)
if i.internalWidth == 0 {
i.internalWidth = graphics.InternalImageSize(i.width)
}
if i.internalHeight == 0 {
i.internalHeight = graphics.InternalImageSize(i.height)
}
return i.internalWidth, i.internalHeight
}
// DrawTriangles draws triangles with the given image.