Sped up rendering significantly

This commit is contained in:
Sasha Koshka 2023-03-06 21:34:14 -05:00
parent 11402cfc25
commit c171273240
2 changed files with 31 additions and 11 deletions

View File

@ -20,17 +20,30 @@ func (pattern Texture) Draw (destination canvas.Canvas, clip image.Rectangle) {
srcData, srcStride := pattern.Buffer()
srcBounds := pattern.Bounds()
point := image.Point { }
for point.Y = bounds.Min.Y; point.Y < bounds.Max.Y; point.Y ++ {
for point.X = bounds.Min.X; point.X < bounds.Max.X; point.X ++ {
srcPoint := point.Sub(realBounds.Min).Add(srcBounds.Min)
dstIndex := point.X + point.Y * dstStride
srcIndex :=
wrap(srcPoint.X, srcBounds.Min.X, srcBounds.Max.X) +
wrap(srcPoint.Y, srcBounds.Min.Y, srcBounds.Max.Y) * srcStride
dstData[dstIndex] = srcData[srcIndex]
}}
dstPoint := image.Point { }
srcPoint := bounds.Min.Sub(realBounds.Min).Add(srcBounds.Min)
srcPoint.X = wrap(srcPoint.X, srcBounds.Min.X, srcBounds.Max.X)
srcPoint.Y = wrap(srcPoint.Y, srcBounds.Min.Y, srcBounds.Max.Y)
for dstPoint.Y = bounds.Min.Y; dstPoint.Y < bounds.Max.Y; dstPoint.Y ++ {
for dstPoint.X = bounds.Min.X; dstPoint.X < bounds.Max.X; dstPoint.X ++ {
dstIndex := dstPoint.X + dstPoint.Y * dstStride
srcIndex :=
srcPoint.X +
srcPoint.Y * srcStride
dstData[dstIndex] = srcData[srcIndex]
srcPoint.X ++
if srcPoint.X >= srcBounds.Max.X {
srcPoint.X = srcBounds.Min.X
}
}
srcPoint.Y ++
if srcPoint.Y >= srcBounds.Max.Y {
srcPoint.Y = srcBounds.Min.Y
}
}
}
func wrap (value, min, max int) int {

View File

@ -3,6 +3,8 @@ package main
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/x"
import _ "net/http/pprof"
import "net/http"
func main () {
tomo.Run(run)
@ -26,4 +28,9 @@ func run () {
window.Adopt(button)
window.OnClose(tomo.Stop)
window.Show()
// just some stuff for profiling, this is not needed for tomo
go func () {
http.ListenAndServe("localhost:9090", nil)
} ()
}