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 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.appendIndices(indices, uint16(q.nextIndex))
q.nextIndex += n q.nextIndex += n
q.tmpNumIndices += len(indices) q.tmpNumIndices += len(indices)

View File

@ -37,11 +37,13 @@ const (
// Image represents an image that is implemented with OpenGL. // Image represents an image that is implemented with OpenGL.
type Image struct { type Image struct {
image driver.Image image driver.Image
width int width int
height int height int
screen bool internalWidth int
id int internalHeight int
screen bool
id int
lastCommand lastCommand lastCommand lastCommand
} }
@ -96,7 +98,13 @@ func (i *Image) Dispose() {
} }
func (i *Image) InternalSize() (int, int) { 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. // DrawTriangles draws triangles with the given image.