diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 840381f44..7fd0e0696 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -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) diff --git a/internal/graphicscommand/image.go b/internal/graphicscommand/image.go index e7d5f9482..94f29e3c1 100644 --- a/internal/graphicscommand/image.go +++ b/internal/graphicscommand/image.go @@ -37,11 +37,13 @@ const ( // Image represents an image that is implemented with OpenGL. type Image struct { - image driver.Image - width int - height int - screen bool - id int + image driver.Image + width int + height int + internalWidth int + internalHeight int + screen bool + id int lastCommand lastCommand } @@ -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.